2016-08-16 19:46:35 -04:00
|
|
|
class PersonalSnippetPolicy < BasePolicy
|
|
|
|
def rules
|
|
|
|
can! :read_personal_snippet if @subject.public?
|
|
|
|
return unless @user
|
|
|
|
|
2017-05-01 09:14:35 -04:00
|
|
|
if @subject.public?
|
|
|
|
can! :comment_personal_snippet
|
|
|
|
end
|
|
|
|
|
2016-08-16 19:46:35 -04:00
|
|
|
if @subject.author == @user
|
|
|
|
can! :read_personal_snippet
|
|
|
|
can! :update_personal_snippet
|
2016-11-26 10:37:26 -05:00
|
|
|
can! :destroy_personal_snippet
|
2016-08-16 19:46:35 -04:00
|
|
|
can! :admin_personal_snippet
|
2017-05-01 09:14:35 -04:00
|
|
|
can! :comment_personal_snippet
|
2016-08-16 19:46:35 -04:00
|
|
|
end
|
|
|
|
|
2016-11-26 10:37:26 -05:00
|
|
|
unless @user.external?
|
|
|
|
can! :create_personal_snippet
|
|
|
|
end
|
|
|
|
|
2016-08-16 19:46:35 -04:00
|
|
|
if @subject.internal? && !@user.external?
|
|
|
|
can! :read_personal_snippet
|
2017-05-01 09:14:35 -04:00
|
|
|
can! :comment_personal_snippet
|
2016-08-16 19:46:35 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|