Skip to content

A platform for community discussion. Free, open, simple.

FIX: ensure context is still visible on handled flags with lingering actions (#43495)

Kris0d241b1f717c
diff --git a/frontend/discourse/app/models/reviewable.js b/frontend/discourse/app/models/reviewable.js
index 062278d08fc..b486c4092bb 100644
--- a/frontend/discourse/app/models/reviewable.js
+++ b/frontend/discourse/app/models/reviewable.js
@@ -123,12 +123,21 @@ export default class Reviewable extends RestModel {
});
}
- @computed("resolvedType", "reviewable_scores", "status")
+ get #offersApproveUser() {
+ return this.bundled_actions?.some((bundle) =>
+ bundle.actions?.some((action) => action.server_action === "approve_user")
+ );
+ }
+
+ @computed("resolvedType", "reviewable_scores", "status", "bundled_actions")
get userReviewableContextQuestion() {
if (this.resolvedType === "ReviewableUser") {
- // in this case the only remaining action is "scrub record" so the question shouldn't show
+ // the spam question must not outlive the pending state: its only
+ // remaining answer would be a "Yes" that approves the user
if (this.status !== PENDING) {
- return null;
+ return this.#offersApproveUser
+ ? i18n("review.context_question.approve_user")
+ : null;
}
const isSuspectUser = this.reviewable_scores?.some(
(score) => score.reason_type === "suspect_user"
diff --git a/frontend/discourse/tests/integration/components/reviewable/item-test.gjs b/frontend/discourse/tests/integration/components/reviewable/item-test.gjs
index 9ca6d77fc9c..d65dcebac73 100644
--- a/frontend/discourse/tests/integration/components/reviewable/item-test.gjs
+++ b/frontend/discourse/tests/integration/components/reviewable/item-test.gjs
@@ -4,7 +4,7 @@ import { click, fillIn, render, settled } from "@ember/test-helpers";
import { module, test } from "qunit";
import ReviewableItem from "discourse/components/reviewable/item";
import { withPluginApi } from "discourse/lib/plugin-api";
-import { APPROVED, PENDING } from "discourse/models/reviewable";
+import { APPROVED, PENDING, REJECTED } from "discourse/models/reviewable";
import { CLAIMED, UNCLAIMED } from "discourse/models/reviewable-history";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { publishToMessageBus } from "discourse/tests/helpers/qunit-helpers";
@@ -29,6 +29,35 @@ function plainReviewable(attrs = {}) {
return { id: 456, topic: null, reviewable_scores: [], ...attrs };
}
+function userReviewable(context, attrs = {}) {
+ return getOwner(context)
+ .lookup("service:store")
+ .createRecord("reviewable", {
+ id: 901,
+ type: "ReviewableUser",
+ status: PENDING,
+ topic: null,
+ reviewable_scores: [],
+ reviewable_histories: [],
+ claimed_by: null,
+ ...attrs,
+ });
+}
+
+function actionBundle(serverAction, label) {
+ return {
+ id: `901-${serverAction}`,
+ actions: [
+ {
+ id: `901-user-${serverAction}`,
+ action_name: `user-${serverAction}`,
+ server_action: serverAction,
+ label,
+ },
+ ],
+ };
+}
+
function editableReviewable(id) {
return plainReviewable({
id,
@@ -103,6 +132,51 @@ module("Integration | Component | Reviewable | Item", function (hooks) {
.exists();
});
+ test("keeps asking the approve question once a user reviewable is resolved but still approvable", async function (assert) {
+ const resolved = userReviewable(this, {
+ status: REJECTED,
+ bundled_actions: [actionBundle("approve_user", "Yes")],
+ });
+
+ await render(
+ <template><ReviewableItem @reviewable={{resolved}} /></template>
+ );
+
+ assert.dom(".review-item__aside-title").hasText("Approve this user?");
+ });
+
+ test("does not reuse the spam question once a user reviewable is resolved", async function (assert) {
+ const resolved = userReviewable(this, {
+ status: REJECTED,
+ reviewable_scores: [
+ {
+ reason_type: "suspect_user",
+ score_type: { type: "needs_approval", title: "Needs approval" },
+ },
+ ],
+ bundled_actions: [actionBundle("approve_user", "Yes")],
+ });
+
+ await render(
+ <template><ReviewableItem @reviewable={{resolved}} /></template>
+ );
+
+ assert.dom(".review-item__aside-title").hasText("Approve this user?");
+ });
+
+ test("falls back to the generic heading when a resolved user reviewable can only be scrubbed", async function (assert) {
+ const resolved = userReviewable(this, {
+ status: REJECTED,
+ bundled_actions: [actionBundle("scrub", "Scrub record")],
+ });
+
+ await render(
+ <template><ReviewableItem @reviewable={{resolved}} /></template>
+ );
+
+ assert.dom(".review-item__aside-title").hasText("Moderator actions");
+ });
+
test("does not render help resources when not required", async function (assert) {
await render(
<template><ReviewableItem @reviewable={{reviewable}} /></template>