summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/current_settings.rb4
-rw-r--r--lib/gitlab/visibility_level.rb20
2 files changed, 13 insertions, 11 deletions
diff --git a/lib/gitlab/current_settings.rb b/lib/gitlab/current_settings.rb
index 1a25eebe7d1..0ebebfa09c4 100644
--- a/lib/gitlab/current_settings.rb
+++ b/lib/gitlab/current_settings.rb
@@ -5,8 +5,7 @@ module Gitlab
RequestStore.store[key] ||= begin
if ActiveRecord::Base.connected? && ActiveRecord::Base.connection.table_exists?('application_settings')
- RequestStore.store[:current_application_settings] =
- (ApplicationSetting.current || ApplicationSetting.create_from_defaults)
+ ApplicationSetting.current || ApplicationSetting.create_from_defaults
else
fake_application_settings
end
@@ -21,6 +20,7 @@ module Gitlab
signin_enabled: Settings.gitlab['signin_enabled'],
gravatar_enabled: Settings.gravatar['enabled'],
sign_in_text: Settings.extra['sign_in_text'],
+ restricted_visibility_levels: Settings.gitlab['restricted_visibility_levels']
)
end
end
diff --git a/lib/gitlab/visibility_level.rb b/lib/gitlab/visibility_level.rb
index d0b6cde3c7e..1851e76067c 100644
--- a/lib/gitlab/visibility_level.rb
+++ b/lib/gitlab/visibility_level.rb
@@ -5,6 +5,8 @@
#
module Gitlab
module VisibilityLevel
+ extend CurrentSettings
+
PRIVATE = 0 unless const_defined?(:PRIVATE)
INTERNAL = 10 unless const_defined?(:INTERNAL)
PUBLIC = 20 unless const_defined?(:PUBLIC)
@@ -23,21 +25,21 @@ module Gitlab
end
def allowed_for?(user, level)
- user.is_admin? || allowed_level?(level)
+ user.is_admin? || allowed_level?(level.to_i)
end
- # Level can be a string `"public"` or a value `20`, first check if valid,
- # then check if the corresponding string appears in the config
+ # Return true if the specified level is allowed for the current user.
+ # Level should be a numeric value, e.g. `20`.
def allowed_level?(level)
- if options.has_key?(level.to_s)
- non_restricted_level?(level)
- elsif options.has_value?(level.to_i)
- non_restricted_level?(options.key(level.to_i).downcase)
- end
+ valid_level?(level) && non_restricted_level?(level)
end
def non_restricted_level?(level)
- ! Gitlab.config.gitlab.restricted_visibility_levels.include?(level)
+ ! current_application_settings.restricted_visibility_levels.include?(level)
+ end
+
+ def valid_level?(level)
+ options.has_value?(level)
end
end