Skip to content

Commit

Permalink
Merge pull request #1773 from datadryad/3379-abandoned-datasets----wi…
Browse files Browse the repository at this point in the history
…thdrawing

added withdrawn functionality and email notification, added final del…
  • Loading branch information
ryscher authored Oct 30, 2024
2 parents e70a5e0 + a5d41a2 commit 4fff5f0
Show file tree
Hide file tree
Showing 44 changed files with 1,533 additions and 150 deletions.
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ group :development, :v3_development, :local_dev, :local, :test do
gem 'pry'
gem 'pry-rails'
# Rails application preloader (https://github.com/rails/spring), says not to install in production
gem 'letter_opener'
gem 'letter_opener_web', '~> 3.0'
gem 'spring'
# rspec command for spring (https://github.com/jonleighton/spring-commands-rspec)
gem 'letter_opener'
gem 'letter_opener_web', '~> 3.0'
gem 'spring-commands-rspec'
end

Expand Down
29 changes: 28 additions & 1 deletion app/controllers/stash_engine/admin_dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,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]
before_action :load, only: %i[edit update edit_delete_reference_date update_delete_reference_date]

def index; end

Expand Down Expand Up @@ -82,6 +82,26 @@ 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 Expand Up @@ -411,5 +431,12 @@ def current_editor_change
end

end

def error_response(message)
@error_message = <<-HTML.chomp.html_safe
#{message}
HTML
render :curation_activity_error
end
# rubocop:enable Metrics/ClassLength
end
114 changes: 114 additions & 0 deletions app/mailers/stash_engine/resource_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
module StashEngine

# Mails users about submissions
class ResourceMailer < ApplicationMailer

def in_progress_delete_notification(resource)
logger.warn('Unable to send in_progress_delete_notification; nil resource') unless resource.present?
return unless resource.present?

assign_variables(resource)
return unless @user.present? && user_email(@user).present?

mail(to: user_email(@user),
subject: "#{rails_env}REMINDER: Dryad submission \"#{@resource.title}\"",
template_path: 'stash_engine/user_mailer',
template_name: 'in_progress_reminder')
end

def peer_review_delete_notification(resource)
logger.warn('Unable to send peer_review_delete_notification; nil resource') unless resource.present?
return unless resource.present?

assign_variables(resource)
return unless @user.present? && user_email(@user).present?

mail(to: user_email(@user),
subject: "#{rails_env}REMINDER: Dryad submission \"#{@resource.title}\"",
template_path: 'stash_engine/user_mailer',
template_name: 'peer_review_reminder')
end

def action_required_delete_notification(resource)
logger.warn('Unable to send action_required_delete_notification; nil resource') unless resource.present?
return unless resource.present?

assign_variables(resource)
return unless @user.present? && user_email(@user).present?

mail(to: user_email(@user),
subject: "#{rails_env}REMINDER: Dryad submission \"#{@resource.title}\"",
template_path: 'stash_engine/user_mailer',
template_name: 'chase_action_required1')
end

def send_set_to_withdrawn_notification(resource)
logger.warn('Unable to send set_to_withdrawn_notification; nil resource') unless resource.present?
return unless resource.present?

assign_variables(resource)
return unless @user.present? && user_email(@user).present?

mail(to: user_email(@user),
subject: "#{rails_env}NOTIFICATION: Dryad submission set to withdrawn \"#{@resource.title}\"")
end

def send_final_withdrawn_notification(resource)
logger.warn('Unable to send send_final_withdrawn_notification; nil resource') unless resource.present?
return unless resource.present?

assign_variables(resource)
return unless @user.present? && user_email(@user).present?

mail(to: user_email(@user),
subject: "#{rails_env}FINAL NOTIFICATION: Dryad submission will be deleted \"#{@resource.title}\"")
end

def delete_notification(resource)
logger.warn('Unable to send delete_notification; nil resource') unless resource.present?
return unless resource.present?

assign_variables(resource)
return unless @user.present? && user_email(@user).present?

mail(to: user_email(@user),
subject: "#{rails_env}DELETE NOTIFICATION: Dryad submission was deleted \"#{@resource.title}\"")
end

private

