Add `permanent?` method to `UserBan`
This commit is contained in:
parent
7330d50023
commit
0c6d79ce0b
|
@ -26,11 +26,11 @@ class ApplicationController < ActionController::Base
|
|||
flash[:notice] = t('flash.ban.error', name: name)
|
||||
current_ban = current_user.bans.current.first
|
||||
unless current_ban&.reason.nil?
|
||||
flash[:notice] += "\n#{t('flash.ban.reason', reason: current_user.bans.current.first.reason)}"
|
||||
flash[:notice] += "\n#{t('flash.ban.reason', reason: current_ban.reason)}"
|
||||
end
|
||||
unless current_ban&.permanently_banned?
|
||||
unless current_ban&.permanent?
|
||||
# TODO format banned_until
|
||||
flash[:notice] += "\n#{t('flash.ban.until', time: current_user.banned_until)}"
|
||||
flash[:notice] += "\n#{t('flash.ban.until', time: current_ban.expires_at)}"
|
||||
end
|
||||
sign_out current_user
|
||||
redirect_to new_user_session_path
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
class UserBan < ApplicationRecord
|
||||
belongs_to :user
|
||||
belongs_to :banned_by, class_name: 'User', optional: true
|
||||
belongs_to :banned_by, class_name: "User", optional: true
|
||||
|
||||
scope :current, -> { where('expires_at IS NULL or expires_at > NOW()') }
|
||||
scope :current, -> { where("expires_at IS NULL or expires_at > NOW()") }
|
||||
|
||||
def permanent?
|
||||
expires_at.nil?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,8 +14,8 @@
|
|||
.modal-body
|
||||
= f.check_box :ban, label: t('views.modal.bancontrol.ban'), checked: user.banned?
|
||||
#ban-controls{ class: user.banned? ? '' : 'd-none' }
|
||||
= f.check_box :permaban, label: t('views.modal.bancontrol.permanent'), checked: user.permanently_banned?
|
||||
#ban-controls-time{ class: user.permanently_banned? ? 'd-none' : '' }
|
||||
= f.check_box :permaban, label: t('views.modal.bancontrol.permanent'), checked: user.permanent?
|
||||
#ban-controls-time{ class: user.permanent? ? 'd-none' : '' }
|
||||
= f.text_field :duration, label: '', required: true
|
||||
.form-check.form-check-inline
|
||||
= f.radio_button :duration_unit, 'hours', label: 'Hours', checked: true
|
||||
|
|
Loading…
Reference in New Issue