Changes: * Change the `expires_at` field to `duration`. * Make moderators choose from a fixed set of standard ban lengths, instead of allowing arbitrary ban lengths. * List `duration` in seconds in the /bans.json API. * Dump bans to BigQuery. Note that some old bans have a negative duration. This is because their expiration date was before their creation date, which is because in 2013 bans were migrated to Danbooru 2 and the original ban creation dates were lost.
23 lines
509 B
Ruby
23 lines
509 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, :user_id, :user_name]
|
|
end
|
|
|
|
def permitted_attributes_for_update
|
|
[:reason, :duration]
|
|
end
|
|
|
|
def html_data_attributes
|
|
super + [:expired?]
|
|
end
|
|
end
|