FIX: show/hide ignored users preferences (#11386)
* FIX: show/hide ignored users preferences based on the current user trust level and the appropriate site setting. * Allow us to await the `updateCurrentUser` call Co-authored-by: Robin Ward <robin.ward@gmail.com>
This commit is contained in:
parent
d7bd9aa3d0
commit
d1d87b6fa3
|
@ -1,5 +1,5 @@
|
|||
import { makeArray } from "discourse-common/lib/helpers";
|
||||
import { alias, gte, or, and } from "@ember/object/computed";
|
||||
import { alias, or, and } from "@ember/object/computed";
|
||||
import { action, computed } from "@ember/object";
|
||||
import Controller from "@ember/controller";
|
||||
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||
|
@ -7,8 +7,14 @@ import discourseComputed from "discourse-common/utils/decorators";
|
|||
|
||||
export default Controller.extend({
|
||||
ignoredUsernames: alias("model.ignored_usernames"),
|
||||
userIsMemberOrAbove: gte("model.trust_level", 2),
|
||||
ignoredEnabled: or("userIsMemberOrAbove", "model.staff"),
|
||||
|
||||
@discourseComputed("model.trust_level")
|
||||
userCanIgnore(trustLevel) {
|
||||
return trustLevel >= this.siteSettings.min_trust_level_to_allow_ignore;
|
||||
},
|
||||
|
||||
ignoredEnabled: or("userCanIgnore", "model.staff"),
|
||||
|
||||
allowPmUsersEnabled: and(
|
||||
"model.user_option.enable_allowed_pm_users",
|
||||
"model.user_option.allow_private_messages"
|
||||
|
|
|
@ -479,3 +479,30 @@ acceptance(
|
|||
});
|
||||
}
|
||||
);
|
||||
|
||||
acceptance("Ignored users", function (needs) {
|
||||
needs.user();
|
||||
needs.settings({ min_trust_level_to_allow_ignore: 1 });
|
||||
|
||||
test("when trust level < min level to ignore", async function (assert) {
|
||||
await visit(`/u/eviltrout/preferences/users`);
|
||||
await updateCurrentUser({ trust_level: 0, moderator: false, admin: false });
|
||||
|
||||
assert.ok(
|
||||
!exists(".user-ignore"),
|
||||
"it does not show the list of ignored users"
|
||||
);
|
||||
});
|
||||
|
||||
test("when trust level >= min level to ignore", async function (assert) {
|
||||
await visit(`/u/eviltrout/preferences/users`);
|
||||
await updateCurrentUser({ trust_level: 1 });
|
||||
assert.ok(exists(".user-ignore"), "it shows the list of ignored users");
|
||||
});
|
||||
|
||||
test("staff can always see ignored users", async function (assert) {
|
||||
await visit(`/u/eviltrout/preferences/users`);
|
||||
await updateCurrentUser({ moderator: true });
|
||||
assert.ok(exists(".user-ignore"), "it shows the list of ignored users");
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Promise } from "rsvp";
|
||||
import { isEmpty } from "@ember/utils";
|
||||
import { later } from "@ember/runloop";
|
||||
import { run, later } from "@ember/runloop";
|
||||
import sessionFixtures from "discourse/tests/fixtures/session-fixtures";
|
||||
import HeaderComponent from "discourse/components/site-header";
|
||||
import { forceMobile, resetMobile } from "discourse/lib/mobile";
|
||||
|
@ -44,7 +44,9 @@ export function currentUser() {
|
|||
}
|
||||
|
||||
export function updateCurrentUser(properties) {
|
||||
User.current().setProperties(properties);
|
||||
run(() => {
|
||||
User.current().setProperties(properties);
|
||||
});
|
||||
}
|
||||
|
||||
// Note: do not use this in acceptance tests. Use `loggedIn: true` instead
|
||||
|
|
|
@ -1422,6 +1422,7 @@ trust:
|
|||
min_trust_level_to_allow_ignore:
|
||||
default: 2
|
||||
enum: "TrustLevelSetting"
|
||||
client: true
|
||||
allow_flagging_staff: true
|
||||
send_tl1_welcome_message: true
|
||||
send_tl2_promotion_message: true
|
||||
|
|
Loading…
Reference in New Issue