2016-08-16 19:46:35 -04:00
|
|
|
class PersonalSnippetPolicy < BasePolicy
|
2017-04-06 17:06:42 -04:00
|
|
|
condition(:public_snippet, scope: :subject) { @subject.public? }
|
|
|
|
condition(:is_author) { @user && @subject.author == @user }
|
|
|
|
condition(:internal_snippet, scope: :subject) { @subject.internal? }
|
2016-08-16 19:46:35 -04:00
|
|
|
|
2017-04-06 17:06:42 -04:00
|
|
|
rule { public_snippet }.policy do
|
|
|
|
enable :read_personal_snippet
|
|
|
|
enable :comment_personal_snippet
|
|
|
|
end
|
2017-05-01 09:14:35 -04:00
|
|
|
|
2017-04-06 17:06:42 -04:00
|
|
|
rule { is_author }.policy do
|
|
|
|
enable :read_personal_snippet
|
|
|
|
enable :update_personal_snippet
|
|
|
|
enable :destroy_personal_snippet
|
|
|
|
enable :admin_personal_snippet
|
|
|
|
enable :comment_personal_snippet
|
|
|
|
end
|
2016-08-16 19:46:35 -04:00
|
|
|
|
2017-04-06 17:06:42 -04:00
|
|
|
rule { ~anonymous }.enable :create_personal_snippet
|
|
|
|
rule { external_user }.prevent :create_personal_snippet
|
2016-11-26 10:37:26 -05:00
|
|
|
|
2017-04-06 17:06:42 -04:00
|
|
|
rule { internal_snippet & ~external_user }.policy do
|
|
|
|
enable :read_personal_snippet
|
|
|
|
enable :comment_personal_snippet
|
2016-08-16 19:46:35 -04:00
|
|
|
end
|
2017-04-06 17:06:42 -04:00
|
|
|
|
|
|
|
rule { anonymous }.prevent :comment_personal_snippet
|
2016-08-16 19:46:35 -04:00
|
|
|
end
|