Skip to content

Commit

Permalink
Merge pull request #40 from CDL-Dryad/in-progress-reminder
Browse files Browse the repository at this point in the history
In-progress items: email reminders
  • Loading branch information
sfisher authored Jan 7, 2020
2 parents bff953a + 7e2936b commit 763d1f7
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 10 deletions.
15 changes: 13 additions & 2 deletions stash/stash_engine/app/mailers/stash_engine/user_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,25 @@ def orcid_invitation(orcid_invite)

# Called from the StashEngine::Repository
def error_report(resource, error)
warn("Unable to report update error #{error}; nil resource") unless resource.present?
logger.warn("Unable to report update error #{error}; nil resource") unless resource.present?
return unless resource.present?
assign_variables(resource)
@backtrace = to_backtrace(error)
mail(to: @submission_error_emails, bcc: @bcc_emails,
subject: "#{rails_env} Submitting dataset \"#{@resource.title}\" (doi:#{@resource.identifier_value}) failed")
end

def in_progress_reminder(resource)
logger.warn('Unable to send in_progress_reminder; nil resource') unless resource.present?
return unless resource.present?
user = resource.authors.first || resource.user
return unless user.present? && user_email(user).present?
@user_name = user_name(user)
assign_variables(resource)
mail(to: user_email(user),
subject: "#{rails_env} REMINDER: Dryad Submission \"#{@resource.title}\"")
end

def dependency_offline(dependency)
return unless dependency.present?
@dependency = dependency
Expand All @@ -71,7 +82,7 @@ def dependency_offline(dependency)
end

def helpdesk_notice(resource, message)
warn('Unable to send helpdesk notice; nil resource') unless resource.present?
logger.warn('Unable to send helpdesk notice; nil resource') unless resource.present?
return unless resource.present?
assign_variables(resource)
@message = message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<tr class="c-lined-table__row">
<td><%= formatted_datetime(curation_activity.created_at) %></td>
<td><%= curation_activity.readable_status %></td>
<td><%= curation_activity.user&.name %></td>
<td><%= curation_activity.user&.name || "System" %></td>
<td><%= curation_activity.note %></td>
<td><%= curation_activity.keywords %></td>
</tr>
</tr>
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
<tr>
<td><%= curation_activity.created_at %></td>
<td><%= curation_activity.readable_status %></td>
<td><%= curation_activity.user.name %></td>
<td><%= curation_activity.user&.name || "System" %></td>
<td><%= curation_activity.note %></td>
<td><%= curation_activity.keywords %></td>
</tr>
<% end %>
</tbody>
</table>
</table>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<p>Dear <%= @user_name %>,</p>

<p>We noticed that you have begun a submission to Dryad, “<%= @resource.title %>”, but have not completed the process.</p>

<p>If you are ready for this dataset to enter the submission process, please follow these steps:</p>
<ol>
<li>Login</li>
<li>Click on “my datasets”</li>
<li>Click “resume” your dataset submission,</li>
<li>On page 3 of the submission form, click “submit”</li>
</ol>

<p>If you do not intend to submit this dataset, you may “delete” this dataset. Please get in touch with any questions at <a href="mailto:<%= @helpdesk_email %>"><%= @helpdesk_email %></a>.</p>

32 changes: 28 additions & 4 deletions stash/stash_engine/lib/tasks/stash_engine_tasks.rake
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ namespace :identifiers do
p "Embargoing: Identifier: #{r[1]}, Resource: #{r[0]}"
StashEngine::CurationActivity.create(
resource_id: r[0],
user_id: r[2],
user_id: 0,
status: 'embargoed',
note: 'Embargo Datasets CRON - publication date has not yet been reached, changing status to `embargo`'
)
Expand All @@ -112,9 +112,8 @@ namespace :identifiers do

resources.each do |res|
begin
last_cur_activity = res.curation_activities.last
res.curation_activities << StashEngine::CurationActivity.create(
user_id: last_cur_activity.user_id,
user_id: 0,
status: 'published',
note: 'Publish Datasets CRON - reached the publication date, changing status to `published`'
)
Expand All @@ -137,7 +136,7 @@ namespace :identifiers do
r.update(hold_for_peer_review: false, peer_review_end_date: nil)
StashEngine::CurationActivity.create(
resource_id: r.id,
user_id: r.current_curation_activity.user_id,
user_id: 0,
status: 'submitted',
note: 'Expire Peer Review CRON - reached the peer review expiration date, changing status to `submitted`'
)
Expand All @@ -147,6 +146,31 @@ namespace :identifiers do
end
end

desc 'Email the submitter when a dataset has been `in_progress` for 3 days'
task in_progess_reminder: :environment do
p "Mailing users whose datasets have been in_progress since #{3.days.ago}"
StashEngine::Resource.joins(:current_resource_state)
.where("stash_engine_resource_states.resource_state = 'in_progress'")
.where('stash_engine_resources.updated_at <= ?', 3.days.ago)
.each do |r|
begin
reminder_flag = 'in_progress_reminder CRON'
if r.curation_activities.where('note LIKE ?', "%#{reminder_flag}%").empty?
p "Mailing submitter about in_progress dataset. Identifier: #{r.identifier_id}, Resource: #{r.id} updated #{r.updated_at}"
StashEngine::UserMailer.in_progress_reminder(r).deliver_now
StashEngine::CurationActivity.create(
resource_id: r.id,
user_id: 0,
status: r.current_curation_activity.status,
note: "#{reminder_flag} - reminded submitter that this item is still `in_progress`"
)
end
rescue StandardError => e
p " Exception! #{e.message}"
end
end
end

desc 'populate publicationName'
task load_publication_names: :environment do
p "Searching CrossRef and the Journal API for publication names: #{Time.now.utc}"
Expand Down

0 comments on commit 763d1f7

Please sign in to comment.