pundit: convert user feedbacks to pundit.

Allow users to delete feedbacks they've given to other users, not just
mods.
This commit is contained in:
evazion
2020-03-17 05:52:38 -05:00
parent 565a6572a7
commit 4cd0b2cbfe
9 changed files with 95 additions and 87 deletions

View File

@@ -0,0 +1,25 @@
class UserFeedbackPolicy < ApplicationPolicy
def create?
unbanned? && user.is_gold? && record.user_id != user.id
end
def update?
create? && (user.is_moderator? || (record.creator_id == user.id && !record.is_deleted?))
end
def show?
!record.is_deleted? || can_view_deleted?
end
def can_view_deleted?
user.is_moderator?
end
def permitted_attributes_for_create
[:body, :category, :user_id, :user_name]
end
def permitted_attributes_for_update
[:body, :category, :is_deleted]
end
end