Sha256: 3968a4fda95c1fbd173086716dd8cfda9e58e37567ad0e1338e50e14439fbbe2

Contents?: true

Size: 1.08 KB

Versions: 12

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module Hyrax
  class PermissionTemplateAccess < ActiveRecord::Base
    self.table_name = 'permission_template_accesses'
    belongs_to :permission_template
    before_destroy :check_if_admin_group

    VIEW = 'view'.freeze
    DEPOSIT = 'deposit'.freeze
    MANAGE = 'manage'.freeze

    enum(
      access: {
        VIEW => VIEW,
        DEPOSIT => DEPOSIT,
        MANAGE => MANAGE
      }
    )

    def label
      return agent_id unless agent_type == 'group'
      case agent_id
      when 'registered'
        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

    def admin_group?
      agent_type == 'group' && agent_id == ::Ability.admin_group_name
    end

    private

      def check_if_admin_group
        return true unless admin_group?
        errors[:base] << I18n.t('hyrax.admin.admin_sets.form.permission_destroy_errors.admin_group')
        throw :abort
      end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
hyrax-2.0.3 app/models/hyrax/permission_template_access.rb
hyrax-2.0.2 app/models/hyrax/permission_template_access.rb
hyrax-2.0.1 app/models/hyrax/permission_template_access.rb
hyrax-2.0.0 app/models/hyrax/permission_template_access.rb
hyrax-2.0.0.rc3 app/models/hyrax/permission_template_access.rb
hyrax-2.0.0.rc2 app/models/hyrax/permission_template_access.rb
hyrax-2.0.0.rc1 app/models/hyrax/permission_template_access.rb
hyrax-2.0.0.beta5 app/models/hyrax/permission_template_access.rb
hyrax-2.0.0.beta4 app/models/hyrax/permission_template_access.rb
hyrax-2.0.0.beta3 app/models/hyrax/permission_template_access.rb
hyrax-2.0.0.beta2 app/models/hyrax/permission_template_access.rb
hyrax-2.0.0.beta1 app/models/hyrax/permission_template_access.rb