2022-06-10 12:03:33 +02:00
|
|
|
class CommentPolicy < ApplicationPolicy
|
2022-06-22 10:17:42 +02:00
|
|
|
def permitted_attributes_for_create
|
2023-01-18 21:11:27 +01:00
|
|
|
if user.moderator?
|
2022-06-22 10:17:42 +02:00
|
|
|
[: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?
|
2022-06-22 10:17:42 +02:00
|
|
|
[: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
|
2022-06-22 10:17:42 +02:00
|
|
|
|
|
|
|
|
def destroy?
|
2023-01-18 21:11:27 +01:00
|
|
|
user == record.user or user.moderator?
|
2022-06-22 10:17:42 +02:00
|
|
|
end
|
2022-06-10 12:03:33 +02:00
|
|
|
end
|