A platform for community discussion. Free, open, simple.
FIX: hide approve on reviewed user reviewables (#43586)
Krisf170d799fc12
diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rbindex 45f648b39f8..67306e9eef3 100644--- a/app/controllers/admin/users_controller.rb+++ b/app/controllers/admin/users_controller.rb@@ -311,12 +311,18 @@ class Admin::UsersController < Admin::StaffControllerReviewableUser.find_by(target: @user) ||Jobs::CreateUserReviewable.new.execute(user_id: @user.id).reviewable- reviewable.perform(current_user, :approve_user)+ reviewable.perform(current_user, :approve_user, allow_reviewed: true)render body: nilenddef approve_bulk- Reviewable.bulk_perform_targets(current_user, :approve_user, "ReviewableUser", params[:users])+ Reviewable.bulk_perform_targets(+ current_user,+ :approve_user,+ "ReviewableUser",+ params[:users],+ allow_reviewed: true,+ )render body: nilenddiff --git a/app/models/reviewable_user.rb b/app/models/reviewable_user.rbindex 40666a6c58c..a8b56685549 100644--- a/app/models/reviewable_user.rb+++ b/app/models/reviewable_user.rb@@ -52,7 +52,10 @@ class ReviewableUser < Reviewablebuild_action(actions, :remove_avatar, icon: "user-xmark", secondary: true)end- if guardian.can_approve?(target)+ # Reviewed items must not offer approval in the queue, but approving an+ # unapproved user directly (e.g. from the admin user page) still goes+ # through this action, so those callers opt in with `allow_reviewed`.+ if (pending? || args[:allow_reviewed]) && guardian.can_approve?(target)actions.add(:approve_user, bundle: nil) do |a|a.icon = "user-plus"a.completed_message = "reviewables.actions.approve_user.complete"diff --git a/frontend/discourse/app/models/reviewable.js b/frontend/discourse/app/models/reviewable.jsindex b486c4092bb..062278d08fc 100644--- a/frontend/discourse/app/models/reviewable.js+++ b/frontend/discourse/app/models/reviewable.js@@ -123,21 +123,12 @@ export default class Reviewable extends RestModel {});}- get #offersApproveUser() {- return this.bundled_actions?.some((bundle) =>- bundle.actions?.some((action) => action.server_action === "approve_user")- );- }-- @computed("resolvedType", "reviewable_scores", "status", "bundled_actions")+ @computed("resolvedType", "reviewable_scores", "status")get userReviewableContextQuestion() {if (this.resolvedType === "ReviewableUser") {- // the spam question must not outlive the pending state: its only- // remaining answer would be a "Yes" that approves the user+ // in this case the only remaining action is "scrub record" so the question shouldn't showif (this.status !== PENDING) {- return this.#offersApproveUser- ? i18n("review.context_question.approve_user")- : null;+ return 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.gjsindex a328ff43d01..f2c434a06dc 100644--- a/frontend/discourse/tests/integration/components/reviewable/item-test.gjs+++ b/frontend/discourse/tests/integration/components/reviewable/item-test.gjs@@ -132,38 +132,6 @@ 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,diff --git a/spec/models/reviewable_user_spec.rb b/spec/models/reviewable_user_spec.rbindex 0cff3c1ed90..aa8b78fe59d 100644--- a/spec/models/reviewable_user_spec.rb+++ b/spec/models/reviewable_user_spec.rb@@ -111,12 +111,16 @@ RSpec.describe ReviewableUser, type: :model doexpect(actions.has?(:delete_user_block)).to eq(false)end- it "still allows approving in the rejected state" do+ it "doesn't return anything in the rejected state while the user is still unapproved" doreviewable.status = Reviewable.statuses[:rejected]actions = reviewable.actions_for(Guardian.new(moderator))- expect(actions.has?(:approve_user)).to eq(true)- expect(actions.has?(:delete_user)).to eq(false)- expect(actions.has?(:delete_user_block)).to eq(false)+ expect(actions.bundles).to be_empty+ end++ it "returns only the approve action in the rejected state when reviewed items are allowed" do+ reviewable.status = Reviewable.statuses[:rejected]+ actions = reviewable.actions_for(Guardian.new(moderator), allow_reviewed: true)+ expect(actions.bundles.flat_map(&:actions).map(&:server_action)).to eq(["approve_user"])endit "doesn't ask for a rejection reason when deleting a user who was flagged as a possible spammer" do@@ -325,7 +329,7 @@ RSpec.describe ReviewableUser, type: :model do)reviewable.update!(status: Reviewable.statuses[:rejected])- reviewable.perform(moderator, :approve_user)+ reviewable.perform(moderator, :approve_user, allow_reviewed: true)expect(reviewable.reload).to be_approvedexpect(score.reload.status).to eq("agreed")diff --git a/spec/requests/admin/users_controller_spec.rb b/spec/requests/admin/users_controller_spec.rbindex 7e3149e93da..f011c8daf46 100644--- a/spec/requests/admin/users_controller_spec.rb+++ b/spec/requests/admin/users_controller_spec.rb@@ -471,6 +471,18 @@ RSpec.describe Admin::UsersController doevil_trout.reloadexpect(evil_trout.approved).to eq(true)end++ it "approves a user whose previous reviewable was rejected" do+ evil_trout.update!(active: true)+ reviewable =+ Fabricate(:reviewable_user, target: evil_trout, status: Reviewable.statuses[:rejected])++ put "/admin/users/approve-bulk.json", params: { users: [evil_trout.id] }++ expect(response.status).to eq(200)+ expect(evil_trout.reload).to be_approved+ expect(reviewable.reload).to be_approved+ endendcontext "when logged in as an admin" dodiff --git a/spec/system/page_objects/pages/review.rb b/spec/system/page_objects/pages/review.rbindex 00a0d464fc9..3a1bd9cc547 100644--- a/spec/system/page_objects/pages/review.rb+++ b/spec/system/page_objects/pages/review.rb@@ -56,6 +56,12 @@ module PageObjectspage.has_no_css?(REVIEWABLE_ACTION_DROPDOWN)end+ def has_no_reviewable_actions?(reviewable)+ within(reviewable_by_id(reviewable.id)) do+ page.has_no_css?(".reviewable-action, #{REVIEWABLE_ACTION_DROPDOWN}")+ end+ end+def has_reviewable_items?(count:)page.has_css?(".review-item", count: count)end@@ -71,10 +77,6 @@ module PageObjectswithin(reviewable_by_id(reviewable.id)) { page.has_css?(".user-scrub") }end- def has_no_scrub_button?(reviewable)- within(reviewable_by_id(reviewable.id)) { page.has_no_css?(".user-scrub") }- end-def click_scrub_user_buttonfind(".user-scrub").clickenddiff --git a/spec/system/reviewables_spec.rb b/spec/system/reviewables_spec.rbindex 739f5d15bfa..fb1adf4e646 100644--- a/spec/system/reviewables_spec.rb+++ b/spec/system/reviewables_spec.rb@@ -164,7 +164,7 @@ describe "Reviewables" doexpect(suspend_user_modal).to be_closedexpect(review_page).to have_reviewable_with_rejected_status(suspect_reviewable)- expect(review_page).to have_no_scrub_button(suspect_reviewable)+ expect(review_page).to have_no_reviewable_actions(suspect_reviewable)expect(suspect_user.reload).to be_suspendedexpect(UserHistory.find_by(