FIX: Bug setting notification level to muted/ignored on user page (#16268)
This commit is contained in:
parent
f3aab19829
commit
a3563336db
|
@ -18,7 +18,7 @@ export default Controller.extend(ModalFunctionality, {
|
|||
this.set("loading", true);
|
||||
this.model
|
||||
.updateNotificationLevel({
|
||||
level: "ignored",
|
||||
level: "ignore",
|
||||
expiringAt: this.ignoredUntil,
|
||||
})
|
||||
.then(() => {
|
||||
|
|
|
@ -168,7 +168,8 @@ export default Controller.extend(CanCheckEmails, {
|
|||
"currentUser.ignored_ids",
|
||||
"model.ignored",
|
||||
"model.muted",
|
||||
function () {
|
||||
{
|
||||
get() {
|
||||
if (this.get("model.ignored")) {
|
||||
return "changeToIgnored";
|
||||
} else if (this.get("model.muted")) {
|
||||
|
@ -176,6 +177,10 @@ export default Controller.extend(CanCheckEmails, {
|
|||
} else {
|
||||
return "changeToNormal";
|
||||
}
|
||||
},
|
||||
set(key, value) {
|
||||
return value;
|
||||
},
|
||||
}
|
||||
),
|
||||
|
||||
|
@ -250,7 +255,7 @@ export default Controller.extend(CanCheckEmails, {
|
|||
},
|
||||
|
||||
updateNotificationLevel(level) {
|
||||
return this.model.updateNotificationLevel({ level });
|
||||
return this.model.updateNotificationLevel(level);
|
||||
},
|
||||
},
|
||||
});
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
{{/d-modal-body}}
|
||||
|
||||
<div class="modal-footer">
|
||||
{{d-button class="btn-primary"
|
||||
{{d-button class="btn-primary ignore-duration-save"
|
||||
disabled=saveDisabled
|
||||
label="user.user_notifications.ignore_duration_save"
|
||||
action=(action "ignore")}}
|
||||
|
|
|
@ -2,6 +2,7 @@ import EmberObject from "@ember/object";
|
|||
import User from "discourse/models/user";
|
||||
import selectKit from "discourse/tests/helpers/select-kit-helper";
|
||||
import sinon from "sinon";
|
||||
import userFixtures from "discourse/tests/fixtures/user-fixtures";
|
||||
import {
|
||||
acceptance,
|
||||
exists,
|
||||
|
@ -9,6 +10,7 @@ import {
|
|||
queryAll,
|
||||
} from "discourse/tests/helpers/qunit-helpers";
|
||||
import { click, currentRouteName, visit } from "@ember/test-helpers";
|
||||
import { cloneJSON } from "discourse-common/lib/object";
|
||||
import { test } from "qunit";
|
||||
|
||||
acceptance("User Routes", function (needs) {
|
||||
|
@ -177,3 +179,118 @@ acceptance("User - Saving user options", function (needs) {
|
|||
);
|
||||
});
|
||||
});
|
||||
|
||||
acceptance("User - Notification level dropdown visibility", function (needs) {
|
||||
needs.user({ username: "eviltrout", id: 1, ignored_ids: [] });
|
||||
|
||||
needs.pretender((server, helper) => {
|
||||
server.get("/u/charlie.json", () => {
|
||||
const cloned = cloneJSON(userFixtures["/u/charlie.json"]);
|
||||
cloned.user.can_ignore_user = false;
|
||||
cloned.user.can_mute_user = false;
|
||||
return helper.response(200, cloned);
|
||||
});
|
||||
});
|
||||
|
||||
test("Notification level button is not rendered for user who cannot mute or ignore another user", async function (assert) {
|
||||
await visit("/u/charlie");
|
||||
assert.notOk(exists(".user-notifications-dropdown"));
|
||||
});
|
||||
});
|
||||
|
||||
acceptance(
|
||||
"User - Muting other user with notification level dropdown",
|
||||
function (needs) {
|
||||
needs.user({ username: "eviltrout", id: 1, ignored_ids: [] });
|
||||
|
||||
needs.pretender((server, helper) => {
|
||||
server.get("/u/charlie.json", () => {
|
||||
const cloned = cloneJSON(userFixtures["/u/charlie.json"]);
|
||||
cloned.user.can_mute_user = true;
|
||||
return helper.response(200, cloned);
|
||||
});
|
||||
|
||||
server.put("/u/charlie/notification_level.json", (request) => {
|
||||
let requestParams = new URLSearchParams(request.requestBody);
|
||||
// Ensure the correct `notification_level` param is sent to the server
|
||||
if (requestParams.get("notification_level") === "mute") {
|
||||
return helper.response(200, {});
|
||||
} else {
|
||||
return helper.response(422, {});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test("Notification level is set to normal and can be changed to muted", async function (assert) {
|
||||
await visit("/u/charlie");
|
||||
assert.ok(
|
||||
exists(".user-notifications-dropdown"),
|
||||
"Notification level dropdown is present"
|
||||
);
|
||||
|
||||
const dropdown = selectKit(".user-notifications-dropdown");
|
||||
await dropdown.expand();
|
||||
assert.strictEqual(dropdown.selectedRow().value(), "changeToNormal");
|
||||
|
||||
await dropdown.selectRowByValue("changeToMuted");
|
||||
await dropdown.expand();
|
||||
assert.strictEqual(dropdown.selectedRow().value(), "changeToMuted");
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
acceptance(
|
||||
"User - Ignoring other user with notification level dropdown",
|
||||
function (needs) {
|
||||
needs.user({ username: "eviltrout", id: 1, ignored_ids: [] });
|
||||
|
||||
needs.pretender((server, helper) => {
|
||||
server.get("/u/charlie.json", () => {
|
||||
const cloned = cloneJSON(userFixtures["/u/charlie.json"]);
|
||||
cloned.user.can_ignore_user = true;
|
||||
return helper.response(200, cloned);
|
||||
});
|
||||
|
||||
server.put("/u/charlie/notification_level.json", (request) => {
|
||||
let requestParams = new URLSearchParams(request.requestBody);
|
||||
// Ensure the correct `notification_level` param is sent to the server
|
||||
if (requestParams.get("notification_level") === "ignore") {
|
||||
return helper.response(200, {});
|
||||
} else {
|
||||
return helper.response(422, {});
|
||||
}
|
||||
});
|
||||
});
|
||||
test("Notification level can be changed to ignored", async function (assert) {
|
||||
await visit("/u/charlie");
|
||||
assert.ok(
|
||||
exists(".user-notifications-dropdown"),
|
||||
"Notification level dropdown is present"
|
||||
);
|
||||
|
||||
const notificationLevelDropdown = selectKit(
|
||||
".user-notifications-dropdown"
|
||||
);
|
||||
await notificationLevelDropdown.expand();
|
||||
assert.strictEqual(
|
||||
notificationLevelDropdown.selectedRow().value(),
|
||||
"changeToNormal"
|
||||
);
|
||||
|
||||
await notificationLevelDropdown.selectRowByValue("changeToIgnored");
|
||||
assert.ok(exists(".ignore-duration-modal"));
|
||||
|
||||
const durationDropdown = selectKit(
|
||||
".ignore-duration-modal .future-date-input-selector"
|
||||
);
|
||||
await durationDropdown.expand();
|
||||
await durationDropdown.selectRowByIndex(0);
|
||||
await click(".modal-footer .ignore-duration-save");
|
||||
await notificationLevelDropdown.expand();
|
||||
assert.strictEqual(
|
||||
notificationLevelDropdown.selectedRow().value(),
|
||||
"changeToIgnored"
|
||||
);
|
||||
});
|
||||
}
|
||||
);
|
||||
|
|
|
@ -1365,6 +1365,8 @@ class UsersController < ApplicationController
|
|||
elsif params[:notification_level] == "normal"
|
||||
MutedUser.where(user: acting_user, muted_user: target_user).delete_all
|
||||
IgnoredUser.where(user: acting_user, ignored_user: target_user).delete_all
|
||||
else
|
||||
return render_json_error(I18n.t("notification_level.invalid_value", value: params[:notification_level]))
|
||||
end
|
||||
|
||||
render json: success_json
|
||||
|
|
|
@ -5154,6 +5154,7 @@ en:
|
|||
ignore_error: "Sorry, you can't ignore that user."
|
||||
mute_error: "Sorry, you can't mute that user."
|
||||
error: "Sorry, you cannot change the notification level for that user."
|
||||
invalid_value: '"%{value}" is not a valid notification level.'
|
||||
|
||||
discord:
|
||||
not_in_allowed_guild: "Authentication failed. You are not a member of a permitted Discord guild."
|
||||
|
|
|
@ -2876,6 +2876,16 @@ describe UsersController do
|
|||
end
|
||||
end
|
||||
|
||||
describe "#notification_level" do
|
||||
it 'raises an error when `notification_level` param is not a valid value' do
|
||||
sign_in(user)
|
||||
invalid_arg = "invalid"
|
||||
put "/u/#{user.username}/notification_level.json", params: { notification_level: invalid_arg }
|
||||
expect(response.status).to eq(422)
|
||||
expect(response.parsed_body["errors"].first).to eq(I18n.t("notification_level.invalid_value", value: invalid_arg))
|
||||
end
|
||||
end
|
||||
|
||||
describe '#ignore' do
|
||||
it 'raises an error when not logged in' do
|
||||
put "/u/#{user1.username}/notification_level.json", params: { notification_level: "" }
|
||||
|
|
Loading…
Reference in New Issue