FEATURE: staff can block users, which prevents them from creating topics and replies

This commit is contained in:
Neil Lalonde 2016-01-14 14:42:06 -05:00
parent 0dec98f50a
commit 12790d8dcc
3 changed files with 45 additions and 15 deletions

View File

@ -264,6 +264,7 @@ const AdminUser = Discourse.User.extend({
},
unblock() {
this.set('blockingUser', true);
return Discourse.ajax('/admin/users/' + this.id + '/unblock', {
type: 'PUT'
}).then(function() {
@ -275,14 +276,33 @@ const AdminUser = Discourse.User.extend({
},
block() {
return Discourse.ajax('/admin/users/' + this.id + '/block', {
type: 'PUT'
}).then(function() {
window.location.reload();
}).catch(function(e) {
var error = I18n.t('admin.user.block_failed', { error: "http: " + e.status + " - " + e.body });
bootbox.alert(error);
});
const user = this,
message = I18n.t("admin.user.block_confirm");
const performBlock = function() {
user.set('blockingUser', true);
return Discourse.ajax('/admin/users/' + user.id + '/block', {
type: 'PUT'
}).then(function() {
window.location.reload();
}).catch(function(e) {
var error = I18n.t('admin.user.block_failed', { error: "http: " + e.status + " - " + e.body });
bootbox.alert(error);
user.set('blockingUser', false);
});
};
const buttons = [{
"label": I18n.t("composer.cancel"),
"class": "cancel",
"link": true
}, {
"label": '<i class="fa fa-exclamation-triangle"></i>' + I18n.t('admin.user.block_accept'),
"class": "btn btn-danger",
"callback": function() { performBlock(); }
}];
bootbox.dialog(message, buttons, { "classes": "delete-user-modal" });
},
sendActivationEmail() {

View File

@ -327,13 +327,21 @@
<div class='field'>{{i18n 'admin.user.blocked'}}</div>
<div class='value'>{{model.blocked}}</div>
<div class='controls'>
{{#if model.blocked}}
<button class='btn' {{action "unblock" target="content"}}>
{{fa-icon "thumbs-o-up"}}
{{i18n 'admin.user.unblock'}}
</button>
{{i18n 'admin.user.block_explanation'}}
{{/if}}
{{#conditional-loading-spinner size="small" condition=model.blockingUser}}
{{#if model.blocked}}
<button class='btn' {{action "unblock" target="content"}}>
{{fa-icon "thumbs-o-up"}}
{{i18n 'admin.user.unblock'}}
</button>
{{i18n 'admin.user.block_explanation'}}
{{else}}
<button class='btn' {{action "block" target="content"}}>
{{fa-icon "ban"}}
{{i18n 'admin.user.block'}}
</button>
{{i18n 'admin.user.block_explanation'}}
{{/if}}
{{/conditional-loading-spinner}}
</div>
</div>
</section>

View File

@ -2448,6 +2448,8 @@ en:
deactivate_failed: "There was a problem deactivating the user."
unblock_failed: 'There was a problem unblocking the user.'
block_failed: 'There was a problem blocking the user.'
block_confirm: 'Are you sure you want to block this user? They will not be able to create any new topics or posts.'
block_accept: 'Yes, block this user'
deactivate_explanation: "A deactivated user must re-validate their email."
suspended_explanation: "A suspended user can't log in."
block_explanation: "A blocked user can't post or start topics."