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)
|
flash[:notice] = t('flash.ban.error', name: name)
|
||||||
current_ban = current_user.bans.current.first
|
current_ban = current_user.bans.current.first
|
||||||
unless current_ban&.reason.nil?
|
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
|
end
|
||||||
unless current_ban&.permanently_banned?
|
unless current_ban&.permanent?
|
||||||
# TODO format banned_until
|
# 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
|
end
|
||||||
sign_out current_user
|
sign_out current_user
|
||||||
redirect_to new_user_session_path
|
redirect_to new_user_session_path
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
class UserBan < ApplicationRecord
|
class UserBan < ApplicationRecord
|
||||||
belongs_to :user
|
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
|
end
|
||||||
|
|
|
@ -14,8 +14,8 @@
|
||||||
.modal-body
|
.modal-body
|
||||||
= f.check_box :ban, label: t('views.modal.bancontrol.ban'), checked: user.banned?
|
= f.check_box :ban, label: t('views.modal.bancontrol.ban'), checked: user.banned?
|
||||||
#ban-controls{ class: user.banned? ? '' : 'd-none' }
|
#ban-controls{ class: user.banned? ? '' : 'd-none' }
|
||||||
= f.check_box :permaban, label: t('views.modal.bancontrol.permanent'), checked: user.permanently_banned?
|
= f.check_box :permaban, label: t('views.modal.bancontrol.permanent'), checked: user.permanent?
|
||||||
#ban-controls-time{ class: user.permanently_banned? ? 'd-none' : '' }
|
#ban-controls-time{ class: user.permanent? ? 'd-none' : '' }
|
||||||
= f.text_field :duration, label: '', required: true
|
= f.text_field :duration, label: '', required: true
|
||||||
.form-check.form-check-inline
|
.form-check.form-check-inline
|
||||||
= f.radio_button :duration_unit, 'hours', label: 'Hours', checked: true
|
= f.radio_button :duration_unit, 'hours', label: 'Hours', checked: true
|
||||||
|
|
Loading…
Reference in New Issue