diff options
author | http://jneen.net/ <jneen@jneen.net> | 2016-08-18 19:59:17 +0300 |
---|---|---|
committer | http://jneen.net/ <jneen@jneen.net> | 2016-08-30 21:39:22 +0300 |
commit | a340829c42617b40696408c3097d6476970e8b87 (patch) | |
tree | e43b843da5aa060af7a771b1abefe59c40c843db /app | |
parent | 5019185edd7718b262eb5ae94f21763f230f0557 (diff) |
port UserPolicy
Diffstat (limited to 'app')
-rw-r--r-- | app/models/ability.rb | 11 | ||||
-rw-r--r-- | app/policies/user_policy.rb | 11 |
2 files changed, 11 insertions, 11 deletions
diff --git a/app/models/ability.rb b/app/models/ability.rb index 7c4210f0706..fe171cd1a8b 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -73,7 +73,6 @@ class Ability def abilities_by_subject_class(user:, subject:) case subject - when User then user_abilities when ExternalIssue, Deployment, Environment then project_abilities(user, subject.project) else [] end + global_abilities(user) @@ -85,17 +84,11 @@ class Ability ProjectPolicy.abilities(nil, subject.project) elsif subject.respond_to?(:group) GroupPolicy.abilities(nil, subject.group) - elsif subject.is_a?(User) - anonymous_user_abilities else [] end end - def anonymous_user_abilities - [:read_user] unless restricted_public_level? - end - def global_abilities(user) rules = [] rules << :create_group if user.can_create_group @@ -136,10 +129,6 @@ class Ability rules end - def user_abilities - [:read_user] - end - def restricted_public_level? current_application_settings.restricted_visibility_levels.include?(Gitlab::VisibilityLevel::PUBLIC) end diff --git a/app/policies/user_policy.rb b/app/policies/user_policy.rb new file mode 100644 index 00000000000..03a2499e263 --- /dev/null +++ b/app/policies/user_policy.rb @@ -0,0 +1,11 @@ +class UserPolicy < BasePolicy + include Gitlab::CurrentSettings + + def rules + can! :read_user if @user || !restricted_public_level? + end + + def restricted_public_level? + current_application_settings.restricted_visibility_levels.include?(Gitlab::VisibilityLevel::PUBLIC) + end +end |