mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 12:53:42 +08:00
More work on trust level 3 requirements page
This commit is contained in:
parent
938361322b
commit
90e195b2e7
|
@ -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
|
||||
|
||||
@class AdminUserController
|
||||
@class AdminUserIndexController
|
||||
@extends Discourse.ObjectController
|
||||
@namespace Discourse
|
||||
@module Discourse
|
||||
|
@ -53,3 +64,4 @@ Discourse.AdminUserIndexController = Discourse.ObjectController.extend({
|
|||
}
|
||||
|
||||
});
|
||||
|
||||
|
|
|
@ -341,7 +341,13 @@ Discourse.AdminUser = Discourse.User.extend({
|
|||
model.setProperties(result);
|
||||
model.set('loadedDetails', true);
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
leaderRequirements: function() {
|
||||
if (this.get('leader_requirements')) {
|
||||
return Discourse.LeaderRequirements.create(this.get('leader_requirements'));
|
||||
}
|
||||
}.property('leader_requirements')
|
||||
|
||||
});
|
||||
|
||||
|
|
21
app/assets/javascripts/admin/models/leader_requirements.js
Normal file
21
app/assets/javascripts/admin/models/leader_requirements.js
Normal 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')
|
||||
});
|
|
@ -0,0 +1 @@
|
|||
{{outlet}}
|
|
@ -189,7 +189,7 @@
|
|||
{{combobox content=trustLevels value=trust_level nameProperty="detailedName"}}
|
||||
</div>
|
||||
<div class="controls">
|
||||
{{#if leader_requirements}}
|
||||
{{#if leaderRequirements}}
|
||||
{{#link-to 'adminUser.leaderRequirements' this class="btn"}}{{i18n admin.user.trust_level_3_requirements}}{{/link-to}}
|
||||
{{/if}}
|
||||
|
||||
|
|
|
@ -1,60 +1,77 @@
|
|||
<div class='admin-controls'>
|
||||
<div class='span15'>
|
||||
<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> {{username}}{{/link-to}}</li>
|
||||
<li>{{#link-to 'adminUsersList.regular'}}{{i18n admin.user.trust_level_2_users}}{{/link-to}}</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="admin-container">
|
||||
<div class="admin-container leader-requirements">
|
||||
<h2>{{username}} - {{i18n admin.user.tl3_requirements.title}}</h2>
|
||||
<br/>
|
||||
<p>{{i18n admin.user.tl3_requirements.table_title}}</p>
|
||||
|
||||
{{#with leader_requirements}}
|
||||
{{#with leaderRequirements}}
|
||||
<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>
|
||||
<tr>
|
||||
<th>{{i18n admin.user.tl3_requirements.visits}}</th>
|
||||
<td><i {{bindAttr class=":fa met.days_visited:fa-check:fa-times"}}></i></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>{{min_days_visited_percent}}%</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{{i18n admin.user.tl3_requirements.topics_with_replies}}</th>
|
||||
<td>
|
||||
{{num_topics_with_replies}}
|
||||
</td>
|
||||
<td><i {{bindAttr class=":fa met.topics_with_replies:fa-check:fa-times"}}></i></td>
|
||||
<td>{{num_topics_with_replies}}</td>
|
||||
<td>{{min_topics_with_replies}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{{i18n admin.user.tl3_requirements.topics_replied_to}}</th>
|
||||
<td>
|
||||
{{num_topics_replied_to}}
|
||||
</td>
|
||||
<td><i {{bindAttr class=":fa met.topics_replied_to:fa-check:fa-times"}}></i></td>
|
||||
<td>{{num_topics_replied_to}}</td>
|
||||
<td>{{min_topics_replied_to}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{{i18n admin.user.tl3_requirements.quality_content}}</th>
|
||||
<td></td>
|
||||
<td style="color: #ccc;">
|
||||
TODO
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{{i18n admin.user.tl3_requirements.reading}}</th>
|
||||
<td></td>
|
||||
<td style="color: #ccc;">
|
||||
TODO
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{{i18n admin.user.tl3_requirements.site_promotion}}</th>
|
||||
<td></td>
|
||||
<td style="color: #ccc;">
|
||||
TODO
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{{i18n admin.user.tl3_requirements.flagged_posts}}</th>
|
||||
<td>
|
||||
{{num_flagged_posts}}
|
||||
</td>
|
||||
<td><i {{bindAttr class=":fa met.flagged_posts:fa-check:fa-times"}}></i></td>
|
||||
<td>{{num_flagged_posts}}</td>
|
||||
<td>{{max_flagged_posts}} {{i18n max}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
|
@ -962,3 +962,12 @@ table.api-keys {
|
|||
width: 95%;
|
||||
}
|
||||
}
|
||||
|
||||
.leader-requirements {
|
||||
.fa-check {
|
||||
color: green;
|
||||
}
|
||||
.fa-times {
|
||||
color: red;
|
||||
}
|
||||
}
|
|
@ -161,6 +161,9 @@ class Admin::UsersController < Admin::AdminController
|
|||
end
|
||||
end
|
||||
|
||||
def leader_requirements
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
|
|
|
@ -4,31 +4,55 @@ class LeaderRequirements
|
|||
|
||||
include ActiveModel::Serialization
|
||||
|
||||
attr_accessor :days_visited, :time_period, :num_topics_with_replies, :num_topics_replied_to,
|
||||
:num_flagged_posts
|
||||
attr_accessor :time_period,
|
||||
: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)
|
||||
@user = user
|
||||
end
|
||||
|
||||
# TODO
|
||||
# def requirements_met?
|
||||
# false
|
||||
# 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
|
||||
@user.user_visits.where("visited_at > ?", time_period.days.ago).count
|
||||
end
|
||||
|
||||
def min_days_visited
|
||||
time_period * 0.5
|
||||
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 min_topics_with_replies
|
||||
5
|
||||
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 min_topics_replied_to
|
||||
10
|
||||
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
|
||||
|
||||
def max_flagged_posts
|
||||
5 # TODO what should it be?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -66,7 +66,7 @@ class AdminDetailedUserSerializer < AdminUserSerializer
|
|||
end
|
||||
|
||||
def include_leader_requirements?
|
||||
object.trust_level == TrustLevel.levels[:regular]
|
||||
object.has_trust_level?(:regular)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
class LeaderRequirementsSerializer < ApplicationSerializer
|
||||
attributes :time_period, :days_visited, :days_visited_percent,
|
||||
:num_topics_with_replies, :num_topics_replied_to, :num_flagged_posts
|
||||
|
||||
def days_visited_percent
|
||||
(days_visited * 100) / time_period
|
||||
end
|
||||
attributes :time_period,
|
||||
: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
|
||||
end
|
||||
|
|
|
@ -108,6 +108,7 @@ en:
|
|||
daily: "daily"
|
||||
weekly: "weekly"
|
||||
every_two_weeks: "every two weeks"
|
||||
max: "max"
|
||||
character_count:
|
||||
one: "{{count}} character"
|
||||
other: "{{count}} characters"
|
||||
|
@ -1486,10 +1487,13 @@ en:
|
|||
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."
|
||||
suspend_modal_title: "Suspend User"
|
||||
trust_level_2_users: "Trust Level 2 Users"
|
||||
trust_level_3_requirements: "Trust Level 3 Requirements"
|
||||
tl3_requirements:
|
||||
title: "Requirements for Trust Level 3"
|
||||
table_title: "In the last 100 days:"
|
||||
value_heading: "Value"
|
||||
requirement_heading: "Requirement"
|
||||
visits: "Visits"
|
||||
days: "days"
|
||||
topics_with_replies: "Topics with Replies"
|
||||
|
|
|
@ -58,6 +58,7 @@ Discourse::Application.routes.draw do
|
|||
put "block"
|
||||
put "unblock"
|
||||
put "trust_level"
|
||||
get "leader_requirements"
|
||||
end
|
||||
|
||||
resources :impersonate, constraints: AdminConstraint.new
|
||||
|
|
Loading…
Reference in New Issue
Block a user