Sha256: 884b43307095e30998ac740fc65079a8e59d97359d998a3585fd91e64ee8a8c9

Contents?: true

Size: 1.73 KB

Versions: 2

Compression:

Stored size: 1.73 KB

Contents

module FcrepoAdmin::Controller
  module ControllerBehavior
    extend ActiveSupport::Concern

    included do
      helper_method :object_is_auditable?
      helper_method :object_is_governable?
      helper_method :object_is_governed_by
    end

    protected

    def load_and_authorize_object
      load_object
      authorize_object
    end

    def load_object
      pid = params[:object_id] || params[:id]
      begin
        @object = ActiveFedora::Base.find(pid, :cast => true)
      rescue ActiveFedora::ObjectNotFoundError
        render :text => "Object not found", :status => 404
      end
    end

    def authorize_object
      authorize! params[:action].to_sym, @object
    end

    def object_is_auditable?
      begin
        @object && @object.is_a?(ActiveFedora::Auditable)
      rescue
        false
      end
    end

    def object_is_governed_by
      @object_is_governed_by ||= object_is_governable? && @object.send(is_governed_by_association_name)
    end

    def object_is_governable?
      !is_governed_by_association_name.nil?
    end

    def is_governed_by_association_name
      @object.reflections.each do |name, reflection|
        if reflection.macro == :belongs_to && reflection.options[:property] == :is_governed_by # TODO add policy class
          return reflection.name
        end
      end
    end

    # #solr_response_for_raw_result and #solr_documents_for_response
    # duplicate Blacklight functionality outside of a full Blacklight
    # catalog controller context.
    def solr_response_for_raw_result(solr_result)
      Blacklight::SolrResponse.new(solr_result, {})
    end

    def solr_documents_for_response(solr_response)
      solr_response.docs.collect { |doc| SolrDocument.new(doc, solr_response) }
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fcrepo_admin-0.5.0 lib/fcrepo_admin/controller/controller_behavior.rb
fcrepo_admin-0.4.1 lib/fcrepo_admin/controller/controller_behavior.rb