bans: fix exception when user with expired ban logs in.
`ban.destroy` fails because users have many `bans`, not a single `ban`. Destroying the expired ban isn't necessary anyway.
This commit is contained in:
@@ -20,7 +20,7 @@ class SessionLoader
|
|||||||
end
|
end
|
||||||
|
|
||||||
if CurrentUser.user
|
if CurrentUser.user
|
||||||
CurrentUser.user.unban! if ban_expired?
|
CurrentUser.user.unban! if CurrentUser.user.ban_expired?
|
||||||
else
|
else
|
||||||
CurrentUser.user = AnonymousUser.new
|
CurrentUser.user = AnonymousUser.new
|
||||||
end
|
end
|
||||||
@@ -86,10 +86,6 @@ private
|
|||||||
session[:user_id] = CurrentUser.user.id
|
session[:user_id] = CurrentUser.user.id
|
||||||
end
|
end
|
||||||
|
|
||||||
def ban_expired?
|
|
||||||
CurrentUser.user.is_banned? && CurrentUser.user.recent_ban && CurrentUser.user.recent_ban.expired?
|
|
||||||
end
|
|
||||||
|
|
||||||
def cookie_password_hash_valid?
|
def cookie_password_hash_valid?
|
||||||
cookies[:password_hash] && cookies.signed[:user_name] && User.authenticate_cookie_hash(cookies.signed[:user_name], cookies[:password_hash])
|
cookies[:password_hash] && cookies.signed[:user_name] && User.authenticate_cookie_hash(cookies.signed[:user_name], cookies[:password_hash])
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ class User < ActiveRecord::Base
|
|||||||
has_many :post_votes
|
has_many :post_votes
|
||||||
has_many :bans, lambda {order("bans.id desc")}
|
has_many :bans, lambda {order("bans.id desc")}
|
||||||
has_one :recent_ban, lambda {order("bans.id desc")}, :class_name => "Ban"
|
has_one :recent_ban, lambda {order("bans.id desc")}, :class_name => "Ban"
|
||||||
|
|
||||||
has_one :api_key
|
has_one :api_key
|
||||||
has_one :dmail_filter
|
has_one :dmail_filter
|
||||||
has_one :super_voter
|
has_one :super_voter
|
||||||
@@ -109,7 +110,10 @@ class User < ActiveRecord::Base
|
|||||||
def unban!
|
def unban!
|
||||||
self.is_banned = false
|
self.is_banned = false
|
||||||
save
|
save
|
||||||
ban.destroy
|
end
|
||||||
|
|
||||||
|
def ban_expired?
|
||||||
|
is_banned? && recent_ban.try(:expired?)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user