Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HYC-1998 - Trigger permission prompt for added embargos #1134

Merged
merged 3 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ def available_admin_sets
Hyrax::AdminSetSelectionPresenter.new(admin_sets: admin_sets)
end

private
# [hyc-override] Capture whether the work had an embargo before changes are saved
alias_method :original_save_permissions, :save_permissions
def save_permissions
original_save_permissions
@original_embargo_state = curation_concern.under_embargo?
end

# [hyc-override] Return true if the permissions have changed or the embargo state has changed
alias_method :original_permissions_changed?, :permissions_changed?
def permissions_changed?
original_permissions_changed? || @original_embargo_state != curation_concern.under_embargo?
end

# [hyc-override] Special permissions for admins indicating they aren't constrained by the admin set
class AdminPermissionTemplate < Hyrax::PermissionTemplate
def release_no_delay?
Expand Down
52 changes: 49 additions & 3 deletions spec/controllers/concerns/hyrax/works_controller_behavior_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
self.curation_concern_type = General
end

before do
ActiveFedora::Cleaner.clean!
Blacklight.default_index.connection.delete_by_query('*:*')
Blacklight.default_index.connection.commit
end

describe '#available_admin_sets' do
context 'with a logged in user' do
before { sign_in user }
Expand All @@ -26,9 +32,6 @@
let(:workflow) { Sipity::Workflow.find_by!(name: 'default', permission_template: permission_template) }

before do
ActiveFedora::Cleaner.clean!
Blacklight.default_index.connection.delete_by_query('*:*')
Blacklight.default_index.connection.commit
Hyrax::PermissionTemplateAccess.create(permission_template: permission_template,
agent_type: 'user',
agent_id: user.user_key,
Expand Down Expand Up @@ -61,4 +64,47 @@
end
end
end

describe '#permissions_changed?' do
let(:user) { FactoryBot.create(:user) }
let(:work) {
General.new(title: ['test work'])
}

context 'with no new permissions or embargo' do
it 'returns false' do
allow(work).to receive(:under_embargo?).and_return(false)
controller.instance_variable_set(:@curation_concern, work)

controller.send(:save_permissions)

expect(controller.send(:permissions_changed?)).to be false
end
end

context 'with an embargo added' do
it 'returns true' do
allow(work).to receive(:under_embargo?).and_return(false)
controller.instance_variable_set(:@curation_concern, work)

controller.send(:save_permissions)

allow(work).to receive(:under_embargo?).and_return(true)

expect(controller.send(:permissions_changed?)).to be true
end
end

context 'with new permissions but no new embargo' do
it 'returns true' do
allow(work).to receive(:under_embargo?).and_return(false)
allow(controller).to receive(:original_permissions_changed?).and_return(true)
controller.instance_variable_set(:@curation_concern, work)

controller.send(:save_permissions)

expect(controller.send(:permissions_changed?)).to be true
end
end
end
end
Loading