Files
danbooru/app/policies/user_feedback_policy.rb
evazion 937653e519 models: move html_data_attributes to policies.
Move html_data_attributes definitions from models to policies. Which
attributes are permitted as data-* attributes is a view level concern
and should be defined on the policy level, not the model level. Models
should be agnostic about how they're used in views.
2020-08-17 22:33:18 -05:00

30 lines
590 B
Ruby

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
def html_data_attributes
super + [:category]
end
end