debian-mirror-gitlab/app/policies/user_policy.rb

30 lines
938 B
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2016-09-29 09:46:39 +05:30
class UserPolicy < BasePolicy
2017-09-10 17:25:29 +05:30
desc "The current user is the user in question"
condition(:user_is_self, score: 0) { @subject == @user }
2016-09-29 09:46:39 +05:30
2017-09-10 17:25:29 +05:30
desc "This is the ghost user"
condition(:subject_ghost, scope: :subject, score: 0) { @subject.ghost? }
2017-08-17 22:00:37 +05:30
2018-11-18 11:00:15 +05:30
desc "The profile is private"
condition(:private_profile, scope: :subject, score: 0) { @subject.private_profile? }
2020-01-01 13:55:28 +05:30
desc "The user is blocked"
condition(:blocked_user, scope: :subject, score: 0) { @subject.blocked? }
2017-09-10 17:25:29 +05:30
rule { ~restricted_public_level }.enable :read_user
rule { ~anonymous }.enable :read_user
2017-08-17 22:00:37 +05:30
2018-10-15 14:42:47 +05:30
rule { ~subject_ghost & (user_is_self | admin) }.policy do
enable :destroy_user
enable :update_user
2018-11-18 11:00:15 +05:30
enable :update_user_status
2018-10-15 14:42:47 +05:30
end
2018-11-18 11:00:15 +05:30
rule { default }.enable :read_user_profile
2020-01-01 13:55:28 +05:30
rule { (private_profile | blocked_user) & ~(user_is_self | admin) }.prevent :read_user_profile
2016-09-29 09:46:39 +05:30
end
2020-03-13 15:44:24 +05:30
UserPolicy.prepend_if_ee('EE::UserPolicy')