pundit: convert bans to pundit.

This commit is contained in:
evazion
2020-03-17 22:47:49 -05:00
parent ff1d71af2e
commit 3d72e62c77
6 changed files with 121 additions and 152 deletions

View File

@@ -0,0 +1,18 @@
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
end