From 2f4d4c61336464e663968db8075e5318f25cedd9 Mon Sep 17 00:00:00 2001 From: Audrey Hamelers Date: Tue, 17 Dec 2024 15:06:30 +0100 Subject: [PATCH] fixed date localization causing test to fail, moved controller methods --- .../admin_dashboard_controller.rb | 22 +----------------- .../stash_engine/admin_datasets_controller.rb | 23 ++++++++++++++++++- ...tifier_delete_reference_date_form.html.erb | 2 +- .../admin_datasets/activity_log.html.erb | 2 +- .../edit_delete_reference_date.js.erb | 0 .../update_delete_reference_date.js.erb | 0 config/routes.rb | 4 ++-- .../stash_engine/curation_activity_spec.rb | 4 ++-- 8 files changed, 29 insertions(+), 28 deletions(-) rename app/views/stash_engine/{admin_dashboard => admin_datasets}/_identifier_delete_reference_date_form.html.erb (91%) rename app/views/stash_engine/{admin_dashboard => admin_datasets}/edit_delete_reference_date.js.erb (100%) rename app/views/stash_engine/{admin_dashboard => admin_datasets}/update_delete_reference_date.js.erb (100%) diff --git a/app/controllers/stash_engine/admin_dashboard_controller.rb b/app/controllers/stash_engine/admin_dashboard_controller.rb index 44f1e5292..bf9a9ad47 100644 --- a/app/controllers/stash_engine/admin_dashboard_controller.rb +++ b/app/controllers/stash_engine/admin_dashboard_controller.rb @@ -9,7 +9,7 @@ class AdminDashboardController < ApplicationController before_action :setup_paging, only: %i[results] before_action :setup_limits, only: %i[index results] before_action :setup_search, only: %i[index results] - before_action :load, only: %i[edit update edit_delete_reference_date update_delete_reference_date] + before_action :load, only: %i[edit update] def index; end @@ -83,26 +83,6 @@ def update respond_to(&:js) end - def edit_delete_reference_date - @desc = 'Edit dataset deletion date reference' - @process_date = @identifier.process_date - respond_to(&:js) - end - - def update_delete_reference_date - delete_calculation_date = params.dig(:process_date, :delete_calculation_date) - return error_response('Date can not be blank') if delete_calculation_date.blank? - - params[:curation_activity][:note] = - "Changed deletion reference date to #{delete_calculation_date}. #{params[:curation_activity][:note]}".html_safe - curation_activity_change - - @identifier.process_date.update(delete_calculation_date: delete_calculation_date) - @resource.process_date.update(delete_calculation_date: delete_calculation_date) - @curation_activity = @resource.last_curation_activity - respond_to(&:js) - end - private def collect_properties diff --git a/app/controllers/stash_engine/admin_datasets_controller.rb b/app/controllers/stash_engine/admin_datasets_controller.rb index 5e2e0fc86..9a63cf0bc 100644 --- a/app/controllers/stash_engine/admin_datasets_controller.rb +++ b/app/controllers/stash_engine/admin_datasets_controller.rb @@ -4,7 +4,7 @@ module StashEngine class AdminDatasetsController < ApplicationController helper SortableTableHelper before_action :require_user_login - before_action :load, only: %i[popup note_popup edit] + before_action :load, only: %i[popup note_popup edit edit_delete_reference_date update_delete_reference_date] def popup case @field @@ -47,6 +47,27 @@ def activity_log redirect_to admin_path, notice: "Identifier ID #{params[:id]} no longer exists." end + def edit_delete_reference_date + @desc = 'Edit dataset deletion date reference' + @process_date = @identifier.process_date + respond_to(&:js) + end + + def update_delete_reference_date + delete_calculation_date = params.dig(:process_date, :delete_calculation_date) + return error_response('Date cannot be blank') if delete_calculation_date.blank? + + @curation_activity = CurationActivity.create( + note: "Changed deletion reference date to #{formatted_date(delete_calculation_date)}. #{params[:curation_activity][:note]}".html_safe, + resource_id: @resource.id, user_id: current_user.id + ) + @resource.reload + + @identifier.process_date.update(delete_calculation_date: delete_calculation_date) + @resource.process_date.update(delete_calculation_date: delete_calculation_date) + respond_to(&:js) + end + def create_salesforce_case authorize %i[stash_engine admin_datasets] # create the case diff --git a/app/views/stash_engine/admin_dashboard/_identifier_delete_reference_date_form.html.erb b/app/views/stash_engine/admin_datasets/_identifier_delete_reference_date_form.html.erb similarity index 91% rename from app/views/stash_engine/admin_dashboard/_identifier_delete_reference_date_form.html.erb rename to app/views/stash_engine/admin_datasets/_identifier_delete_reference_date_form.html.erb index 6339fe646..7efaa70a4 100644 --- a/app/views/stash_engine/admin_dashboard/_identifier_delete_reference_date_form.html.erb +++ b/app/views/stash_engine/admin_datasets/_identifier_delete_reference_date_form.html.erb @@ -1,5 +1,5 @@

<%= @desc %>

-<%= form_with(url: admin_dash_update_delete_reference_date_path(@identifier.id), method: :post, local: false) do |form| -%> +<%= form_with(url: update_delete_reference_date_path(@identifier.id), method: :post, local: false) do |form| -%> <%= hidden_field_tag :field, @field %>

diff --git a/app/views/stash_engine/admin_datasets/activity_log.html.erb b/app/views/stash_engine/admin_datasets/activity_log.html.erb index 7750344ff..10c3ba96a 100644 --- a/app/views/stash_engine/admin_datasets/activity_log.html.erb +++ b/app/views/stash_engine/admin_datasets/activity_log.html.erb @@ -10,7 +10,7 @@ <% end %> <% if policy([:stash_engine, :admin_datasets]).change_delete_schedule? %> - <%= form_with(url: admin_dash_edit_delete_reference_date_path(id: @identifier&.id, field: 'curation_activity'), method: :get, local: false) do %> + <%= form_with(url: edit_delete_reference_date_path(id: @identifier&.id, field: 'curation_activity'), method: :get, local: false) do %>