Make ban UI more intuitive when a user is already banned
This commit is contained in:
parent
9a35584284
commit
ea62d91014
|
@ -49,7 +49,7 @@ class User < ApplicationRecord
|
|||
has_one :profile, dependent: :destroy
|
||||
has_one :theme, dependent: :destroy
|
||||
|
||||
has_many :user_bans, dependent: :destroy
|
||||
has_many :bans, class_name: 'UserBan', dependent: :destroy
|
||||
has_many :banned_users, class_name: 'UserBan',
|
||||
foreign_key: 'banned_by_id',
|
||||
dependent: :nullify
|
||||
|
@ -224,11 +224,11 @@ class User < ApplicationRecord
|
|||
# endregion
|
||||
|
||||
def banned?
|
||||
self.user_bans.current.any?
|
||||
self.bans.current.any?
|
||||
end
|
||||
|
||||
def unban
|
||||
self.user_bans.current.update!(expires_at: DateTime.now)
|
||||
self.bans.current.update!(expires_at: DateTime.now)
|
||||
end
|
||||
|
||||
# Bans a user.
|
||||
|
@ -237,7 +237,7 @@ class User < ApplicationRecord
|
|||
# @param reason [String] Reason for the ban. This is displayed to the user.
|
||||
# @param banned_by [User] User who instated the ban
|
||||
def ban(duration, duration_unit = 'hours', reason = nil, banned_by = nil)
|
||||
self.user_bans.create(expires_at: expiry, reason: reason, banned_by: banned_by)
|
||||
self.bans.create(expires_at: expiry, reason: reason, banned_by: banned_by)
|
||||
end
|
||||
|
||||
def can_export?
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
- current_ban = user.bans.current.first
|
||||
.modal.fade#modal-ban{ aria: { hidden: true, labelledby: 'modal-ban-label' }, role: :dialog, tabindex: -1 }
|
||||
.modal-dialog
|
||||
.modal-content
|
||||
|
@ -9,6 +10,7 @@
|
|||
%span.sr-only Close
|
||||
= bootstrap_form_tag(url: '/mod/ban', html: { method: :post, novalidate: :novalidate }) do |f|
|
||||
= f.hidden_field :user, value: user.screen_name
|
||||
- if current_ban.nil?
|
||||
.modal-body#ban-control-super
|
||||
= f.check_box :ban, label: t('views.modal.bancontrol.ban'), checked: user.banned?
|
||||
#ban-controls{ style: user.banned? ? '' : 'display: none' }
|
||||
|
@ -24,3 +26,22 @@
|
|||
.modal-footer
|
||||
%button.btn.btn-default{ name: 'stop-time', type: :button, data: { dismiss: :modal } }= t 'views.actions.close'
|
||||
= f.submit t('views.modal.bancontrol.hammertime'), class: 'btn btn-primary', name: 'hammer-time'
|
||||
- else
|
||||
= f.hidden_field :ban, value: '0'
|
||||
.modal-body#ban-control-super
|
||||
- if current_ban.expires_at.nil?
|
||||
This user is currently permanently banned for
|
||||
%strong= current_ban.reason
|
||||
- else
|
||||
This user is currently banned until
|
||||
%strong= current_ban.expires_at
|
||||
for
|
||||
%strong= current_ban.reason
|
||||
- if current_ban.banned_by.present?
|
||||
%br
|
||||
This ban was instated by
|
||||
%strong= current_ban.banned_by.safe_name
|
||||
on
|
||||
%strong= current_ban.created_at
|
||||
.modal-footer
|
||||
= f.submit 'Unban', class: 'btn btn-primary', name: 'hammer-time'
|
||||
|
|
Loading…
Reference in New Issue