More work on trust level 3 requirements page

This commit is contained in:
Neil Lalonde 2014-01-23 16:40:10 -05:00
parent 938361322b
commit 90e195b2e7
13 changed files with 123 additions and 26 deletions

View file

@ -1,7 +1,18 @@
/**
The top-level controller for user pages in admin.
Ember assertion says that this class needs to be defined even if it's empty.
@class AdminUserController
@extends Discourse.ObjectController
@namespace Discourse
@module Discourse
**/
Discourse.AdminUserController = Discourse.ObjectController.extend({});
/** /**
A controller related to viewing a user in the admin section A controller related to viewing a user in the admin section
@class AdminUserController @class AdminUserIndexController
@extends Discourse.ObjectController @extends Discourse.ObjectController
@namespace Discourse @namespace Discourse
@module Discourse @module Discourse
@ -53,3 +64,4 @@ Discourse.AdminUserIndexController = Discourse.ObjectController.extend({
} }
}); });

View file

@ -341,7 +341,13 @@ Discourse.AdminUser = Discourse.User.extend({
model.setProperties(result); model.setProperties(result);
model.set('loadedDetails', true); model.set('loadedDetails', true);
}); });
},
leaderRequirements: function() {
if (this.get('leader_requirements')) {
return Discourse.LeaderRequirements.create(this.get('leader_requirements'));
} }
}.property('leader_requirements')
}); });

View file

@ -0,0 +1,21 @@
Discourse.LeaderRequirements = Discourse.Model.extend({
days_visited_percent: function() {
return ((this.get('days_visited') * 100) / this.get('time_period'));
}.property('days_visited', 'time_period'),
min_days_visited_percent: function() {
return ((this.get('min_days_visited') * 100) / this.get('time_period'));
}.property('min_days_visited', 'time_period'),
met: function() {
return {
days_visited: this.get('days_visited') >= this.get('min_days_visited'),
topics_with_replies: this.get('num_topics_with_replies') >= this.get('min_topics_with_replies'),
topics_replied_to: this.get('num_topics_replied_to') >= this.get('min_topics_replied_to'),
flagged_posts: this.get('num_flagged_posts') < this.get('max_flagged_posts')
};
}.property('days_visited', 'min_days_visited',
'num_topics_with_replies', 'min_topics_with_replies',
'num_topics_replied_to', 'min_topics_replied_to',
'num_flagged_posts', 'max_flagged_posts')
});

View file

@ -0,0 +1 @@
{{outlet}}

View file

@ -189,7 +189,7 @@
{{combobox content=trustLevels value=trust_level nameProperty="detailedName"}} {{combobox content=trustLevels value=trust_level nameProperty="detailedName"}}
</div> </div>
<div class="controls"> <div class="controls">
{{#if leader_requirements}} {{#if leaderRequirements}}
{{#link-to 'adminUser.leaderRequirements' this class="btn"}}{{i18n admin.user.trust_level_3_requirements}}{{/link-to}} {{#link-to 'adminUser.leaderRequirements' this class="btn"}}{{i18n admin.user.trust_level_3_requirements}}{{/link-to}}
{{/if}} {{/if}}

View file

@ -1,60 +1,77 @@
<div class='admin-controls'> <div class='admin-controls'>
<div class='span15'> <div class='span15'>
<ul class="nav nav-pills"> <ul class="nav nav-pills">
<li>{{#link-to 'adminUser' this}}{{i18n go_back}}{{/link-to}}</li> <li>{{#link-to 'adminUser' this}}<i class="fa fa-caret-left"></i> &nbsp;{{username}}{{/link-to}}</li>
<li>{{#link-to 'adminUsersList.regular'}}{{i18n admin.user.trust_level_2_users}}{{/link-to}}</li>
</ul> </ul>
</div> </div>
</div> </div>
<div class="admin-container"> <div class="admin-container leader-requirements">
<h2>{{username}} - {{i18n admin.user.tl3_requirements.title}}</h2> <h2>{{username}} - {{i18n admin.user.tl3_requirements.title}}</h2>
<br/> <br/>
<p>{{i18n admin.user.tl3_requirements.table_title}}</p> <p>{{i18n admin.user.tl3_requirements.table_title}}</p>
{{#with leader_requirements}} {{#with leaderRequirements}}
<table class="table" style="width: 50%;"> <table class="table" style="width: 50%;">
<thead>
<tr>
<th></th>
<th></th>
<th>{{i18n admin.user.tl3_requirements.value_heading}}</th>
<th>{{i18n admin.user.tl3_requirements.requirement_heading}}</th>
</tr>
</thead>
<tbody> <tbody>
<tr> <tr>
<th>{{i18n admin.user.tl3_requirements.visits}}</th> <th>{{i18n admin.user.tl3_requirements.visits}}</th>
<td><i {{bindAttr class=":fa met.days_visited:fa-check:fa-times"}}></i></td>
<td> <td>
<strong>{{days_visited_percent}}%</strong> ({{days_visited}} / {{time_period}} {{i18n admin.user.tl3_requirements.days}}) {{days_visited_percent}}% ({{days_visited}} / {{time_period}} {{i18n admin.user.tl3_requirements.days}})
</td> </td>
<td>{{min_days_visited_percent}}%</td>
</tr> </tr>
<tr> <tr>
<th>{{i18n admin.user.tl3_requirements.topics_with_replies}}</th> <th>{{i18n admin.user.tl3_requirements.topics_with_replies}}</th>
<td> <td><i {{bindAttr class=":fa met.topics_with_replies:fa-check:fa-times"}}></i></td>
{{num_topics_with_replies}} <td>{{num_topics_with_replies}}</td>
</td> <td>{{min_topics_with_replies}}</td>
</tr> </tr>
<tr> <tr>
<th>{{i18n admin.user.tl3_requirements.topics_replied_to}}</th> <th>{{i18n admin.user.tl3_requirements.topics_replied_to}}</th>
<td> <td><i {{bindAttr class=":fa met.topics_replied_to:fa-check:fa-times"}}></i></td>
{{num_topics_replied_to}} <td>{{num_topics_replied_to}}</td>
</td> <td>{{min_topics_replied_to}}</td>
</tr> </tr>
<tr> <tr>
<th>{{i18n admin.user.tl3_requirements.quality_content}}</th> <th>{{i18n admin.user.tl3_requirements.quality_content}}</th>
<td></td>
<td style="color: #ccc;"> <td style="color: #ccc;">
TODO TODO
</td> </td>
<td></td>
</tr> </tr>
<tr> <tr>
<th>{{i18n admin.user.tl3_requirements.reading}}</th> <th>{{i18n admin.user.tl3_requirements.reading}}</th>
<td></td>
<td style="color: #ccc;"> <td style="color: #ccc;">
TODO TODO
</td> </td>
<td></td>
</tr> </tr>
<tr> <tr>
<th>{{i18n admin.user.tl3_requirements.site_promotion}}</th> <th>{{i18n admin.user.tl3_requirements.site_promotion}}</th>
<td></td>
<td style="color: #ccc;"> <td style="color: #ccc;">
TODO TODO
</td> </td>
<td></td>
</tr> </tr>
<tr> <tr>
<th>{{i18n admin.user.tl3_requirements.flagged_posts}}</th> <th>{{i18n admin.user.tl3_requirements.flagged_posts}}</th>
<td> <td><i {{bindAttr class=":fa met.flagged_posts:fa-check:fa-times"}}></i></td>
{{num_flagged_posts}} <td>{{num_flagged_posts}}</td>
</td> <td>{{max_flagged_posts}} {{i18n max}}</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>

View file

@ -962,3 +962,12 @@ table.api-keys {
width: 95%; width: 95%;
} }
} }
.leader-requirements {
.fa-check {
color: green;
}
.fa-times {
color: red;
}
}

View file

@ -161,6 +161,9 @@ class Admin::UsersController < Admin::AdminController
end end
end end
def leader_requirements
end
private private

View file

@ -4,31 +4,55 @@ class LeaderRequirements
include ActiveModel::Serialization include ActiveModel::Serialization
attr_accessor :days_visited, :time_period, :num_topics_with_replies, :num_topics_replied_to, attr_accessor :time_period,
:num_flagged_posts :days_visited, :min_days_visited,
:num_topics_with_replies, :min_topics_with_replies,
:num_topics_replied_to, :min_topics_replied_to,
:num_flagged_posts, :max_flagged_posts
def initialize(user) def initialize(user)
@user = user @user = user
end end
# TODO
# def requirements_met?
# false
# end
def time_period def time_period
100 # days 100 # days
end end
def days_visited def days_visited
# This is naive. The user may have visited the site, but not read any posts. # 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 @user.user_visits.where("visited_at > ?", time_period.days.ago).count
end
def min_days_visited
time_period * 0.5
end end
def num_topics_with_replies def num_topics_with_replies
@user.topics.where('posts_count > 1 AND participant_count > 1 AND created_at > ?', time_period.days.ago).count @user.topics.where('posts_count > 1 AND participant_count > 1 AND created_at > ?', time_period.days.ago).count
end end
def min_topics_with_replies
5
end
def num_topics_replied_to def num_topics_replied_to
@user.posts.select('distinct topic_id').where('created_at > ? AND post_number > 1', time_period.days.ago).count @user.posts.select('distinct topic_id').where('created_at > ? AND post_number > 1', time_period.days.ago).count
end end
def min_topics_replied_to
10
end
def num_flagged_posts 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 @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
def max_flagged_posts
5 # TODO what should it be?
end
end end

View file

@ -66,7 +66,7 @@ class AdminDetailedUserSerializer < AdminUserSerializer
end end
def include_leader_requirements? def include_leader_requirements?
object.trust_level == TrustLevel.levels[:regular] object.has_trust_level?(:regular)
end end
end end

View file

@ -1,8 +1,7 @@
class LeaderRequirementsSerializer < ApplicationSerializer class LeaderRequirementsSerializer < ApplicationSerializer
attributes :time_period, :days_visited, :days_visited_percent, attributes :time_period,
:num_topics_with_replies, :num_topics_replied_to, :num_flagged_posts :days_visited, :min_days_visited,
:num_topics_with_replies, :min_topics_with_replies,
def days_visited_percent :num_topics_replied_to, :min_topics_replied_to,
(days_visited * 100) / time_period :num_flagged_posts, :max_flagged_posts
end
end end

View file

@ -108,6 +108,7 @@ en:
daily: "daily" daily: "daily"
weekly: "weekly" weekly: "weekly"
every_two_weeks: "every two weeks" every_two_weeks: "every two weeks"
max: "max"
character_count: character_count:
one: "{{count}} character" one: "{{count}} character"
other: "{{count}} characters" other: "{{count}} characters"
@ -1486,10 +1487,13 @@ en:
block_explanation: "A blocked user can't post or start topics." block_explanation: "A blocked user can't post or start topics."
trust_level_change_failed: "There was a problem changing the user's trust level." trust_level_change_failed: "There was a problem changing the user's trust level."
suspend_modal_title: "Suspend User" suspend_modal_title: "Suspend User"
trust_level_2_users: "Trust Level 2 Users"
trust_level_3_requirements: "Trust Level 3 Requirements" trust_level_3_requirements: "Trust Level 3 Requirements"
tl3_requirements: tl3_requirements:
title: "Requirements for Trust Level 3" title: "Requirements for Trust Level 3"
table_title: "In the last 100 days:" table_title: "In the last 100 days:"
value_heading: "Value"
requirement_heading: "Requirement"
visits: "Visits" visits: "Visits"
days: "days" days: "days"
topics_with_replies: "Topics with Replies" topics_with_replies: "Topics with Replies"

View file

@ -58,6 +58,7 @@ Discourse::Application.routes.draw do
put "block" put "block"
put "unblock" put "unblock"
put "trust_level" put "trust_level"
get "leader_requirements"
end end
resources :impersonate, constraints: AdminConstraint.new resources :impersonate, constraints: AdminConstraint.new