Skip to content

Commit

Permalink
Add notification to curators when an intem is marked complete
Browse files Browse the repository at this point in the history
fixes #505
  • Loading branch information
carolyncole committed Oct 25, 2022
1 parent 4777aaf commit a46517d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/models/work.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Work < ApplicationRecord
end

event :complete_submission do
transitions from: :draft, to: :awaiting_approval, guard: :valid_to_submit
transitions from: :draft, to: :awaiting_approval, guard: :valid_to_submit, after: :notify_collection_curators
end

event :request_changes do
Expand Down Expand Up @@ -723,5 +723,11 @@ def publish_precurated_files

delete_pre_curation_s3_dir
end

def notify_collection_curators(current_user)
curators = collection.administrators.map { |admin| "@#{admin.uid}" }.join(", ")
notification = "#{curators} The [work](#{work_path(self)}) is ready for review."
WorkActivity.add_system_activity(id, notification, current_user.id)
end
end
# rubocop:ensable Metrics/ClassLength
9 changes: 9 additions & 0 deletions spec/models/work_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,15 @@
it "can not transition from awaiting_approval to draft" do
expect { awaiting_approval_work.draft!(user) }.to raise_error AASM::InvalidTransition
end

it "notifies the curators it is ready for review" do
curator = FactoryBot.create(:research_data_moderator)
expect { awaiting_approval_work }.to change { WorkActivity.where(activity_type: "SYSTEM").count }.by(2)
expect(WorkActivity.where(activity_type: "SYSTEM").last.message).to eq("marked as awaiting_approval")
curator_notification = WorkActivity.where(activity_type: "SYSTEM").first.message
expect(curator_notification).to include("@#{curator.uid}")
expect(curator_notification). to include(Rails.application.routes.url_helpers.work_path(awaiting_approval_work))
end
end

describe "#approve" do
Expand Down

0 comments on commit a46517d

Please sign in to comment.