Class: GroupDeployToken

Inherits:
ApplicationRecord show all
Defined in:
app/models/group_deploy_token.rb

Instance Method Summary collapse

Methods inherited from ApplicationRecord

at_most, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, underscore, without_order

Instance Method Details

#has_access_to?(requested_project) ⇒ Boolean

Returns:

  • (Boolean)

11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/models/group_deploy_token.rb', line 11

def has_access_to?(requested_project)
  return false unless Feature.enabled?(:allow_group_deploy_token, default_enabled: true)

  requested_project_group = requested_project&.group
  return false unless requested_project_group
  return true if requested_project_group.id == group_id

  requested_project_group
    .ancestors
    .where(id: group_id)
    .exists?
end