Skip to content

Commit

Permalink
Display the workflow actions you can take on an item
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Sep 22, 2016
1 parent 87a95de commit 2ed0b91
Show file tree
Hide file tree
Showing 15 changed files with 113 additions and 36 deletions.
1 change: 0 additions & 1 deletion .rubocop.yml
Expand Up @@ -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:
Expand Down
17 changes: 17 additions & 0 deletions README.md
Expand Up @@ -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).
14 changes: 2 additions & 12 deletions app/presenters/curation_concerns/work_show_presenter.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
38 changes: 38 additions & 0 deletions 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
Expand Up @@ -91,6 +91,5 @@ def associate_workflow_role_at_entity_level(workflow_role)
end
end
end
private_constant :PermissionGenerator
end
end
18 changes: 3 additions & 15 deletions app/views/curation_concerns/base/_advisor_actions.html.erb
@@ -1,17 +1,5 @@
<h4>Actions</h4>

<div class="radio">
<label for="advisor_approve"><input type="radio" name="optRadios" id="advisor_approve">Approve</label>
</div>
<div class="radio">
<label for="advisor_reject"><input type="radio" name="optRadios" id="advisor_reject">Reject</label>
</div>
<div class="radio">
<label for="advisor_flag"><input type="radio" name="optRadios" id="advisor_flag">Flag</label>
</div>
<div class="radio">
<label for="advisor_takedown"><input type="radio" name="optRadios" id="advisor_takedown">Take Down</label>
</div>
<div class="radio">
<label for="advisor_restore"><input type="radio" name="optRadios" id="advisor_restore">Restore</label>
</div>
<%= 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 %>
Expand Up @@ -6,7 +6,7 @@
<div id="advisor_controls_collapse" class="row panel-collapse collapse">
<form>
<div class="col-sm-3 advisor_actions">
<%= render 'advisor_actions.html.erb' %>
<%= render 'advisor_actions', presenter: presenter %>
</div>
<div class="col-sm-9 advisor_comments">
<%= render 'advisor_comments.html.erb' %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/curation_concerns/base/show.html.erb
@@ -1,7 +1,7 @@
<% provide :page_title, @presenter.page_title %>
<% provide :page_header do %>
<h1><%= @presenter %> </h1>
<span class="state state-<%= @presenter.workflow_state %>"><%= @presenter.workflow_state_label %></span>
<span class="state state-<%= @presenter.workflow.state %>"><%= @presenter.workflow.state_label %></span>
<% if @parent_presenter %>
<ul class="breadcrumb">
<li><%= link_to @parent_presenter, polymorphic_path([main_app, @parent_presenter]) %></li>
Expand All @@ -22,5 +22,5 @@
<%= render 'multiple_upload', presenter: @presenter %>
<% end %>
<%= render 'show_advisor_actions', presenter: @presenter %>
<%= render 'show_advisor_actions', presenter: @presenter if @presenter.workflow.actions.present? %>
<%= render "show_actions", collector: collector, editor: editor%>
3 changes: 3 additions & 0 deletions config/locales/curation_concerns.en.yml
Expand Up @@ -143,6 +143,9 @@ en:
expiration:
time: "in %{value} hours"
lesser_time: in less than one hour
workflow:
generic_work:
finalize_digitization: "Finalize Digitization"
blacklight:
search:
fields:
Expand Down
1 change: 0 additions & 1 deletion lib/curation_concerns/rails/routes.rb
Expand Up @@ -9,7 +9,6 @@ def curation_concerns_basic_routes(&block)
resources :downloads, only: :show
resources :upload_sets, only: [:edit, :update]


namespace :curation_concerns, path: :concern do
namespaced_resources 'workflow_actions', only: [:update]
concerns_to_route.each do |curation_concern_name|
Expand Down
7 changes: 7 additions & 0 deletions spec/factories/sipity_entities.rb
@@ -0,0 +1,7 @@
FactoryGirl.define do
factory :sipity_entity, class: Sipity::Entity do
proxy_for_global_id 'gid://internal/Mock/1'
workflow { workflow_state.workflow }
workflow_state
end
end
13 changes: 12 additions & 1 deletion spec/presenters/curation_concerns/work_show_presenter_spec.rb
Expand Up @@ -6,7 +6,8 @@
let(:date_value) { Date.today }
let(:date_index) { date_value.to_s }
let(:attributes) do
{ "title_tesim" => ['foo', 'bar'],
{ "id" => '888888',
"title_tesim" => ['foo', 'bar'],
"human_readable_type_tesim" => ["Generic Work"],
"has_model_ssim" => ["GenericWork"],
"date_created_tesim" => ['an unformatted date'],
Expand Down Expand Up @@ -177,6 +178,16 @@
end
end

context "with workflow" do
let(:user) { create(:user) }
let(:ability) { Ability.new(user) }
let(:entity) { instance_double(Sipity::Entity) }
describe "#workflow" do
subject { presenter.workflow }
it { is_expected.to be_kind_of CurationConcerns::WorkflowPresenter }
end
end

describe "graph export methods" do
let(:graph) do
RDF::Graph.new.tap do |g|
Expand Down
26 changes: 26 additions & 0 deletions spec/presenters/curation_concerns/workflow_presenter_spec.rb
@@ -0,0 +1,26 @@
require 'spec_helper'

RSpec.describe CurationConcerns::WorkflowPresenter do
let(:solr_document) { SolrDocument.new(attributes) }
let(:attributes) do
{ "id" => '888888',
"has_model_ssim" => ["GenericWork"] }
end

let(:user) { create(:user) }
let(:ability) { Ability.new(user) }
let(:presenter) { described_class.new(solr_document, ability) }
let(:entity) { instance_double(Sipity::Entity) }

describe "#actions" do
let(:workflow) { create(:workflow, name: 'testing') }
before do
allow(CurationConcerns::Workflow::PermissionQuery).to receive(:scope_permitted_workflow_actions_available_for_current_state).and_return([Sipity::WorkflowAction.new(name: "complete", workflow: workflow)])
allow(I18n).to receive(:t).with('curation_concerns.workflow.testing.complete').and_return("Approve")
allow(presenter).to receive(:sipity_entity).and_return(entity)
end

subject { presenter.actions }
it { is_expected.to eq [['complete', 'Approve']] }
end
end
Expand Up @@ -19,7 +19,7 @@ module Workflow
end
before { CurationConcerns::Workflow::WorkflowImporter.new(data: workflow_config).call }
let(:sipity_entity) do
Sipity::Entity.create!(proxy_for_global_id: 'gid://Mock/1',
Sipity::Entity.create!(proxy_for_global_id: 'gid://internal/Mock/1',
workflow: sipity_workflow,
workflow_state: PowerConverter.convert_to_sipity_workflow_state('initial', scope: sipity_workflow)
)
Expand Down
Expand Up @@ -31,7 +31,7 @@
SolrDocument.new(parent.to_solr.merge(id: "resource"), nil)
end
let(:parent_presenter) do
CurationConcerns::WorkShowPresenter.new(parent_solr_doc, nil)
CurationConcerns::WorkShowPresenter.new(parent_solr_doc, nil, view)
end

let(:blacklight_config) { CatalogController.new.blacklight_config }
Expand Down

0 comments on commit 2ed0b91

Please sign in to comment.