Sha256: e8443d37a462cdfd4a7de135fb920339ad5f23779d53924310b2a6bb80dff823

Contents?: true

Size: 1.38 KB

Versions: 36

Compression:

Stored size: 1.38 KB

Contents

module Hyrax
  class CollectionTypeParticipant < ActiveRecord::Base
    self.table_name = 'collection_type_participants'
    belongs_to :hyrax_collection_type, class_name: 'CollectionType', foreign_key: 'hyrax_collection_type_id'

    MANAGE_ACCESS = 'manage'.freeze
    CREATE_ACCESS = 'create'.freeze

    GROUP_TYPE = 'group'.freeze
    USER_TYPE = 'user'.freeze

    validates :agent_id, presence: true
    validates :agent_type, presence: true, inclusion: { in: [GROUP_TYPE, USER_TYPE],
                                                        message: "%<value>s is not a valid agent type.  Accepts: #{GROUP_TYPE}, #{USER_TYPE}" }
    validates :access, presence: true, inclusion: { in: [MANAGE_ACCESS, CREATE_ACCESS],
                                                    message: "%<value>s is not a valid access.  Accepts: #{MANAGE_ACCESS}, #{CREATE_ACCESS}" }
    validates :hyrax_collection_type_id, presence: true

    def manager?
      access == MANAGE_ACCESS
    end

    def creator?
      access == CREATE_ACCESS
    end

    def label
      return agent_id unless agent_type == GROUP_TYPE
      case agent_id
      when ::Ability.registered_group_name
        I18n.t('hyrax.admin.admin_sets.form_participant_table.registered_users')
      when ::Ability.admin_group_name
        I18n.t('hyrax.admin.admin_sets.form_participant_table.admin_users')
      else
        agent_id
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
hyrax-2.9.6 app/models/hyrax/collection_type_participant.rb
hyrax-2.9.5 app/models/hyrax/collection_type_participant.rb
hyrax-2.9.4 app/models/hyrax/collection_type_participant.rb
hyrax-2.9.3 app/models/hyrax/collection_type_participant.rb
hyrax-2.9.2 app/models/hyrax/collection_type_participant.rb
hyrax-2.9.1 app/models/hyrax/collection_type_participant.rb
hyrax-2.9.0 app/models/hyrax/collection_type_participant.rb
hyrax-2.8.0 app/models/hyrax/collection_type_participant.rb
hyrax-2.7.2 app/models/hyrax/collection_type_participant.rb
hyrax-2.7.1 app/models/hyrax/collection_type_participant.rb
hyrax-2.7.0 app/models/hyrax/collection_type_participant.rb
hyrax-2.6.0 app/models/hyrax/collection_type_participant.rb
hyrax-3.0.0.pre.rc1 app/models/hyrax/collection_type_participant.rb
hyrax-3.0.0.pre.beta3 app/models/hyrax/collection_type_participant.rb
hyrax-2.5.1 app/models/hyrax/collection_type_participant.rb
hyrax-2.5.0 app/models/hyrax/collection_type_participant.rb
hyrax-3.0.0.pre.beta2 app/models/hyrax/collection_type_participant.rb
hyrax-2.4.1 app/models/hyrax/collection_type_participant.rb
hyrax-3.0.0.pre.beta1 app/models/hyrax/collection_type_participant.rb
hyrax-2.4.0 app/models/hyrax/collection_type_participant.rb