mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
Can delete users via the moderation queue
This commit is contained in:
parent
3cb4554bbb
commit
ecafbb0a63
7 changed files with 70 additions and 5 deletions
|
@ -1,10 +1,16 @@
|
||||||
import BufferedContent from 'discourse/mixins/buffered-content';
|
import BufferedContent from 'discourse/mixins/buffered-content';
|
||||||
import { popupAjaxError } from 'discourse/lib/ajax-error';
|
import { popupAjaxError } from 'discourse/lib/ajax-error';
|
||||||
|
|
||||||
function updateState(state) {
|
function updateState(state, opts) {
|
||||||
|
opts = opts || {};
|
||||||
|
|
||||||
return function() {
|
return function() {
|
||||||
const post = this.get('post');
|
const post = this.get('post');
|
||||||
post.update({ state }).then(() => {
|
const args = { state };
|
||||||
|
|
||||||
|
if (opts.deleteUser) { args.delete_user = true; }
|
||||||
|
|
||||||
|
post.update(args).then(() => {
|
||||||
this.get('controllers.queued-posts.model').removeObject(post);
|
this.get('controllers.queued-posts.model').removeObject(post);
|
||||||
}).catch(popupAjaxError);
|
}).catch(popupAjaxError);
|
||||||
};
|
};
|
||||||
|
@ -17,10 +23,18 @@ export default Ember.Controller.extend(BufferedContent, {
|
||||||
|
|
||||||
editing: Discourse.computed.propertyEqual('model', 'currentlyEditing'),
|
editing: Discourse.computed.propertyEqual('model', 'currentlyEditing'),
|
||||||
|
|
||||||
|
_confirmDelete: updateState('rejected', {deleteUser: true}),
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
approve: updateState('approved'),
|
approve: updateState('approved'),
|
||||||
reject: updateState('rejected'),
|
reject: updateState('rejected'),
|
||||||
|
|
||||||
|
deleteUser() {
|
||||||
|
bootbox.confirm(I18n.t('queue.delete_prompt', {username: this.get('model.user.username')}), (confirmed) => {
|
||||||
|
if (confirmed) { this._confirmDelete(); }
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
edit() {
|
edit() {
|
||||||
// This is stupid but pagedown cannot be on the screen twice or it will break
|
// This is stupid but pagedown cannot be on the screen twice or it will break
|
||||||
this.set('currentlyEditing', null);
|
this.set('currentlyEditing', null);
|
||||||
|
|
|
@ -13,7 +13,7 @@ export default Ember.ArrayProxy.extend({
|
||||||
this.set('loadingMore', true);
|
this.set('loadingMore', true);
|
||||||
|
|
||||||
const self = this;
|
const self = this;
|
||||||
return this.store.appendResults(this, this.get('__type'), loadMoreUrl).then(function() {
|
return this.store.appendResults(this, this.get('__type'), loadMoreUrl).finally(function() {
|
||||||
self.set('loadingMore', false);
|
self.set('loadingMore', false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ export default Ember.ArrayProxy.extend({
|
||||||
|
|
||||||
const self = this;
|
const self = this;
|
||||||
this.set('refreshing', true);
|
this.set('refreshing', true);
|
||||||
return this.store.refreshResults(this, this.get('__type'), refreshUrl).then(function() {
|
return this.store.refreshResults(this, this.get('__type'), refreshUrl).finally(function() {
|
||||||
self.set('refreshing', false);
|
self.set('refreshing', false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,6 @@
|
||||||
icon="times"
|
icon="times"
|
||||||
disabled=ctrl.post.isSaving
|
disabled=ctrl.post.isSaving
|
||||||
class="btn-danger cancel"}}
|
class="btn-danger cancel"}}
|
||||||
|
|
||||||
{{else}}
|
{{else}}
|
||||||
{{d-button action="approve"
|
{{d-button action="approve"
|
||||||
disabled=ctrl.post.isSaving
|
disabled=ctrl.post.isSaving
|
||||||
|
@ -62,6 +61,11 @@
|
||||||
label="queue.reject"
|
label="queue.reject"
|
||||||
icon="times"
|
icon="times"
|
||||||
class="btn-danger reject"}}
|
class="btn-danger reject"}}
|
||||||
|
{{d-button action="deleteUser"
|
||||||
|
disabled=ctrl.post.isSaving
|
||||||
|
label="queue.delete_user"
|
||||||
|
icon="trash"
|
||||||
|
class="btn-danger delete-user"}}
|
||||||
{{d-button action="edit"
|
{{d-button action="edit"
|
||||||
disabled=ctrl.post.isSaving
|
disabled=ctrl.post.isSaving
|
||||||
label="queue.edit"
|
label="queue.edit"
|
||||||
|
|
|
@ -29,9 +29,29 @@ class QueuedPostsController < ApplicationController
|
||||||
qp.approve!(current_user)
|
qp.approve!(current_user)
|
||||||
elsif state == 'rejected'
|
elsif state == 'rejected'
|
||||||
qp.reject!(current_user)
|
qp.reject!(current_user)
|
||||||
|
if params[:queued_post][:delete_user] == 'true' && guardian.can_delete_user?(qp.user)
|
||||||
|
UserDestroyer.new(current_user).destroy(qp.user, user_deletion_opts)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
render_serialized(qp, QueuedPostSerializer, root: :queued_posts)
|
render_serialized(qp, QueuedPostSerializer, root: :queued_posts)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def user_deletion_opts
|
||||||
|
base = {
|
||||||
|
context: I18n.t('queue.delete_reason', {performed_by: current_user.username}),
|
||||||
|
delete_posts: true,
|
||||||
|
delete_as_spammer: true
|
||||||
|
}
|
||||||
|
|
||||||
|
if Rails.env.production? && ENV["Staging"].nil?
|
||||||
|
base.merge!({block_email: true, block_ip: true})
|
||||||
|
end
|
||||||
|
|
||||||
|
base
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -231,11 +231,13 @@ en:
|
||||||
topic: "Topic:"
|
topic: "Topic:"
|
||||||
approve: 'Approve'
|
approve: 'Approve'
|
||||||
reject: 'Reject'
|
reject: 'Reject'
|
||||||
|
delete_user: 'Delete User'
|
||||||
title: "Needs Approval"
|
title: "Needs Approval"
|
||||||
none: "There are no posts to review."
|
none: "There are no posts to review."
|
||||||
edit: "Edit"
|
edit: "Edit"
|
||||||
cancel: "Cancel"
|
cancel: "Cancel"
|
||||||
confirm: "Save Changes"
|
confirm: "Save Changes"
|
||||||
|
delete_prompt: "Are you sure you want to delete <b>%{username}</b>? This will remove all of their posts and block their email and ip address."
|
||||||
|
|
||||||
approval:
|
approval:
|
||||||
title: "Post Needs Approval"
|
title: "Post Needs Approval"
|
||||||
|
|
|
@ -177,6 +177,9 @@ en:
|
||||||
|
|
||||||
excerpt_image: "image"
|
excerpt_image: "image"
|
||||||
|
|
||||||
|
queue:
|
||||||
|
delete_reason: "Deleted via post moderation queue"
|
||||||
|
|
||||||
groups:
|
groups:
|
||||||
errors:
|
errors:
|
||||||
can_not_modify_automatic: "You can not modify an automatic group"
|
can_not_modify_automatic: "You can not modify an automatic group"
|
||||||
|
|
|
@ -20,6 +20,28 @@ test("reject a post", () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("delete user", () => {
|
||||||
|
visit("/queued-posts");
|
||||||
|
|
||||||
|
click('.queued-post:eq(0) button.delete-user');
|
||||||
|
andThen(() => {
|
||||||
|
ok(exists('.bootbox.modal'), 'it pops up a confirmation dialog');
|
||||||
|
});
|
||||||
|
|
||||||
|
click('.modal-footer a:eq(1)');
|
||||||
|
andThen(() => {
|
||||||
|
ok(!exists('.bootbox.modal'), 'it dismisses the modal');
|
||||||
|
ok(exists('.queued-post'), "it doesn't remove the post");
|
||||||
|
});
|
||||||
|
|
||||||
|
click('.queued-post:eq(0) button.delete-user');
|
||||||
|
click('.modal-footer a:eq(0)');
|
||||||
|
andThen(() => {
|
||||||
|
ok(!exists('.bootbox.modal'), 'it dismisses the modal');
|
||||||
|
ok(!exists('.queued-post'), "it removes the post");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test("edit a post - cancel", () => {
|
test("edit a post - cancel", () => {
|
||||||
visit("/queued-posts");
|
visit("/queued-posts");
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue