diff --git a/app/forms/hyrax/forms/permission_template_form.rb b/app/forms/hyrax/forms/permission_template_form.rb index c9d1a3f72b..bb41c2245a 100644 --- a/app/forms/hyrax/forms/permission_template_form.rb +++ b/app/forms/hyrax/forms/permission_template_form.rb @@ -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 diff --git a/spec/controllers/hyrax/admin/permission_templates_controller_spec.rb b/spec/controllers/hyrax/admin/permission_templates_controller_spec.rb index c8d70e181f..7001ff808c 100644 --- a/spec/controllers/hyrax/admin/permission_templates_controller_spec.rb +++ b/spec/controllers/hyrax/admin/permission_templates_controller_spec.rb @@ -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 diff --git a/spec/forms/hyrax/forms/permission_template_form_spec.rb b/spec/forms/hyrax/forms/permission_template_form_spec.rb index e77532882a..3c757a75e1 100644 --- a/spec/forms/hyrax/forms/permission_template_form_spec.rb +++ b/spec/forms/hyrax/forms/permission_template_form_spec.rb @@ -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: "bob@example.com") } + 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