Skip to content

Commit

Permalink
Assign group permissions to proquest files and add test to verify
Browse files Browse the repository at this point in the history
  • Loading branch information
bbpennel committed Nov 7, 2023
1 parent bc9fe8b commit 9b83acb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/services/tasks/proquest_ingest_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def process_package(package_path)
file_set = ingest_proquest_file(parent: resource,
resource: metadata.merge({ title: [f] }),
f: file_path)
file_set.update permissions_attributes: group_permissions
ordered_members << file_set if file_set
end
end
Expand All @@ -106,8 +107,7 @@ def process_package(package_path)

# Force visibility to private since it seems to be saving as public
fileset.visibility = Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE
fileset.permissions_attributes = group_permissions
fileset.save
fileset.update permissions_attributes: group_permissions

resource.ordered_members << fileset

Expand Down
30 changes: 30 additions & 0 deletions spec/services/tasks/proquest_ingest_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,22 @@
# most processing functionality is tested in process_all_packages
# this test is to make sure only selected packages are processed
describe '#process_packages' do
let(:manager) do
FactoryBot.create(:user, email: '[email protected]', guest: false, uid: 'manager')
end
let(:manager_agent) { Sipity::Agent.where(proxy_for_id: 'dissertation_manager', proxy_for_type: 'Hyrax::Group').first_or_create }

before do
Dissertation.delete_all

Hyrax::PermissionTemplateAccess.create(permission_template: permission_template,
agent_type: 'group',
agent_id: 'dissertation_manager',
access: 'manage')
Hyrax::Workflow::PermissionGenerator.call(roles: 'managing', workflow: workflow, agents: manager_agent)
manager_role = Role.where(name: 'dissertation_manager').first_or_create
manager_role.users << manager
manager_role.save
end

let(:filepath_array) { ['spec/fixtures/proquest/proquest-attach0.zip'] }
Expand All @@ -152,6 +166,22 @@
expect(package1['status']).to eq 'Complete'
expect(package1['status_timestamp']).to_not be_nil
expect(package1['error']).to be_nil

# Dissertation and both of its files should have the manager role assigned to it
dissertation = Dissertation.first
expect_to_have_manager_permission(dissertation)

diss_file_sets = dissertation.file_sets
expect(diss_file_sets.length).to eq 2
expect_to_have_manager_permission(diss_file_sets[0])
expect_to_have_manager_permission(diss_file_sets[1])
expect(diss_file_sets[1].visibility).to eq Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE
end

def expect_to_have_manager_permission(item)
perm = item.permissions.first
expect(perm.agent.first.id).to eq 'http://projecthydra.org/ns/auth/group#dissertation_manager'
expect(perm.mode.first.id).to eq 'http://www.w3.org/ns/auth/acl#Write'
end
end

Expand Down

0 comments on commit 9b83acb

Please sign in to comment.