Add a page in admin to view trust level 3 requirements for a user. Only shows for users who are currently at trust level 2.

This commit is contained in:
Neil Lalonde
2014-01-22 17:09:56 -05:00
parent c1fec2d3e2
commit ae3b53bb76
11 changed files with 165 additions and 8 deletions

View File

@@ -0,0 +1,34 @@
# This class performs calculations to determine if a user qualifies for
# the Leader (3) trust level.
class LeaderRequirements
include ActiveModel::Serialization
attr_accessor :days_visited, :time_period, :num_topics_with_replies, :num_topics_replied_to,
:num_flagged_posts
def initialize(user)
@user = user
end
def time_period
100 # days
end
def days_visited
# This is naive. The user may have visited the site, but not read any posts.
@user.user_visits.where("visited_at >= ?", time_period.days.ago).count
end
def num_topics_with_replies
@user.topics.where('posts_count > 1 AND participant_count > 1 AND created_at > ?', time_period.days.ago).count
end
def num_topics_replied_to
@user.posts.select('distinct topic_id').where('created_at > ? AND post_number > 1', time_period.days.ago).count
end
def num_flagged_posts
@user.posts.where('created_at > ? AND (off_topic_count > 0 OR spam_count > 0 OR illegal_count > 0 OR inappropriate_count > 0 OR notify_moderators_count > 0)', time_period.days.ago).count
end
end

View File

@@ -527,6 +527,10 @@ class User < ActiveRecord::Base
last_sent_email_address || email
end
def leader_requirements
@lq ||= LeaderRequirements.new(self)
end
protected
def cook