Sha256: 29393d2e103eb0cdea03bd603d0f4490e54956b2e4a0f383d02811ab919235d1

Contents?: true

Size: 1.49 KB

Versions: 7

Compression:

Stored size: 1.49 KB

Contents

module CurationConcerns
  module Ability
    extend ActiveSupport::Concern
    included do
      self.ability_logic += [:curation_concerns_permissions, :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

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

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

      can :manage, curation_concerns_models
    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-0.13.1 app/models/concerns/curation_concerns/ability.rb
curation_concerns-0.13.0 app/models/concerns/curation_concerns/ability.rb
curation_concerns-0.12.0 app/models/concerns/curation_concerns/ability.rb
curation_concerns-0.12.0.pre9 app/models/concerns/curation_concerns/ability.rb
curation_concerns-0.12.0.pre8 app/models/concerns/curation_concerns/ability.rb
curation_concerns-0.12.0.pre7 app/models/concerns/curation_concerns/ability.rb
curation_concerns-0.12.0.pre6 app/models/concerns/curation_concerns/ability.rb