From e5e904aa4e17a5bf0f8a0c1bc6330701520ea00d Mon Sep 17 00:00:00 2001 From: Matt Van Horn 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 ef15c0316fa1e..e7bb0f0605cd6 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -215,7 +215,7 @@ def self.listable_count_per_day(sinceDaysAgo=30) end def private_message? - self.archetype == Archetype.private_message + archetype == Archetype.private_message end def links_grouped @@ -532,10 +532,8 @@ def update_action_counts 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 @@ def toggle_star(user, starred) 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 @@ def toggle_mute(user_id) 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 97aa9915e8b87..e0d98d8be420c 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 13f5b5362d0a8..d21bf0a95b1c4 100644 --- a/lib/guardian.rb +++ b/lib/guardian.rb @@ -109,7 +109,7 @@ def can_approve?(target) 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?