Skip to content

Commit

Permalink
Apply permission template doesn't overwrite user shares
Browse files Browse the repository at this point in the history
Fixes #3130
  • Loading branch information
jcoyne committed Mar 5, 2017
1 parent 50b47ec commit ab374fe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
8 changes: 4 additions & 4 deletions app/actors/sufia/apply_permission_template_actor.rb
Expand Up @@ -10,10 +10,10 @@ def create(attributes)
def add_edit_users(attributes)
return unless attributes[:admin_set_id].present?
template = Sufia::PermissionTemplate.find_by!(admin_set_id: attributes[:admin_set_id])
curation_concern.edit_users = template.access_grants.where(agent_type: 'user', access: 'manage').pluck(:agent_id)
curation_concern.edit_groups = template.access_grants.where(agent_type: 'group', access: 'manage').pluck(:agent_id)
curation_concern.read_users = template.access_grants.where(agent_type: 'user', access: 'view').pluck(:agent_id)
curation_concern.read_groups = template.access_grants.where(agent_type: 'group', access: 'view').pluck(:agent_id)
curation_concern.edit_users += template.access_grants.where(agent_type: 'user', access: 'manage').pluck(:agent_id)
curation_concern.edit_groups += template.access_grants.where(agent_type: 'group', access: 'manage').pluck(:agent_id)
curation_concern.read_users += template.access_grants.where(agent_type: 'user', access: 'view').pluck(:agent_id)
curation_concern.read_groups += template.access_grants.where(agent_type: 'group', access: 'view').pluck(:agent_id)
end
end
end
10 changes: 7 additions & 3 deletions spec/actors/sufia/apply_permission_template_actor_spec.rb
Expand Up @@ -11,7 +11,11 @@
CurationConcerns::Actors::ActorStack.new(work, depositor, [described_class])
end
let(:depositor) { create(:user) }
let(:work) { build(:generic_work) }
let(:work) do
build(:generic_work,
edit_users: ['Kevin'],
read_users: ['Taraji'])
end
let(:attributes) { { admin_set_id: admin_set.id } }
let(:admin_set) { create(:admin_set) }
let(:permission_template) { create(:permission_template, admin_set_id: admin_set.id) }
Expand Down Expand Up @@ -54,9 +58,9 @@

it "adds the template users to the work" do
expect(actor.create(attributes)).to be true
expect(work.edit_users).to include 'hannah'
expect(work.edit_users).to include('hannah', 'Kevin')
expect(work.edit_groups).to include 'librarians'
expect(work.read_users).to include 'gary'
expect(work.read_users).to include('gary', 'Taraji')
expect(work.read_groups).to include 'readers'
end
end
Expand Down

0 comments on commit ab374fe

Please sign in to comment.