Sha256: bc1512917de6261ded65dd4850e3a7215df367e000890ef85fc142183bdcfb41

Contents?: true

Size: 1.99 KB

Versions: 1

Compression:

Stored size: 1.99 KB

Contents

module FcrepoAdmin
  class ObjectsController < ApplicationController

    layout 'fcrepo_admin/objects'
    
    PROPERTIES = [:owner_id, :state, :create_date, :modified_date, :label]

    helper_method :object_properties

    before_filter :load_and_authorize_object
    before_filter :load_apo_info, :only => :show

    def show
    end

    def audit_trail
      # XXX Update when new version of ActiveFedora released
      @audit_trail = @object.respond_to?(:audit_trail) ? @object.audit_trail : @object.inner_object.audit_trail
      if params[:download]
        send_data @audit_trail.to_xml, :disposition => 'inline', :type => 'text/xml'
      end
    end

    private

    def load_and_authorize_object
      load_object
      authorize_object
    end

    def load_object
      @object = ActiveFedora::Base.find(params[:id], :cast => true)
    end

    def authorize_object
      action = params[:action] == 'audit_trail' ? :read : params[:action].to_sym
      authorize! action, @object
    end

    protected

    def object_properties
      unless @object_properties
        @object_properties = {}
        PROPERTIES.each { |p| @object_properties[p] = @object.send(p) }
      end
      @object_properties
    end

    def apo_relationship_name
      @object.reflections.each_value do |reflection|
        # XXX This test should also check that reflection class is identical to admin policy class
        return reflection.name if reflection.options[:property] == :is_governed_by && reflection.macro == :belongs_to
      end
      nil
    end

    def load_apo_info
      @apo_relationship_name ||= apo_relationship_name
      @object_admin_policy ||= @apo_relationship_name ? @object.send(@apo_relationship_name) : nil
      # Including Hydra::PolicyAwareAccessControlsEnforcement in ApplicationController 
      # appears to be the only way that APO access control enforcement can be enabled.
      @apo_enforcement_enabled ||= self.class.ancestors.include?(Hydra::PolicyAwareAccessControlsEnforcement)
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fcrepo_admin-0.3.2 app/controllers/fcrepo_admin/objects_controller.rb