Files
astuto/app/policies/comment_policy.rb

25 lines
455 B
Ruby
Raw Permalink Normal View History

2022-06-10 12:03:33 +02:00
class CommentPolicy < ApplicationPolicy
def permitted_attributes_for_create
2023-01-18 21:11:27 +01:00
if user.moderator?
[:body, :parent_id, :is_post_update]
else
[:body, :parent_id]
end
end
def permitted_attributes_for_update
2023-01-18 21:11:27 +01:00
if user.moderator?
[:body, :is_post_update]
else
[:body]
end
end
2022-06-10 12:03:33 +02:00
def update?
2023-01-18 21:11:27 +01:00
user == record.user or user.moderator?
2022-06-10 12:03:33 +02:00
end
def destroy?
2023-01-18 21:11:27 +01:00
user == record.user or user.moderator?
end
2022-06-10 12:03:33 +02:00
end