Class: ProjectFeature

Inherits:
ApplicationRecord show all
Includes:
Featurable
Defined in:
app/models/project_feature.rb

Constant Summary collapse

FEATURES =
%i(issues forking merge_requests wiki snippets builds repository pages metrics_dashboard operations).freeze
PRIVATE_FEATURES_MIN_ACCESS_LEVEL =
{ merge_requests: Gitlab::Access::REPORTER, metrics_dashboard: Gitlab::Access::REPORTER }.freeze
PRIVATE_FEATURES_MIN_ACCESS_LEVEL_FOR_PRIVATE_PROJECT =
{ repository: Gitlab::Access::REPORTER }.freeze

Constants included from Featurable

Featurable::DISABLED, Featurable::ENABLED, Featurable::PRIVATE, Featurable::PUBLIC, Featurable::STRING_OPTIONS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Featurable

#access_level, #feature_available?, #string_access_level

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, where_exists, with_fast_statement_timeout, without_order

Class Method Details

.required_minimum_access_level(feature) ⇒ Object


14
15
16
17
18
# File 'app/models/project_feature.rb', line 14

def required_minimum_access_level(feature)
  feature = ensure_feature!(feature)

  PRIVATE_FEATURES_MIN_ACCESS_LEVEL.fetch(feature, Gitlab::Access::GUEST)
end

.required_minimum_access_level_for_private_project(feature) ⇒ Object

Guest users can perform certain features on public and internal projects, but not private projects.


21
22
23
24
25
26
27
# File 'app/models/project_feature.rb', line 21

def required_minimum_access_level_for_private_project(feature)
  feature = ensure_feature!(feature)

  PRIVATE_FEATURES_MIN_ACCESS_LEVEL_FOR_PRIVATE_PROJECT.fetch(feature) do
    required_minimum_access_level(feature)
  end
end

Instance Method Details

#private_pages?Boolean

Returns:

  • (Boolean)

66
67
68
# File 'app/models/project_feature.rb', line 66

def private_pages?
  !public_pages?
end

#public_pages?Boolean

Returns:

  • (Boolean)

58
59
60
61
62
63
64
# File 'app/models/project_feature.rb', line 58

def public_pages?
  return true unless Gitlab.config.pages.access_control

  return false if ::Gitlab::Pages.access_control_is_forced?

  pages_access_level == PUBLIC || pages_access_level == ENABLED && project.public?
end