mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
FEATURE: implement lock/unlock trust level mechanics
This commit is contained in:
parent
e665bfd72a
commit
0fc6c751cb
9 changed files with 52 additions and 37 deletions
|
@ -182,6 +182,10 @@ Discourse.AdminUser = Discourse.User.extend({
|
|||
});
|
||||
},
|
||||
|
||||
canLockTrustLevel: function(){
|
||||
return this.get('trust_level') < 4;
|
||||
}.property('trust_level'),
|
||||
|
||||
isSuspended: Em.computed.equal('suspended', true),
|
||||
canSuspend: Em.computed.not('staff'),
|
||||
|
||||
|
|
|
@ -10,15 +10,5 @@
|
|||
Discourse.AdminUserTl3RequirementsRoute = Discourse.Route.extend({
|
||||
model: function() {
|
||||
return this.modelFor('adminUser');
|
||||
},
|
||||
|
||||
actions: {
|
||||
lock_trust_level: function() {
|
||||
this.modelFor('adminUser').lockTrustLevel(true);
|
||||
},
|
||||
|
||||
unlock_trust_level: function() {
|
||||
this.modelFor('adminUser').lockTrustLevel(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -267,12 +267,6 @@
|
|||
<div class='field'>{{i18n trust_level}}</div>
|
||||
<div class="value">
|
||||
{{combo-box content=trustLevels value=trust_level nameProperty="detailedName"}}
|
||||
</div>
|
||||
<div class="controls">
|
||||
{{#if tl3Requirements}}
|
||||
{{#link-to 'adminUser.tl3Requirements' this class="btn"}}{{i18n admin.user.trust_level_3_requirements}}{{/link-to}}
|
||||
{{/if}}
|
||||
|
||||
{{#if dirty}}
|
||||
<div>
|
||||
<button class='btn ok no-text' {{action saveTrustLevel target="content"}}><i class='fa fa-check'></i></button>
|
||||
|
@ -280,6 +274,19 @@
|
|||
</div>
|
||||
{{/if}}
|
||||
</div>
|
||||
<div class="controls">
|
||||
{{#if model.canLockTrustLevel}}
|
||||
{{#if model.trust_level_locked}}
|
||||
<i title='{{i18n admin.user.trust_level_locked_tip}}' {{action lockTrustLevel false target="model"}} class='fa fa-lock'></i> <button class="btn" {{action lockTrustLevel false target="model"}}>{{i18n admin.user.unlock_trust_level}}</button>
|
||||
{{else}}
|
||||
<i title='{{i18n admin.user.trust_level_unlocked_tip}}' class='fa fa-unlock'></i> <button class="btn" {{action lockTrustLevel true target="model"}}>{{i18n admin.user.lock_trust_level}}</button>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
{{#if tl3Requirements}}
|
||||
{{#link-to 'adminUser.tl3Requirements' this class="btn"}}{{i18n admin.user.trust_level_3_requirements}}{{/link-to}}
|
||||
{{/if}}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div {{bind-attr class=":display-row isSuspended:highlight-danger"}}>
|
||||
|
|
|
@ -85,17 +85,6 @@
|
|||
<td>{{num_likes_received}}</td>
|
||||
<td>{{min_likes_received}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{{i18n admin.user.tl3_requirements.trust_level_locked}}</th>
|
||||
<td><i {{bind-attr class=":fa met.level_locked:fa-lock:fa-unlock"}}></i></td>
|
||||
{{#if trust_level_locked}}
|
||||
<td>{{i18n yes_value}}</td>
|
||||
<td><a class="btn" {{action unlock_trust_level}}>{{i18n admin.user.tl3_requirements.unlock_tl}}</a></td>
|
||||
{{else}}
|
||||
<td>{{i18n no_value}}</td>
|
||||
<td><a class="btn" {{action lock_trust_level}}>{{i18n admin.user.tl3_requirements.lock_tl}}</a></td>
|
||||
{{/if}}
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
{{/with}}
|
||||
|
|
|
@ -128,7 +128,20 @@ class Admin::UsersController < Admin::AdminController
|
|||
|
||||
def trust_level
|
||||
guardian.ensure_can_change_trust_level!(@user)
|
||||
@user.change_trust_level!(params[:level].to_i, log_action_for: current_user)
|
||||
level = params[:level].to_i
|
||||
|
||||
|
||||
if !@user.trust_level_locked && [0,1,2].include?(level) && Promotion.send("tl#{level+1}_met?", @user)
|
||||
@user.trust_level_locked = true
|
||||
@user.save
|
||||
end
|
||||
|
||||
if !@user.trust_level_locked && level == 3 && Promotion.tl3_lost?(@user)
|
||||
@user.trust_level_locked = true
|
||||
@user.save
|
||||
end
|
||||
|
||||
@user.change_trust_level!(level, log_action_for: current_user)
|
||||
|
||||
render_serialized(@user, AdminUserSerializer)
|
||||
rescue Discourse::InvalidAccess => e
|
||||
|
@ -138,13 +151,23 @@ class Admin::UsersController < Admin::AdminController
|
|||
def trust_level_lock
|
||||
guardian.ensure_can_change_trust_level!(@user)
|
||||
|
||||
new_lock = params[:locked]
|
||||
unless new_lock =~ /t|f|true|false/
|
||||
new_lock = params[:locked].to_s
|
||||
unless new_lock =~ /true|false/
|
||||
return render_json_error I18n.t('errors.invalid_boolaen')
|
||||
end
|
||||
|
||||
@user.trust_level_locked = !!(new_lock =~ /t|true/)
|
||||
@user.trust_level_locked = new_lock == "true"
|
||||
@user.save
|
||||
|
||||
unless @user.trust_level_locked
|
||||
p = Promotion.new(@user)
|
||||
2.times{ p.review }
|
||||
p.review_tl2
|
||||
if @user.trust_level == 3 && Promotion.tl3_lost?(@user)
|
||||
@user.change_trust_level!(2, log_action_for: current_user)
|
||||
end
|
||||
end
|
||||
|
||||
render nothing: true
|
||||
end
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ class AdminUserSerializer < BasicUserSerializer
|
|||
:created_at_age,
|
||||
:username_lower,
|
||||
:trust_level,
|
||||
:trust_level_locked,
|
||||
:flag_level,
|
||||
:username,
|
||||
:title,
|
||||
|
|
|
@ -1959,6 +1959,10 @@ en:
|
|||
suspend_modal_title: "Suspend User"
|
||||
trust_level_2_users: "Trust Level 2 Users"
|
||||
trust_level_3_requirements: "Trust Level 3 Requirements"
|
||||
trust_level_locked_tip: "trust level is locked, system will not promote or demote user"
|
||||
trust_level_unlocked_tip: "trust level is unlocked, system will may promote or demote user"
|
||||
lock_trust_level: "Lock Trust Level"
|
||||
unlock_trust_level: "Unlock Trust Level"
|
||||
tl3_requirements:
|
||||
title: "Requirements for Trust Level 3"
|
||||
table_title: "In the last 100 days:"
|
||||
|
@ -1975,9 +1979,6 @@ en:
|
|||
flagged_by_users: "Users Who Flagged"
|
||||
likes_given: "Likes Given"
|
||||
likes_received: "Likes Received"
|
||||
trust_level_locked: "Trust Level Locked"
|
||||
lock_tl: "Lock"
|
||||
unlock_tl: "Unlock"
|
||||
qualifies: "Qualifies for trust level 3."
|
||||
does_not_qualify: "Doesn't qualify for trust level 3."
|
||||
will_be_promoted: "Will be promoted soon."
|
||||
|
|
|
@ -297,7 +297,7 @@ en:
|
|||
title: "regular"
|
||||
elder:
|
||||
title: "leader"
|
||||
change_failed_explanation: "You attempted to demote %{user_name} to '%{new_trust_level}'. However their trust level is already '%{current_trust_level}'. %{user_name} will remain at '%{current_trust_level}'"
|
||||
change_failed_explanation: "You attempted to demote %{user_name} to '%{new_trust_level}'. However their trust level is already '%{current_trust_level}'. %{user_name} will remain at '%{current_trust_level}' - if you wish to demote user lock trust level first"
|
||||
|
||||
|
||||
rate_limiter:
|
||||
|
|
|
@ -12,7 +12,7 @@ class Promotion
|
|||
# Returns true if the user was promoted, false otherwise.
|
||||
def review
|
||||
# nil users are never promoted
|
||||
return false if @user.blank?
|
||||
return false if @user.blank? || @user.trust_level_locked
|
||||
|
||||
# Promotion beyond basic requires some expensive queries, so don't do that here.
|
||||
return false if @user.trust_level >= TrustLevel[2]
|
||||
|
@ -42,7 +42,7 @@ class Promotion
|
|||
old_level = @user.trust_level
|
||||
new_level = level
|
||||
|
||||
if new_level < old_level
|
||||
if new_level < old_level && !@user.trust_level_locked
|
||||
next_up = new_level+1
|
||||
key = "tl#{next_up}_met?"
|
||||
if self.class.respond_to?(key) && self.class.send(key, @user)
|
||||
|
|
Loading…
Reference in a new issue