Commit a340829c authored by http://jneen.net/'s avatar http://jneen.net/

port UserPolicy

parent 5019185e
...@@ -73,7 +73,6 @@ class Ability ...@@ -73,7 +73,6 @@ class Ability
def abilities_by_subject_class(user:, subject:) def abilities_by_subject_class(user:, subject:)
case subject case subject
when User then user_abilities
when ExternalIssue, Deployment, Environment then project_abilities(user, subject.project) when ExternalIssue, Deployment, Environment then project_abilities(user, subject.project)
else [] else []
end + global_abilities(user) end + global_abilities(user)
...@@ -85,17 +84,11 @@ class Ability ...@@ -85,17 +84,11 @@ class Ability
ProjectPolicy.abilities(nil, subject.project) ProjectPolicy.abilities(nil, subject.project)
elsif subject.respond_to?(:group) elsif subject.respond_to?(:group)
GroupPolicy.abilities(nil, subject.group) GroupPolicy.abilities(nil, subject.group)
elsif subject.is_a?(User)
anonymous_user_abilities
else else
[] []
end end
end end
def anonymous_user_abilities
[:read_user] unless restricted_public_level?
end
def global_abilities(user) def global_abilities(user)
rules = [] rules = []
rules << :create_group if user.can_create_group rules << :create_group if user.can_create_group
...@@ -136,10 +129,6 @@ class Ability ...@@ -136,10 +129,6 @@ class Ability
rules rules
end end
def user_abilities
[:read_user]
end
def restricted_public_level? def restricted_public_level?
current_application_settings.restricted_visibility_levels.include?(Gitlab::VisibilityLevel::PUBLIC) current_application_settings.restricted_visibility_levels.include?(Gitlab::VisibilityLevel::PUBLIC)
end end
......
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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment