Sha256: 82da624e4bc3ef02c6c77293ab15a3eb05804ecaa85b34bb95b2d55475713121

Contents?: true

Size: 1.42 KB

Versions: 7

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true
module Hyrax
  class WorkflowActionsController < ApplicationController
    DEFAULT_FORM_CLASS = Hyrax::Forms::WorkflowActionForm

    ##
    # @!attribute [r] curation_concern
    #   @api private
    #   @return [Hyrax::Resource]
    attr_reader :curation_concern

    load_resource class: Hyrax::Resource, instance_name: :curation_concern
    before_action :authenticate_user!

    def update
      if workflow_action_form.save
        after_update_response
      else
        respond_to do |wants|
          wants.html { render 'hyrax/base/unauthorized', status: :unauthorized }
          wants.json { render_json_response(response_type: :unprocessable_entity, options: { errors: workflow_action_form.errors }) }
        end
      end
    end

    private

    def workflow_action_form
      @workflow_action_form ||= DEFAULT_FORM_CLASS.new(
        current_ability: current_ability,
        work: curation_concern,
        attributes: workflow_action_params
      )
    end

    def workflow_action_params
      params.require(:workflow_action).permit(:name, :comment)
    end

    def after_update_response
      respond_to do |wants|
        wants.html { redirect_to [main_app, curation_concern], notice: "The #{curation_concern.human_readable_type} has been updated." }
        wants.json { render 'hyrax/base/show', status: :ok, location: polymorphic_path([main_app, curation_concern]) }
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
hyrax-4.0.0.beta2 app/controllers/hyrax/workflow_actions_controller.rb
hyrax-3.4.2 app/controllers/hyrax/workflow_actions_controller.rb
hyrax-4.0.0.beta1 app/controllers/hyrax/workflow_actions_controller.rb
hyrax-3.4.1 app/controllers/hyrax/workflow_actions_controller.rb
hyrax-3.4.0 app/controllers/hyrax/workflow_actions_controller.rb
hyrax-3.3.0 app/controllers/hyrax/workflow_actions_controller.rb
hyrax-3.2.0 app/controllers/hyrax/workflow_actions_controller.rb