Class: Hyrax::PermissionTemplateAccess

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/hyrax/permission_template_access.rb

Overview

Models a single grant of access to an agent (user or group) on a PermissionTemplate

Constant Summary collapse

VIEW =
'view'
DEPOSIT =
'deposit'
MANAGE =
'manage'
GROUP =
'group'
USER =
'user'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.for_user(ability:, access:, exclude_groups: []) ⇒ ActiveRecord::Relation

The permissions template access a given user has.

Parameters:

  • access (Array<String>)

    one or more types of access (e.g. Hyrax::PermissionTemplateAccess::MANAGE, Hyrax::PermissionTemplateAccess::DEPOSIT, Hyrax::PermissionTemplateAccess::VIEW)

  • ability (Ability)

    the ability coming from cancan ability check

  • exclude_groups (Array<String>) (defaults to: [])

    name of groups to exclude from the results

Returns:

  • (ActiveRecord::Relation)

    relation of templates for which the user has specified roles



37
38
39
40
41
42
43
44
# File 'app/models/hyrax/permission_template_access.rb', line 37

def self.for_user(ability:, access:, exclude_groups: [])
  PermissionTemplateAccess.where(
    user_where(access: access, ability: ability)
  ).or(
    PermissionTemplateAccess
      .where(group_where(access: access, ability: ability, exclude_groups: exclude_groups))
  )
end

Instance Method Details

#admin_group?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'app/models/hyrax/permission_template_access.rb', line 58

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

#labelObject



46
47
48
49
50
51
52
53
54
55
56
# File 'app/models/hyrax/permission_template_access.rb', line 46

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