Skip to content

Instantly share code, notes, and snippets.

@anusharanganathan
Created March 1, 2019 11:59
Show Gist options
  • Save anusharanganathan/1cab314607f1fe53611796afe289ce9a to your computer and use it in GitHub Desktop.
Save anusharanganathan/1cab314607f1fe53611796afe289ce9a to your computer and use it in GitHub Desktop.
Mediated deposit workflow for publishing works
{
"workflows": [
{
"name": "publishing_workflow",
"label": "Mediated deposit workflow for publishing works",
"description": "A single-step workflow for mediated deposit in which all deposits must be approved by a reviewer. Reviewer may send deposits back to the depositor or reject a work from being published.",
"allows_access_grant": false,
"actions": [
{
"name": "deposit",
"from_states": [],
"transition_to": "pending_review",
"notifications": [
{
"notification_type": "email",
"name": "Hyrax::Workflow::PendingReviewNotification",
"to": ["approving"]
}
],
"methods": [
"Hyrax::Workflow::DeactivateObject"
]
}, {
"name": "request_changes",
"from_states": [{"names": ["deposited", "pending_review"], "roles": ["approving"]}],
"transition_to": "changes_required",
"notifications": [
{
"notification_type": "email",
"name": "Hyrax::Workflow::ChangesRequiredNotification",
"to": ["approving"]
}
],
"methods": [
"Hyrax::Workflow::DeactivateObject",
"Hyrax::Workflow::GrantEditToDepositor"
]
}, {
"name": "approve",
"from_states": [{"names": ["pending_review"], "roles": ["approving"]}],
"transition_to": "deposited",
"notifications": [
{
"notification_type": "email",
"name": "Hyrax::Workflow::DepositedNotification",
"to": ["approving"]
}
],
"methods": [
"Hyrax::Workflow::GrantReadToDepositor",
"Hyrax::Workflow::RevokeEditFromDepositor",
"Hyrax::Workflow::ActivateObject"
]
}, {
"name": "reject",
"from_states": [{"names": ["pending_review"], "roles": ["approving"]}],
"transition_to": "rejected",
"notifications": [
{
"notification_type": "email",
"name": "Hyrax::Workflow::RejectedNotification",
"to": ["approving"]
}
],
"methods": [
"Hyrax::Workflow::GrantReadToDepositor",
"Hyrax::Workflow::RevokeEditFromDepositor",
"Hyrax::Workflow::ActivateObject"
]
}, {
"name": "request_review",
"from_states": [{"names": ["changes_required"], "roles": ["depositing"]}],
"transition_to": "pending_review",
"notifications": [
{
"notification_type": "email",
"name": "Hyrax::Workflow::PendingReviewNotification",
"to": ["approving"]
}
]
}, {
"name": "comment_only",
"from_states": [
{ "names": ["pending_review", "deposited", "rejected"], "roles": ["approving"] },
{ "names": ["changes_required"], "roles": ["depositing"] }
]
}
]
}
]
}
@anusharanganathan
Copy link
Author

anusharanganathan commented Mar 1, 2019

Rejected notification

# app/services/hyrax/workflow/rejected_notification.rb
module Hyrax
  module Workflow
    class RejectedNotification < AbstractNotification
      private

        def subject
          I18n.t('ngdr.notifications.workflow.rejected.subject')
        end

        def message
          I18n.t('ngdr.notifications.workflow.rejected.message',
                    title: title,
                    link: (link_to work_id, document_path),
                    user: user.user_key,
                    comment: comment
          )
        end

        def users_to_notify
          user_key = ActiveFedora::Base.find(work_id).depositor
          super << ::User.find_by(email: user_key)
        end
    end
  end
end

@anusharanganathan
Copy link
Author

Translations

# config/locales/en.yml
en:
  ngdr:
    notifications:
      workflow:
        deposited:
          message: "%{title} (%{link}) was rejected by %{user}. %{comment}"
          subject: Deposit has been rejected for publishing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment