Add `permanently_banned?` method to user model

This commit is contained in:
Karina Kwiatek 2022-06-26 15:48:25 +02:00 committed by Karina Kwiatek
parent cd168df9b2
commit 73274988c1
2 changed files with 6 additions and 2 deletions

View File

@ -229,6 +229,10 @@ class User < ApplicationRecord
end end
# endregion # endregion
def permanently_banned?
bans.current.first&.permanent? || false
end
def banned? def banned?
self.bans.current.count > 0 self.bans.current.count > 0
end end

View File

@ -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.permanent? = f.check_box :permaban, label: t('views.modal.bancontrol.permanent'), checked: user.permanently_banned?
#ban-controls-time{ class: user.permanent? ? 'd-none' : '' } #ban-controls-time{ class: user.permanently_banned? ? '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