From 36d836ba403bce0be00381198256333c99a05a41 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Fri, 26 Jan 2018 15:40:03 -0500 Subject: [PATCH] Link suspensions to the staff logs page --- .../admin/controllers/admin-user-index.js.es6 | 6 ++++++ .../admin/routes/admin-user-index.js.es6 | 10 ---------- .../javascripts/admin/services/admin-tools.js.es6 | 12 ++++++++++++ .../javascripts/discourse/controllers/user.js.es6 | 14 ++++++++++---- .../javascripts/discourse/templates/user.hbs | 6 +++++- 5 files changed, 33 insertions(+), 15 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 bdc783592da..41869d976e2 100644 --- a/app/assets/javascripts/admin/controllers/admin-user-index.js.es6 +++ b/app/assets/javascripts/admin/controllers/admin-user-index.js.es6 @@ -64,6 +64,12 @@ export default Ember.Controller.extend(CanCheckEmails, { anonymize() { return this.get('model').anonymize(); }, destroy() { return this.get('model').destroy(); }, + viewActionLogs() { + this.get('adminTools').showActionLogs(this, { + target_user: this.get('model.username'), + }); + }, + showFlagsReceived() { this.get('adminTools').showFlagsReceived(this.get('model')); }, diff --git a/app/assets/javascripts/admin/routes/admin-user-index.js.es6 b/app/assets/javascripts/admin/routes/admin-user-index.js.es6 index 36d1d8cedd0..930b45c8b14 100644 --- a/app/assets/javascripts/admin/routes/admin-user-index.js.es6 +++ b/app/assets/javascripts/admin/routes/admin-user-index.js.es6 @@ -21,15 +21,5 @@ export default Discourse.Route.extend({ availableGroups: this._availableGroups, model }); - }, - - actions: { - viewActionLogs(username) { - const controller = this.controllerFor('adminLogs.staffActionLogs'); - this.transitionTo('adminLogs.staffActionLogs').then(() => { - controller.set('filters', Ember.Object.create()); - controller._changeFilters({ target_user: username }); - }); - } } }); diff --git a/app/assets/javascripts/admin/services/admin-tools.js.es6 b/app/assets/javascripts/admin/services/admin-tools.js.es6 index 42be2eadd75..a6a56d0f145 100644 --- a/app/assets/javascripts/admin/services/admin-tools.js.es6 +++ b/app/assets/javascripts/admin/services/admin-tools.js.es6 @@ -17,6 +17,14 @@ export default Ember.Service.extend({ this.siteSettings = getOwner(this).lookup('site-settings:main'); }, + showActionLogs(target, filters) { + const controller = getOwner(target).lookup('controller:adminLogs.staffActionLogs'); + target.transitionToRoute('adminLogs.staffActionLogs').then(() => { + controller.set('filters', Ember.Object.create()); + controller._changeFilters(filters); + }); + }, + showFlagsReceived(user) { showModal(`admin-flags-received`, { admin: true, model: user }); }, @@ -25,6 +33,10 @@ export default Ember.Service.extend({ return AdminUser.find(userId).then(au => this.spammerDetails(au)); }, + deleteUser(id) { + AdminUser.find(id).then(user => user.destroy({ deletePosts: true })); + }, + spammerDetails(adminUser) { return { deleteUser: () => this._deleteSpammer(adminUser), diff --git a/app/assets/javascripts/discourse/controllers/user.js.es6 b/app/assets/javascripts/discourse/controllers/user.js.es6 index 37e88e21acc..c11210ee8ba 100644 --- a/app/assets/javascripts/discourse/controllers/user.js.es6 +++ b/app/assets/javascripts/discourse/controllers/user.js.es6 @@ -1,12 +1,14 @@ import CanCheckEmails from 'discourse/mixins/can-check-emails'; import computed from 'ember-addons/ember-computed-decorators'; import User from 'discourse/models/user'; +import optionalService from 'discourse/lib/optional-service'; export default Ember.Controller.extend(CanCheckEmails, { indexStream: false, application: Ember.inject.controller(), userNotifications: Ember.inject.controller('user-notifications'), currentPath: Ember.computed.alias('application.currentPath'), + adminTools: optionalService(), @computed("content.username") viewingSelf(username) { @@ -93,11 +95,15 @@ export default Ember.Controller.extend(CanCheckEmails, { this.set('forceExpand', true); }, - adminDelete() { - // I really want this deferred, don't want to bring in all this code till used - const AdminUser = requirejs('admin/models/admin-user').default; - AdminUser.find(this.get('model.id')).then(user => user.destroy({deletePosts: true})); + showSuspensions() { + this.get('adminTools').showActionLogs(this, { + target_user: this.get('model.username'), + action_name: 'suspend_user' + }); }, + adminDelete() { + this.get('adminTools').deleteUser(this.get('model.id')); + } } }); diff --git a/app/assets/javascripts/discourse/templates/user.hbs b/app/assets/javascripts/discourse/templates/user.hbs index e97ab3cefbe..882b312c80c 100644 --- a/app/assets/javascripts/discourse/templates/user.hbs +++ b/app/assets/javascripts/discourse/templates/user.hbs @@ -23,7 +23,11 @@ {{/if}} {{#if model.number_of_suspensions}} -
{{model.number_of_suspensions}}{{i18n 'user.staff_counters.suspensions'}}
+
+ + {{model.number_of_suspensions}}{{i18n 'user.staff_counters.suspensions'}} + +
{{/if}} {{#if model.warnings_received_count}}
{{model.warnings_received_count}}{{i18n 'user.staff_counters.warnings_received'}}