# rubocop:disable Style/NestedTernaryOperator
def user_email(user)
user.present? ? (user.respond_to?(:author_email) ? user.author_email : user.email) : nil
end

def user_name(user)
user.present? ? (user.respond_to?(:author_standard_name) ? user.author_standard_name : user.name) : nil
end

# rubocop:enable Style/NestedTernaryOperator

def assign_variables(resource)
@resource = resource
@user = resource.owner_author || resource.user
@user_name = user_name(@user)
@helpdesk_email = APP_CONFIG['helpdesk_email'] || 'help@datadryad.org'
@bcc_emails = APP_CONFIG['submission_bc_emails'] || [@helpdesk_email]
@submission_error_emails = APP_CONFIG['submission_error_email'] || [@helpdesk_email]
@page_error_emails = APP_CONFIG['page_error_email'] || [@helpdesk_email]
end

def rails_env
return "[#{Rails.env}] " unless Rails.env.include?('production')

''
end

def address_list(addresses)
addresses = [addresses] unless addresses.respond_to?(:join)
addresses.flatten.reject(&:blank?).join(',')
end

end

end
22 changes: 17 additions & 5 deletions app/models/stash_engine/curation_activity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class CurationActivity < ApplicationRecord # rubocop:disable Metrics/ClassLength
(ca.published? || ca.embargoed?) && curation_status_changed?
}

after_create :process_dates, if: %i[curation_status_changed? first_time_in_status?]
after_create :process_dates, if: %i[curation_status_changed?]

# the publication flags need to be set before creating datacite metadata (after create below)
after_create :update_publication_flags, if: proc { |ca| %w[published embargoed peer_review withdrawn].include?(ca.status) }
Expand All @@ -113,9 +113,9 @@ class CurationActivity < ApplicationRecord # rubocop:disable Metrics/ClassLength
if: proc { |ca| ca.published? && curation_status_changed? && !resource.skip_emails }

after_create :update_salesforce_metadata, if: proc { |_ca|
curation_status_changed? &&
CurationActivity.where(resource_id: resource_id).count > 1
}
curation_status_changed? &&
CurationActivity.where(resource_id: resource_id).count > 1
}

# Class methods
# ------------------------------------------
Expand Down Expand Up @@ -187,6 +187,7 @@ def self.allowed_states(current_state)

# Private methods
# ------------------------------------------

private

# Callbacks
Expand Down Expand Up @@ -227,7 +228,10 @@ def update_solr
end

def process_dates
update_dates = {}
update_dates = { last_status_date: created_at }
# update delete_calculation_date if the status changed after the date set by the curators
update_dates[:delete_calculation_date] = delete_calculation_date_value

if first_time_in_status?
case status
when 'processing', 'peer_review', 'submitted', 'withdrawn'
Expand Down Expand Up @@ -291,6 +295,7 @@ def email_status_change_notices
StashEngine::UserMailer.status_change(resource, status).deliver_now unless user.min_curator?
when 'withdrawn'
return if note.include?('final action required reminder') # this has already gotten a special withdrawal email
return if note.include?('notification that this item was set to `withdrawn`') # is automatic withdrawal action, no email required

if user_id == 0
StashEngine::UserMailer.user_journal_withdrawn(resource, status).deliver_now
Expand Down Expand Up @@ -406,5 +411,12 @@ def user_name

'System'
end

def delete_calculation_date_value
existing_date = resource.identifier.process_date[:delete_calculation_date]
return created_at if existing_date.blank?

[created_at, existing_date].max
end
end
end
7 changes: 7 additions & 0 deletions app/models/stash_engine/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,13 @@ def purge_duplicate_subjects!
end
end

def withdrawn_by_curator?
return false if last_curation_activity.status != 'withdrawn'

first_withdrawn = curation_activities.where(status: 'withdrawn').order(created_at: :asc).first
first_withdrawn.user_id != 0
end

private

def save_first_pub_date
Expand Down
3 changes: 3 additions & 0 deletions app/policies/stash_engine/admin_datasets_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@ def waiver_add?
@user.superuser?
end

def change_delete_schedule?
@user.superuser?
end
end
end
Loading

0 comments on commit 4fff5f0

Please sign in to comment.