From 2ed0b917932be266b7832e428ea1a45a2ff61f5f Mon Sep 17 00:00:00 2001 From: Justin Coyne Date: Thu, 22 Sep 2016 14:16:29 -0400 Subject: [PATCH] Display the workflow actions you can take on an item --- .rubocop.yml | 1 - README.md | 17 +++++++++ .../curation_concerns/work_show_presenter.rb | 14 +------ .../curation_concerns/workflow_presenter.rb | 38 +++++++++++++++++++ .../workflow/permission_generator.rb | 1 - .../base/_advisor_actions.html.erb | 18 ++------- .../base/_show_advisor_actions.html.erb | 2 +- .../curation_concerns/base/show.html.erb | 4 +- config/locales/curation_concerns.en.yml | 3 ++ lib/curation_concerns/rails/routes.rb | 1 - spec/factories/sipity_entities.rb | 7 ++++ .../work_show_presenter_spec.rb | 13 ++++++- .../workflow_presenter_spec.rb | 26 +++++++++++++ .../workflow/permission_query_spec.rb | 2 +- .../base/file_manager.html.erb_spec.rb | 2 +- 15 files changed, 113 insertions(+), 36 deletions(-) create mode 100644 app/presenters/curation_concerns/workflow_presenter.rb create mode 100644 spec/factories/sipity_entities.rb create mode 100644 spec/presenters/curation_concerns/workflow_presenter_spec.rb diff --git a/.rubocop.yml b/.rubocop.yml index 95fe79654..9f6ae468b 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -40,7 +40,6 @@ Metrics/ClassLength: Exclude: - lib/curation_concerns/configuration.rb - 'lib/generators/curation_concerns/templates/catalog_controller.rb' - - 'app/presenters/curation_concerns/work_show_presenter.rb' - 'app/actors/curation_concerns/file_set_actor.rb' Metrics/ModuleLength: diff --git a/README.md b/README.md index 1710bd19b..325fe666c 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,23 @@ rake engine_cart:generate rake curation_concerns:spec ``` +### Workflow + +Load the workflows: + +``` +$ rails curation_concers:workflow:load +``` + +Give all the roles to all the users. This works for testing, but you probably don't want this in production: +```ruby +CurationConcerns::Workflow::PermissionGenerator.call(roles: Sipity::Role.all, + workflow: Sipity::Workflow.last, + agents: User.all) +``` + +_Something about notification should go here._ + ## Help If you have questions or need help, please email the [Hydra community tech list](mailto:hydra-tech@googlegroups.com) or stop by the [Hydra community IRC channel](irc://irc.freenode.net/projecthydra). diff --git a/app/presenters/curation_concerns/work_show_presenter.rb b/app/presenters/curation_concerns/work_show_presenter.rb index 63f9baadf..3d6cd7530 100644 --- a/app/presenters/curation_concerns/work_show_presenter.rb +++ b/app/presenters/curation_concerns/work_show_presenter.rb @@ -46,12 +46,8 @@ def file_set_presenters @file_set_presenters ||= member_presenters(ordered_ids & file_set_ids) end - def workflow_state - sipity_entity.workflow_state_name if sipity_entity - end - - def workflow_state_label - workflow_state + def workflow + @workflow ||= WorkflowPresenter.new(solr_document, current_ability) end # @return FileSetPresenter presenter for the representative FileSets @@ -111,12 +107,6 @@ def export_as_ttl private - def sipity_entity - PowerConverter.convert(solr_document, to: :sipity_entity) - rescue PowerConverter::ConversionError - nil - end - def graph GraphExporter.new(solr_document, request).fetch end diff --git a/app/presenters/curation_concerns/workflow_presenter.rb b/app/presenters/curation_concerns/workflow_presenter.rb new file mode 100644 index 000000000..0e8316010 --- /dev/null +++ b/app/presenters/curation_concerns/workflow_presenter.rb @@ -0,0 +1,38 @@ +module CurationConcerns + class WorkflowPresenter + def initialize(solr_document, current_ability) + @solr_document = solr_document + @current_ability = current_ability + end + + attr_reader :solr_document, :current_ability + + def state + sipity_entity.workflow_state_name if sipity_entity + end + + # TODO: maybe i18n here? + def state_label + state + end + + # Returns an array of tuples (key, label) appropriate for a radio group + def actions + return [] unless sipity_entity && current_ability + actions = CurationConcerns::Workflow::PermissionQuery.scope_permitted_workflow_actions_available_for_current_state(entity: sipity_entity, user: current_ability.current_user) + actions.map { |action| [action.name, action_label(action)] } + end + + private + + def action_label(action) + I18n.t("curation_concerns.workflow.#{action.workflow.name}.#{action.name}") + end + + def sipity_entity + PowerConverter.convert(solr_document, to: :sipity_entity) + rescue PowerConverter::ConversionError + nil + end + end +end diff --git a/app/services/curation_concerns/workflow/permission_generator.rb b/app/services/curation_concerns/workflow/permission_generator.rb index af1bda692..26400e51f 100644 --- a/app/services/curation_concerns/workflow/permission_generator.rb +++ b/app/services/curation_concerns/workflow/permission_generator.rb @@ -91,6 +91,5 @@ def associate_workflow_role_at_entity_level(workflow_role) end end end - private_constant :PermissionGenerator end end diff --git a/app/views/curation_concerns/base/_advisor_actions.html.erb b/app/views/curation_concerns/base/_advisor_actions.html.erb index 21a507eeb..591b11ebd 100644 --- a/app/views/curation_concerns/base/_advisor_actions.html.erb +++ b/app/views/curation_concerns/base/_advisor_actions.html.erb @@ -1,17 +1,5 @@

Actions

-
- -
-
- -
-
- -
-
- -
-
- -
\ No newline at end of file + <%= form_tag main_app.curation_concerns_workflow_action_path(presenter), method: :put do %> + <%= collection_radio_buttons(:workflow_action, :name, presenter.workflow.actions, :first, :last) %> + <% end %> diff --git a/app/views/curation_concerns/base/_show_advisor_actions.html.erb b/app/views/curation_concerns/base/_show_advisor_actions.html.erb index 0febff7d7..ed3986422 100644 --- a/app/views/curation_concerns/base/_show_advisor_actions.html.erb +++ b/app/views/curation_concerns/base/_show_advisor_actions.html.erb @@ -6,7 +6,7 @@
- <%= render 'advisor_actions.html.erb' %> + <%= render 'advisor_actions', presenter: presenter %>
<%= render 'advisor_comments.html.erb' %> diff --git a/app/views/curation_concerns/base/show.html.erb b/app/views/curation_concerns/base/show.html.erb index d4a498069..9ff130913 100644 --- a/app/views/curation_concerns/base/show.html.erb +++ b/app/views/curation_concerns/base/show.html.erb @@ -1,7 +1,7 @@ <% provide :page_title, @presenter.page_title %> <% provide :page_header do %>

<%= @presenter %>

- <%= @presenter.workflow_state_label %> + <%= @presenter.workflow.state_label %> <% if @parent_presenter %>