From c658fb6e3172ad2851a291cc17c155966e1e3238 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Fri, 25 May 2018 11:33:01 -0400 Subject: [PATCH] Move some display logic out of model, upgrade old code patterns --- .../admin/controllers/admin-user-index.js.es6 | 30 ++++++++++++++++++ .../admin/models/admin-user.js.es6 | 31 ------------------- .../admin/templates/user-index.hbs | 17 +++++----- app/serializers/penalty_counts_serializer.rb | 6 +++- 4 files changed, 42 insertions(+), 42 deletions(-) diff --git a/app/assets/javascripts/admin/controllers/admin-user-index.js.es6 b/app/assets/javascripts/admin/controllers/admin-user-index.js.es6 index ee49a1c119e..cbba833b659 100644 --- a/app/assets/javascripts/admin/controllers/admin-user-index.js.es6 +++ b/app/assets/javascripts/admin/controllers/admin-user-index.js.es6 @@ -50,6 +50,36 @@ export default Ember.Controller.extend(CanCheckEmails, { return userPath(`${username}/preferences`); }, + @computed('model.can_delete_all_posts', 'model.staff', 'model.post_count') + deleteAllPostsExplanation(canDeleteAllPosts, staff, postCount) { + if (canDeleteAllPosts) { + return null; + } + + if (staff) { + return I18n.t('admin.user.delete_posts_forbidden_because_staff'); + } + if (postCount > this.siteSettings.delete_all_posts_max) { + return I18n.t('admin.user.cant_delete_all_too_many_posts', {count: this.siteSettings.delete_all_posts_max}); + } else { + return I18n.t('admin.user.cant_delete_all_posts', {count: this.siteSettings.delete_user_max_post_age}); + } + }, + + @computed('model.canBeDeleted', 'model.staff') + deleteExplanation(canBeDeleted, staff) { + if (canBeDeleted) { + return null; + } + + if (staff) { + return I18n.t('admin.user.delete_forbidden_because_staff'); + } else { + return I18n.t('admin.user.delete_forbidden', {count: this.siteSettings.delete_user_max_post_age}); + } + }, + + actions: { impersonate() { return this.get("model").impersonate(); }, diff --git a/app/assets/javascripts/admin/models/admin-user.js.es6 b/app/assets/javascripts/admin/models/admin-user.js.es6 index 0d3edd9675b..ba7528258d7 100644 --- a/app/assets/javascripts/admin/models/admin-user.js.es6 +++ b/app/assets/javascripts/admin/models/admin-user.js.es6 @@ -87,21 +87,6 @@ const AdminUser = Discourse.User.extend({ }).then(() => this.set('api_key', null)); }, - deleteAllPostsExplanation: function() { - if (!this.get('can_delete_all_posts')) { - if (this.get('deleteForbidden') && this.get('staff')) { - return I18n.t('admin.user.delete_posts_forbidden_because_staff'); - } - if (this.get('post_count') > Discourse.SiteSettings.delete_all_posts_max) { - return I18n.t('admin.user.cant_delete_all_too_many_posts', {count: Discourse.SiteSettings.delete_all_posts_max}); - } else { - return I18n.t('admin.user.cant_delete_all_posts', {count: Discourse.SiteSettings.delete_user_max_post_age}); - } - } else { - return null; - } - }.property('can_delete_all_posts', 'deleteForbidden'), - deleteAllPosts() { const user = this, message = I18n.messageFormat('admin.user.delete_all_posts_confirm_MF', { "POSTS": user.get('post_count'), "TOPICS": user.get('topic_count') }), @@ -351,8 +336,6 @@ const AdminUser = Discourse.User.extend({ }).catch(popupAjaxError); }, - anonymizeForbidden: Em.computed.not("can_be_anonymized"), - anonymize() { const user = this, message = I18n.t("admin.user.anonymize_confirm"); @@ -391,20 +374,6 @@ const AdminUser = Discourse.User.extend({ bootbox.dialog(message, buttons, { "classes": "delete-user-modal" }); }, - deleteForbidden: Em.computed.not("canBeDeleted"), - - deleteExplanation: function() { - if (this.get('deleteForbidden')) { - if (this.get('staff')) { - return I18n.t('admin.user.delete_forbidden_because_staff'); - } else { - return I18n.t('admin.user.delete_forbidden', {count: Discourse.SiteSettings.delete_user_max_post_age}); - } - } else { - return null; - } - }.property('deleteForbidden'), - destroy(opts) { const user = this, message = I18n.t("admin.user.delete_confirm"), diff --git a/app/assets/javascripts/admin/templates/user-index.hbs b/app/assets/javascripts/admin/templates/user-index.hbs index 9fd8d35fff7..aec1b986f20 100644 --- a/app/assets/javascripts/admin/templates/user-index.hbs +++ b/app/assets/javascripts/admin/templates/user-index.hbs @@ -408,7 +408,6 @@ {{/if}} - {{#if currentUser.admin}} @@ -469,7 +468,7 @@ {{d-button class="btn-danger" action="deleteAllPosts" icon="trash-o" label="admin.user.delete_all_posts"}} {{/if}} {{else}} - {{model.deleteAllPostsExplanation}} + {{deleteAllPostsExplanation}} {{/if}} @@ -550,28 +549,26 @@ {{/if}} {{/if}} - {{#unless model.anonymizeForbidden}} + {{#if model.can_be_anonymized}} {{d-button label="admin.user.anonymize" icon="exclamation-triangle" class="btn-danger" - disabled=model.anonymizeForbidden action="anonymize"}} - {{/unless}} + {{/if}} - {{#unless model.deleteForbidden}} + {{#if model.canBeDeleted}} {{d-button label="admin.user.delete" icon="exclamation-triangle" class="btn-danger" - disabled=model.deleteForbidden action="destroy"}} - {{/unless}} + {{/if}} - {{#if model.deleteExplanation}} + {{#if deleteExplanation}}

- {{d-icon "exclamation-triangle"}} {{model.deleteExplanation}} + {{d-icon "exclamation-triangle"}} {{deleteExplanation}}
{{/if}} diff --git a/app/serializers/penalty_counts_serializer.rb b/app/serializers/penalty_counts_serializer.rb index 68d1641f14b..94f5722ee0d 100644 --- a/app/serializers/penalty_counts_serializer.rb +++ b/app/serializers/penalty_counts_serializer.rb @@ -1,5 +1,9 @@ class PenaltyCountsSerializer < ApplicationSerializer - attributes :silenced, :suspended + attributes :silenced, :suspended, :total + + def total + object.silenced + object.suspended + end def silenced object.silenced