2018-07-24 06:00:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-18 12:59:17 -04:00
|
|
|
class UserPolicy < BasePolicy
|
2017-04-06 17:06:42 -04:00
|
|
|
desc "The current user is the user in question"
|
|
|
|
condition(:user_is_self, score: 0) { @subject == @user }
|
2017-02-17 09:58:12 -05:00
|
|
|
|
2017-04-06 17:06:42 -04:00
|
|
|
desc "This is the ghost user"
|
|
|
|
condition(:subject_ghost, scope: :subject, score: 0) { @subject.ghost? }
|
2017-02-17 09:58:12 -05:00
|
|
|
|
2018-07-24 08:46:19 -04:00
|
|
|
desc "The profile is private"
|
|
|
|
condition(:private_profile, scope: :subject, score: 0) { @subject.private_profile? }
|
|
|
|
|
2019-12-16 13:08:22 -05:00
|
|
|
desc "The user is blocked"
|
|
|
|
condition(:blocked_user, scope: :subject, score: 0) { @subject.blocked? }
|
|
|
|
|
2017-04-06 17:06:42 -04:00
|
|
|
rule { ~restricted_public_level }.enable :read_user
|
|
|
|
rule { ~anonymous }.enable :read_user
|
|
|
|
|
2018-04-25 10:54:26 -04:00
|
|
|
rule { ~subject_ghost & (user_is_self | admin) }.policy do
|
|
|
|
enable :destroy_user
|
|
|
|
enable :update_user
|
2018-07-13 11:52:31 -04:00
|
|
|
enable :update_user_status
|
2020-08-06 17:10:15 -04:00
|
|
|
enable :read_user_personal_access_tokens
|
2020-10-30 14:08:56 -04:00
|
|
|
enable :read_group_count
|
2018-04-25 10:54:26 -04:00
|
|
|
end
|
2018-07-24 08:46:19 -04:00
|
|
|
|
|
|
|
rule { default }.enable :read_user_profile
|
2019-12-16 13:08:22 -05:00
|
|
|
rule { (private_profile | blocked_user) & ~(user_is_self | admin) }.prevent :read_user_profile
|
2020-08-20 11:10:18 -04:00
|
|
|
rule { user_is_self | admin }.enable :disable_two_factor
|
2020-11-09 07:09:24 -05:00
|
|
|
rule { (user_is_self | admin) & ~blocked }.enable :create_user_personal_access_token
|
2016-08-18 12:59:17 -04:00
|
|
|
end
|
2020-01-16 04:08:46 -05:00
|
|
|
|
|
|
|
UserPolicy.prepend_if_ee('EE::UserPolicy')
|