FEATURE: Add a messages view for all official warnings of a user (#12659)

Moderators are allowed to see the warnings list, with an access warning.

https://meta.discourse.org/t/why-arent-warnings-easily-accessible-like-suspensions-are/164043
This commit is contained in:
Kane York
2021-06-14 14:01:17 -07:00
committed by GitHub
parent 7d8483f698
commit c780ae9d25
13 changed files with 118 additions and 2 deletions
@@ -5,6 +5,7 @@ import I18n from "I18n";
import Topic from "discourse/models/topic";
import bootbox from "bootbox";
import discourseComputed from "discourse-common/utils/decorators";
import { VIEW_NAME_WARNINGS } from "discourse/routes/user-private-messages-warnings";
export default Controller.extend({
userTopicsList: controller("user-topics-list"),
@@ -27,6 +28,11 @@ export default Controller.extend({
return bulkSelectEnabled && selected && selected.length > 0;
},
@discourseComputed("viewingSelf", "pmView", "currentUser.admin")
showWarningsWarning(viewingSelf, pmView, isAdmin) {
return pmView === VIEW_NAME_WARNINGS && !viewingSelf && !isAdmin;
},
bulkOperation(operation) {
const selected = this.selected;
let params = { type: operation };
@@ -149,6 +149,7 @@ export default function () {
function () {
this.route("sent");
this.route("archive");
this.route("warnings");
this.route("group", { path: "group/:name" });
this.route("groupArchive", { path: "group/:name/archive" });
this.route("tags");
@@ -0,0 +1,9 @@
import createPMRoute from "discourse/routes/build-private-messages-route";
export const VIEW_NAME_WARNINGS = "warnings";
export default createPMRoute(
VIEW_NAME_WARNINGS,
"private-messages-warnings",
null /* no message bus notifications */
);
@@ -38,7 +38,11 @@
</div>
{{/if}}
{{#if model.warnings_received_count}}
<div><span class="warnings-received">{{model.warnings_received_count}}</span>{{i18n "user.staff_counters.warnings_received"}}</div>
<div>
{{#link-to "userPrivateMessages.warnings" model}}
<span class="warnings-received">{{model.warnings_received_count}}</span>{{i18n "user.staff_counters.warnings_received"}}
{{/link-to}}
</div>
{{/if}}
</div>
{{/if}}
@@ -87,5 +87,8 @@
}}
{{/if}}
</div>
{{#if showWarningsWarning}}
<div class="alert alert-info">{{html-safe (i18n "admin.user.warnings_list_warning")}}</div>
{{/if}}
{{outlet}}
</section>
@@ -121,3 +121,18 @@ acceptance(
});
}
);
acceptance("User Routes - Moderator viewing warnings", function (needs) {
needs.user({
username: "notEviltrout",
moderator: true,
staff: true,
admin: false,
});
test("Messages - Warnings", async function (assert) {
await visit("/u/eviltrout/messages/warnings");
assert.ok($("body.user-messages-page").length, "has the body class");
assert.ok($("div.alert-info").length, "has the permissions alert");
});
});
@@ -210,6 +210,10 @@ export function applyDefaultHandlers(pretender) {
return response(fixturesByUrl["/topics/private-messages/eviltrout.json"]);
});
pretender.get("/topics/private-messages-warnings/eviltrout.json", () => {
return response(fixturesByUrl["/topics/private-messages/eviltrout.json"]);
});
pretender.get("/topics/feature_stats.json", () => {
return response({
pinned_in_category_count: 0,