Skip to content

Commit

Permalink
Merge pull request #1952 from datadryad/ref-date-locale
Browse files Browse the repository at this point in the history
Fix date localization causing test to fail
  • Loading branch information
alinvetian authored Dec 17, 2024
2 parents bcdd8fd + 2f4d4c6 commit 00e160d
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 28 deletions.
22 changes: 1 addition & 21 deletions app/controllers/stash_engine/admin_dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
23 changes: 22 additions & 1 deletion app/controllers/stash_engine/admin_datasets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<h1><%= @desc %></h1>
<%= 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 %>

<p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
<button class="o-button__submit" aria-haspopup="dialog" aria-expanded="false" id="reference_button_<%= @identifier&.id %>"
style="width: auto; margin-left: 10px; white-space: nowrap">
Change delete reference date
Expand Down
4 changes: 2 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,6 @@
post 'admin_dashboard/:id', to: 'admin_dashboard#update', as: 'admin_dash_update'
get 'admin_search', to: 'admin_dashboard#new_search', as: 'new_admin_search'
match 'admin_search/:id', to: 'admin_dashboard#save_search', via: %i[put patch], as: 'save_admin_search'
get 'admin_dashboard/:id/edit_delete_reference_date', to: 'admin_dashboard#edit_delete_reference_date', as: 'admin_dash_edit_delete_reference_date'
post 'admin_dashboard/:id/update_delete_reference_date', to: 'admin_dashboard#update_delete_reference_date', as: 'admin_dash_update_delete_reference_date'

# saved_searches
# get 'account/saved_searches/:type', to: 'saved_searches#index'
Expand All @@ -326,6 +324,8 @@

# activity log
get 'ds_admin/:id/create_salesforce_case', to: 'admin_datasets#create_salesforce_case', as: 'create_salesforce_case'
get 'ds_admin/:id/edit_delete_reference_date', to: 'admin_datasets#edit_delete_reference_date', as: 'edit_delete_reference_date'
post 'ds_admin/:id/update_delete_reference_date', to: 'admin_datasets#update_delete_reference_date', as: 'update_delete_reference_date'
get 'ds_admin/:id/activity_log', to: 'admin_datasets#activity_log', as: 'activity_log'
get 'ds_admin/:id/edit/:field', to: 'admin_datasets#popup', as: 'ds_admin_popup'
post 'ds_admin/:id', to: 'admin_datasets#edit', as: 'ds_admin_edit'
Expand Down
4 changes: 2 additions & 2 deletions spec/features/stash_engine/curation_activity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@

expect(page).to have_text('Activity log for')
click_button 'Change delete reference date'
fill_in('[process_date][delete_calculation_date]', with: '01.08.2024')
fill_in('[process_date][delete_calculation_date]', with: Date.new(2024, 1, 8))
fill_in('[curation_activity][note]', with: 'Some Note')
click_button('Submit')

expect(page).to have_text('Changed deletion reference date to 2024-01-08.')
expect(page).to have_text('Changed deletion reference date to Jan 08, 2024.')
expect(page).to have_text('Some Note')
end

Expand Down

0 comments on commit 00e160d

Please sign in to comment.