Skip to content

Commit

Permalink
minor refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
mattvanhorn committed May 24, 2013
1 parent d7817cf commit e5e904a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
11 changes: 5 additions & 6 deletions app/models/topic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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?
Expand Down
3 changes: 3 additions & 0 deletions app/models/topic_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/guardian.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down

0 comments on commit e5e904a

Please sign in to comment.