Skip to content

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

FEATURE: Update the ReviewableUser UI for the review queue refresh. (#35515)

Gary Pendergast3b3064498bee
diff --git a/app/assets/stylesheets/common/base/review.scss b/app/assets/stylesheets/common/base/review.scss
index 6b3ef10cc2e..3315ffe2fe6 100644
--- a/app/assets/stylesheets/common/base/review.scss
+++ b/app/assets/stylesheets/common/base/review.scss
@@ -225,7 +225,7 @@
}
&.--other,
- &.--needs_approval {
+ &.--needs-approval {
background-color: var(--d-review-reason-other-bg);
color: var(--d-review-reason-other-text);
}
@@ -265,7 +265,8 @@
color: var(--d-review-reason-inappropriate-count-text);
}
- &.--other {
+ &.--other,
+ &.--needs-approval {
background-color: var(--d-review-reason-other-count-bg);
color: var(--d-review-reason-other-count-text);
}
diff --git a/app/models/concerns/reviewable_action_builder.rb b/app/models/concerns/reviewable_action_builder.rb
index c5961bd913e..fecc17b6e94 100644
--- a/app/models/concerns/reviewable_action_builder.rb
+++ b/app/models/concerns/reviewable_action_builder.rb
@@ -244,12 +244,15 @@ module ReviewableActionBuilder
private
# Returns the user associated with the reviewable, if applicable.
- # For most reviewables, this will be the user who created the reviewable, though some
- # reviewables may need to implement this method differently (for example, ReviewableUser).
+ # For most reviewables, this will be the user who created the reviewable target.
#
# @return [User] The user associated with the reviewable.
def target_user
- try(:target_created_by)
+ if target_type == "User"
+ try(:target)
+ else
+ try(:target_created_by)
+ end
end
# Returns the post associated with the reviewable, if applicable.
diff --git a/app/models/reviewable_user.rb b/app/models/reviewable_user.rb
index 75141590a90..c7b42133117 100644
--- a/app/models/reviewable_user.rb
+++ b/app/models/reviewable_user.rb
@@ -11,19 +11,40 @@ class ReviewableUser < Reviewable
{ reject_reason: params[:reject_reason], send_email: params[:send_email] != "false" }
end
- def build_actions(actions, guardian, args)
- return unless pending?
- super
- end
-
def build_legacy_combined_actions(actions, guardian, args)
+ return if status != "pending"
build_action(actions, :approve_user, icon: "user-plus") if guardian.can_approve?(target)
delete_user_actions(actions, require_reject_reason: !is_a_suspect_user?)
end
+ def build_actions(actions, guardian, args)
+ return if approved?
+ super
+ end
+
+ # TODO (reviewable-refresh): Move to build_actions when fully migrated to new UI
def build_new_separated_actions
- build_legacy_combined_actions(@actions, @guardian, @action_args)
+ bundle_actions = {}
+ if status == "pending"
+ bundle_actions[:approve_user] = {} if target_user && !target_user.approved? &&
+ guardian.can_approve?(target_user)
+
+ if @guardian.can_delete_user?(target_user)
+ bundle_actions[:delete_user] = {}
+ bundle_actions[:delete_user_block] = {}
+ end
+ end
+ if status == "rejected" && !payload["scrubbed_by"]
+ bundle_actions[:scrub] = { client_action: "scrub" }
+ end
+
+ build_bundle(
+ "#{id}-user-actions",
+ "reviewables.actions.user_actions.bundle_title",
+ bundle_actions,
+ source: "core",
+ )
end
def perform_approve_user(performed_by, args)
@@ -102,6 +123,7 @@ class ReviewableUser < Reviewable
else
I18n.t("user.destroy_reasons.reviewable_reject")
end
+ delete_args[:from_reviewable] = true
destroyer.destroy(target, delete_args)
rescue UserDestroyer::PostsExistError, Discourse::InvalidAccess
diff --git a/app/serializers/reviewable_serializer.rb b/app/serializers/reviewable_serializer.rb
index a37dd550fb8..6ceecbb2ad9 100644
--- a/app/serializers/reviewable_serializer.rb
+++ b/app/serializers/reviewable_serializer.rb
@@ -9,6 +9,8 @@ class ReviewableSerializer < ApplicationSerializer
:type_source,
:topic_id,
:topic_url,
+ :target_type,
+ :target_id,
:target_url,
:topic_tags,
:category_id,
@@ -143,7 +145,11 @@ class ReviewableSerializer < ApplicationSerializer
end
def target_created_by
- user = object.target_created_by
+ if object.target_type == "User"
+ user = object.target
+ else
+ user = object.target_created_by
+ end
return nil unless user
serializer_class =
diff --git a/app/services/user_destroyer.rb b/app/services/user_destroyer.rb
index 39fc1431620..acfec664534 100644
--- a/app/services/user_destroyer.rb
+++ b/app/services/user_destroyer.rb
@@ -114,10 +114,10 @@ class UserDestroyer
end
end
- # After the user is deleted, remove the reviewable
- if reviewable = ReviewableUser.pending.find_by(target: user)
- reviewable.perform(@actor, :delete_user)
- end
+ # After the user is deleted, remove the reviewable unless request comes from reviewable
+ return result if opts[:from_reviewable]
+ reviewable = ReviewableUser.pending.find_by(target: user)
+ reviewable.perform(@actor, :delete_user) if reviewable
result
end
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index efc7a2130ee..3aacd7353a9 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -5852,6 +5852,8 @@ en:
reject_and_keep_deleted:
title: "Keep post deleted"
complete: "Post rejected and kept deleted."
+ scrub:
+ title: Scrub record
approve_and_restore:
title: "Approve and Restore post"
complete: "Post approved and restored."
@@ -5915,6 +5917,10 @@ en:
title: "Delete & block"
description: "Delete the user and block their IP/email"
complete: "User deleted and blocked"
+ delete_user_block:
+ title: "Delete & block"
+ description: "Delete the user and block their IP/email"
+ complete: "User deleted and blocked"
email_style:
html_missing_placeholder: "The html template must include %{placeholder}"
diff --git a/frontend/discourse/app/components/reviewable-refresh/insights.gjs b/frontend/discourse/app/components/reviewable-refresh/insights.gjs
index 1a4ad90fe97..1f7658c09b0 100644
--- a/frontend/discourse/app/components/reviewable-refresh/insights.gjs
+++ b/frontend/discourse/app/components/reviewable-refresh/insights.gjs
@@ -31,12 +31,12 @@ export default class ReviewableInsights extends Component {
});
// Similar posts insight
- if (user.flags_agreed) {
+ if (user?.flags_agreed) {
insights.push({
icon: "clock-rotate-left",
label: i18n("review.insights.similar_posts"),
description: i18n("review.insights.flagged_in_timeframe", {
- count: user.user_stat.flags_agreed,
+ count: user.user_stat?.flags_agreed || 0,
}),
});
}
@@ -44,19 +44,21 @@ export default class ReviewableInsights extends Component {
// User activity insight
const activities = [];
- if (Date.now() - Date.parse(user.created_at) < 7 * 24 * 60 * 60 * 1000) {
- activities.push(i18n("review.insights.activities.new_account"));
- }
- if (user.trustLevel) {
- activities.push(
- i18n("review.insights.activities.trust_level", {
- trustLevelName: user.trustLevel.name,
- })
- );
+ if (user) {
+ if (Date.now() - Date.parse(user.created_at) < 7 * 24 * 60 * 60 * 1000) {
+ activities.push(i18n("review.insights.activities.new_account"));
+ }
+ if (user.trustLevel) {
+ activities.push(
+ i18n("review.insights.activities.trust_level", {
+ trustLevelName: user.trustLevel.name,
+ })
+ );
+ }
}
activities.push(
i18n("review.insights.activities.posts", {
- count: user.post_count,
+ count: user?.post_count || 0,
})
);
insights.push({
@@ -66,7 +68,7 @@ export default class ReviewableInsights extends Component {
});
// Visibility insight
- if (!reviewable?.topic?.visible) {
+ if (reviewable?.topic && !reviewable?.topic?.visible) {
insights.push({
icon: "far-eye-slash",
label: i18n("review.insights.visibility"),
diff --git a/frontend/discourse/app/components/reviewable-refresh/item.gjs b/frontend/discourse/app/components/reviewable-refresh/item.gjs
index ccd21dba8c6..e9294e29b24 100644
--- a/frontend/discourse/app/components/reviewable-refresh/item.gjs
+++ b/frontend/discourse/app/components/reviewable-refresh/item.gjs
@@ -33,6 +33,7 @@ import Category from "discourse/models/category";
import Composer from "discourse/models/composer";
import Topic from "discourse/models/topic";
import { i18n } from "discourse-i18n";
+import ScrubRejectedUserModal from "admin/components/modal/scrub-rejected-user";
let _components = {};
@@ -180,9 +181,13 @@ export default class ReviewableItem extends Component {
@discourseComputed(
"claimEnabled",
"siteSettings.reviewable_claiming",
- "reviewable.claimed_by"
+ "reviewable.claimed_by",
+ "reviewable.bundled_actions"
)
- canPerform(claimEnabled, claimMode, claimedBy) {
+ canPerform(claimEnabled, claimMode, claimedBy, bundledActions) {
+ if (bundledActions?.length === 0) {
+ return false;
+ }
if (!claimEnabled) {
return true;
}
@@ -389,6 +394,29 @@ export default class ReviewableItem extends Component {
}
}
+ @action
+ clientScrub() {
+ this.modal.show(ScrubRejectedUserModal, {
+ model: {
+ confirmScrub: this.scrubRejectedUser,
+ },
+ });
+ }
+
+ @bind
+ async scrubRejectedUser(reason) {
+ try {
+ await ajax({
+ url: `/review/${this.reviewable.id}/scrub`,
+ type: "PUT",
+ data: { reason },
+ });
+ this.store.find("reviewable", this.reviewable.id);
+ } catch (e) {
+ popupAjaxError(e);
+ }
+ }
+
clientSuspend(reviewable, performAction) {
return this._penalize("showSuspendModal", reviewable, performAction);
}
diff --git a/frontend/discourse/app/components/reviewable-refresh/timeline.gjs b/frontend/discourse/app/components/reviewable-refresh/timeline.gjs
index b234c8bdb4e..d749bc1ca5b 100644
--- a/frontend/discourse/app/components/reviewable-refresh/timeline.gjs
+++ b/frontend/discourse/app/components/reviewable-refresh/timeline.gjs
@@ -159,7 +159,7 @@ export default class ReviewableTimeline extends Component {
user: note.user,
icon: "far-pen-to-square",
titleKey: "review.timeline.note_added_by",
- description: note.content,
+ description: htmlSafe(note.content),
noteId: note.id,
canDelete:
this.currentUser &&
diff --git a/frontend/discourse/app/components/reviewable-refresh/user.gjs b/frontend/discourse/app/components/reviewable-refresh/user.gjs
new file mode 100644
index 00000000000..dfa2320b8e4
--- /dev/null
+++ b/frontend/discourse/app/components/reviewable-refresh/user.gjs
@@ -0,0 +1,13 @@
+/* eslint-disable ember/no-classic-components */
+import Component from "@ember/component";
+import LegacyReviewableUser from "../reviewable-user";
+
+export default class ReviewableUser extends Component {
+ <template>
+ <div class="review-item__meta-content">
+ <LegacyReviewableUser @reviewable={{@reviewable}}>
+ {{yield}}
+ </LegacyReviewableUser>
+ </div>
+ </template>
+}
diff --git a/frontend/discourse/app/components/reviewable-user.gjs b/frontend/discourse/app/components/reviewable-user.gjs
index b64595618fa..284ec64a613 100644
--- a/frontend/discourse/app/components/reviewable-user.gjs
+++ b/frontend/discourse/app/components/reviewable-user.gjs
@@ -26,7 +26,12 @@ export default class ReviewableUser extends Component {
@discourseComputed("reviewable.status", "currentUser", "isScrubbed")
canScrubRejectedUser(status, currentUser, isScrubbed) {
- return status === REJECTED && currentUser.admin && !isScrubbed;
+ return (
+ status === REJECTED &&
+ currentUser.admin &&
+ !isScrubbed &&
+ !currentUser.use_reviewable_ui_refresh
+ );
}
@discourseComputed("reviewable.payload")
@@ -93,7 +98,7 @@ export default class ReviewableUser extends Component {
href={{getUrl
(concat
"/admin/users/"
- this.reviewable.user_id
+ this.reviewable.user.id
"/"
this.reviewable.payload.username
)
diff --git a/spec/models/reviewable_user_spec.rb b/spec/models/reviewable_user_spec.rb
index 99ca11aebfb..17e73bbd63c 100644
--- a/spec/models/reviewable_user_spec.rb
+++ b/spec/models/reviewable_user_spec.rb
@@ -329,4 +329,17 @@ RSpec.describe ReviewableUser, type: :model do
end
end
end
+ describe "#build_new_separated_actions" do
+ fab!(:reviewable)
+
+ it "returns correct actions in the pending state" do
+ reviewable.actions_for(Guardian.new(moderator))
+ expect(reviewable.build_new_separated_actions.actions.map(&:id)).to eq(
+ %w[user-approve_user user-delete_user user-delete_user_block],
+ )
+
+ reviewable.update!(status: Reviewable.statuses[:rejected])
+ expect(reviewable.build_new_separated_actions.actions.map(&:id)).to eq(%w[user-scrub])
+ end
+ end
end
diff --git a/spec/requests/reviewables_controller_spec.rb b/spec/requests/reviewables_controller_spec.rb
index ebdd49d607e..49a49dc32c4 100644
--- a/spec/requests/reviewables_controller_spec.rb
+++ b/spec/requests/reviewables_controller_spec.rb
@@ -51,7 +51,7 @@ RSpec.describe ReviewablesController do
end
it "returns JSON with reviewable content" do
- reviewable = Fabricate(:reviewable)
+ reviewable = Fabricate(:reviewable_flagged_post)
get "/review.json"
expect(response.code).to eq("200")
@@ -62,7 +62,7 @@ RSpec.describe ReviewablesController do
expect(json_review["id"]).to eq(reviewable.id)
expect(json_review["created_by_id"]).to eq(reviewable.created_by_id)
expect(json_review["status"]).to eq(Reviewable.statuses[:pending])
- expect(json_review["type"]).to eq("ReviewableUser")
+ expect(json_review["type"]).to eq("ReviewableFlaggedPost")
expect(json_review["target_created_by_id"]).to eq(reviewable.target_created_by_id)
expect(json_review["score"]).to eq(reviewable.score)
expect(json_review["version"]).to eq(reviewable.version)
@@ -352,7 +352,7 @@ RSpec.describe ReviewablesController do
user.custom_fields["private_field"] = "private"
user.save!
- reviewable = Fabricate(:reviewable, target_created_by: user)
+ reviewable = Fabricate(:reviewable_flagged_post, target_created_by: user)
get "/review.json"
json = response.parsed_body
diff --git a/spec/serializers/reviewable_serializer_spec.rb b/spec/serializers/reviewable_serializer_spec.rb
index 7a7b275e47f..4bd5712cbcf 100644
--- a/spec/serializers/reviewable_serializer_spec.rb
+++ b/spec/serializers/reviewable_serializer_spec.rb
@@ -2,6 +2,7 @@
RSpec.describe ReviewableSerializer do
fab!(:reviewable, :reviewable_queued_post)
+ fab!(:reviewable_user)
fab!(:admin)
it "serializes all the fields" do
@@ -55,4 +56,16 @@ RSpec.describe ReviewableSerializer do
expect(json[:topic_url]).to eq(reviewable.topic.url)
end
end
+
+ describe "target_created_by" do
+ it "serializes the user who created a reviewable post" do
+ json = described_class.new(reviewable, scope: Guardian.new(admin), root: nil).as_json
+ expect(json[:target_created_by_id]).to eq(reviewable.target_created_by.id)
+ end
+
+ it "serializes a reviewable user directly" do
+ json = described_class.new(reviewable_user, scope: Guardian.new(admin), root: nil).as_json
+ expect(json[:target_created_by_id]).to eq(reviewable_user.target.id)
+ end
+ end
end
diff --git a/spec/system/page_objects/pages/refreshed_review.rb b/spec/system/page_objects/pages/refreshed_review.rb
new file mode 100644
index 00000000000..ede0e735468
--- /dev/null
+++ b/spec/system/page_objects/pages/refreshed_review.rb
@@ -0,0 +1,71 @@
+# frozen_string_literal: true
+
+module PageObjects
+ module Pages
+ class RefreshedReview < PageObjects::Pages::Base
+ REVIEWABLE_ACTION_DROPDOWN = ".reviewable-action-dropdown"
+
+ def visit_reviewable(reviewable)
+ page.visit("/review/#{reviewable.id}")
+ self
+ end
+
+ def click_timeline_tab
+ find(".action-list li.timeline").click
+ end
+
+ def click_insights_tab
+ find(".action-list li.insights").click
+ end
+
+ def select_bundled_action(reviewable, value)
+ within(reviewable_by_id(reviewable.id)) do
+ reviewable_action_dropdown.select_row_by_value(value)
+ end
+ end
+
+ def select_action(reviewable, value)
+ within(reviewable_by_id(reviewable.id)) do
+ find(".reviewable-action.#{value.dasherize}").click
+ end
+ end
+
+ def has_reviewable_with_rejected_status?(reviewable)
+ within(reviewable_by_id(reviewable.id)) { page.has_css?(".review-item__status.--rejected") }
+ end
+
+ def has_reviewable_with_approved_status?(reviewable)
+ within(reviewable_by_id(reviewable.id)) { page.has_css?(".review-item__status.--approved") }
+ end
+
+ def has_reviewable_with_scrubbed_by?(reviewable, scrubbed_by)
+ within(reviewable_by_id(reviewable.id)) do
+ page.has_css?(".reviewable-user-details.scrubbed-by .value", text: scrubbed_by)
+ end
+ end
+
+ def has_reviewable_with_scrubbed_reason?(reviewable, scrubbed_reason)
+ within(reviewable_by_id(reviewable.id)) do
+ page.has_css?(".reviewable-user-details.scrubbed-reason .value", text: scrubbed_reason)
+ end
+ end
+
+ def has_reviewable_with_scrubbed_at?(reviewable, scrubbed_at)
+ within(reviewable_by_id(reviewable.id)) do
+ page.has_css?(".reviewable-user-details.scrubbed-at .value", text: scrubbed_at)
+ end
+ end
+
+ private
+
+ def reviewable_by_id(id)
+ find(".review-item[data-reviewable-id=\"#{id}\"]")
+ end
+
+ def reviewable_action_dropdown
+ @reviewable_action_dropdown ||=
+ PageObjects::Components::SelectKit.new(REVIEWABLE_ACTION_DROPDOWN)
+ end
+ end
+ end
+end
diff --git a/spec/system/page_objects/pages/review.rb b/spec/system/page_objects/pages/review.rb
index aac27b17c24..4c66bff6b28 100644
--- a/spec/system/page_objects/pages/review.rb
+++ b/spec/system/page_objects/pages/review.rb
@@ -154,14 +154,6 @@ module PageObjects
PageObjects::Components::Review::TopicLink.new
end
- def click_timeline_tab
- find(".action-list li.timeline").click
- end
-
- def click_insights_tab
- find(".action-list li.insights").click
- end
-
private
def reviewable_action_dropdown
diff --git a/spec/system/viewing_reviewable_spec.rb b/spec/system/viewing_reviewable_spec.rb
index 325ac6a5911..64a326647f5 100644
--- a/spec/system/viewing_reviewable_spec.rb
+++ b/spec/system/viewing_reviewable_spec.rb
@@ -6,6 +6,7 @@ describe "Viewing reviewable item", type: :system do
fab!(:reviewable_flagged_post)
let(:review_page) { PageObjects::Pages::Review.new }
+ let(:refreshed_review_page) { PageObjects::Pages::RefreshedReview.new }
let(:review_note_form) { PageObjects::Components::ReviewNoteForm.new }
describe "when user is part of the groups list of the `reviewable_ui_refresh` site setting" do
@@ -108,13 +109,78 @@ describe "Viewing reviewable item", type: :system do
end
it "allows to add notes and persists them when toggle tabs" do
- review_page.visit_reviewable(reviewable_flagged_post)
- review_page.click_timeline_tab
+ refreshed_review_page.visit_reviewable(reviewable_flagged_post)
+ refreshed_review_page.click_timeline_tab
review_note_form.add_note("This is a review note.")
- review_page.click_insights_tab
- review_page.click_timeline_tab
+ refreshed_review_page.click_insights_tab
+ refreshed_review_page.click_timeline_tab
expect(page).to have_text("This is a review note.")
end
end
+
+ describe "when the reviewable item is a user" do
+ fab!(:user)
+ let(:rejection_reason_modal) { PageObjects::Modals::RejectReasonReviewable.new }
+ let(:scrub_user_modal) { PageObjects::Modals::ScrubRejectedUser.new }
+
+ before do
+ SiteSetting.must_approve_users = true
+ Jobs.run_immediately!
+ user.update!(approved: false)
+ user.activate
+ end
+
+ it "Allow to delete and scrub user" do
+ reviewable = ReviewableUser.find_by_target_id(user.id)
+
+ refreshed_review_page.visit_reviewable(reviewable)
+
+ expect(page).to have_text(user.name)
+ expect(page).to have_link(user.username, href: "/admin/users/#{user.id}/#{user.username}")
+
+ refreshed_review_page.select_bundled_action(reviewable, "user-delete_user")
+ expect(refreshed_review_page).to have_reviewable_with_rejected_status(reviewable)
+
+ expect(page).to have_text(user.name)
+
+ refreshed_review_page.select_bundled_action(reviewable, "user-scrub")
+
+ scrubbing_reason = "a spammer who knows how to make GDPR requests"
+ scrub_user_modal.fill_in_scrub_reason(scrubbing_reason)
+ expect(scrub_user_modal.scrub_button).not_to be_disabled
+ scrub_user_modal.scrub_button.click
+
+ expect(refreshed_review_page).to have_reviewable_with_scrubbed_by(
+ reviewable,
+ admin.username,
+ )
+ expect(refreshed_review_page).to have_reviewable_with_scrubbed_reason(
+ reviewable,
+ scrubbing_reason,
+ )
+ expect(refreshed_review_page).to have_reviewable_with_scrubbed_at(
+ reviewable,
+ reviewable.payload["scrubbed_at"],
+ )
+ expect(page).not_to have_text(user.name)
+ end
+
+ it "Allows to delete and block user" do
+ reviewable = ReviewableUser.find_by_target_id(user.id)
+
+ refreshed_review_page.visit_reviewable(reviewable)
+ refreshed_review_page.select_bundled_action(reviewable, "user-delete_user_block")
+ expect(refreshed_review_page).to have_reviewable_with_rejected_status(reviewable)
+ end
+
+ it "Allows to approve user" do
+ reviewable = ReviewableUser.find_by_target_id(user.id)
+
+ refreshed_review_page.visit_reviewable(reviewable)
+ refreshed_review_page.select_bundled_action(reviewable, "user-approve_user")
+
+ expect(refreshed_review_page).to have_reviewable_with_approved_status(reviewable)
+ end
+ end
end
end