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