users: rename recent_ban to active_ban.

This commit is contained in:
evazion
2021-05-15 03:14:39 -05:00
parent 2537145b02
commit 8ca757244a
6 changed files with 9 additions and 8 deletions

View File

@@ -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)

View File

@@ -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