From 0535237704bb8551c81eb0bb3f3f6c98a1f37bb3 Mon Sep 17 00:00:00 2001 From: r888888888 Date: Tue, 7 May 2013 18:19:30 -0700 Subject: [PATCH] fixes #1512 --- app/logical/session_loader.rb | 2 +- app/models/forum_post.rb | 5 ++++- app/models/user.rb | 3 ++- app/presenters/user_presenter.rb | 2 +- app/views/users/_ban_notice.html.erb | 4 ++-- app/views/users/_secondary_links.html.erb | 2 +- 6 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/logical/session_loader.rb b/app/logical/session_loader.rb index af3836c9b..c8d321ee8 100644 --- a/app/logical/session_loader.rb +++ b/app/logical/session_loader.rb @@ -74,7 +74,7 @@ private end def ban_expired? - CurrentUser.user.is_banned? && CurrentUser.user.ban && CurrentUser.user.ban.expired? + CurrentUser.user.is_banned? && CurrentUser.user.recent_ban && CurrentUser.user.recent_ban.expired? end def cookie_password_hash_valid? diff --git a/app/models/forum_post.rb b/app/models/forum_post.rb index 0d46d60d4..c8755205c 100644 --- a/app/models/forum_post.rb +++ b/app/models/forum_post.rb @@ -97,7 +97,10 @@ class ForumPost < ActiveRecord::Base end def update_topic_updated_at_on_destroy - topic.update_column(:updated_at, ForumPost.where(:topic_id => topic.id).maximum(:updated_at)) + max = ForumPost.where(:topic_id => topic.id).maximum(:updated_at) + if max + topic.update_column(:updated_at, max) + end end def initialize_creator diff --git a/app/models/user.rb b/app/models/user.rb index bf9d87e89..71e3ba6f2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -40,7 +40,8 @@ class User < ActiveRecord::Base before_create :promote_to_admin_if_first_user has_many :feedback, :class_name => "UserFeedback", :dependent => :destroy has_many :posts, :foreign_key => "uploader_id" - has_one :ban + has_many :bans, :order => "bans.id desc" + has_one :recent_ban, :class_name => "Ban", :order => "bans.id desc" has_many :subscriptions, :class_name => "TagSubscription", :foreign_key => "creator_id", :order => "name" has_many :note_versions, :foreign_key => "updater_id" has_many :dmails, :foreign_key => "owner_id", :order => "dmails.id desc" diff --git a/app/presenters/user_presenter.rb b/app/presenters/user_presenter.rb index 608b01baa..79faeb971 100644 --- a/app/presenters/user_presenter.rb +++ b/app/presenters/user_presenter.rb @@ -19,7 +19,7 @@ class UserPresenter def ban_reason if user.is_banned? - "#{user.ban.reason}; expires #{user.ban.expires_at}" + "#{user.recent_ban.reason}; expires #{user.recent_ban.expires_at} (#{user.bans.count} bans total)" else nil end diff --git a/app/views/users/_ban_notice.html.erb b/app/views/users/_ban_notice.html.erb index 4f9de5b75..89e2f3c9b 100644 --- a/app/views/users/_ban_notice.html.erb +++ b/app/views/users/_ban_notice.html.erb @@ -1,5 +1,5 @@

Your account has been temporarily banned

-

Reason: <%= CurrentUser.user.ban.reason %>

-

Your ban will expire in <%= time_ago_in_words(CurrentUser.user.ban.expires_at) %>

+

Reason: <%= CurrentUser.user.recent_ban.reason %>

+

Your ban will expire in <%= time_ago_in_words(CurrentUser.user.recent_ban.expires_at) %>

diff --git a/app/views/users/_secondary_links.html.erb b/app/views/users/_secondary_links.html.erb index 74e5eff01..18bd6b648 100644 --- a/app/views/users/_secondary_links.html.erb +++ b/app/views/users/_secondary_links.html.erb @@ -28,7 +28,7 @@ <% if CurrentUser.is_moderator? %>
  • <%= link_to "Promote", edit_admin_user_path(@user) %>
  • <% if @user.is_banned? %> -
  • <%= link_to "Unban", ban_path(@user.ban) %>
  • +
  • <%= link_to "Unban", ban_path(@user.recent_ban) %>
  • <% else %>
  • <%= link_to "Ban", new_ban_path(:ban => {:user_id => @user.id}) %>
  • <% end %>