Skip to content

Commit b3eeac8

Browse files
Merge pull request #1767 from psu-libraries/1766-libanswer-ticket-change
1766 libanswer ticket change
2 parents 971eec0 + 90ae5cf commit b3eeac8

File tree

7 files changed

+116
-37
lines changed

7 files changed

+116
-37
lines changed

app/models/actor.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,17 @@ def update_index(_options = {})
9595
Collection.reindex_all(relation: created_collections)
9696
end
9797

98+
# Whether an actor/depositor is still an active part of the PSU community
99+
# Staff, students, etc. will have their affiliation listed in the PsuIdentity.affiliation array
100+
# But those with only "MEMBER" are those that are not PSU affiliated.
101+
# This could be incoming students, outgoing staff, people with those "Friends of Penn State" accounts
102+
def active?
103+
identity = PsuIdentity::SearchService::Client.new.userid(psu_id)
104+
identity.affiliation != ['MEMBER']
105+
rescue PsuIdentity::SearchService::NotFound
106+
false
107+
end
108+
98109
# Fields that contain single values automatically remove blank values
99110
%i[
100111
surname

app/services/libanswers_api_service.rb

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ class LibanswersApiError < StandardError; end
99

1010
def admin_create_ticket(id, type = 'work_curation', base_url = '')
1111
depositor = get_depositor(id, type)
12-
raise LibanswersApiError, I18n.t('resources.contact_depositor_button.error_message') unless depositor_active?(depositor)
12+
if type != 'work_accessibility' && !depositor.active?
13+
raise LibanswersApiError, I18n.t('resources.contact_depositor_button.error_message')
14+
end
1315

1416
admin_subject = get_admin_subject(id, type)
1517
ticket_details = get_ticket_details(id, type, admin_subject, base_url)
@@ -42,14 +44,6 @@ def get_depositor(id, type)
4244
deposit.depositor
4345
end
4446

45-
def depositor_active?(depositor)
46-
access_id = depositor.psu_id
47-
identity = PsuIdentity::SearchService::Client.new.userid(access_id)
48-
identity.affiliation != ['MEMBER']
49-
rescue PsuIdentity::SearchService::NotFound
50-
false
51-
end
52-
5347
def get_admin_subject(id, type)
5448
case type
5549
when 'collection'
@@ -132,12 +126,4 @@ def oauth_token_path
132126
def host
133127
'https://psu.libanswers.com'
134128
end
135-
136-
def user_active?(work)
137-
access_id = work.depositor.psu_id
138-
identity = PsuIdentity::SearchService::Client.new.userid(access_id)
139-
identity.affiliation != ['MEMBER']
140-
rescue PsuIdentity::SearchService::NotFound
141-
false
142-
end
143129
end

app/views/dashboard/works/edit.html.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@
5757
<h1 class="h2 mb-2"><%= t('.heading', work_title: @work.latest_version.title) %></h1>
5858
<% if current_user.admin? %>
5959
<div class="row no-gutters">
60+
<% unless @work.depositor.active? %>
61+
<p><%= I18n.t('resources.contact_depositor_button.warning') %></p>
62+
<% end %>
6063
<%= button_to I18n.t('resources.contact_depositor_button.text'),
6164
admin_create_curation_ticket_url(id: @work.id, ticket_type: 'curation'),
6265
class: 'btn btn-primary mr-2 mb-2',

config/locales/en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,7 @@ en:
745745
text: 'Contact Depositor via LibAnswers >>'
746746
confirm_message: 'This will create a ticket in LibAnswers and direct you to it. An email will not be sent to the depositor until the form is completed in LibAnswers.'
747747
error_message: 'Depositor access no longer active'
748+
warning: 'This work no longer has an active depositor. The depositor will not respond to any request for curation.'
748749
contact_accessibility_team_button:
749750
text: 'Contact Accessibility Team via LibAnswers >>'
750751
confirm_message: 'This will create a ticket in LibAnswers and direct you to it. An email will not be sent to the accessibility team until the form is completed in LibAnswers.'

spec/features/dashboard/work_settings_spec.rb

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,13 @@
452452
end
453453

454454
describe 'Contact depositor button' do
455+
let(:active_member) { object_double(PsuIdentity::SearchService::Person.new, affiliation: ['FACULTY', 'MEMBER']) }
456+
let(:inactive_member) { object_double(PsuIdentity::SearchService::Person.new, affiliation: ['MEMBER']) }
457+
let(:mock_identity_search) { instance_spy('PsuIdentity::SearchService::Client') }
458+
455459
before do
460+
allow(PsuIdentity::SearchService::Client).to receive(:new).and_return(mock_identity_search)
461+
allow(mock_identity_search).to receive(:userid).and_return(active_member)
456462
visit edit_dashboard_work_path(work)
457463
end
458464

@@ -490,12 +496,27 @@
490496
end
491497

492498
describe 'clicking the accessibility team depositor button' do
493-
context 'when there is no error' do
494-
it 'directs to that ticket in libanswers', :vcr do
495-
click_button I18n.t('resources.contact_accessibility_team_button.text')
496-
rescue ActionController::RoutingError
497-
expect(page.driver.browser.last_response['Location']).to eq 'https://psu.libanswers.com/admin/ticket?qid=14782516'
498-
end
499+
it 'directs to that ticket in libanswers', :vcr do
500+
click_button I18n.t('resources.contact_accessibility_team_button.text')
501+
rescue ActionController::RoutingError
502+
expect(page.driver.browser.last_response['Location']).to eq 'https://psu.libanswers.com/admin/ticket?qid=14782516'
503+
end
504+
end
505+
506+
describe 'when the depositor is active' do
507+
it 'does not display the inactive warning' do
508+
expect(page).to have_no_content(I18n.t('resources.contact_depositor_button.warning'))
509+
end
510+
end
511+
512+
describe 'when the depositor is no longer active' do
513+
before do
514+
allow(mock_identity_search).to receive(:userid).and_return(inactive_member)
515+
visit edit_dashboard_work_path(work)
516+
end
517+
518+
it 'displays an inactive warning to the admin' do
519+
expect(page).to have_content(I18n.t('resources.contact_depositor_button.warning'))
499520
end
500521
end
501522
end

spec/models/actor_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,32 @@
126126
end
127127
end
128128

129+
describe '#active?' do
130+
let(:actor) { create(:actor) }
131+
let(:mock_identity_search) { instance_spy('PsuIdentity::SearchService::Client') }
132+
let!(:member_only_actor) { object_double(PsuIdentity::SearchService::Person.new, affiliation: ['MEMBER']) }
133+
let!(:active_actor) { object_double(PsuIdentity::SearchService::Person.new, affiliation: ['MEMBER', 'STUDENT']) }
134+
135+
before do
136+
allow(PsuIdentity::SearchService::Client).to receive(:new).and_return(mock_identity_search)
137+
end
138+
139+
it 'returns false if an error is thrown' do
140+
allow(mock_identity_search).to receive(:userid).and_raise(PsuIdentity::SearchService::NotFound)
141+
expect(actor.active?).to eq(false)
142+
end
143+
144+
it 'returns false if identity affiliation is only MEMBER' do
145+
allow(mock_identity_search).to receive(:userid).and_return(member_only_actor)
146+
expect(actor.active?).to eq(false)
147+
end
148+
149+
it 'returns true if identity affiliation is more than just member' do
150+
allow(mock_identity_search).to receive(:userid).and_return(active_actor)
151+
expect(actor.active?).to eq(true)
152+
end
153+
end
154+
129155
describe 'singlevalued fields' do
130156
it_behaves_like 'a singlevalued field', :surname
131157
it_behaves_like 'a singlevalued field', :given_name

spec/services/libanswers_api_service_spec.rb

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,6 @@
5252
allow(mock_faraday_connection).to receive(:post).and_return dummy_response
5353
end
5454

55-
context 'when the user is not an active member' do
56-
let!(:inactive_member) { object_double(PsuIdentity::SearchService::Person.new, affiliation: ['MEMBER']) }
57-
58-
before do
59-
allow(mock_identity_search).to receive(:userid).and_return(inactive_member)
60-
end
61-
62-
it 'raises an error' do
63-
expect { described_class.new.admin_create_ticket(work.id) }.to raise_error(
64-
LibanswersApiService::LibanswersApiError, I18n.t('resources.contact_depositor_button.error_message')
65-
)
66-
end
67-
end
68-
6955
context 'when the ticket is a Work Curation Ticket' do
7056
it 'uses id 5477 for quid and ScholarSphere Deposit Curation for question' do
7157
described_class.new.admin_create_ticket(work.id, 'work_curation')
@@ -75,6 +61,20 @@
7561
work.latest_version.title}&pname=#{work.display_name}&pemail=#{work.email}"
7662
)
7763
end
64+
65+
context 'when the user is not an active member' do
66+
let!(:inactive_member) { object_double(PsuIdentity::SearchService::Person.new, affiliation: ['MEMBER']) }
67+
68+
before do
69+
allow(mock_identity_search).to receive(:userid).and_return(inactive_member)
70+
end
71+
72+
it 'raises an error' do
73+
expect { described_class.new.admin_create_ticket(work.id, 'work_curation') }.to raise_error(
74+
LibanswersApiService::LibanswersApiError, I18n.t('resources.contact_depositor_button.error_message')
75+
)
76+
end
77+
end
7878
end
7979

