Files
danbooru/app/policies/ban_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

23 lines
535 B
Ruby

class BanPolicy < ApplicationPolicy
def bannable?
user.is_moderator? && (record.user.blank? || (record.user.level < user.level))
end
alias_method :edit?, :bannable?
alias_method :create?, :bannable?
alias_method :update?, :bannable?
alias_method :destroy?, :bannable?
def permitted_attributes_for_create
[:reason, :duration, :expires_at, :user_id, :user_name]
end
def permitted_attributes_for_update
[:reason, :duration, :expires_at]
end
def html_data_attributes
super + [:expired?]
end
end