Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Andrew <mail@timothyandrew.net>2017-06-29 10:43:41 +0300
committerTimothy Andrew <mail@timothyandrew.net>2017-06-30 16:06:03 +0300
commit3c88a7869b87693ba8c3fb9814d39437dd569a31 (patch)
tree4335dcc017f75c382757047a37d7936704cfe9d5 /app/policies
parentc39e4ccfb7cb76b9bdb613399aba2c2467b77751 (diff)
Implement review comments for !12445 from @godfat and @rymai.
- Use `GlobalPolicy` to authorize the users that a non-authenticated user can fetch from `/api/v4/users`. We allow access if the `Gitlab::VisibilityLevel::PUBLIC` visibility level is not restricted. - Further, as before, `/api/v4/users` is only accessible to unauthenticated users if the `username` parameter is passed. - Turn off `authenticate!` for the `/api/v4/users` endpoint by matching on the actual route + method, rather than the description. - Change the type of `current_user` check in `UsersFinder` to be more compatible with EE.
Diffstat (limited to 'app/policies')
-rw-r--r--app/policies/base_policy.rb6
-rw-r--r--app/policies/global_policy.rb3
-rw-r--r--app/policies/user_policy.rb6
3 files changed, 8 insertions, 7 deletions
diff --git a/app/policies/base_policy.rb b/app/policies/base_policy.rb
index 623424c63e0..261a2e780c5 100644
--- a/app/policies/base_policy.rb
+++ b/app/policies/base_policy.rb
@@ -1,4 +1,6 @@
class BasePolicy
+ include Gitlab::CurrentSettings
+
class RuleSet
attr_reader :can_set, :cannot_set
def initialize(can_set, cannot_set)
@@ -124,4 +126,8 @@ class BasePolicy
yield
@rule_set
end
+
+ def restricted_public_level?
+ current_application_settings.restricted_visibility_levels.include?(Gitlab::VisibilityLevel::PUBLIC)
+ end
end
diff --git a/app/policies/global_policy.rb b/app/policies/global_policy.rb
index 2683aaad981..e9be43a5037 100644
--- a/app/policies/global_policy.rb
+++ b/app/policies/global_policy.rb
@@ -1,9 +1,10 @@
class GlobalPolicy < BasePolicy
def rules
+ can! :read_users_list unless restricted_public_level?
+
return unless @user
can! :create_group if @user.can_create_group
- can! :read_users_list
unless @user.blocked? || @user.internal?
can! :log_in unless @user.access_locked?
diff --git a/app/policies/user_policy.rb b/app/policies/user_policy.rb
index 229846e368c..265c56aba53 100644
--- a/app/policies/user_policy.rb
+++ b/app/policies/user_policy.rb
@@ -1,6 +1,4 @@
class UserPolicy < BasePolicy
- include Gitlab::CurrentSettings
-
def rules
can! :read_user if @user || !restricted_public_level?
@@ -12,8 +10,4 @@ class UserPolicy < BasePolicy
cannot! :destroy_user if @subject.ghost?
end
end
-
- def restricted_public_level?
- current_application_settings.restricted_visibility_levels.include?(Gitlab::VisibilityLevel::PUBLIC)
- end
end