Sha256: d91e364fd9fbb12b0cbc053885e24ef60eb0bca5589ebd1bb4fec5d78dbedaef

Contents?: true

Size: 1.79 KB

Versions: 7

Compression:

Stored size: 1.79 KB

Contents

module CurationConcerns
  module Ability
    extend ActiveSupport::Concern
    included do
      self.ability_logic += [:curation_concerns_permissions,
                             :operation_abilities,
                             :add_to_collection]
    end

    def curation_concerns_permissions
      unless current_user.new_record?
        can :create, CurationConcerns::ClassifyConcern
      end

      # user can version if they can edit
      alias_action :versions, to: :update
      alias_action :file_manager, to: :update

      if admin?
        admin_permissions
      else
        cannot :index, Hydra::AccessControls::Embargo
        cannot :index, Hydra::AccessControls::Lease
      end
    end

    def operation_abilities
      can :read, Operation, user_id: current_user.id
    end

    def admin_permissions
      can :read, :admin_dashboard
      alias_action :edit, to: :update
      alias_action :show, to: :read
      alias_action :discover, to: :read

      can :manage, curation_concerns_models
      can :manage, Sipity::WorkflowResponsibility
    end

    # Override this method in your ability model if you use a different group
    # or other logic to designate an administrator.
    def admin?
      user_groups.include? 'admin'
    end

    def add_to_collection
      return if current_user.new_record?
      can :collect, :all
    end

    def registered_user?
      user_groups.include? 'registered'
    end

    # Add this to your ability_logic if you want all logged in users to be able
    # to submit content
    def everyone_can_create_curation_concerns
      return unless registered_user?
      can :create, curation_concerns_models
    end

    private

      def curation_concerns_models
        [::FileSet, ::Collection] + CurationConcerns.config.curation_concerns
      end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
curation_concerns-1.7.8 app/models/concerns/curation_concerns/ability.rb
curation_concerns-1.7.7 app/models/concerns/curation_concerns/ability.rb
curation_concerns-2.0.0 app/models/concerns/curation_concerns/ability.rb
curation_concerns-2.0.0.rc2 app/models/concerns/curation_concerns/ability.rb
curation_concerns-1.7.6 app/models/concerns/curation_concerns/ability.rb
curation_concerns-1.7.5 app/models/concerns/curation_concerns/ability.rb
curation_concerns-1.7.4 app/models/concerns/curation_concerns/ability.rb