FEATURE: add a button for staff to delete a user on their profile page

This commit is contained in:
Neil Lalonde 2014-11-14 15:23:09 -05:00
parent ac245ede43
commit ebcf21585c
4 changed files with 34 additions and 3 deletions

View File

@ -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

View File

@ -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});
});
}
}
});

View File

@ -126,6 +126,12 @@
{{/each}}
</dd>
{{/if}}
{{#if canDeleteUser}}
<button class="btn btn-danger" {{action "adminDelete"}}>
<i class="fa fa-exclamation-triangle"></i>
{{i18n admin.user.delete}}
</button>
{{/if}}
</dl>
{{plugin-outlet "user-profile-secondary"}}
</div>

View File

@ -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
###