Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: users list show was loading multiple times with different params #7058

Merged
merged 3 commits into from Feb 26, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,12 +1,11 @@
import debounce from "discourse/lib/debounce";
import { i18n } from "discourse/lib/computed";
import AdminUser from "admin/models/admin-user";
import { observes } from "ember-addons/ember-computed-decorators";
import CanCheckEmails from "discourse/mixins/can-check-emails";

export default Ember.Controller.extend(CanCheckEmails, {
model: null,
query: null,
queryParams: ["order", "ascending"],
order: null,
ascending: null,
showEmails: false,
Expand Down Expand Up @@ -47,8 +46,7 @@ export default Ember.Controller.extend(CanCheckEmails, {
this._refreshUsers();
}, 250).observes("listFilter"),

@observes("order", "ascending")
_refreshUsers: function() {
_refreshUsers() {
this.set("refreshing", true);

AdminUser.findAll(this.get("query"), {
Expand All @@ -57,12 +55,8 @@ export default Ember.Controller.extend(CanCheckEmails, {
order: this.get("order"),
ascending: this.get("ascending")
})
.then(result => {
this.set("model", result);
})
.finally(() => {
this.set("refreshing", false);
});
.then(result => this.set("model", result))
.finally(() => this.set("refreshing", false));
},

actions: {
Expand Down Expand Up @@ -95,7 +89,7 @@ export default Ember.Controller.extend(CanCheckEmails, {

showEmails: function() {
this.set("showEmails", true);
this._refreshUsers(true);
this._refreshUsers();
}
}
});
33 changes: 21 additions & 12 deletions app/assets/javascripts/admin/routes/admin-users-list-show.js.es6
@@ -1,17 +1,26 @@
import AdminUser from "admin/models/admin-user";

export default Discourse.Route.extend({
model: function(params) {
this.userFilter = params.filter;
return AdminUser.findAll(params.filter);
queryParams: {
order: { refreshModel: true },
ascending: { refreshModel: true }
},

setupController: function(controller, model) {
controller.setProperties({
model: model,
query: this.userFilter,
showEmails: false,
refreshing: false
});
beforeModel(transition) {
ZogStriP marked this conversation as resolved.
Show resolved Hide resolved
const routeName = "adminUsersList.show";

if (transition.targetName === routeName) {
const params = transition.params[routeName];
const controller = this.controllerFor(routeName);
if (controller) {
controller.setProperties({
order: transition.queryParams.order,
ascending: transition.queryParams.ascending,
query: params.filter,
showEmails: false,
refreshing: false
});

controller._refreshUsers();
}
}
}
});
39 changes: 39 additions & 0 deletions test/javascripts/acceptance/admin-users-list-test.js.es6
Expand Up @@ -8,3 +8,42 @@ QUnit.test("lists users", async assert => {
assert.ok(exists(".users-list .user"));
assert.ok(!exists(".user:eq(0) .email small"), "escapes email");
});

QUnit.test("switching tabs", async assert => {
const activeUser = "<small>eviltrout@example.com</small>";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird, you are calling text and it's returning the <small> tags? I thought it only ever returned text.

Since this is the case, think it would be better if your selector was ... .email small instead so you can compare the email address without markup.

Copy link
Contributor Author

@jjaffeux jjaffeux Feb 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done this way because this is escaped and I would need to htmlilfy it first before being able to search inside it. See the existing test and the !exists :

QUnit.test("lists users", async assert => {
  await visit("/admin/users/list/active");

  assert.ok(exists(".users-list .user"));
-->  assert.ok(!exists(".user:eq(0) .email small"), "escapes email");
});

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood, thanks for clarifying!

const suspectUser = "<small>sam@example.com</small>";
const activeTitle = I18n.t("admin.users.titles.active");
const suspectTitle = I18n.t("admin.users.titles.suspect");

await visit("/admin/users/list/active");

assert.equal(find(".admin-title h2").text(), activeTitle);
assert.equal(
find(".users-list .user:nth-child(1) .email").text(),
activeUser
);

await click('a[href="/admin/users/list/suspect"]');

assert.equal(find(".admin-title h2").text(), suspectTitle);
assert.equal(
find(".users-list .user:nth-child(1) .email").text(),
suspectUser
);

await click(".users-list .sortable:nth-child(4)");

assert.equal(find(".admin-title h2").text(), suspectTitle);
assert.equal(
find(".users-list .user:nth-child(1) .email").text(),
suspectUser
);

await click('a[href="/admin/users/list/active"]');

assert.equal(find(".admin-title h2").text(), activeTitle);
assert.equal(
find(".users-list .user:nth-child(1) .email").text(),
activeUser
);
});
10 changes: 10 additions & 0 deletions test/javascripts/helpers/create-pretender.js.es6
Expand Up @@ -458,6 +458,16 @@ export default function() {
]);
});

this.get("/admin/users/list/suspect.json", () => {
return response(200, [
{
id: 2,
username: "sam",
email: "<small>sam@example.com</small>"
}
]);
});

this.get("/admin/customize/site_texts", request => {
if (request.queryParams.overridden) {
return response(200, { site_texts: [overridden] });
Expand Down