-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Valkyrizes jobs that revoke edit permissions
Allows jobs that revoke edit permissions from file set objects and from file sets that are members of a work to use Valkyrie. Refs #4102 Refs #4103
- Loading branch information
Showing
4 changed files
with
65 additions
and
23 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 |
---|---|---|
@@ -1,14 +1,21 @@ | ||
module Hyrax | ||
# Revokes the user's edit access on the provided FileSet | ||
class RevokeEditJob < ApplicationJob | ||
class RevokeEditJob < Hyrax::ApplicationJob | ||
queue_as Hyrax.config.ingest_queue_name | ||
|
||
# @param [String] file_set_id - the identifier of the object to revoke access from | ||
# @param [String] user_key - the user to remove | ||
def perform(file_set_id, user_key) | ||
file_set = ::FileSet.find(file_set_id) | ||
file_set.edit_users -= [user_key] | ||
file_set.save! | ||
def perform(file_set_id, user_key, use_valkyrie: Hyrax.config.use_valkyrie?) | ||
if use_valkyrie | ||
file_set_resource = Hyrax.query_service.find_by(id: file_set_id) | ||
acl = Hyrax::AccessControlList.new(resource: file_set_resource) | ||
acl.revoke(:edit).from(::User.find_by_user_key(user_key)) | ||
acl.save | ||
else | ||
file_set = ::FileSet.find(file_set_id) | ||
file_set.edit_users -= [user_key] | ||
file_set.save! | ||
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 |
---|---|---|
@@ -1,16 +1,33 @@ | ||
RSpec.describe Hyrax::RevokeEditFromMembersJob do | ||
let(:depositor) { create(:user) } | ||
let(:work) { build(:work) } | ||
let(:file_set_ids) { ['xyz123abc', 'abc789zyx'] } | ||
|
||
before do | ||
allow_any_instance_of(described_class).to receive(:file_set_ids).with(work).and_return(file_set_ids) | ||
|
||
context "when use_valkyrie is false" do | ||
let(:work) { build(:work) } | ||
let(:file_set_ids) { ['xyz123abc', 'abc789zyx'] } | ||
|
||
before do | ||
allow_any_instance_of(described_class).to receive(:file_set_ids).with(work).and_return(file_set_ids) | ||
end | ||
|
||
it 'loops over FileSet IDs, spawning a job for each' do | ||
file_set_ids.each do |file_set_id| | ||
expect(Hyrax::GrantReadJob).to receive(:perform_now).with(file_set_id, depositor.user_key, use_valkyre: false).once | ||
end | ||
described_class.perform_now(work, depositor.user_key, use_valkyrie: false) | ||
end | ||
end | ||
|
||
it 'loops over FileSet IDs, spawning a job for each' do | ||
file_set_ids.each do |file_set_id| | ||
expect(Hyrax::RevokeEditJob).to receive(:perform_now).with(file_set_id, depositor.user_key).once | ||
context "when use_valkyrie is true" do | ||
let(:file_set1) { valkyrie_create(:hyrax_file_set) } | ||
let(:file_set2) { valkyrie_create(:hyrax_file_set) } | ||
let(:work) { valkyrie_create(:hyrax_work, member_ids: [file_set1.id, file_set2.id]) } | ||
|
||
it 'loops over FileSet IDs, spawning a job for each' do | ||
work.member_ids.each do |file_set_id| | ||
expect(Hyrax::RevokeEditJob).to receive(:perform_now).with(file_set_id, depositor.user_key, use_valkyre: true).once | ||
end | ||
described_class.perform_now(work, depositor.user_key, use_valkyrie: true) | ||
end | ||
described_class.perform_now(work, depositor.user_key) | ||
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 |
---|---|---|
@@ -1,11 +1,23 @@ | ||
RSpec.describe Hyrax::RevokeEditJob do | ||
let(:depositor) { create(:user) } | ||
let(:file_set) { build(:file_set, user: depositor) } | ||
|
||
it 'revokes edit access from a FileSet' do | ||
expect(FileSet).to receive(:find).with(file_set.id).and_return(file_set) | ||
expect(file_set).to receive(:edit_users=).with([]) | ||
expect(file_set).to receive(:save!) | ||
described_class.perform_now(file_set.id, depositor.user_key) | ||
context 'when use_valkyire is false' do | ||
let(:file_set) { create(:file_set, user: depositor) } | ||
|
||
it "revokes a user's edit access to a FileSet" do | ||
described_class.perform_now(file_set.id, depositor.user_key, use_valkyrie: false) | ||
file_set.reload | ||
expect(file_set.edit_users).not_to include depositor.user_key | ||
end | ||
end | ||
|
||
context 'when use_valkyire is true' do | ||
let(:valk_file_set) { valkyrie_create(:hyrax_file_set) } | ||
|
||
it "revokes a user's edit access to a FileSet" do | ||
described_class.perform_now(valk_file_set.id.to_s, depositor.user_key, use_valkyrie: true) | ||
reloaded_file_set = Hyrax.query_service.find_by(id: valk_file_set.id) | ||
expect(reloaded_file_set.edit_users.to_a).not_to include depositor.user_key | ||
end | ||
end | ||
end |