Sha256: f62b81873d18398bbe1ffd88f8ceb6e43eb6bcd6f9d6495dacb5f09e2fd7998b

Contents?: true

Size: 1.79 KB

Versions: 2

Compression:

Stored size: 1.79 KB

Contents

# frozen_string_literal: true

module Spotlight
  ##
  # Default Spotlight CanCan abilities
  module Ability
    include CanCan::Ability

    # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
    def initialize(user)
      user ||= Spotlight::Engine.user_class.new

      alias_action :process_import, to: :import

      can :manage, :all if user.superadmin?

      # exhibit admin
      can %i[update import export destroy], Spotlight::Exhibit, id: user.admin_roles.pluck(:resource_id)
      can :manage, [Spotlight::BlacklightConfiguration, Spotlight::ContactEmail, Spotlight::Language], exhibit_id: user.admin_roles.pluck(:resource_id)
      can :manage, Spotlight::Role, resource_id: user.admin_roles.pluck(:resource_id), resource_type: 'Spotlight::Exhibit'

      can :manage, [PaperTrail::Version, Spotlight::FeaturedImage] if user.roles.any?

      # exhibit curator
      can :manage, [
        Spotlight::Attachment,
        Spotlight::Search,
        Spotlight::Group,
        Spotlight::Resource,
        Spotlight::Page,
        Spotlight::Contact,
        Spotlight::CustomField,
        Spotlight::CustomSearchField,
        Translation
      ], exhibit_id: user.exhibit_roles.pluck(:resource_id)

      can :manage, Spotlight::Lock, by: user

      can :read, Spotlight::Language, exhibit_id: user.exhibit_roles.pluck(:resource_id)
      can %i[read curate tag], Spotlight::Exhibit, id: user.exhibit_roles.pluck(:resource_id)

      # public
      can :read, Spotlight::HomePage
      can :read, Spotlight::Exhibit, published: true
      can :read, Spotlight::Page, published: true
      can :read, Spotlight::Search, published: true
      can :read, Spotlight::Group, published: true
      can :read, Spotlight::Language, public: true
    end
    # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
blacklight-spotlight-3.0.0.rc4 app/models/spotlight/ability.rb
blacklight-spotlight-3.0.0.rc3 app/models/spotlight/ability.rb