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? }
|
|
|
|
|
2020-11-26 07:09:48 -05:00
|
|
|
desc "The user is unconfirmed"
|
|
|
|
condition(:unconfirmed_user, scope: :subject, score: 0) { !@subject.confirmed? }
|
|
|
|
|
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
|
2022-03-10 07:07:07 -05:00
|
|
|
enable :create_saved_replies
|
2022-03-14 20:07:30 -04:00
|
|
|
enable :update_saved_replies
|
2022-03-18 11:07:23 -04:00
|
|
|
enable :destroy_saved_replies
|
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
|
2021-08-23 17:11:23 -04:00
|
|
|
enable :read_user_groups
|
2022-03-10 07:07:07 -05:00
|
|
|
enable :read_saved_replies
|
2018-04-25 10:54:26 -04:00
|
|
|
end
|
2018-07-24 08:46:19 -04:00
|
|
|
|
|
|
|
rule { default }.enable :read_user_profile
|
2020-11-26 07:09:48 -05:00
|
|
|
rule { (private_profile | blocked_user | unconfirmed_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
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
UserPolicy.prepend_mod_with('UserPolicy')
|