From e5e904aa4e17a5bf0f8a0c1bc6330701520ea00d Mon Sep 17 00:00:00 2001
From: Matt Van Horn <mattvanhorn@gmail.com>
Date: Fri, 24 May 2013 09:13:31 -0700
Subject: [PATCH] minor refactorings

---
 app/models/topic.rb      | 11 +++++------
 app/models/topic_user.rb |  3 +++
 lib/guardian.rb          |  2 +-
 3 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/app/models/topic.rb b/app/models/topic.rb
index ef15c0316..e7bb0f060 100644
--- a/app/models/topic.rb
+++ b/app/models/topic.rb
@@ -215,7 +215,7 @@ class Topic < ActiveRecord::Base
   end
 
   def private_message?
-    self.archetype == Archetype.private_message
+    archetype == Archetype.private_message
   end
 
   def links_grouped
@@ -532,10 +532,8 @@ class Topic < ActiveRecord::Base
   def feature_topic_users(args={})
     reload
 
-    to_feature = posts
-
     # Don't include the OP or the last poster
-    to_feature = to_feature.where('user_id NOT IN (?, ?)', user_id, last_post_user_id)
+    to_feature = posts.where('user_id NOT IN (?, ?)', user_id, last_post_user_id)
 
     # Exclude a given post if supplied (in the case of deletes)
     to_feature = to_feature.where("id <> ?", args[:except_post_id]) if args[:except_post_id].present?
@@ -633,7 +631,7 @@ class Topic < ActiveRecord::Base
   end
 
   def self.starred_counts_per_day(sinceDaysAgo=30)
-    TopicUser.where('starred_at > ?', sinceDaysAgo.days.ago).group('date(starred_at)').order('date(starred_at)').count
+    TopicUser.starred_since(sinceDaysAgo).by_date_starred.count
   end
 
   def slug
@@ -721,7 +719,8 @@ class Topic < ActiveRecord::Base
 
   def auto_close_days=(num_days)
     @ignore_category_auto_close = true
-    self.auto_close_at = (num_days and num_days.to_i > 0.0 ? num_days.to_i.days.from_now : nil)
+    num_days = num_days.to_i
+    self.auto_close_at = (num_days > 0 ? num_days.days.from_now : nil)
   end
 
   def secure_category?
diff --git a/app/models/topic_user.rb b/app/models/topic_user.rb
index 97aa9915e..e0d98d8be 100644
--- a/app/models/topic_user.rb
+++ b/app/models/topic_user.rb
@@ -2,6 +2,9 @@ class TopicUser < ActiveRecord::Base
   belongs_to :user
   belongs_to :topic
 
+  scope :starred_since, lambda { |sinceDaysAgo| where('starred_at > ?', sinceDaysAgo.days.ago) }
+  scope :by_date_starred, group('date(starred_at)').order('date(starred_at)')
+
   # Class methods
   class << self
 
diff --git a/lib/guardian.rb b/lib/guardian.rb
index 13f5b5362..d21bf0a95 100644
--- a/lib/guardian.rb
+++ b/lib/guardian.rb
@@ -109,7 +109,7 @@ class Guardian
   alias :can_activate? :can_approve?
 
   def can_ban?(user)
-    user && is_staff? && not(user.staff?)
+    user && is_staff? && user.regular?
   end
   alias :can_deactivate? :can_ban?