Module: Hyrax::Ability

Extended by:
ActiveSupport::Concern
Defined in:
app/models/concerns/hyrax/ability.rb

Instance Method Summary collapse

Instance Method Details

#admin?Boolean

Override this method in your ability model if you use a different group or other logic to designate an administrator.

Returns:

  • (Boolean)


53
54
55
# File 'app/models/concerns/hyrax/ability.rb', line 53

def admin?
  user_groups.include? admin_group_name
end

#admin_set_ids_for_depositArray<String>

Returns a list of admin set ids for admin sets the user has deposit or manage permissions to.

Returns:

  • (Array<String>)

    a list of admin set ids for admin sets the user has deposit or manage permissions to.



59
60
61
# File 'app/models/concerns/hyrax/ability.rb', line 59

def admin_set_ids_for_deposit
  admin_set_ids_for_roles(['deposit', 'manage'])
end

#admin_set_ids_for_managementArray<String>

Returns a list of admin set ids for admin sets the user has manage permissions to.

Returns:

  • (Array<String>)

    a list of admin set ids for admin sets the user has manage permissions to.



65
66
67
# File 'app/models/concerns/hyrax/ability.rb', line 65

def admin_set_ids_for_management
  admin_set_ids_for_roles(['manage'])
end

#admin_set_ids_for_roles(roles) ⇒ Array<String>

Returns a list of admin set ids for admin sets the user that match the roles.

Parameters:

  • roles (Array<String>)

    the roles to be used when searching for admin sets for the user

Returns:

  • (Array<String>)

    a list of admin set ids for admin sets the user that match the roles



73
74
75
76
77
78
79
80
81
82
83
84
# File 'app/models/concerns/hyrax/ability.rb', line 73

def admin_set_ids_for_roles(roles)
  PermissionTemplateAccess.joins(:permission_template)
                          .where(agent_type: 'user',
                                 agent_id: current_user.user_key,
                                 access: roles)
                          .or(
                            PermissionTemplateAccess.joins(:permission_template)
                                                    .where(agent_type: 'group',
                                                           agent_id: user_groups,
                                                           access: roles)
                          ).pluck('DISTINCT admin_set_id')
end

#can_create_any_work?Boolean

Returns true if can create at least one type of work and they can deposit into at least one AdminSet

Returns:

  • (Boolean)


45
46
47
48
49
# File 'app/models/concerns/hyrax/ability.rb', line 45

def can_create_any_work?
  Hyrax.config.curation_concerns.any? do |curation_concern_type|
    can?(:create, curation_concern_type)
  end && admin_set_ids_for_deposit.any?
end

#download_groups(id) ⇒ Object

Samvera doesn’t use download user/groups, so make it an alias to read Grant all groups with read or edit access permission to download



26
27
28
29
30
31
32
# File 'app/models/concerns/hyrax/ability.rb', line 26

def download_groups(id)
  doc = permissions_doc(id)
  return [] if doc.nil?
  groups = Array(doc[self.class.read_group_field]) + Array(doc[self.class.edit_group_field])
  Rails.logger.debug("[CANCAN] download_groups: #{groups.inspect}")
  groups
end

#download_users(id) ⇒ Object

Grant all users with read or edit access permission to download



35
36
37
38
39
40
41
# File 'app/models/concerns/hyrax/ability.rb', line 35

def download_users(id)
  doc = permissions_doc(id)
  return [] if doc.nil?
  users = Array(doc[self.class.read_user_field]) + Array(doc[self.class.edit_user_field])
  Rails.logger.debug("[CANCAN] download_users: #{users.inspect}")
  users
end