diff options
author | Vinnie Okada <vokada@mrvinn.com> | 2015-03-01 18:06:46 +0300 |
---|---|---|
committer | Vinnie Okada <vokada@mrvinn.com> | 2015-03-07 23:11:08 +0300 |
commit | cacac147de2b317d02788c5da1cdc6010f00a340 (patch) | |
tree | 079ba9eb2adb0d34c47205bd778066dda7ce3d60 /lib/gitlab/visibility_level.rb | |
parent | 3cf4359b00d13959741e8c4909112c21b021c86c (diff) |
Move restricted visibility settings to the UI
Add checkboxes to the application settings page for restricted
visibility levels, and remove those settings from gitlab.yml.
Diffstat (limited to 'lib/gitlab/visibility_level.rb')
-rw-r--r-- | lib/gitlab/visibility_level.rb | 20 |
1 files changed, 11 insertions, 9 deletions
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 |