diff --git a/app/assets/javascripts/admin/models/admin_user.js b/app/assets/javascripts/admin/models/admin_user.js index a37a7cf7d74..f27a1abd859 100644 --- a/app/assets/javascripts/admin/models/admin_user.js +++ b/app/assets/javascripts/admin/models/admin_user.js @@ -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'), diff --git a/app/assets/javascripts/admin/routes/admin_user_tl3_requirements_route.js b/app/assets/javascripts/admin/routes/admin_user_tl3_requirements_route.js index cc71692e9bd..934ccbb556c 100644 --- a/app/assets/javascripts/admin/routes/admin_user_tl3_requirements_route.js +++ b/app/assets/javascripts/admin/routes/admin_user_tl3_requirements_route.js @@ -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); - } } }); diff --git a/app/assets/javascripts/admin/templates/user_index.hbs b/app/assets/javascripts/admin/templates/user_index.hbs index f4f11d36743..7bac456429f 100644 --- a/app/assets/javascripts/admin/templates/user_index.hbs +++ b/app/assets/javascripts/admin/templates/user_index.hbs @@ -267,12 +267,6 @@
{{i18n trust_level}}
{{combo-box content=trustLevels value=trust_level nameProperty="detailedName"}} -
-
- {{#if tl3Requirements}} - {{#link-to 'adminUser.tl3Requirements' this class="btn"}}{{i18n admin.user.trust_level_3_requirements}}{{/link-to}} - {{/if}} - {{#if dirty}}
@@ -280,6 +274,19 @@
{{/if}}
+
+ {{#if model.canLockTrustLevel}} + {{#if model.trust_level_locked}} + + {{else}} + + {{/if}} + {{/if}} + {{#if tl3Requirements}} + {{#link-to 'adminUser.tl3Requirements' this class="btn"}}{{i18n admin.user.trust_level_3_requirements}}{{/link-to}} + {{/if}} + +
diff --git a/app/assets/javascripts/admin/templates/user_leader_requirements.hbs b/app/assets/javascripts/admin/templates/user_leader_requirements.hbs index 0a5d4c01b20..50c27bc4f53 100644 --- a/app/assets/javascripts/admin/templates/user_leader_requirements.hbs +++ b/app/assets/javascripts/admin/templates/user_leader_requirements.hbs @@ -85,17 +85,6 @@ {{num_likes_received}} {{min_likes_received}} - - {{i18n admin.user.tl3_requirements.trust_level_locked}} - - {{#if trust_level_locked}} - {{i18n yes_value}} - {{i18n admin.user.tl3_requirements.unlock_tl}} - {{else}} - {{i18n no_value}} - {{i18n admin.user.tl3_requirements.lock_tl}} - {{/if}} - {{/with}} diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 728b7d513a4..94665f59294 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -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 diff --git a/app/serializers/admin_user_serializer.rb b/app/serializers/admin_user_serializer.rb index 3a765e20aa2..461bf67d20c 100644 --- a/app/serializers/admin_user_serializer.rb +++ b/app/serializers/admin_user_serializer.rb @@ -9,6 +9,7 @@ class AdminUserSerializer < BasicUserSerializer :created_at_age, :username_lower, :trust_level, + :trust_level_locked, :flag_level, :username, :title, diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 3fd009e8870..9278a17e962 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -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." diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index aa6af53ad55..4d4ec306cf3 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -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: diff --git a/lib/promotion.rb b/lib/promotion.rb index e0f4d273858..14e89c86886 100644 --- a/lib/promotion.rb +++ b/lib/promotion.rb @@ -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)