Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added withdrawn functionality and email notification, added final del… #1773

Merged
merged 21 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
368c217
added new deletion reminders, added letter_opener
alinvetian Jul 15, 2024
b62d068
Merge branch 'main' of github.com:datadryad/dryad-app into 3377-aband…
alinvetian Jul 15, 2024
0533f00
fixed rubocop offenses
alinvetian Jul 15, 2024
da8f694
added withdrawn functionality and email notification, added final del…
alinvetian Jul 17, 2024
5b23e8e
Merge branch 'main' of github.com:datadryad/dryad-app into 3378-aband…
alinvetian Jul 18, 2024
acbf270
added option for admin users to change deletion date reference
alinvetian Jul 19, 2024
fb0f9dd
fixed rubocop
alinvetian Jul 19, 2024
fc7fcbc
fixed merge conflicts
alinvetian Jul 23, 2024
0fe8e35
removed doubled gems
alinvetian Jul 23, 2024
223a191
fixed merge conflicts
alinvetian Aug 20, 2024
cd8c449
updated emails content and footer
alinvetian Aug 21, 2024
468374e
updated mailers views, updated daily email tasks
alinvetian Aug 26, 2024
24723dc
added tests, fixed existing ones
alinvetian Aug 26, 2024
f9ea9d5
renamed service, updated daily job, added more tests
alinvetian Aug 27, 2024
2b965be
Merge branch 'main' of github.com:datadryad/dryad-app into 3379-aband…
alinvetian Aug 27, 2024
bf4b8ad
updated permissions, fixed tests
alinvetian Aug 28, 2024
1035b77
Closes https://github.com/datadryad/dryad-product-roadmap/issues/3639
ahamelers Sep 24, 2024
d818aad
rspec (incomplete test identifier creation) fix
ahamelers Sep 24, 2024
4bcac7a
Merge branch 'main' of github.com:datadryad/dryad-app into 3379-aband…
alinvetian Oct 8, 2024
47dd773
updated wording
alinvetian Oct 8, 2024
a5d41a2
Merge remote-tracking branch 'origin/main' into 3379-abandoned-datase…
ryscher Oct 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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