diff --git a/app/assets/javascripts/admin/controllers/admin_flags_controller.js b/app/assets/javascripts/admin/controllers/admin_flags_controller.js index 8218f1734..f65c89cdb 100644 --- a/app/assets/javascripts/admin/controllers/admin_flags_controller.js +++ b/app/assets/javascripts/admin/controllers/admin_flags_controller.js @@ -56,6 +56,16 @@ Discourse.AdminFlagsController = Ember.ArrayController.extend({ }); }, + /** + Deletes a user and all posts and topics created by that user. + + @method deleteSpammer + @param {Discourse.FlaggedPost} item The post to delete + **/ + deleteSpammer: function(item) { + item.get('user').deleteAsSpammer(function() { window.location.reload(); }); + }, + /** Are we viewing the 'old' view? diff --git a/app/assets/javascripts/admin/models/admin_user.js b/app/assets/javascripts/admin/models/admin_user.js index 8f20c1a28..0ec3f8ca5 100644 --- a/app/assets/javascripts/admin/models/admin_user.js +++ b/app/assets/javascripts/admin/models/admin_user.js @@ -264,6 +264,36 @@ Discourse.AdminUser = Discourse.User.extend({ bootbox.dialog(message, buttons, {"classes": "delete-user-modal"}); }, + deleteAsSpammer: function(successCallback) { + var user = this; + var message = I18n.t('flagging.delete_confirm', {posts: user.get('post_count'), topics: user.get('topic_count'), email: user.get('email')}); + var buttons = [{ + "label": I18n.t("composer.cancel"), + "class": "cancel", + "link": true + }, { + "label": I18n.t("flagging.yes_delete_spammer"), + "class": "btn btn-danger", + "callback": function() { + Discourse.ajax("/admin/users/" + user.get('id') + '.json', { + type: 'DELETE', + data: {delete_posts: true, block_email: true} + }).then(function(data) { + if (data.deleted) { + bootbox.alert(I18n.t("admin.user.deleted"), function() { + if (successCallback) successCallback(); + }); + } else { + bootbox.alert(I18n.t("admin.user.delete_failed")); + } + }, function(jqXHR, status, error) { + bootbox.alert(I18n.t("admin.user.delete_failed")); + }); + } + }]; + bootbox.dialog(message, buttons, {"classes": "flagging-delete-spammer"}); + }, + loadDetails: function() { var model = this; if (model.get('loadedDetails')) { return Ember.RSVP.resolve(model); } diff --git a/app/assets/javascripts/admin/models/flagged_post.js b/app/assets/javascripts/admin/models/flagged_post.js index 4acc260d4..05d26e1ff 100644 --- a/app/assets/javascripts/admin/models/flagged_post.js +++ b/app/assets/javascripts/admin/models/flagged_post.js @@ -57,6 +57,14 @@ Discourse.FlaggedPost = Discourse.Post.extend({ return !this.get('topic_visible'); }.property('topic_hidden'), + flaggedForSpam: function() { + return !_.every(this.get('post_actions'), function(action) { return action.name_key !== 'spam'; }); + }.property('post_actions.@each.name_key'), + + canDeleteAsSpammer: function() { + return (Discourse.User.current('staff') && this.get('flaggedForSpam') && this.get('user.can_delete_all_posts') && this.get('user.can_be_deleted')); + }.property('flaggedForSpam'), + deletePost: function() { if (this.get('post_number') === '1') { return Discourse.ajax('/t/' + this.topic_id, { type: 'DELETE', cache: false }); diff --git a/app/assets/javascripts/admin/templates/flags.js.handlebars b/app/assets/javascripts/admin/templates/flags.js.handlebars index 20f3b91f2..2baad82fa 100644 --- a/app/assets/javascripts/admin/templates/flags.js.handlebars +++ b/app/assets/javascripts/admin/templates/flags.js.handlebars @@ -22,17 +22,17 @@
- {{#each flag in content}} -{{#linkTo 'adminUser' this.user}}{{avatar this.user imageSize="small"}} {{/linkTo}} @@ -50,7 +50,7 @@ | |||
{{#if adminActiveFlagsView}} - {{#if flag.postHidden}} - - + {{#if flaggedPost.postHidden}} + + {{else}} - - + + {{/if}} - + + {{#if flaggedPost.canDeleteAsSpammer}} + + {{/if}} + + {{/if}} |