Refactor user suspension modal
This commit is contained in:
parent
561fa7d0cd
commit
daceeb9700
|
@ -6,6 +6,7 @@ import { popupAjaxError } from 'discourse/lib/ajax-error';
|
||||||
import computed from 'ember-addons/ember-computed-decorators';
|
import computed from 'ember-addons/ember-computed-decorators';
|
||||||
|
|
||||||
export default Ember.Controller.extend(CanCheckEmails, {
|
export default Ember.Controller.extend(CanCheckEmails, {
|
||||||
|
adminTools: Ember.inject.service(),
|
||||||
editingUsername: false,
|
editingUsername: false,
|
||||||
editingName: false,
|
editingName: false,
|
||||||
editingTitle: false,
|
editingTitle: false,
|
||||||
|
@ -64,6 +65,11 @@ export default Ember.Controller.extend(CanCheckEmails, {
|
||||||
anonymize() { return this.get('model').anonymize(); },
|
anonymize() { return this.get('model').anonymize(); },
|
||||||
destroy() { return this.get('model').destroy(); },
|
destroy() { return this.get('model').destroy(); },
|
||||||
|
|
||||||
|
showSuspendModal() {
|
||||||
|
this.get('adminTools').showSuspendModal(this.get('model'));
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
toggleUsernameEdit() {
|
toggleUsernameEdit() {
|
||||||
this.set('userUsernameValue', this.get('model.username'));
|
this.set('userUsernameValue', this.get('model.username'));
|
||||||
this.toggleProperty('editingUsername');
|
this.toggleProperty('editingUsername');
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import showModal from 'discourse/lib/show-modal';
|
|
||||||
import Group from 'discourse/models/group';
|
import Group from 'discourse/models/group';
|
||||||
|
|
||||||
export default Discourse.Route.extend({
|
export default Discourse.Route.extend({
|
||||||
|
@ -25,11 +24,6 @@ export default Discourse.Route.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
showSuspendModal(model) {
|
|
||||||
showModal('admin-suspend-user', { model, admin: true });
|
|
||||||
this.controllerFor('modal').set('modalClass', 'suspend-user-modal');
|
|
||||||
},
|
|
||||||
|
|
||||||
viewActionLogs(username) {
|
viewActionLogs(username) {
|
||||||
const controller = this.controllerFor('adminLogs.staffActionLogs');
|
const controller = this.controllerFor('adminLogs.staffActionLogs');
|
||||||
this.transitionTo('adminLogs.staffActionLogs').then(() => {
|
this.transitionTo('adminLogs.staffActionLogs').then(() => {
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
import AdminUser from 'admin/models/admin-user';
|
import AdminUser from 'admin/models/admin-user';
|
||||||
import { iconHTML } from 'discourse-common/lib/icon-library';
|
import { iconHTML } from 'discourse-common/lib/icon-library';
|
||||||
import { ajax } from 'discourse/lib/ajax';
|
import { ajax } from 'discourse/lib/ajax';
|
||||||
|
import showModal from 'discourse/lib/show-modal';
|
||||||
|
|
||||||
export default Ember.Service.extend({
|
export default Ember.Service.extend({
|
||||||
|
|
||||||
|
@ -19,6 +20,14 @@ export default Ember.Service.extend({
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
showSuspendModal(user) {
|
||||||
|
showModal('admin-suspend-user', {
|
||||||
|
user,
|
||||||
|
admin: true,
|
||||||
|
modalClass: 'suspend-user-modal'
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
_deleteSpammer(adminUser) {
|
_deleteSpammer(adminUser) {
|
||||||
return adminUser.checkEmail().then(() => {
|
return adminUser.checkEmail().then(() => {
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{{#d-modal-body title="admin.user.suspend_modal_title"}}
|
{{#d-modal-body title="admin.user.suspend_modal_title"}}
|
||||||
<form>
|
<form>
|
||||||
{{i18n 'admin.user.suspend_duration'}}
|
{{i18n 'admin.user.suspend_duration'}}
|
||||||
{{text-field value=duration maxlength="5" autofocus="autofocus"}}
|
{{text-field value=duration maxlength="5" autofocus="autofocus" class="suspend-duration"}}
|
||||||
{{i18n 'admin.user.suspend_duration_units'}}<br/>
|
{{i18n 'admin.user.suspend_duration_units'}}<br/>
|
||||||
<br/>
|
<br/>
|
||||||
{{#if siteSettings.hide_suspension_reasons}}
|
{{#if siteSettings.hide_suspension_reasons}}
|
||||||
|
@ -11,11 +11,16 @@
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
<br/>
|
<br/>
|
||||||
{{text-field value=reason class="span8"}}
|
{{text-field value=reason class="suspend-reason"}}
|
||||||
</form>
|
</form>
|
||||||
{{/d-modal-body}}
|
{{/d-modal-body}}
|
||||||
|
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button class='btn btn-danger' {{action "suspend"}} disabled={{submitDisabled}}>{{d-icon "ban"}}{{i18n 'admin.user.suspend'}}</button>
|
{{d-button
|
||||||
<a {{action "closeModal"}}>{{i18n 'cancel'}}</a>
|
class="btn-danger perform-suspend"
|
||||||
|
action="suspend"
|
||||||
|
disabled=submitDisabled
|
||||||
|
icon="ban"
|
||||||
|
label="admin.user.suspend"}}
|
||||||
|
<a {{action "closeModal"}} class="cancel-suspend">{{i18n 'cancel'}}</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -306,7 +306,11 @@
|
||||||
{{i18n 'admin.user.suspended_explanation'}}
|
{{i18n 'admin.user.suspended_explanation'}}
|
||||||
{{else}}
|
{{else}}
|
||||||
{{#if model.canSuspend}}
|
{{#if model.canSuspend}}
|
||||||
{{d-button class="btn-danger" action="showSuspendModal" actionParam=model icon="ban" label="admin.user.suspend"}}
|
{{d-button
|
||||||
|
class="btn-danger suspend-user"
|
||||||
|
action="showSuspendModal"
|
||||||
|
icon="ban"
|
||||||
|
label="admin.user.suspend"}}
|
||||||
{{i18n 'admin.user.suspended_explanation'}}
|
{{i18n 'admin.user.suspended_explanation'}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
import { acceptance } from "helpers/qunit-helpers";
|
||||||
|
|
||||||
|
acceptance("Admin - Suspend User", { loggedIn: true });
|
||||||
|
|
||||||
|
QUnit.test("suspend a user - cancel", assert => {
|
||||||
|
visit("/admin/users/1234/regular");
|
||||||
|
click(".suspend-user");
|
||||||
|
|
||||||
|
andThen(() => {
|
||||||
|
assert.equal(find('.suspend-user-modal:visible').length, 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
click('.cancel-suspend');
|
||||||
|
andThen(() => {
|
||||||
|
assert.equal(find('.suspend-user-modal:visible').length, 0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
QUnit.test("suspend a user", assert => {
|
||||||
|
visit("/admin/users/1234/regular");
|
||||||
|
click(".suspend-user");
|
||||||
|
|
||||||
|
andThen(() => {
|
||||||
|
assert.equal(find('.perform-suspend[disabled]').length, 1, 'disabled by default');
|
||||||
|
});
|
||||||
|
fillIn('.suspend-duration', 12);
|
||||||
|
fillIn('.suspend-reason', "for breaking the rules");
|
||||||
|
andThen(() => {
|
||||||
|
assert.equal(find('.perform-suspend[disabled]').length, 0);
|
||||||
|
});
|
||||||
|
click('.perform-suspend');
|
||||||
|
andThen(() => {
|
||||||
|
assert.equal(find('.suspend-user-modal:visible').length, 0);
|
||||||
|
});
|
||||||
|
});
|
|
@ -23,4 +23,4 @@ QUnit.test('revoke key', function(assert) {
|
||||||
return adminUser.revokeApiKey().then(function() {
|
return adminUser.revokeApiKey().then(function() {
|
||||||
assert.blank(adminUser.get('api_key'), 'it cleared the api_key');
|
assert.blank(adminUser.get('api_key'), 'it cleared the api_key');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -271,6 +271,10 @@ export default function() {
|
||||||
return response(200, fixturesByUrl['/groups.json']);
|
return response(200, fixturesByUrl['/groups.json']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.get("groups/search.json", () => {
|
||||||
|
return response(200, []);
|
||||||
|
});
|
||||||
|
|
||||||
this.get("/groups/discourse/topics.json", () => {
|
this.get("/groups/discourse/topics.json", () => {
|
||||||
return response(200, fixturesByUrl['/groups/discourse/posts.json']);
|
return response(200, fixturesByUrl['/groups/discourse/posts.json']);
|
||||||
});
|
});
|
||||||
|
@ -345,6 +349,14 @@ export default function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
this.get('/tag_groups', () => response(200, {tag_groups: []}));
|
this.get('/tag_groups', () => response(200, {tag_groups: []}));
|
||||||
|
|
||||||
|
this.get('/admin/users/1234.json', request => {
|
||||||
|
return response(200, {
|
||||||
|
id: 1234,
|
||||||
|
username: 'regular',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
this.post('/admin/users/:user_id/generate_api_key', success);
|
this.post('/admin/users/:user_id/generate_api_key', success);
|
||||||
this.delete('/admin/users/:user_id/revoke_api_key', success);
|
this.delete('/admin/users/:user_id/revoke_api_key', success);
|
||||||
this.delete('/admin/users/:user_id.json', () => response(200, { deleted: true }));
|
this.delete('/admin/users/:user_id.json', () => response(200, { deleted: true }));
|
||||||
|
|
Loading…
Reference in New Issue