From ebcf21585c1a7ab0697ee90a23169bd47f0b379a Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Fri, 14 Nov 2014 15:23:09 -0500 Subject: [PATCH] FEATURE: add a button for staff to delete a user on their profile page --- app/assets/javascripts/admin/models/admin_user.js | 5 ++++- .../javascripts/discourse/controllers/user.js.es6 | 14 +++++++++++++- .../javascripts/discourse/templates/user/user.hbs | 6 ++++++ app/serializers/user_serializer.rb | 12 +++++++++++- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/admin/models/admin_user.js b/app/assets/javascripts/admin/models/admin_user.js index 7b04290d4..c89b54097 100644 --- a/app/assets/javascripts/admin/models/admin_user.js +++ b/app/assets/javascripts/admin/models/admin_user.js @@ -314,7 +314,7 @@ Discourse.AdminUser = Discourse.User.extend({ } }.property('deleteForbidden'), - destroy: function() { + destroy: function(opts) { var user = this; var performDestroy = function(block) { @@ -324,6 +324,9 @@ Discourse.AdminUser = Discourse.User.extend({ formData["block_urls"] = true; formData["block_ip"] = true; } + if (opts && opts.deletePosts) { + formData["delete_posts"] = true; + } Discourse.ajax("/admin/users/" + user.get('id') + '.json', { type: 'DELETE', data: formData diff --git a/app/assets/javascripts/discourse/controllers/user.js.es6 b/app/assets/javascripts/discourse/controllers/user.js.es6 index 7fa9b8aea..c88a24264 100644 --- a/app/assets/javascripts/discourse/controllers/user.js.es6 +++ b/app/assets/javascripts/discourse/controllers/user.js.es6 @@ -38,6 +38,10 @@ export default ObjectController.extend(CanCheckEmails, { return Discourse.User.currentProp('can_invite_to_forum'); }.property(), + canDeleteUser: function() { + return this.get('can_be_deleted') && this.get('can_delete_all_posts'); + }.property('can_be_deleted', 'can_delete_all_posts'), + loadedAllItems: function() { switch (this.get("datasource")) { case "badges": { return true; } @@ -61,5 +65,13 @@ export default ObjectController.extend(CanCheckEmails, { privateMessagesActive: Em.computed.equal('pmView', 'index'), privateMessagesMineActive: Em.computed.equal('pmView', 'mine'), - privateMessagesUnreadActive: Em.computed.equal('pmView', 'unread') + privateMessagesUnreadActive: Em.computed.equal('pmView', 'unread'), + + actions: { + adminDelete: function() { + Discourse.AdminUser.find(this.get('username').toLowerCase()).then(function(user){ + user.destroy({deletePosts: true}); + }); + } + } }); diff --git a/app/assets/javascripts/discourse/templates/user/user.hbs b/app/assets/javascripts/discourse/templates/user/user.hbs index 0656ca879..640d809b1 100644 --- a/app/assets/javascripts/discourse/templates/user/user.hbs +++ b/app/assets/javascripts/discourse/templates/user/user.hbs @@ -126,6 +126,12 @@ {{/each}} {{/if}} + {{#if canDeleteUser}} + + {{/if}} {{plugin-outlet "user-profile-secondary"}} diff --git a/app/serializers/user_serializer.rb b/app/serializers/user_serializer.rb index 00d5f27dc..a5b116b0b 100644 --- a/app/serializers/user_serializer.rb +++ b/app/serializers/user_serializer.rb @@ -59,7 +59,9 @@ class UserSerializer < BasicUserSerializer :number_of_flagged_posts, :number_of_flags_given, :number_of_suspensions, - :number_of_warnings + :number_of_warnings, + :can_be_deleted, + :can_delete_all_posts private_attributes :locale, :email_digests, @@ -239,6 +241,14 @@ class UserSerializer < BasicUserSerializer UserHistory.for(object, :suspend_user).count end + def can_be_deleted + scope.can_delete_user?(object) + end + + def can_delete_all_posts + scope.can_delete_all_posts?(object) + end + ### ### PRIVATE ATTRIBUTES ###