Module: Featurable

Extended by:
ActiveSupport::Concern
Included in:
ProjectFeature
Defined in:
app/models/concerns/featurable.rb

Overview

Featurable concern

This concern adds features (tools) functionality to Project and Group To enable features you need to call `set_available_features`

Example:

class ProjectFeature

include Featurable
set_available_features %i(wiki merge_request)

Constant Summary collapse

DISABLED =

Can be enabled only for members, everyone or disabled Access control is made only for non private containers.

Permission levels:

Disabled: not enabled for anyone Private: enabled only for team members Enabled: enabled for everyone able to access the project Public: enabled for everyone (only allowed for pages)

0
PRIVATE =
10
ENABLED =
20
PUBLIC =
30
STRING_OPTIONS =
HashWithIndifferentAccess.new({
  'disabled' => DISABLED,
  'private'  => PRIVATE,
  'enabled'  => ENABLED,
  'public'   => PUBLIC
}).freeze

Instance Method Summary collapse

Instance Method Details

#access_level(feature) ⇒ Object


86
87
88
# File 'app/models/concerns/featurable.rb', line 86

def access_level(feature)
  public_send(self.class.access_level_attribute(feature)) # rubocop:disable GitlabSecurity/PublicSend
end

#feature_available?(feature, user) ⇒ Boolean

Returns:

  • (Boolean)

90
91
92
93
94
95
# File 'app/models/concerns/featurable.rb', line 90

def feature_available?(feature, user)
  # This feature might not be behind a feature flag at all, so default to true
  return false unless ::Feature.enabled?(feature, user, default_enabled: true)

  get_permission(user, feature)
end

#string_access_level(feature) ⇒ Object


97
98
99
# File 'app/models/concerns/featurable.rb', line 97

def string_access_level(feature)
  self.class.str_from_access_level(access_level(feature))
end