diff --git a/app/assets/javascripts/admin/models/leader_requirements.js b/app/assets/javascripts/admin/models/leader_requirements.js
index 6c7fd45e5..f2fdd3cb6 100644
--- a/app/assets/javascripts/admin/models/leader_requirements.js
+++ b/app/assets/javascripts/admin/models/leader_requirements.js
@@ -13,6 +13,8 @@ Discourse.LeaderRequirements = Discourse.Model.extend({
topics_replied_to: this.get('num_topics_replied_to') >= this.get('min_topics_replied_to'),
topics_viewed: this.get('topics_viewed') >= this.get('min_topics_viewed'),
posts_read: this.get('posts_read') >= this.get('min_posts_read'),
+ topics_viewed_all_time: this.get('topics_viewed_all_time') >= this.get('min_topics_viewed_all_time'),
+ posts_read_all_time: this.get('posts_read_all_time') >= this.get('min_posts_read_all_time'),
flagged_posts: this.get('num_flagged_posts') <= this.get('max_flagged_posts'),
flagged_by_users: this.get('num_flagged_by_users') <= this.get('max_flagged_by_users')
};
@@ -21,5 +23,7 @@ Discourse.LeaderRequirements = Discourse.Model.extend({
'topics_viewed', 'min_topics_viewed',
'posts_read', 'min_posts_read',
'num_flagged_posts', 'max_flagged_posts',
+ 'topics_viewed_all_time', 'min_topics_viewed_all_time',
+ 'posts_read_all_time', 'min_posts_read_all_time',
'num_flagged_by_users', 'max_flagged_by_users')
});
diff --git a/app/assets/javascripts/admin/templates/user_leader_requirements.js.handlebars b/app/assets/javascripts/admin/templates/user_leader_requirements.js.handlebars
index cf5d348ea..168e9dc0c 100644
--- a/app/assets/javascripts/admin/templates/user_leader_requirements.js.handlebars
+++ b/app/assets/javascripts/admin/templates/user_leader_requirements.js.handlebars
@@ -25,7 +25,7 @@
{{i18n admin.user.tl3_requirements.visits}} |
- |
+ |
{{days_visited_percent}}% ({{days_visited}} / {{time_period}} {{i18n admin.user.tl3_requirements.days}})
|
@@ -33,31 +33,43 @@
{{i18n admin.user.tl3_requirements.topics_replied_to}} |
- |
+ |
{{num_topics_replied_to}} |
{{min_topics_replied_to}} |
{{i18n admin.user.tl3_requirements.topics_viewed}} |
- |
+ |
{{topics_viewed}} |
{{min_topics_viewed}} |
+
+ {{i18n admin.user.tl3_requirements.topics_viewed_all_time}} |
+ |
+ {{topics_viewed_all_time}} |
+ {{min_topics_viewed_all_time}} |
+
{{i18n admin.user.tl3_requirements.posts_read}} |
- |
+ |
{{posts_read}} |
{{min_posts_read}} |
+
+ {{i18n admin.user.tl3_requirements.posts_read_all_time}} |
+ |
+ {{posts_read_all_time}} |
+ {{min_posts_read_all_time}} |
+
{{i18n admin.user.tl3_requirements.flagged_posts}} |
- |
+ |
{{num_flagged_posts}} |
{{max_flagged_posts}} {{i18n max}} |
{{i18n admin.user.tl3_requirements.flagged_by_users}} |
- |
+ |
{{num_flagged_by_users}} |
{{max_flagged_by_users}} {{i18n max}} |
diff --git a/app/models/leader_requirements.rb b/app/models/leader_requirements.rb
index aaa0790cb..7ae448576 100644
--- a/app/models/leader_requirements.rb
+++ b/app/models/leader_requirements.rb
@@ -10,6 +10,8 @@ class LeaderRequirements
:num_topics_replied_to, :min_topics_replied_to,
:topics_viewed, :min_topics_viewed,
:posts_read, :min_posts_read,
+ :topics_viewed_all_time, :min_topics_viewed_all_time,
+ :posts_read_all_time, :min_posts_read_all_time,
:num_flagged_posts, :max_flagged_posts
def initialize(user)
@@ -22,6 +24,8 @@ class LeaderRequirements
topics_viewed >= min_topics_viewed &&
posts_read >= min_posts_read &&
num_flagged_posts <= max_flagged_posts &&
+ topics_viewed_all_time >= min_topics_viewed_all_time &&
+ posts_read_all_time >= min_posts_read_all_time &&
num_flagged_by_users <= max_flagged_by_users
end
@@ -41,8 +45,12 @@ class LeaderRequirements
SiteSetting.leader_requires_topics_replied_to
end
+ def topics_viewed_query
+ View.where(user_id: @user.id, parent_type: 'Topic').select('distinct(parent_id)')
+ end
+
def topics_viewed
- View.where('viewed_at > ?', TIME_PERIOD.days.ago).where(user_id: @user.id, parent_type: 'Topic').select('distinct(parent_id)').count
+ topics_viewed_query.where('viewed_at > ?', TIME_PERIOD.days.ago).count
end
def min_topics_viewed
@@ -57,6 +65,22 @@ class LeaderRequirements
(LeaderRequirements.num_posts_in_time_period.to_i * (SiteSetting.leader_requires_posts_read.to_f / 100.0)).round
end
+ def topics_viewed_all_time
+ topics_viewed_query.count
+ end
+
+ def min_topics_viewed_all_time
+ SiteSetting.leader_requires_topics_viewed_all_time
+ end
+
+ def posts_read_all_time
+ @user.user_visits.pluck(:posts_read).sum
+ end
+
+ def min_posts_read_all_time
+ SiteSetting.leader_requires_posts_read_all_time
+ end
+
def num_flagged_posts
PostAction.with_deleted.where(post_id: flagged_post_ids).where.not(user_id: @user.id).pluck(:post_id).uniq.count
end
diff --git a/app/serializers/leader_requirements_serializer.rb b/app/serializers/leader_requirements_serializer.rb
index 54008ed36..9f7742d42 100644
--- a/app/serializers/leader_requirements_serializer.rb
+++ b/app/serializers/leader_requirements_serializer.rb
@@ -5,6 +5,8 @@ class LeaderRequirementsSerializer < ApplicationSerializer
:num_topics_replied_to, :min_topics_replied_to,
:topics_viewed, :min_topics_viewed,
:posts_read, :min_posts_read,
+ :topics_viewed_all_time, :min_topics_viewed_all_time,
+ :posts_read_all_time, :min_posts_read_all_time,
:num_flagged_posts, :max_flagged_posts,
:num_flagged_by_users, :max_flagged_by_users
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index f80b4ab2f..7517076aa 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -1807,7 +1807,9 @@ en:
days: "days"
topics_replied_to: "Topics Replied To"
topics_viewed: "Topics Viewed"
+ topics_viewed_all_time: "Topics Viewed (all time)"
posts_read: "Posts Read"
+ posts_read_all_time: "Posts Read (all time)"
flagged_posts: "Flagged Posts"
flagged_by_users: "Users Who Flagged"
qualifies: "Qualifies for trust level 3."
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index 8ebce5b41..608e63bd9 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -807,6 +807,8 @@ en:
leader_requires_topics_replied_to: "Minimum number of topics a user needs to have replied to in the last 100 days to qualify for promotion to leader (3) trust level. (0 or higher)"
leader_requires_topics_viewed: "The percentage of topics created in the last 100 days that a user needs to have viewed to qualify for promotion to leader (3) trust level. (0 to 100)"
leader_requires_posts_read: "The percentage of posts created in the last 100 days that a user needs to have viewed to qualify for promotion to leader (3) trust level. (0 to 100)"
+ leader_requires_topics_viewed_all_time: "The minimum total number of topics a user must have viewed to qualify for leader (3) trust level."
+ leader_requires_posts_read_all_time: "The minimum total number of posts a user must have read to qualify for leader (3) trust level."
leader_requires_max_flagged: "User must not have had more than x posts flagged by x different users in the last 100 days to qualify for promotion to leader (3) trust level, where x is this setting's value. (0 or higher)"
min_trust_to_create_topic: "The minimum trust level required to create a new topic."
diff --git a/config/site_settings.yml b/config/site_settings.yml
index 76ca285e4..5c9a56034 100644
--- a/config/site_settings.yml
+++ b/config/site_settings.yml
@@ -468,6 +468,12 @@ trust:
default: 25
min: 0
max: 100
+ leader_requires_topics_viewed_all_time:
+ default: 200
+ min: 0
+ leader_requires_posts_read_all_time:
+ default: 500
+ min: 0
leader_requires_max_flagged:
default: 5
min: 0
diff --git a/spec/models/leader_requirements_spec.rb b/spec/models/leader_requirements_spec.rb
index ad5e22d90..a726a29c8 100644
--- a/spec/models/leader_requirements_spec.rb
+++ b/spec/models/leader_requirements_spec.rb
@@ -9,6 +9,10 @@ describe LeaderRequirements do
described_class.clear_cache
end
+ def make_view(id, at, user_id)
+ View.create!(parent_id: id, parent_type: 'Topic', ip_address: '11.22.33.44', viewed_at: at, user_id: user_id)
+ end
+
describe "requirements" do
it "min_days_visited uses site setting" do
SiteSetting.stubs(:leader_requires_days_visited).returns(66)
@@ -32,6 +36,16 @@ describe LeaderRequirements do
leader_requirements.min_posts_read.should == 814
end
+ it "min_topics_viewed_all_time depends on site setting" do
+ SiteSetting.stubs(:leader_requires_topics_viewed_all_time).returns(75)
+ leader_requirements.min_topics_viewed_all_time.should == 75
+ end
+
+ it "min_posts_read_all_time depends on site setting" do
+ SiteSetting.stubs(:leader_requires_posts_read_all_time).returns(1001)
+ leader_requirements.min_posts_read_all_time.should == 1001
+ end
+
it "max_flagged_posts depends on site setting" do
SiteSetting.stubs(:leader_requires_max_flagged).returns(3)
leader_requirements.max_flagged_posts.should == 3
@@ -67,10 +81,6 @@ describe LeaderRequirements do
end
describe "topics_viewed" do
- def make_view(id, at, user_id)
- View.create!(parent_id: id, parent_type: 'Topic', ip_address: '11.22.33.44', viewed_at: at, user_id: user_id)
- end
-
it "counts topics views within last 100 days, not counting a topic more than once" do
user.save
make_view(9, 1.day.ago, user.id)
@@ -92,6 +102,25 @@ describe LeaderRequirements do
end
end
+ describe "topics_viewed_all_time" do
+ it "counts topics viewed at any time" do
+ user.save
+ make_view(10, 1.day.ago, user.id)
+ make_view(9, 100.days.ago, user.id)
+ make_view(8, 101.days.ago, user.id)
+ leader_requirements.topics_viewed_all_time.should == 3
+ end
+ end
+
+ describe "posts_read_all_time" do
+ it "counts posts read at any time" do
+ user.save
+ user.update_posts_read!(3, 2.days.ago)
+ user.update_posts_read!(1, 101.days.ago)
+ leader_requirements.posts_read_all_time.should == 4
+ end
+ end
+
context "with flagged posts" do
before do
user.save