From c19f17a7f164e086c96859467baf465edd8ed45a Mon Sep 17 00:00:00 2001 From: "Michael J. Giarlo" Date: Tue, 20 Dec 2016 11:51:46 -0800 Subject: [PATCH] Load workflows when rendering workflow roles UI. 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 projecthydra-labs/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 --- .../hyrax/admin/workflow_roles_controller.rb | 41 +++++++++++++++++++ app/presenters/hyku/menu_presenter.rb | 6 +++ app/views/hyrax/admin/_sidebar.html.erb | 17 ++++++++ config/locales/hyrax.en.yml | 5 ++- config/locales/hyrax.es.yml | 3 ++ .../workflows/mediated_deposit_workflow.json | 35 ++++++++++++++-- .../admin/workflow_roles_controller_spec.rb | 17 ++++++++ spec/presenters/hyku/menu_presenter_spec.rb | 16 ++++++++ 8 files changed, 134 insertions(+), 6 deletions(-) create mode 100644 app/controllers/hyrax/admin/workflow_roles_controller.rb create mode 100644 spec/controllers/hyrax/admin/workflow_roles_controller_spec.rb diff --git a/app/controllers/hyrax/admin/workflow_roles_controller.rb b/app/controllers/hyrax/admin/workflow_roles_controller.rb new file mode 100644 index 0000000000..58c60e9359 --- /dev/null +++ b/app/controllers/hyrax/admin/workflow_roles_controller.rb @@ -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 diff --git a/app/presenters/hyku/menu_presenter.rb b/app/presenters/hyku/menu_presenter.rb index 9144656030..af3c49de83 100644 --- a/app/presenters/hyku/menu_presenter.rb +++ b/app/presenters/hyku/menu_presenter.rb @@ -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? diff --git a/app/views/hyrax/admin/_sidebar.html.erb b/app/views/hyrax/admin/_sidebar.html.erb index 1997eddeaf..db5f08002e 100644 --- a/app/views/hyrax/admin/_sidebar.html.erb +++ b/app/views/hyrax/admin/_sidebar.html.erb @@ -67,6 +67,23 @@ <%= t('hyrax.admin.sidebar.admin_sets') %> <% end %> +
  • + + <% workflows_class = 'collapse ' unless menu.workflows_section? %> + +
  • + <% if can?(:manage, Role) || can?(:manage, User) %>