Module: Featurable

Extended by:
ActiveSupport::Concern
Included in:
Groups::FeatureSetting, 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



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

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

#feature_available?(feature, user = nil) ⇒ Boolean

Returns:

  • (Boolean)


100
101
102
# File 'app/models/concerns/featurable.rb', line 100

def feature_available?(feature, user = nil)
  has_permission?(user, feature)
end

#string_access_level(feature) ⇒ Object



104
105
106
# File 'app/models/concerns/featurable.rb', line 104

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