8080
context 'when the ticket is a Collection Curation Ticket' do
@@ -86,6 +86,20 @@
8686
collection.metadata['title']}&pname=#{collection.depositor.display_name}&pemail=#{work.depositor.email}"
8787
)
8888
end
89+
90+
context 'when the user is not an active member' do
91+
let!(:inactive_member) { object_double(PsuIdentity::SearchService::Person.new, affiliation: ['MEMBER']) }
92+
93+
before do
94+
allow(mock_identity_search).to receive(:userid).and_return(inactive_member)
95+
end
96+
97+
it 'raises an error' do
98+
expect { described_class.new.admin_create_ticket(collection.id, 'collection') }.to raise_error(
99+
LibanswersApiService::LibanswersApiError, I18n.t('resources.contact_depositor_button.error_message')
100+
)
101+
end
102+
end
89103
end
90104

91105
context 'when the ticket is a Work Accessibility Ticket' do
@@ -100,6 +114,23 @@
100114
)
101115
end
102116

117+
context 'when the user is not an active member' do
118+
let!(:inactive_member) { object_double(PsuIdentity::SearchService::Person.new, affiliation: ['MEMBER']) }
119+
120+
before do
121+
allow(mock_identity_search).to receive(:userid).and_return(inactive_member)
122+
end
123+
124+
it 'creates a ticket' do
125+
described_class.new.admin_create_ticket(work.id, 'work_accessibility', base_url)
126+
expect(mock_faraday_connection).to have_received(:post).with(
127+
'/api/1.1/ticket/create',
128+
"quid=#{accessibility_quid}&pquestion=ScholarSphere Deposit Accessibility Curation: #{
129+
work.latest_version.title}&pname=#{work.display_name}&pemail=#{work.email}"
130+
)
131+
end
132+
end
133+
103134
context 'when accessibility report exists' do
104135
let!(:work_2) { create(:work, depositor: user.actor) }
105136
let(:file_resource) { create(:file_resource, :pdf) }

0 commit comments

Comments
 (0)