Skip to content

Commit

Permalink
🐛 Depositor role cannot deposit into admin set fix
Browse files Browse the repository at this point in the history
We implemented a fix for this bug in PALS and are contributing it back to Hyku.

Issue:
- notch8/palni-palci#864
  • Loading branch information
Shana Moore committed Oct 23, 2023
1 parent 94c8f0e commit 37a133c
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
17 changes: 16 additions & 1 deletion app/models/concerns/hyrax/ability/work_ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,24 @@ def work_roles
doc = permissions_doc(id)
all_work_types_and_files.include?(doc.hydra_model)
end
elsif work_depositor?
elsif work_depositor? || admin_set_with_deposit?
can %i[create], all_work_types_and_files
end

# OVERRIDE HYRAX 3.5.0 to return false if no ids are found
# @return [Boolean] true if the user has at least one admin set they can deposit into.
def admin_set_with_deposit?
ids = PermissionTemplateAccess.for_user(ability: self,
access: ['deposit', 'manage'])
.joins(:permission_template)
.select(:source_id)
.distinct
.pluck(:source_id)

return false if ids.empty?

Hyrax.custom_queries.find_ids_by_model(model: Hyrax::AdministrativeSet, ids: ids).any?
end
end
end
end
Expand Down
50 changes: 50 additions & 0 deletions spec/features/create_work_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,54 @@
click_link "Share Your Work"
expect(page).to have_button "Create work"
end

context 'as a user with no roles' do
let(:user) { create(:user) }

it 'cannot see the add new work button' do
visit '/dashboard/my/works'
expect(page).not_to have_link "Add New Work"
end

context 'who has deposit access for a specific admin set' do
let(:admin_set_2) do
create(:admin_set, title: ["Another Admin Set"],
description: ["A description"])
end

before do
create(:permission_template_access,
:deposit,
permission_template: create(:permission_template, source_id: admin_set_2.id, with_admin_set: true, with_active_workflow: true),
agent_type: 'user',
agent_id: user.user_key)
end

it 'can see the add new work button' do
visit '/dashboard/my/works'
expect(page).to have_link "Add New Work"
end
end

context 'who belongs to a group with deposit access for a specific admin set' do
let(:admin_set_3) do
create(:admin_set, title: ["Yet Another Admin Set"],
description: ["A description"])
end
let(:depositors_group) { create(:depositors_group, name: 'deposit', member_users: [user]) }

before do
create(:permission_template_access,
:deposit,
permission_template: create(:permission_template, source_id: admin_set_3.id, with_admin_set: true, with_active_workflow: true),
agent_type: 'group',
agent_id: depositors_group.name)
end

it 'can see the add new work button' do
visit '/dashboard/my/works'
expect(page).to have_link "Add New Work"
end
end
end
end

0 comments on commit 37a133c

Please sign in to comment.