Skip to content

Commit

Permalink
Load workflows when rendering workflow roles UI.
Browse files Browse the repository at this point in the history
Refs #563

This is a temporary hack to automatically load workflows in the demo instance. It also:

* Overrides the WorkflowRolesController to specify the admin layout (workaround for samvera/hyrax#67)
* Adds breadcrumbs to the WorkflowRolesController override (should also be done in Hyrax)
* Pulls in the workflow section to the admin sidebar from Hyrax (and tweaked to use the Hyku MenuPresenter)
* Adds I18n for the workflow roles header
* Updates the hyku mediated deposit json to pull in the latest from Hyrax
  • Loading branch information
mjgiarlo committed Dec 20, 2016
1 parent 1c517bf commit c19f17a
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 6 deletions.
41 changes: 41 additions & 0 deletions app/controllers/hyrax/admin/workflow_roles_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module Hyrax
module Admin
class WorkflowRolesController < ApplicationController
before_action :require_permissions
layout 'admin'

def index
# TODO: Find a better way to make sure workflows are loaded
Hyrax::Workflow::WorkflowImporter.load_workflows
add_breadcrumb t(:'hyrax.controls.home'), root_path
add_breadcrumb t(:'hyrax.toolbar.admin.menu'), hyrax.admin_path
add_breadcrumb t(:'hyrax.admin.workflow_roles.header'), hyrax.admin_workflow_roles_path
@presenter = WorkflowRolePresenter.new
end

def destroy
responsibility = Sipity::WorkflowResponsibility.find(params[:id])
authorize! :destroy, responsibility
responsibility.destroy
redirect_to admin_workflow_roles_path
end

def create
authorize! :create, Sipity::WorkflowResponsibility
form = Forms::WorkflowResponsibilityForm.new(params[:sipity_workflow_responsibility])
begin
form.save!
rescue ActiveRecord::RecordNotUnique
logger.info "Not unique *****\n\n\n"
end
redirect_to admin_workflow_roles_path
end

private

def require_permissions
authorize! :read, :admin_dashboard
end
end
end
end
6 changes: 6 additions & 0 deletions app/presenters/hyku/menu_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ def settings_section?
%w(appearances content_blocks labels features).include?(controller_name)
end

# Returns true if the current controller happens to be one of the controllers that deals
# with workflow. This is used to keep the parent section on the sidebar open.
def workflows_section?
%w(admin workflow_roles).include?(controller_name)
end

# Returns true if the current controller happens to be one of the controllers that deals
# with roles and permissions. This is used to keep the parent section on the sidebar open.
def roles_and_permissions_section?
Expand Down
17 changes: 17 additions & 0 deletions app/views/hyrax/admin/_sidebar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,23 @@
<span class="fa fa-sitemap"></span> <%= t('hyrax.admin.sidebar.admin_sets') %>
<% end %>

<li>
<a role="button" class="collapsed collapse-toggle" data-toggle="collapse" href="#collapseWorkflows" aria-expanded="false" aria-controls="collapseWorkflows">
<span class="fa fa-code-fork"></span>
<span><%= t('hyrax.admin.sidebar.workflow') %></span>
</a>
<% workflows_class = 'collapse ' unless menu.workflows_section? %>
<ul class="<%= workflows_class %>nav nav-pills nav-stacked" id="collapseWorkflows">
<%= menu.nav_link(hyrax.admin_workflow_roles_path) do %>
<span class="fa fa-users"></span> <%= t('hyrax.admin.sidebar.workflow_roles') %>
<% end %>
<%= menu.nav_link(hyrax.admin_workflows_path) do %>
<span class="fa fa-flag"></span> <%= t('hyrax.admin.sidebar.workflow_review') %>
<% end %>
</ul>
</li>

<% if can?(:manage, Role) || can?(:manage, User) %>
<li>
<a role="button" class="collapsed collapse-toggle" data-toggle="collapse" href="#collapseRoles" aria-expanded="false" aria-controls="collapseRoles">
Expand Down
5 changes: 3 additions & 2 deletions config/locales/hyrax.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ en:
account_name: "Hydra in a Box Account Id"
directory:
suffix: "@hydrainabox.org"
footer:
copyright_html: "<strong>Copyright &copy; 2016 Project Hydra</strong> Licensed under the Apache License, Version 2.0"
admin:
workflow_roles:
header: "Workflow Roles"
3 changes: 3 additions & 0 deletions config/locales/hyrax.es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ es:
account_name: "Hydra-en-una-Caja Cuenta ID"
directory:
suffix: "@hydrainabox.org"
admin:
workflow_roles:
header: "Funciones del Flujo de Trabajo"
35 changes: 31 additions & 4 deletions config/workflows/mediated_deposit_workflow.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"name": "one_step_mediated_deposit",
"label": "One-step mediated deposit workflow",
"description": "A single-step workflow for mediated deposit",
"description": "A single-step workflow for mediated deposit in which all deposits must be approved by a reviewer. Reviewer may also send deposits back to the depositor.",
"actions": [
{
"name": "deposit",
Expand All @@ -15,9 +15,25 @@
"name": "Hyrax::Workflow::PendingReviewNotification",
"to": ["approving"]
}
],
"methods": [
"Hyrax::Workflow::DeactivateObject"
]
},
{
}, {
"name": "request_changes",
"from_states": [{"names": ["complete", "pending_review"], "roles": ["approving"]}],
"transition_to": "changes_required",
"notifications": [
{
"notification_type": "email",
"name": "Hyrax::Workflow::ChangesRequiredNotification",
"to": ["approving"]
}
],
"methods": [
"Hyrax::Workflow::DeactivateObject"
]
}, {
"name": "approve",
"from_states": [{"names": ["pending_review"], "roles": ["approving"]}],
"transition_to": "complete",
Expand All @@ -29,7 +45,18 @@
}
],
"methods": [
"CurationConcerns::Workflow::ActivateObject"
"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"]
}
]
}
]
Expand Down
17 changes: 17 additions & 0 deletions spec/controllers/hyrax/admin/workflow_roles_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'spec_helper'

RSpec.describe Hyrax::Admin::WorkflowRolesController, :no_clean do
routes { Hyrax::Engine.routes }

describe "#get overrides" do
before do
allow(controller).to receive(:authorize!).with(:read, :admin_dashboard).and_return(true)
end

it "loads workflows and renders with the admin layout" do
expect(Hyrax::Workflow::WorkflowImporter).to receive(:load_workflows).once
get :index
expect(response).to render_template(layout: 'admin')
end
end
end
16 changes: 16 additions & 0 deletions spec/presenters/hyku/menu_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@
end
end

describe "#workflows_section?" do
before do
allow(context).to receive(:controller_name).and_return(controller_name)
allow(context).to receive(:controller).and_return(controller)
end
subject { instance.workflows_section? }
context "for the WorkflowRolesController" do
let(:controller) { Hyrax::Admin::WorkflowRolesController.new }
it { is_expected.to be true }
end
context "for the Admin::UsersController" do
let(:controller) { Admin::UsersController.new }
it { is_expected.to be false }
end
end

describe "#roles_and_permissions_section?" do
before do
allow(context).to receive(:controller_name).and_return(controller_name)
Expand Down

0 comments on commit c19f17a

Please sign in to comment.