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? }
|
|
|
|
|
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
|
|
|
|
rule { private_profile & ~(user_is_self | admin) }.prevent :read_user_profile
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|