users: rename recent_ban to active_ban.
This commit is contained in:
@@ -14,6 +14,7 @@ class Ban < ApplicationRecord
|
||||
|
||||
scope :unexpired, -> { where("bans.created_at + bans.duration > ?", Time.now) }
|
||||
scope :expired, -> { where("bans.created_at + bans.duration <= ?", Time.now) }
|
||||
scope :active, -> { unexpired }
|
||||
|
||||
def self.search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :duration, :reason, :user, :banner)
|
||||
|
||||
@@ -132,7 +132,7 @@ class User < ApplicationRecord
|
||||
has_many :received_upgrades, class_name: "UserUpgrade", foreign_key: :recipient_id, dependent: :destroy
|
||||
has_many :purchased_upgrades, class_name: "UserUpgrade", foreign_key: :purchaser_id, dependent: :destroy
|
||||
has_many :user_events, dependent: :destroy
|
||||
has_one :recent_ban, -> {order("bans.id desc")}, :class_name => "Ban"
|
||||
has_one :active_ban, -> { active }, class_name: "Ban"
|
||||
|
||||
has_one :email_address, dependent: :destroy
|
||||
has_many :api_keys, dependent: :destroy
|
||||
@@ -166,7 +166,7 @@ class User < ApplicationRecord
|
||||
end
|
||||
|
||||
def ban_expired?
|
||||
is_banned? && recent_ban.try(:expired?)
|
||||
is_banned? && active_ban.blank?
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ class UserPresenter
|
||||
|
||||
def ban_reason
|
||||
if user.is_banned?
|
||||
"#{user.recent_ban.reason}; expires #{user.recent_ban.expires_at} (#{user.bans.count} bans total)"
|
||||
"#{user.active_ban.reason}; expires #{user.active_ban.expires_at} (#{user.bans.count} bans total)"
|
||||
else
|
||||
nil
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<div class="notice notice-error notice-large" id="ban-notice">
|
||||
<h2>Your account has been temporarily banned</h2>
|
||||
<div>Reason: <span class="prose"><%= format_text CurrentUser.user.recent_ban.reason, inline: true %></span></div>
|
||||
<div>Your ban will expire in <%= time_ago_in_words(CurrentUser.user.recent_ban.expires_at) %></div>
|
||||
<div>Reason: <span class="prose"><%= format_text CurrentUser.user.active_ban.reason, inline: true %></span></div>
|
||||
<div>Your ban will expire in <%= time_ago_in_words(CurrentUser.user.active_ban.expires_at) %></div>
|
||||
</div>
|
||||
|
||||
@@ -28,8 +28,8 @@
|
||||
<% end %>
|
||||
|
||||
<% if policy(Ban.new(user: @user)).create? %>
|
||||
<% if @user.is_banned? && @user.recent_ban.present? %>
|
||||
<%= subnav_link_to "Unban", ban_path(@user.recent_ban) %>
|
||||
<% if @user.is_banned? && @user.active_ban.present? %>
|
||||
<%= subnav_link_to "Unban", ban_path(@user.active_ban) %>
|
||||
<% else %>
|
||||
<%= subnav_link_to "Ban", new_ban_path(:ban => {:user_id => @user.id}) %>
|
||||
<% end %>
|
||||
|
||||
@@ -89,7 +89,7 @@
|
||||
<td><%= presenter.permissions %></td>
|
||||
</tr>
|
||||
|
||||
<% if user.is_banned? && user.recent_ban %>
|
||||
<% if user.is_banned? %>
|
||||
<tr>
|
||||
<th>Ban reason</th>
|
||||
<td>
|
||||
|
||||
Reference in New Issue
Block a user