Skip to content

Commit

Permalink
Don't clear embargo dates while adding user to admin participants lis…
Browse files Browse the repository at this point in the history
…t. (#6163)

* Don't clear embargo dates while adding user to admin participants list.

* Add unique test for method #permission_template_update_params.
  • Loading branch information
lsitu authored Aug 23, 2023
1 parent 4720476 commit e6376d6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/forms/hyrax/forms/permission_template_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ def select_release_varies_option(permission_template)
# rubocop:disable Metrics/CyclomaticComplexity
# rubocop:disable Metrics/PerceivedComplexity
def permission_template_update_params
return attributes unless attributes.key?(:release_varies) || attributes.key?(:release_embargo)

filtered_attributes = attributes.except(:release_varies, :release_embargo)
# If 'varies' before date option selected, then set release_period='before' and save release_date as-is
if attributes[:release_varies] == Hyrax::PermissionTemplate::RELEASE_TEXT_VALUE_BEFORE_DATE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,24 @@
expect(response).to redirect_to(hyrax.edit_dashboard_collection_path(permission_template.source_id, locale: 'en', anchor: 'sharing'))
expect(flash[:notice]).to eq(I18n.t('sharing', scope: 'hyrax.dashboard.collections.form.permission_update_notices'))
end

context "with embargo date" do
let(:release_date) { '2023-09-30' }

before do
permission_template.update(release_date: release_date)
end

it "is successful with embargo date intact" do
expect(controller).to receive(:authorize!).with(:update, Hyrax::PermissionTemplate)
expect(form).to receive(:update).with(ActionController::Parameters.new(form_attributes).permit!).and_return(updated: true, content_tab: 'sharing')
put :update, params: input_params
expect(response).to redirect_to(hyrax.edit_dashboard_collection_path(permission_template.source_id, locale: 'en', anchor: 'sharing'))

updated = Hyrax::PermissionTemplate.find_by(id: permission_template.id)
expect(updated.release_date.strftime('%Y-%m-%d')).to eq(release_date)
end
end
end
end
end
17 changes: 17 additions & 0 deletions spec/forms/hyrax/forms/permission_template_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -598,5 +598,22 @@ def count_workflow_roles_for(user)
).permit!
end
end

context "update params for workflow role with no :release_varies and :release_embargo keys" do
let(:user_bob) { FactoryBot.create(:user, email: "[email protected]") }
let(:input_params) do
ActionController::Parameters.new(agent_type: "user",
agent_id: user_bob.user_key,
access: "view").permit!
end

it "should not change" do
expect(subject).to eq ActionController::Parameters.new(
agent_type: "user",
agent_id: user_bob.user_key,
access: "view"
).permit!
end
end
end
end

0 comments on commit e6376d6

Please sign in to comment.