-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1052 from UNC-Libraries/hyc-1818-share
HYC-1818 - Fix share with user error
- Loading branch information
Showing
3 changed files
with
107 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# frozen_string_literal: true | ||
require 'rails_helper' | ||
|
||
require Rails.root.join('app/overrides/actors/hyrax/actors/base_actor_override.rb') | ||
|
||
RSpec.describe Hyrax::Actors::BaseActor do | ||
before do | ||
ActiveFedora::Cleaner.clean! | ||
Blacklight.default_index.connection.delete_by_query('*:*') | ||
Blacklight.default_index.connection.commit | ||
allow(Hyrax::VirusCheckerService).to receive(:file_has_virus?).and_return(false) | ||
Sipity::WorkflowState.create(workflow_id: workflow.id, name: 'deposited') | ||
end | ||
|
||
let(:depositor) { FactoryBot.create(:user) } | ||
let(:admin_set) { AdminSet.create(title: ['an admin set']) } | ||
|
||
let(:permission_template) do | ||
Hyrax::PermissionTemplate.create!(source_id: admin_set.id) | ||
end | ||
|
||
let(:workflow) do | ||
Sipity::Workflow.create(name: 'test', allows_access_grant: true, active: true, | ||
permission_template_id: permission_template.id) | ||
end | ||
|
||
describe '#update' do | ||
context 'update work with non-admin non-depositor view permission' do | ||
let!(:basic_user) { FactoryBot.create(:user) } | ||
let(:ability) { ::Ability.new(depositor) } | ||
|
||
let(:work) { | ||
General.create(title: ['work for sharing'], | ||
depositor: depositor.email, | ||
admin_set_id: admin_set.id) | ||
} | ||
let(:file_set1) { FactoryBot.create(:file_set) } | ||
|
||
let!(:entity) { Sipity::Entity.create(proxy_for_global_id: work.to_global_id.to_s, workflow_id: workflow.id) } | ||
|
||
let(:terminator) { Hyrax::Actors::Terminator.new } | ||
|
||
subject(:middleware) do | ||
stack = ActionDispatch::MiddlewareStack.new.tap do |middleware| | ||
middleware.use Hyrax::Actors::CreateWithFilesActor | ||
middleware.use Hyrax::Actors::AddToWorkActor | ||
middleware.use Hyrax::Actors::InterpretVisibilityActor | ||
middleware.use Hyrax::Actors::GeneralActor | ||
end | ||
stack.build(terminator) | ||
end | ||
|
||
let(:attributes) { | ||
{ | ||
permissions_attributes: { | ||
"0": { | ||
type: 'person', | ||
name: basic_user.email, | ||
access: 'read' | ||
} | ||
} | ||
} | ||
} | ||
|
||
before do | ||
allow(terminator).to receive(:update).and_return(true) | ||
work.ordered_members << file_set1 | ||
end | ||
|
||
it 'adds the user permission to the work' do | ||
env = Hyrax::Actors::Environment.new(work, ability, attributes) | ||
middleware.update(env) | ||
|
||
user_perm = work.permissions.to_a.find { |perm| perm.agent.first.id == "http://projecthydra.org/ns/auth/person##{basic_user.uid}" } | ||
expect(user_perm.mode.first.id).to eq 'http://www.w3.org/ns/auth/acl#Read' | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,8 +13,8 @@ | |
end | ||
|
||
let(:depositor) { | ||
User.create(email: 'test@example.com', | ||
uid: '[email protected]', | ||
User.create(email: 'test_depositor@example.com', | ||
uid: 'test_depositor', | ||
password: 'password', | ||
password_confirmation: 'password') | ||
} | ||
|
@@ -65,17 +65,18 @@ | |
permissions_attributes: { | ||
"0": { | ||
type: 'person', | ||
name: 'test@example.com', | ||
name: 'test_depositor@example.com', | ||
access: 'edit' | ||
} | ||
} | ||
} | ||
} | ||
|
||
it 'assigns user agent permissions' do | ||
expect(Hyrax::Workflow::PermissionGenerator).to receive(:call) | ||
|
||
subject.update(env) | ||
|
||
approver_perm = curation_concern.permissions.to_a.find { |perm| perm.agent.first.id == 'http://projecthydra.org/ns/auth/person#test_depositor' } | ||
expect(approver_perm.mode.first.id).to eq 'http://www.w3.org/ns/auth/acl#Write' | ||
end | ||
end | ||
|
||
|
@@ -93,8 +94,10 @@ | |
} | ||
|
||
it 'assigns group agent permissions' do | ||
expect_create_workflow_permissions_called(entity, 'viewing', workflow) | ||
subject.update(env) | ||
|
||
reader_perm = curation_concern.permissions.to_a.find { |perm| perm.agent.first.id == 'http://projecthydra.org/ns/auth/group#agroup' } | ||
expect(reader_perm.mode.first.id).to eq 'http://www.w3.org/ns/auth/acl#Read' | ||
end | ||
end | ||
|
||
|
@@ -109,6 +112,8 @@ | |
expect(Hyrax::Workflow::PermissionGenerator).not_to receive(:call) | ||
|
||
subject.update(env) | ||
|
||
expect(curation_concern.permissions.to_a).to be_empty | ||
end | ||
end | ||
|
||
|
@@ -120,17 +125,18 @@ | |
'0': { | ||
index: '0', | ||
type: 'person', | ||
name: 'test@example.com', | ||
name: 'test_depositor@example.com', | ||
access: 'edit' | ||
} | ||
} | ||
} | ||
} | ||
|
||
it 'assigns user agent permissions' do | ||
expect_create_workflow_permissions_called(entity, 'approving', workflow) | ||
|
||
subject.update(env) | ||
|
||
approver_perm = curation_concern.permissions.to_a.find { |perm| perm.agent.first.id == 'http://projecthydra.org/ns/auth/person#test_depositor' } | ||
expect(approver_perm.mode.first.id).to eq 'http://www.w3.org/ns/auth/acl#Write' | ||
end | ||
end | ||
|
||
|
@@ -143,8 +149,6 @@ | |
} | ||
|
||
it 'saves person details to work' do | ||
expect(Hyrax::Workflow::PermissionGenerator).not_to receive(:call) | ||
|
||
subject.update(env) | ||
|
||
first_creator = curation_concern.creators.first | ||
|
@@ -171,8 +175,6 @@ | |
} | ||
|
||
it 'logs the id of the work containing the deleted person' do | ||
expect(Hyrax::Workflow::PermissionGenerator).not_to receive(:call) | ||
|
||
subject.update(env) | ||
|
||
File.open(ENV['DELETED_PEOPLE_FILE'], 'r') do |file| | ||
|
@@ -207,17 +209,18 @@ | |
permissions_attributes: { | ||
"0": { | ||
type: 'person', | ||
name: 'test@example.com', | ||
name: 'test_depositor@example.com', | ||
access: 'edit' | ||
} | ||
} | ||
} | ||
} | ||
|
||
it 'assigns user agent permissions' do | ||
expect_create_workflow_permissions_called(entity, 'approving', workflow) | ||
|
||
middleware.create(env) | ||
|
||
approver_perm = curation_concern.permissions.to_a.find { |perm| perm.agent.first.id == 'http://projecthydra.org/ns/auth/person#test_depositor' } | ||
expect(approver_perm.mode.first.id).to eq 'http://www.w3.org/ns/auth/acl#Write' | ||
end | ||
end | ||
end | ||
|