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? }
|
|
|
|
|
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
|
|
|
|
end
|
2018-07-24 08:46:19 -04:00
|
|
|
|
|
|
|
rule { default }.enable :read_user_profile
|
|
|
|
rule { private_profile & ~(user_is_self | admin) }.prevent :read_user_profile
|
2016-08-18 12:59:17 -04:00
|
|
|
end
|