Skip to content

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

FEATURE: Classify reviewables during DSA moderation (#44629)

Alan Guo Xiang Tan069751e11d6c
diff --git a/app/assets/stylesheets/common/base/dsa-classification.scss b/app/assets/stylesheets/common/base/dsa-classification.scss
index f63e149fff3..8f2e38b8621 100644
--- a/app/assets/stylesheets/common/base/dsa-classification.scss
+++ b/app/assets/stylesheets/common/base/dsa-classification.scss
@@ -1,3 +1,5 @@
+@use "lib/viewport";
+
.dsa-classification {
min-width: 0;
overflow-wrap: anywhere;
@@ -46,3 +48,62 @@
.dsa-classification-modal__help {
margin-inline-end: auto;
}
+
+.dsa-moderation-action__user {
+ white-space: nowrap;
+ vertical-align: baseline;
+
+ .avatar {
+ margin-right: var(--space-1);
+ }
+}
+
+html:has(.dsa-moderation-action) .fk-d-menu[data-identifier="usercard"] {
+ z-index: z("modal", "popover");
+}
+
+.dsa-moderation-steps {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 0 var(--space-2);
+ list-style: none;
+ margin: 0;
+ padding: var(--space-2) var(--space-6);
+ border-block-end: 1px solid var(--content-border-color);
+ color: var(--primary-medium);
+
+ @include viewport.until(sm) {
+ font-size: var(--font-down-1);
+ }
+
+ li {
+ display: flex;
+ gap: 0 var(--space-2);
+ align-items: center;
+ }
+
+ .d-icon {
+ color: var(--primary-medium);
+ font-weight: normal;
+ font-size: var(--font-down-1);
+ }
+
+ .--current {
+ color: var(--primary);
+ font-weight: bold;
+ }
+
+ &__back.btn {
+ min-height: 0;
+ padding: 0;
+ color: inherit;
+ font-size: inherit;
+ line-height: inherit;
+
+ &:hover,
+ &:focus-visible {
+ background: transparent;
+ color: var(--primary);
+ }
+ }
+}
diff --git a/app/controllers/reviewables_controller.rb b/app/controllers/reviewables_controller.rb
index 06e01bee57a..e1bc9837501 100644
--- a/app/controllers/reviewables_controller.rb
+++ b/app/controllers/reviewables_controller.rb
@@ -265,6 +265,7 @@ class ReviewablesController < ApplicationController
def perform
args = { version: params[:version].to_i }
+ args[:dsa_classification] = dsa_classification_args if params.has_key?(:dsa_classification)
result = nil
begin
@@ -342,6 +343,24 @@ class ReviewablesController < ApplicationController
end
end
+ def dsa_classification_args
+ raise Discourse::InvalidAccess unless DsaStatementOfRecord.classification_enabled?
+
+ unless params[:dsa_classification].is_a?(ActionController::Parameters)
+ raise Discourse::InvalidParameters.new(:dsa_classification)
+ end
+
+ classification =
+ DsaStatementOfRecord::ClassificationContract.new(
+ **params.require(:dsa_classification).permit(:community_rule, :category).to_h,
+ )
+ rule = classification.rule
+
+ raise Discourse::InvalidParameters.new(:dsa_classification) if !classification.valid? || !rule
+
+ { community_rule: rule, category: classification.category }
+ end
+
def find_reviewable
reviewable = Reviewable.viewable_by(current_user).where(id: params[:reviewable_id]).first
raise Discourse::NotFound.new if reviewable.blank?
diff --git a/app/models/concerns/reviewable_action_builder.rb b/app/models/concerns/reviewable_action_builder.rb
index 71130db881a..773d11635ae 100644
--- a/app/models/concerns/reviewable_action_builder.rb
+++ b/app/models/concerns/reviewable_action_builder.rb
@@ -54,9 +54,10 @@ module ReviewableActionBuilder
confirm: false,
require_reject_reason: false,
secondary: false,
+ dsa_classification_required: false,
source: nil
)
- actions.add(id, bundle:, secondary:) do |action|
+ actions.add(id, bundle:, secondary:, dsa_classification_required:) do |action|
source ||= type_source
if source == "core"
prefix = "reviewables.actions.#{id}"
@@ -80,15 +81,36 @@ module ReviewableActionBuilder
nil
end
- def build_penalty_actions(actions, bundle:, silence:, suspend:, user: target_user)
+ def build_penalty_actions(
+ actions,
+ bundle:,
+ silence:,
+ suspend:,
+ user: target_user,
+ dsa_classification_required: false
+ )
return if user.blank? || !guardian.can_suspend?(user)
if !user.silenced?
- build_action(actions, silence, icon: "microphone-slash", bundle:, client_action: "silence")
+ build_action(
+ actions,
+ silence,
+ icon: "microphone-slash",
+ bundle:,
+ client_action: "silence",
+ dsa_classification_required:,
+ )
end
if !user.suspended?
- build_action(actions, suspend, icon: "ban", bundle:, client_action: "suspend")
+ build_action(
+ actions,
+ suspend,
+ icon: "ban",
+ bundle:,
+ client_action: "suspend",
+ dsa_classification_required:,
+ )
end
end
diff --git a/app/models/dsa_statement_of_record.rb b/app/models/dsa_statement_of_record.rb
index 972ca7a2e42..f9104a800c8 100644
--- a/app/models/dsa_statement_of_record.rb
+++ b/app/models/dsa_statement_of_record.rb
@@ -70,6 +70,46 @@ class DsaStatementOfRecord < ActiveRecord::Base
def classification_enabled?
SiteSetting.dsa_reporting_enabled && JSON.parse(SiteSetting.dsa_community_rules).present?
end
+
+ def record!(reviewable:, attributes:, performed_by:, classification: nil)
+ statement =
+ create!(
+ reviewable_id: reviewable.id,
+ payload:
+ attributes.merge(
+ application_date: Date.current.iso8601,
+ territorial_scope: TERRITORIAL_SCOPE,
+ source_type: "SOURCE_VOLUNTARY",
+ decision_ground: "DECISION_GROUND_INCOMPATIBLE_CONTENT",
+ ),
+ )
+
+ if classification
+ statement.classify!(**classification, classified_by: performed_by)
+
+ if Reviewable.exists?(reviewable.id)
+ reviewable.reviewable_notes.create!(
+ user: performed_by,
+ content: statement.classification_note,
+ )
+ end
+ end
+
+ statement
+ end
+ end
+
+ def classification_note
+ I18n.t(
+ "dsa_statements.classification_note",
+ locale: SiteSetting.default_locale,
+ ground: payload.fetch("incompatible_content_ground"),
+ category:
+ I18n.t(
+ "dsa_statements.categories.#{payload.fetch("category")}",
+ locale: SiteSetting.default_locale,
+ ),
+ )
end
def classify!(community_rule:, category:, classified_by:)
diff --git a/app/models/reviewable.rb b/app/models/reviewable.rb
index cb1a9ef3d60..ebaa935e93d 100644
--- a/app/models/reviewable.rb
+++ b/app/models/reviewable.rb
@@ -457,15 +457,11 @@ class Reviewable < ActiveRecord::Base
)
if attributes
- DsaStatementOfRecord.create!(
- reviewable_id: id,
- payload:
- attributes.merge(
- application_date: Date.current.iso8601,
- territorial_scope: DsaStatementOfRecord::TERRITORIAL_SCOPE,
- source_type: "SOURCE_VOLUNTARY",
- decision_ground: "DECISION_GROUND_INCOMPATIBLE_CONTENT",
- ),
+ DsaStatementOfRecord.record!(
+ reviewable: self,
+ attributes:,
+ performed_by:,
+ classification: args[:dsa_classification],
)
end
end
@@ -948,7 +944,12 @@ class Reviewable < ActiveRecord::Base
target_type == "User" ? target : target_created_by
end
- def delete_user_actions(actions, bundle = nil, require_reject_reason: false)
+ def delete_user_actions(
+ actions,
+ bundle = nil,
+ require_reject_reason: false,
+ dsa_classification_required: false
+ )
bundle ||=
actions.add_bundle(
"#{id}-reject_user",
@@ -961,7 +962,7 @@ class Reviewable < ActiveRecord::Base
username = target_user&.username
confirmable = !require_reject_reason && username.present?
- actions.add(:delete_user, bundle: bundle) do |a|
+ actions.add(:delete_user, bundle: bundle, dsa_classification_required:) do |a|
a.icon = "user-xmark"
a.label = "reviewables.actions.reject_user.delete.title"
a.description = "reviewables.actions.reject_user.delete.description"
@@ -973,7 +974,7 @@ class Reviewable < ActiveRecord::Base
end
end
- actions.add(:delete_user_block, bundle: bundle) do |a|
+ actions.add(:delete_user_block, bundle: bundle, dsa_classification_required:) do |a|
a.icon = "ban"
a.label = "reviewables.actions.reject_user.block.title"
a.require_reject_reason = require_reject_reason
diff --git a/app/models/reviewable_flagged_post.rb b/app/models/reviewable_flagged_post.rb
index da0bfae5a7f..dfc7755ebd5 100644
--- a/app/models/reviewable_flagged_post.rb
+++ b/app/models/reviewable_flagged_post.rb
@@ -63,11 +63,29 @@ class ReviewableFlaggedPost < Reviewable
actions.add_bundle("#{id}-agree", icon: "thumbs-up", label: "reviewables.actions.agree.title")
if post.user_deleted? || post.trashed?
- build_action(actions, :agree_and_keep_deleted, icon: "far-eye-slash", bundle: agree_bundle)
+ build_action(
+ actions,
+ :agree_and_keep_deleted,
+ icon: "far-eye-slash",
+ bundle: agree_bundle,
+ dsa_classification_required: true,
+ )
elsif post.hidden?
- build_action(actions, :agree_and_keep_hidden, icon: "far-eye-slash", bundle: agree_bundle)
+ build_action(
+ actions,
+ :agree_and_keep_hidden,
+ icon: "far-eye-slash",
+ bundle: agree_bundle,
+ dsa_classification_required: true,
+ )
else
- build_action(actions, :agree_and_hide, icon: "far-eye-slash", bundle: agree_bundle)
+ build_action(
+ actions,
+ :agree_and_hide,
+ icon: "far-eye-slash",
+ bundle: agree_bundle,
+ dsa_classification_required: true,
+ )
build_action(actions, :agree_and_keep, icon: "far-eye", bundle: agree_bundle)
build_action(
actions,
@@ -75,6 +93,7 @@ class ReviewableFlaggedPost < Reviewable
icon: "pencil",
bundle: agree_bundle,
client_action: "edit",
+ dsa_classification_required: true,
)
end
@@ -83,7 +102,13 @@ class ReviewableFlaggedPost < Reviewable
can_delete_post_or_topic && !post.user_deleted? && !post.trashed?
if can_delete_existing_post_or_topic
- build_action(actions, :delete_and_agree, icon: "trash-can", bundle: agree_bundle)
+ build_action(
+ actions,
+ :delete_and_agree,
+ icon: "trash-can",
+ bundle: agree_bundle,
+ dsa_classification_required: true,
+ )
if post.reply_count > 0
build_action(
@@ -92,6 +117,7 @@ class ReviewableFlaggedPost < Reviewable
icon: "trash-can",
bundle: agree_bundle,
confirm: true,
+ dsa_classification_required: true,
)
end
end
@@ -101,10 +127,11 @@ class ReviewableFlaggedPost < Reviewable
bundle: agree_bundle,
silence: :agree_and_silence,
suspend: :agree_and_suspend,
+ dsa_classification_required: true,
)
if (potential_spam? || potentially_illegal?) && guardian.can_delete_user?(target_created_by)
- delete_user_actions(actions, agree_bundle)
+ delete_user_actions(actions, agree_bundle, dsa_classification_required: true)
end
if post.user_deleted? && !post.trashed? && !user_penalized_for_deleted_post?
@@ -153,7 +180,13 @@ class ReviewableFlaggedPost < Reviewable
build_action(actions, :ignore_and_do_nothing, icon: "xmark", bundle: disagree_bundle)
end
if can_delete_existing_post_or_topic
- build_action(actions, :delete_and_ignore, icon: "trash-can", bundle: disagree_bundle)
+ build_action(
+ actions,
+ :delete_and_ignore,
+ icon: "trash-can",
+ bundle: disagree_bundle,
+ dsa_classification_required: true,
+ )
if post.reply_count > 0
build_action(
actions,
@@ -161,6 +194,7 @@ class ReviewableFlaggedPost < Reviewable
icon: "trash-can",
confirm: true,
bundle: disagree_bundle,
+ dsa_classification_required: true,
)
end
end
diff --git a/app/models/reviewable_post.rb b/app/models/reviewable_post.rb
index a962cc9457a..fc3e42703df 100644
--- a/app/models/reviewable_post.rb
+++ b/app/models/reviewable_post.rb
@@ -57,18 +57,34 @@ class ReviewablePost < Reviewable
if post.trashed?
if can_penalize
- build_action(actions, :reject_and_keep_deleted, icon: "trash-can", bundle: reject)
+ build_action(
+ actions,
+ :reject_and_keep_deleted,
+ icon: "trash-can",
+ bundle: reject,
+ dsa_classification_required: true,
+ )
else
- actions.add(:reject_and_keep_deleted, bundle: reject) do |a|
+ actions.add(
+ :reject_and_keep_deleted,
+ bundle: reject,
+ dsa_classification_required: true,
+ ) do |a|
a.icon = "trash-can"
a.label = "reviewables.actions.reject_and_keep_deleted_standalone.title"
end
end
elsif guardian.can_delete_post_or_topic?(post)
if can_penalize
- build_action(actions, :reject_and_delete, icon: "trash-can", bundle: reject)
+ build_action(
+ actions,
+ :reject_and_delete,
+ icon: "trash-can",
+ bundle: reject,
+ dsa_classification_required: true,
+ )
else
- actions.add(:reject_and_delete, bundle: reject) do |a|
+ actions.add(:reject_and_delete, bundle: reject, dsa_classification_required: true) do |a|
a.icon = "trash-can"
a.label = "reviewables.actions.reject_and_delete_standalone.title"
end
@@ -80,6 +96,7 @@ class ReviewablePost < Reviewable
bundle: reject,
silence: :reject_and_silence,
suspend: :reject_and_suspend,
+ dsa_classification_required: true,
)
end
diff --git a/app/models/reviewable_queued_post.rb b/app/models/reviewable_queued_post.rb
index 8e0f38381ee..207d6da0bfb 100644
--- a/app/models/reviewable_queued_post.rb
+++ b/app/models/reviewable_queued_post.rb
@@ -48,9 +48,21 @@ class ReviewableQueuedPost < Reviewable
label: "reviewables.actions.reject_post_bundle.title",
)
- build_action(actions, :reject_post, bundle: reject_bundle, icon: "xmark")
+ build_action(
+ actions,
+ :reject_post,
+ bundle: reject_bundle,
+ icon: "xmark",
+ dsa_classification_required: true,
+ )
if target_created_by.present?
- build_action(actions, :revise_and_reject_post, bundle: reject_bundle, icon: "envelope")
+ build_action(
+ actions,
+ :revise_and_reject_post,
+ bundle: reject_bundle,
+ icon: "envelope",
+ dsa_classification_required: true,
+ )
end
build_penalty_actions(
@@ -58,9 +70,12 @@ class ReviewableQueuedPost < Reviewable
bundle: reject_bundle,
silence: :reject_and_silence,
suspend: :reject_and_suspend,
+ dsa_classification_required: true,
)
- delete_user_actions(actions, reject_bundle) if guardian.can_delete_user?(target_created_by)
+ if guardian.can_delete_user?(target_created_by)
+ delete_user_actions(actions, reject_bundle, dsa_classification_required: true)
+ end
end
build_action(actions, :delete) if guardian.can_delete?(self)
diff --git a/app/models/reviewable_user.rb b/app/models/reviewable_user.rb
index f35844deba3..2e7ff7c81b4 100644
--- a/app/models/reviewable_user.rb
+++ b/app/models/reviewable_user.rb
@@ -51,13 +51,30 @@ class ReviewableUser < Reviewable
label: "reviewables.actions.confirm_spam.title",
)
- build_penalty_actions(actions, bundle:, silence: :silence_user, suspend: :suspend_user)
-
- delete_user_actions(actions, bundle, require_reject_reason: false)
+ build_penalty_actions(
+ actions,
+ bundle:,
+ silence: :silence_user,
+ suspend: :suspend_user,
+ dsa_classification_required: true,
+ )
+
+ delete_user_actions(
+ actions,
+ bundle,
+ require_reject_reason: false,
+ dsa_classification_required: true,
+ )
end
if status == "pending" && target&.uploaded_avatar_id.present?
- build_action(actions, :remove_avatar, icon: "user-xmark", secondary: true)
+ build_action(
+ actions,
+ :remove_avatar,
+ icon: "user-xmark",
+ secondary: true,
+ dsa_classification_required: is_a_suspect_user?,
+ )
end
# Reviewed items must not offer approval in the queue, but approving an
@@ -218,6 +235,8 @@ class ReviewableUser < Reviewable
private
def dsa_statement_attributes(action_id:, result:, automated_detection:, automated_decision:)
+ return if !is_a_suspect_user? && !target&.approved?
+
case action_id
when :suspend_user
user = target.reload
diff --git a/app/serializers/dsa_classification_serializer.rb b/app/serializers/dsa_classification_serializer.rb
index 1a7aec32758..c5f904ead9c 100644
--- a/app/serializers/dsa_classification_serializer.rb
+++ b/app/serializers/dsa_classification_serializer.rb
@@ -14,7 +14,7 @@ class DsaClassificationSerializer < ApplicationSerializer
end
def include_community_rules?
- scope.is_staff? && DsaStatementOfRecord.classification_enabled?
+ scope.can_see_review_queue? && DsaStatementOfRecord.classification_enabled?
end
alias_method :include_categories?, :include_community_rules?
diff --git a/app/serializers/reviewable_action_serializer.rb b/app/serializers/reviewable_action_serializer.rb
index 2eb47fd72fe..e386f6fdd92 100644
--- a/app/serializers/reviewable_action_serializer.rb
+++ b/app/serializers/reviewable_action_serializer.rb
@@ -13,7 +13,8 @@ class ReviewableActionSerializer < ApplicationSerializer
:client_action,
:require_reject_reason,
:completed_message,
- :penalty_effect
+ :penalty_effect,
+ :dsa_classification_required
def label
I18n.t(object.label)
@@ -55,6 +56,10 @@ class ReviewableActionSerializer < ApplicationSerializer
object.require_reject_reason.present?
end
+ def include_dsa_classification_required?
+ object.dsa_classification_required && DsaStatementOfRecord.classification_enabled?
+ end
+
def include_penalty_effect?
object.penalty_effect.present?
end
diff --git a/app/services/dsa_statement_of_record/classification_contract.rb b/app/services/dsa_statement_of_record/classification_contract.rb
new file mode 100644
index 00000000000..4311f4436d7
--- /dev/null
+++ b/app/services/dsa_statement_of_record/classification_contract.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class DsaStatementOfRecord::ClassificationContract < Service::ContractBase
+ attribute :community_rule, :string
+ attribute :category, :string
+
+ validates :community_rule, presence: true
+ validates :category, inclusion: { in: DsaStatementOfRecord::CATEGORIES }
+
+ def rule
+ DsaStatementOfRecord.community_rules.find { |entry| entry["id"] == community_rule }
+ end
+end
diff --git a/app/services/dsa_statement_of_record/classify.rb b/app/services/dsa_statement_of_record/classify.rb
index dd3a757e3ae..3599f6f3f6a 100644
--- a/app/services/dsa_statement_of_record/classify.rb
+++ b/app/services/dsa_statement_of_record/classify.rb
@@ -6,14 +6,11 @@ class DsaStatementOfRecord::Classify
policy :staff
policy :classification_enabled
- params do
+ params base_class: DsaStatementOfRecord::ClassificationContract do
attribute :reviewable_id, :integer
- attribute :community_rule, :string
- attribute :category, :string
attribute :statement_ids, :array
- validates :reviewable_id, :community_rule, :statement_ids, presence: true
- validates :category, inclusion: { in: DsaStatementOfRecord::CATEGORIES }
+ validates :reviewable_id, :statement_ids, presence: true
end
model :community_rule
@@ -37,7 +34,7 @@ class DsaStatementOfRecord::Classify
end
def fetch_community_rule(params:)
- DsaStatementOfRecord.community_rules.find { |rule| rule["id"] == params.community_rule }
+ params.rule
end
def fetch_reviewable(params:, guardian:)
@@ -61,23 +58,9 @@ class DsaStatementOfRecord::Classify
end
end
- def save_note(reviewable:, community_rule:, params:, guardian:)
+ def save_note(reviewable:, statements:, guardian:)
note = reviewable.reviewable_notes.new
-
- note.update(
- user: guardian.user,
- content:
- I18n.t(
- "dsa_statements.classification_note",
- locale: SiteSetting.default_locale,
- ground: community_rule["ground"],
- category:
- I18n.t(
- "dsa_statements.categories.#{params.category}",
- locale: SiteSetting.default_locale,
- ),
- ),
- )
+ note.update(user: guardian.user, content: statements.first.classification_note)
note
end
end
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 2f1aa021df8..1f6de1621d5 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -1023,6 +1023,11 @@ en:
saving: "Saving…"
saved: "Classification saved"
review:
+ continue_to_editor: "Continue to editor"
+ moderation_steps:
+ label: "Moderation steps"
+ action: "Action details"
+ confirm: "Confirm action"
show_more: "Show more"
show_less: "Show less"
back_to_queue: "Back to queue"
diff --git a/frontend/discourse/admin/components/modal/penalize-user.gjs b/frontend/discourse/admin/components/modal/penalize-user.gjs
index 5e9d9ae23ca..4b2457c7f15 100644
--- a/frontend/discourse/admin/components/modal/penalize-user.gjs
+++ b/frontend/discourse/admin/components/modal/penalize-user.gjs
@@ -9,8 +9,8 @@ import { isEmpty } from "@ember/utils";
import AdminPenaltyPostAction from "discourse/admin/components/admin-penalty-post-action";
import AdminPenaltyReason from "discourse/admin/components/admin-penalty-reason";
import AdminPenaltySimilarUsers from "discourse/admin/components/admin-penalty-similar-users";
+import DsaModeration from "discourse/components/dsa-moderation";
import { extractError } from "discourse/lib/ajax-error";
-import DButton from "discourse/ui-kit/d-button";
import DFutureDateInput from "discourse/ui-kit/d-future-date-input";
import DModal from "discourse/ui-kit/d-modal";
import I18n, { i18n } from "discourse-i18n";
@@ -24,7 +24,7 @@ export default class PenalizeUser extends Component {
@tracked confirmClose = false;
@tracked otherUserIds = [];
- @tracked postAction = "delete";
+ @tracked postAction = this.args.model.postId ? "delete" : "none";
@tracked postEdit = this.args.model.postEdit;
@tracked flash;
@tracked reason;
@@ -76,13 +76,12 @@ export default class PenalizeUser extends Component {
this.penalizing ||
isEmpty(this.penalizeUntil) ||
!this.reason ||
- this.reason.length < 1 ||
(this.postAction === "delete_all" && !this.readyToDeleteAll)
);
}
@action
- async penalizeUser() {
+ async penalizeUser(additionalData = {}) {
if (this.submitDisabled) {
return;
}
@@ -104,6 +103,7 @@ export default class PenalizeUser extends Component {
post_edit: this.postEdit,
other_user_ids: this.otherUserIds,
reviewable_id: this.args.model.reviewableId,
+ ...additionalData,
};
if (this.args.model.penaltyType === "suspend") {
@@ -136,16 +136,25 @@ export default class PenalizeUser extends Component {
}
@action
- warnBeforeClosing() {
+ async cancelPenalty() {
+ if (await this.warnBeforeClosing()) {
+ this.args.closeModal({ success: false });
+ }
+ }
+
+ @action
+ async warnBeforeClosing() {
+ if (this.penalizing) {
+ return false;
+ }
+
if (!this.confirmClose && (this.reason?.length || this.message?.length)) {
- this.dialog.confirm({
+ return this.dialog.confirm({
message: i18n("admin.user.confirm_cancel_penalty"),
- didConfirm: () => this.args.closeModal({ success: false }),
});
- return false;
}
- this.args.closeModal({ success: false });
+ return true;
}
@action
@@ -159,97 +168,115 @@ export default class PenalizeUser extends Component {
}
<template>
- <DModal
- class="{{@model.penaltyType}}-user-modal --large"
- @closeModal={{this.warnBeforeClosing}}
- @flash={{this.flash}}
- @title={{i18n this.modalTitle}}
+ <DsaModeration
+ @onSubmit={{this.penalizeUser}}
+ @options={{if this.canPenalize @model.dsaClassification}}
+ as |flow|
>
- <:body>
- {{#if this.canPenalize}}
- <div class="penalty-duration-controls">
- {{#if (eq @model.penaltyType "suspend")}}
- <DFutureDateInput
- class="suspend-until"
- @clearable={{false}}
- @input={{this.penalizeUntil}}
- @label="admin.user.suspend_duration"
- @onChangeInput={{fn (mut this.penalizeUntil)}}
- />
- {{else if (eq @model.penaltyType "silence")}}
- <DFutureDateInput
- class="silence-until"
- @clearable={{false}}
- @input={{this.penalizeUntil}}
- @label="admin.user.silence_duration"
- @onChangeInput={{fn (mut this.penalizeUntil)}}
+ <DModal
+ class="{{@model.penaltyType}}-user-modal --large"
+ @beforeClose={{this.warnBeforeClosing}}
+ @closeModal={{@closeModal}}
+ @dismissable={{not this.penalizing}}
+ @flash={{this.flash}}
+ @title={{i18n this.modalTitle}}
+ >
+ <:belowHeader>
+ <flow.Steps @disabled={{this.penalizing}} />
+ </:belowHeader>
+ <:body>
+ <flow.Body>
+ {{#if this.canPenalize}}
+ <div class="penalty-duration-controls">
+ {{#if (eq @model.penaltyType "suspend")}}
+ <DFutureDateInput
+ class="suspend-until"
+ @clearable={{false}}
+ @input={{this.penalizeUntil}}
+ @label="admin.user.suspend_duration"
+ @onChangeInput={{fn (mut this.penalizeUntil)}}
+ />
+ {{else if (eq @model.penaltyType "silence")}}
+ <DFutureDateInput
+ class="silence-until"
+ @clearable={{false}}
+ @input={{this.penalizeUntil}}
+ @label="admin.user.silence_duration"
+ @onChangeInput={{fn (mut this.penalizeUntil)}}
+ />
+ {{/if}}
+ </div>
+ {{#if (eq @model.penaltyType "suspend")}}
+ <div class="penalty-reason-visibility">
+ {{#if this.siteSettings.hide_suspension_reasons}}
+ {{trustHTML
+ (i18n "admin.user.suspend_reason_hidden_label")
+ }}
+ {{else}}
+ {{trustHTML (i18n "admin.user.suspend_reason_label")}}
+ {{/if}}
+ </div>
+ {{else if (eq @model.penaltyType "silence")}}
+ <div class="penalty-reason-visibility">
+ {{#if this.siteSettings.hide_silencing_reasons}}
+ {{trustHTML
+ (i18n "admin.user.silence_reason_hidden_label")
+ }}
+ {{else}}
+ {{trustHTML (i18n "admin.user.silence_reason_label")}}
+ {{/if}}
+ </div>
+ {{/if}}
+ <AdminPenaltyReason
+ @message={{this.message}}
+ @onChangeMessage={{fn (mut this.message)}}
+ @onChangeReason={{fn (mut this.reason)}}
+ @penaltyType={{@model.penaltyType}}
/>
- {{/if}}
- </div>
- {{#if (eq @model.penaltyType "suspend")}}
- <div class="penalty-reason-visibility">
- {{#if this.siteSettings.hide_suspension_reasons}}
- {{trustHTML (i18n "admin.user.suspend_reason_hidden_label")}}
- {{else}}
- {{trustHTML (i18n "admin.user.suspend_reason_label")}}
+ {{#if @model.postId}}
+ <AdminPenaltyPostAction
+ @onChangePostAction={{fn (mut this.postAction)}}
+ @onChangePostEdit={{fn (mut this.postEdit)}}
+ @onDeleteAllPostsReady={{this.updateReadyToDeleteAll}}
+ @postAction={{this.postAction}}
+ @postEdit={{this.postEdit}}
+ @user={{@model.user}}
+ />
+ {{/if}}
+ {{#if @model.user.similar_users_count}}
+ <AdminPenaltySimilarUsers
+ @onUsersChanged={{this.similarUsersChanged}}
+ @penaltyType={{@model.penaltyType}}
+ @selectedUserIds={{this.otherUserIds}}
+ @user={{@model.user}}
+ />
{{/if}}
- </div>
- {{else if (eq @model.penaltyType "silence")}}
- <div class="penalty-reason-visibility">
- {{#if this.siteSettings.hide_silencing_reasons}}
- {{trustHTML (i18n "admin.user.silence_reason_hidden_label")}}
- {{else}}
- {{trustHTML (i18n "admin.user.silence_reason_label")}}
+ {{else}}
+ {{#if (eq @model.penaltyType "suspend")}}
+ <div class="cant-suspend">{{i18n
+ "admin.user.cant_suspend"
+ }}</div>
+ {{else if (eq @model.penaltyType "silence")}}
+ <div class="cant-silence">{{i18n
+ "admin.user.cant_silence"
+ }}</div>
{{/if}}
- </div>
- {{/if}}
- <AdminPenaltyReason
- @message={{this.message}}
- @onChangeMessage={{fn (mut this.message)}}
- @onChangeReason={{fn (mut this.reason)}}
- @penaltyType={{@model.penaltyType}}
+ {{/if}}
+ <div class="penalty-history">{{trustHTML this.penaltyHistory}}</div>
+ </flow.Body>
+ </:body>
+ <:footer>
+ <flow.Footer
+ @cancel={{this.cancelPenalty}}
+ @cancelDisabled={{this.penalizing}}
+ @disabled={{this.submitDisabled}}
+ @isLoading={{this.penalizing}}
+ @submitClass="btn-danger perform-penalize"
+ @submitIcon="ban"
+ @submitLabel={{i18n this.buttonLabel}}
/>
- {{#if @model.postId}}
- <AdminPenaltyPostAction
- @onChangePostAction={{fn (mut this.postAction)}}
- @onChangePostEdit={{fn (mut this.postEdit)}}
- @onDeleteAllPostsReady={{this.updateReadyToDeleteAll}}
- @postAction={{this.postAction}}
- @postEdit={{this.postEdit}}
- @user={{@model.user}}
- />
- {{/if}}
- {{#if @model.user.similar_users_count}}
- <AdminPenaltySimilarUsers
- @onUsersChanged={{this.similarUsersChanged}}
- @penaltyType={{@model.penaltyType}}
- @selectedUserIds={{this.otherUserIds}}
- @user={{@model.user}}
- />
- {{/if}}
- {{else}}
- {{#if (eq @model.penaltyType "suspend")}}
- <div class="cant-suspend">{{i18n "admin.user.cant_suspend"}}</div>
- {{else if (eq @model.penaltyType "silence")}}
- <div class="cant-silence">{{i18n "admin.user.cant_silence"}}</div>
- {{/if}}
- {{/if}}
- <div class="penalty-history">{{trustHTML this.penaltyHistory}}</div>
- </:body>
- <:footer>
- <DButton
- class="btn-danger perform-penalize"
- @action={{this.penalizeUser}}
- @disabled={{this.submitDisabled}}
- @icon="ban"
- @label={{this.buttonLabel}}
- />
- <DButton
- class="btn-flat d-modal-cancel"
- @action={{this.warnBeforeClosing}}
- @label="cancel"
- />
- </:footer>
- </DModal>
+ </:footer>
+ </DModal>
+ </DsaModeration>
</template>
}
diff --git a/frontend/discourse/admin/services/admin-tools.js b/frontend/discourse/admin/services/admin-tools.js
index 25659363230..19ff385fc7b 100644
--- a/frontend/discourse/admin/services/admin-tools.js
+++ b/frontend/discourse/admin/services/admin-tools.js
@@ -108,7 +108,7 @@ export default class AdminToolsService extends Service {
opts = opts || {};
const loadedUser = user.adminUserView
? user
- : await AdminUser.find(user.get("id"));
+ : await AdminUser.find(user.id);
const originalSuccessCallback = opts.successCallback;
return this.modal.show(PenalizeUserModal, {
model: {
@@ -116,6 +116,7 @@ export default class AdminToolsService extends Service {
postId: opts.postId,
postEdit: opts.postEdit,
reviewableId: opts.reviewableId,
+ dsaClassification: opts.dsaClassification,
user: loadedUser,
before: opts.before,
perform: opts.perform,
diff --git a/frontend/discourse/app/components/dsa-moderation-details.gjs b/frontend/discourse/app/components/dsa-moderation-details.gjs
new file mode 100644
index 00000000000..0924ae85e66
--- /dev/null
+++ b/frontend/discourse/app/components/dsa-moderation-details.gjs
@@ -0,0 +1,60 @@
+import Component from "@glimmer/component";
+import Form from "discourse/components/form";
+import { i18n } from "discourse-i18n";
+
+export function defaultClassification(options) {
+ const rules = options?.community_rules;
+ return rules?.length === 1 ? { community_rule: rules[0].id } : {};
+}
+
+export default class DsaModerationDetails extends Component {
+ formData = defaultClassification(this.args.options);
+
+ <template>
+ <Form
+ class="dsa-moderation-details"
+ id={{@formId}}
+ ...attributes
+ @data={{this.formData}}
+ @onSubmit={{@onSubmit}}
+ as |form|
+ >
+ <form.Field
+ @format="full"
+ @name="community_rule"
+ @title={{i18n "dsa_statements.rule"}}
+ @type="select"
+ @validation="required"
+ as |field|
+ >
+ <field.Control
+ @nonePlaceholder={{i18n "dsa_statements.rule_prompt"}}
+ as |select|
+ >
+ {{#each @options.community_rules as |rule|}}
+ <select.Option @value={{rule.id}}>{{rule.ground}}</select.Option>
+ {{/each}}
+ </field.Control>
+ </form.Field>
+ <form.Field
+ @format="full"
+ @name="category"
+ @title={{i18n "dsa_statements.category"}}
+ @type="select"
+ @validation="required"
+ as |field|
+ >
+ <field.Control
+ @nonePlaceholder={{i18n "dsa_statements.category_prompt"}}
+ as |select|
+ >
+ {{#each @options.categories as |category|}}
+ <select.Option
+ @value={{category.id}}
+ >{{category.name}}</select.Option>
+ {{/each}}
+ </field.Control>
+ </form.Field>
+ </Form>
+ </template>
+}
diff --git a/frontend/discourse/app/components/dsa-moderation.gjs b/frontend/discourse/app/components/dsa-moderation.gjs
new file mode 100644
index 00000000000..9c2f30a1466
--- /dev/null
+++ b/frontend/discourse/app/components/dsa-moderation.gjs
@@ -0,0 +1,181 @@
+import Component from "@glimmer/component";
+import { tracked } from "@glimmer/tracking";
+import { hash } from "@ember/helper";
+import { action } from "@ember/object";
+import { guidFor } from "@ember/object/internals";
+import didUpdate from "@ember/render-modifiers/modifiers/did-update";
+import DsaModerationDetails from "discourse/components/dsa-moderation-details";
+import DButton from "discourse/ui-kit/d-button";
+import dIcon from "discourse/ui-kit/helpers/d-icon";
+import { i18n } from "discourse-i18n";
+
+const Steps = <template>
+ {{#if @flow.nextStepLabel}}
+ <ol
+ aria-label={{i18n "review.moderation_steps.label"}}
+ class="dsa-moderation-steps"
+ >
+ <li aria-current="step" class="--current">{{i18n
+ "dsa_statements.title"
+ }}</li>
+ <li>
+ {{dIcon "angle-right"}}
+ {{@flow.nextStepLabel}}
+ </li>
+ </ol>
+ {{else if (and @flow.enabled @flow.hasActionDetails)}}
+ <ol
+ aria-label={{i18n "review.moderation_steps.label"}}
+ class="dsa-moderation-steps"
+ {{didUpdate @flow.focusCurrentStep @flow.classificationStep}}
+ >
+ <li
+ aria-current={{if @flow.showContinue "step"}}
+ class={{if @flow.showContinue "--current"}}
+ tabindex="-1"
+ >
+ {{#if @flow.showBack}}
+ <DButton
+ class="btn-transparent dsa-moderation-steps__back"
+ @action={{@flow.back}}
+ @disabled={{@disabled}}
+ @translatedLabel={{@flow.actionStepLabel}}
+ />
+ {{else}}
+ {{@flow.actionStepLabel}}
+ {{/if}}
+ </li>
+ <li
+ aria-current={{unless @flow.showContinue "step"}}
+ class={{unless @flow.showContinue "--current"}}
+ tabindex="-1"
+ >
+ {{dIcon "angle-right"}}
+ {{i18n "dsa_statements.title"}}
+ </li>
+ </ol>
+ {{/if}}
+</template>;
+
+const Body = <template>
+ {{#if @flow.enabled}}
+ {{#if @flow.hasActionDetails}}
+ <div hidden={{not @flow.showContinue}}>{{yield}}</div>
+ {{/if}}
+ <div hidden={{@flow.showContinue}}>
+ <DsaModerationDetails
+ @formId={{@flow.formId}}
+ @onSubmit={{@flow.classify}}
+ @options={{@flow.options}}
+ />
+ </div>
+ {{else}}
+ {{yield}}
+ {{/if}}
+</template>;
+
+const Footer = <template>
+ {{#if @flow.showContinue}}
+ <DButton
+ class="btn-primary"
+ @action={{@flow.continue}}
+ @disabled={{@disabled}}
+ @label="continue"
+ />
+ {{else}}
+ <DButton
+ class={{@submitClass}}
+ type={{if @flow.enabled "submit" "button"}}
+ @action={{unless @flow.enabled @flow.submit}}
+ @disabled={{@disabled}}
+ @form={{if @flow.enabled @flow.formId}}
+ @icon={{@submitIcon}}
+ @isLoading={{@isLoading}}
+ @translatedLabel={{@submitLabel}}
+ />
+ {{/if}}
+ {{#if @flow.showBack}}
+ <DButton
+ class="btn-flat"
+ @action={{@flow.back}}
+ @disabled={{@isLoading}}
+ @label="back_button"
+ />
+ {{else if @cancel}}
+ <DButton
+ class="btn-flat d-modal-cancel"
+ @action={{@cancel}}
+ @disabled={{@cancelDisabled}}
+ @label="cancel"
+ />
+ {{/if}}
+</template>;
+
+export default class DsaModeration extends Component {
+ @tracked classificationStep = false;
+
+ formId = `dsa-moderation-${guidFor(this)}`;
+
+ get actionStepLabel() {
+ return this.args.actionStepLabel ?? i18n("review.moderation_steps.action");
+ }
+
+ get enabled() {
+ return Boolean(this.args.options);
+ }
+
+ get hasActionDetails() {
+ return this.args.hasActionDetails !== false;
+ }
+
+ get nextStepLabel() {
+ return this.args.nextStepLabel;
+ }
+
+ get options() {
+ return this.args.options;
+ }
+
+ get showContinue() {
+ return this.enabled && this.hasActionDetails && !this.classificationStep;
+ }
+
+ get showBack() {
+ return this.enabled && this.hasActionDetails && this.classificationStep;
+ }
+
+ @action
+ back() {
+ this.classificationStep = false;
+ }
+
+ @action
+ classify(classification) {
+ return this.args.onSubmit({ dsa_classification: { ...classification } });
+ }
+
+ @action
+ continue() {
+ this.classificationStep = true;
+ }
+
+ @action
+ focusCurrentStep(element) {
+ element.querySelector('[aria-current="step"]').focus();
+ }
+
+ @action
+ submit() {
+ return this.args.onSubmit();
+ }
+
+ <template>
+ {{yield
+ (hash
+ Body=(component Body flow=this)
+ Footer=(component Footer flow=this)
+ Steps=(component Steps flow=this)
+ )
+ }}
+ </template>
+}
diff --git a/frontend/discourse/app/components/dsa-statement-classification.gjs b/frontend/discourse/app/components/dsa-statement-classification.gjs
index 10c68889ada..d79c94890dd 100644
--- a/frontend/discourse/app/components/dsa-statement-classification.gjs
+++ b/frontend/discourse/app/components/dsa-statement-classification.gjs
@@ -3,6 +3,7 @@ import { tracked } from "@glimmer/tracking";
import { action } from "@ember/object";
import { service } from "@ember/service";
import DsaClassificationConfirmation from "discourse/components/dialog-messages/dsa-classification-confirmation";
+import { defaultClassification } from "discourse/components/dsa-moderation-details";
import Form from "discourse/components/form";
import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
@@ -15,7 +16,7 @@ export default class DsaStatementClassification extends Component {
@tracked saving = false;
- formData = {};
+ formData = defaultClassification(this.args.classificationOptions);
get classification() {
return this.args.reviewable.dsa_classification;
diff --git a/frontend/discourse/app/components/modal/dsa-moderation-action.gjs b/frontend/discourse/app/components/modal/dsa-moderation-action.gjs
new file mode 100644
index 00000000000..38a960b9fe5
--- /dev/null
+++ b/frontend/discourse/app/components/modal/dsa-moderation-action.gjs
@@ -0,0 +1,101 @@
+import Component from "@glimmer/component";
+import { tracked } from "@glimmer/tracking";
+import { action } from "@ember/object";
+import DsaModeration from "discourse/components/dsa-moderation";
+import { extractError } from "discourse/lib/ajax-error";
+import DModal from "discourse/ui-kit/d-modal";
+import { i18n } from "discourse-i18n";
+
+export default class DsaModerationAction extends Component {
+ @tracked flash;
+ @tracked saving = false;
+
+ get buttonClass() {
+ return this.hasActionDetails && !this.#editing
+ ? "btn-danger"
+ : "btn-primary";
+ }
+
+ get buttonLabel() {
+ if (this.#editing) {
+ return i18n("review.continue_to_editor");
+ }
+ return this.hasActionDetails
+ ? this.args.model.action.label
+ : i18n("dsa_statements.save");
+ }
+
+ get hasActionDetails() {
+ return Boolean(this.args.model.action.confirm_message);
+ }
+
+ get nextStepLabel() {
+ return this.#editing ? this.args.model.action.label : null;
+ }
+
+ get title() {
+ return this.hasActionDetails || this.#editing
+ ? this.args.model.action.label
+ : i18n("dsa_statements.title");
+ }
+
+ get #editing() {
+ return this.args.model.action.client_action === "edit";
+ }
+
+ @action
+ async submit(data) {
+ if (this.saving) {
+ return;
+ }
+ this.saving = true;
+ this.flash = null;
+ try {
+ await this.args.model.perform(data);
+ this.args.closeModal();
+ } catch (error) {
+ this.flash = extractError(error);
+ } finally {
+ this.saving = false;
+ }
+ }
+
+ <template>
+ <DsaModeration
+ @actionStepLabel={{i18n "review.moderation_steps.confirm"}}
+ @hasActionDetails={{this.hasActionDetails}}
+ @nextStepLabel={{this.nextStepLabel}}
+ @onSubmit={{this.submit}}
+ @options={{@model.options}}
+ as |flow|
+ >
+ <DModal
+ class="dsa-moderation-action"
+ ...attributes
+ @closeModal={{@closeModal}}
+ @dismissable={{not this.saving}}
+ @flash={{this.flash}}
+ @title={{this.title}}
+ >
+ <:belowHeader>
+ <flow.Steps @disabled={{this.saving}} />
+ </:belowHeader>
+ <:body>
+ <flow.Body>
+ <p>{{@model.action.confirm_message}}</p>
+ </flow.Body>
+ </:body>
+ <:footer>
+ <flow.Footer
+ @cancel={{if @model.action.confirm_message @closeModal}}
+ @cancelDisabled={{this.saving}}
+ @disabled={{this.saving}}
+ @isLoading={{this.saving}}
+ @submitClass={{this.buttonClass}}
+ @submitLabel={{this.buttonLabel}}
+ />
+ </:footer>
+ </DModal>
+ </DsaModeration>
+ </template>
+}
diff --git a/frontend/discourse/app/components/modal/revise-and-reject-post-reviewable.gjs b/frontend/discourse/app/components/modal/revise-and-reject-post-reviewable.gjs
index 12c3117a24b..e997f1d11aa 100644
--- a/frontend/discourse/app/components/modal/revise-and-reject-post-reviewable.gjs
+++ b/frontend/discourse/app/components/modal/revise-and-reject-post-reviewable.gjs
@@ -5,10 +5,10 @@ import { fn } from "@ember/helper";
import { action } from "@ember/object";
import { service } from "@ember/service";
import { isEmpty } from "@ember/utils";
+import DsaModeration from "discourse/components/dsa-moderation";
import ReviewableQueuedPost from "discourse/components/reviewable/queued-post";
import { popupAjaxError } from "discourse/lib/ajax-error";
import ComboBox from "discourse/select-kit/components/combo-box";
-import DButton from "discourse/ui-kit/d-button";
import DModal from "discourse/ui-kit/d-modal";
import DTextarea from "discourse/ui-kit/d-textarea";
import { i18n } from "discourse-i18n";
@@ -50,7 +50,7 @@ export default class ReviseAndRejectPostReviewable extends Component {
}
@action
- async rejectAndSendPM() {
+ async rejectAndSendPM(additionalData = {}) {
this.submitting = true;
try {
@@ -58,6 +58,7 @@ export default class ReviseAndRejectPostReviewable extends Component {
revise_reason: this.reason,
revise_custom_reason: this.customReason,
revise_feedback: this.feedback,
+ ...additionalData,
});
this.args.closeModal();
} catch (error) {
@@ -68,72 +69,79 @@ export default class ReviseAndRejectPostReviewable extends Component {
}
<template>
- <DModal
- class="revise-and-reject-reviewable"
- @closeModal={{@closeModal}}
- @title={{i18n "review.revise_and_reject_post.title"}}
+ <DsaModeration
+ @onSubmit={{this.rejectAndSendPM}}
+ @options={{@model.classificationOptions}}
+ as |flow|
>
- <:body>
- <div class="revise-and-reject-reviewable__queued-post">
- <ReviewableQueuedPost @reviewable={{@model.reviewable}} />
- </div>
+ <DModal
+ class="revise-and-reject-reviewable"
+ @closeModal={{@closeModal}}
+ @title={{i18n "review.revise_and_reject_post.title"}}
+ >
+ <:belowHeader>
+ <flow.Steps @disabled={{this.submitting}} />
+ </:belowHeader>
+ <:body>
+ <flow.Body>
+ <div class="revise-and-reject-reviewable__queued-post">
+ <ReviewableQueuedPost @reviewable={{@model.reviewable}} />
+ </div>
- <div class="control-group">
- <label class="control-label" for="reason">{{i18n
- "review.revise_and_reject_post.reason"
- }}</label>
- <ComboBox
- class="revise-and-reject-reviewable__reason"
- @content={{this.configuredReasons}}
- @name="reason"
- @onChange={{fn (mut this.reason)}}
- @value={{this.reason}}
- />
- </div>
+ <div class="control-group">
+ <label class="control-label" for="reason">{{i18n
+ "review.revise_and_reject_post.reason"
+ }}</label>
+ <ComboBox
+ class="revise-and-reject-reviewable__reason"
+ @content={{this.configuredReasons}}
+ @name="reason"
+ @onChange={{fn (mut this.reason)}}
+ @value={{this.reason}}
+ />
+ </div>
- {{#if this.showCustomReason}}
- <div class="control-group">
- <label class="control-label" for="custom_reason">{{i18n
- "review.revise_and_reject_post.custom_reason"
- }}</label>
- <Input
- class="revise-and-reject-reviewable__custom-reason"
- name="custom_reason"
- @type="text"
- @value={{this.customReason}}
- />
- </div>
- {{/if}}
+ {{#if this.showCustomReason}}
+ <div class="control-group">
+ <label class="control-label" for="custom_reason">{{i18n
+ "review.revise_and_reject_post.custom_reason"
+ }}</label>
+ <Input
+ class="revise-and-reject-reviewable__custom-reason"
+ name="custom_reason"
+ @type="text"
+ @value={{this.customReason}}
+ />
+ </div>
+ {{/if}}
- <div class="control-group">
- <label class="control-label" for="feedback">{{i18n
- "review.revise_and_reject_post.feedback"
- }}
- <span class="revise-and-reject-reviewable__optional">({{i18n
- "review.revise_and_reject_post.optional"
- }})</span>
- </label>
- <DTextarea
- class="revise-and-reject-reviewable__feedback"
- @name="feedback"
- @onChange={{fn (mut this.feedback)}}
- @value={{this.feedback}}
+ <div class="control-group">
+ <label class="control-label" for="feedback">{{i18n
+ "review.revise_and_reject_post.feedback"
+ }}
+ <span class="revise-and-reject-reviewable__optional">({{i18n
+ "review.revise_and_reject_post.optional"
+ }})</span>
+ </label>
+ <DTextarea
+ class="revise-and-reject-reviewable__feedback"
+ @name="feedback"
+ @onChange={{fn (mut this.feedback)}}
+ @value={{this.feedback}}
+ />
+ </div>
+ </flow.Body>
+ </:body>
+ <:footer>
+ <flow.Footer
+ @cancel={{@closeModal}}
+ @disabled={{this.sendPMDisabled}}
+ @isLoading={{this.submitting}}
+ @submitClass="btn-primary"
+ @submitLabel={{i18n "review.revise_and_reject_post.send_pm"}}
/>
- </div>
- </:body>
- <:footer>
- <DButton
- class="btn-primary"
- @action={{this.rejectAndSendPM}}
- @disabled={{this.sendPMDisabled}}
- @label="review.revise_and_reject_post.send_pm"
- />
- <DButton
- class="btn-flat d-modal-cancel"
- @action={{@closeModal}}
- @label="cancel"
- />
- </:footer>
- </DModal>
+ </:footer>
+ </DModal>
+ </DsaModeration>
</template>
}
diff --git a/frontend/discourse/app/components/reviewable/item.gjs b/frontend/discourse/app/components/reviewable/item.gjs
index 00505340f98..7226d81f7e5 100644
--- a/frontend/discourse/app/components/reviewable/item.gjs
+++ b/frontend/discourse/app/components/reviewable/item.gjs
@@ -110,6 +110,7 @@ export default class ReviewableItem extends Component {
@service store;
@service toasts;
@service messageBus;
+ @service reviewableDsa;
@optionalService adminTools;
@tracked disabled = false;
@@ -172,8 +173,7 @@ export default class ReviewableItem extends Component {
return (
(reviewable?.created_from_flag &&
reviewable?.status === PENDING &&
- (this.claimOptional ||
- (this.claimRequired && reviewable?.claimed_by !== null))) ||
+ (!this.claimRequired || reviewable?.claimed_by !== null)) ||
this.isAiReviewable
);
}
@@ -205,13 +205,6 @@ export default class ReviewableItem extends Component {
);
}
- get claimOptional() {
- return (
- !this.claimEnabled ||
- this.siteSettings?.reviewable_claiming === "optional"
- );
- }
-
get claimRequired() {
return (
this.claimEnabled && this.siteSettings?.reviewable_claiming === "required"
@@ -338,12 +331,22 @@ export default class ReviewableItem extends Component {
}
}
- clientSuspend(reviewable, performAction) {
- return this._penalize("showSuspendModal", reviewable, performAction);
+ clientSuspend(reviewable, performAction, dsaClassification) {
+ return this._penalize(
+ "showSuspendModal",
+ reviewable,
+ performAction,
+ dsaClassification
+ );
}
- clientSilence(reviewable, performAction) {
- return this._penalize("showSilenceModal", reviewable, performAction);
+ clientSilence(reviewable, performAction, dsaClassification) {
+ return this._penalize(
+ "showSilenceModal",
+ reviewable,
+ performAction,
+ dsaClassification
+ );
}
async clientEdit(reviewable, performAction) {
@@ -427,6 +430,22 @@ export default class ReviewableItem extends Component {
? RejectReasonReviewableModal
: actionModalClassMap[performableAction.server_action];
+ if (
+ this.reviewableDsa.handlesConfirmation({
+ action: performableAction,
+ options: this.args.classificationOptions,
+ modalClass: actionModalClass,
+ })
+ ) {
+ return this._performConfirmed(
+ performableAction,
+ {},
+ {
+ modalClass: actionModalClass,
+ }
+ );
+ }
+
if (message) {
if (await this.#claimReviewable()) {
const confirmOptions = {
@@ -629,7 +648,11 @@ export default class ReviewableItem extends Component {
}
@bind
- async _performConfirmed(performableAction, additionalData = {}) {
+ async _performConfirmed(
+ performableAction,
+ additionalData = {},
+ { modalClass } = {}
+ ) {
let reviewable = this.args.reviewable;
let performAction = async (actionData = {}) => {
@@ -672,22 +695,48 @@ export default class ReviewableItem extends Component {
});
};
- try {
- if (performableAction.client_action) {
- let actionMethod =
- this[`client${classify(performableAction.client_action)}`];
- if (actionMethod) {
- if (await this.#claimReviewable()) {
- await actionMethod.call(this, reviewable, performAction);
- }
- } else {
- // eslint-disable-next-line no-console
- console.error(
- `No handler for ${performableAction.client_action} found`
+ const classificationOptions = this.reviewableDsa.optionsFor({
+ action: performableAction,
+ options: this.args.classificationOptions,
+ });
+
+ const dispatch = async (perform) => {
+ if (!performableAction.client_action) {
+ return perform();
+ }
+
+ const actionMethod =
+ this[`client${classify(performableAction.client_action)}`];
+ if (actionMethod) {
+ if (await this.#claimReviewable()) {
+ return actionMethod.call(
+ this,
+ reviewable,
+ perform,
+ classificationOptions
);
}
} else {
- await performAction();
+ // eslint-disable-next-line no-console
+ console.error(
+ `No handler for ${performableAction.client_action} found`
+ );
+ }
+ };
+
+ try {
+ if (classificationOptions) {
+ await this.reviewableDsa.perform({
+ action: performableAction,
+ reviewable,
+ options: classificationOptions,
+ modalClass,
+ claim: () => this.#claimReviewable(),
+ dispatch,
+ performAction,
+ });
+ } else {
+ await dispatch(performAction);
}
} catch (error) {
popupAjaxError(error);
@@ -724,17 +773,21 @@ export default class ReviewableItem extends Component {
}
}
- _penalize(adminToolMethod, reviewable, performAction) {
+ _penalize(adminToolMethod, reviewable, performAction, dsaClassification) {
if (!this.adminTools) {
return;
}
- return this.adminTools[adminToolMethod](reviewable.target_created_by, {
- postId: reviewable.post_id,
- postEdit: reviewable.raw ?? reviewable.payload?.raw,
- reviewableId: reviewable.id,
- perform: performAction,
- });
+ return this.adminTools[adminToolMethod](
+ reviewable.target_created_by ?? reviewable.target_user,
+ {
+ postId: reviewable.post_id,
+ postEdit: reviewable.raw ?? reviewable.payload?.raw,
+ reviewableId: reviewable.id,
+ dsaClassification,
+ perform: performAction,
+ }
+ );
}
<template>
@@ -880,7 +933,10 @@ export default class ReviewableItem extends Component {
<div
class={{dConcatClass
"review-item__aside"
- (if @reviewable.dsa_classification "--dsa-classification")
+ (if
+ @reviewable.dsa_classification.statement_ids.length
+ "--dsa-classification"
+ )
}}
>
@@ -981,7 +1037,7 @@ export default class ReviewableItem extends Component {
@reviewable={{reviewable}}
/>
{{/each}}
- {{else if (and @showHelp (not @reviewable.dsa_classification))}}
+ {{else if @showHelp}}
<ReviewableHelpResources />
{{/if}}
</div>
diff --git a/frontend/discourse/app/services/reviewable-dsa.js b/frontend/discourse/app/services/reviewable-dsa.js
new file mode 100644
index 00000000000..06ba9b11b44
--- /dev/null
+++ b/frontend/discourse/app/services/reviewable-dsa.js
@@ -0,0 +1,76 @@
+import Service, { service } from "@ember/service";
+import DsaModerationAction from "discourse/components/modal/dsa-moderation-action";
+
+export default class ReviewableDsa extends Service {
+ @service modal;
+
+ optionsFor({ action, options }) {
+ if (
+ action.dsa_classification_required &&
+ options?.community_rules?.length
+ ) {
+ return options;
+ }
+ }
+
+ handlesConfirmation({ action, options, modalClass }) {
+ return (
+ this.optionsFor({ action, options }) &&
+ (!modalClass || action.server_action === "revise_and_reject_post")
+ );
+ }
+
+ async perform({
+ action,
+ reviewable,
+ options,
+ modalClass,
+ claim,
+ dispatch,
+ performAction,
+ }) {
+ const classify = async (perform, data = {}) => {
+ if (await claim()) {
+ return this.modal.show(DsaModerationAction, {
+ model: {
+ action,
+ options,
+ reviewable,
+ perform: (classification) =>
+ perform({ ...data, ...classification }),
+ },
+ });
+ }
+ };
+
+ if (action.client_action === "edit") {
+ return classify((classification) =>
+ dispatch((data) => performAction({ ...data, ...classification }))
+ );
+ }
+
+ if (modalClass) {
+ if (await claim()) {
+ return this.modal.show(modalClass, {
+ model: {
+ action,
+ reviewable,
+ classificationOptions: options,
+ performConfirmed: (_action, data) => performAction(data),
+ },
+ });
+ }
+ return;
+ }
+
+ let classificationPromise;
+ await dispatch((data) => {
+ if (data?.dsa_classification) {
+ return performAction(data);
+ }
+ classificationPromise = classify(performAction, data);
+ return classificationPromise;
+ });
+ return classificationPromise;
+ }
+}
diff --git a/lib/reviewable/actions.rb b/lib/reviewable/actions.rb
index b42e673929b..093183834c2 100644
--- a/lib/reviewable/actions.rb
+++ b/lib/reviewable/actions.rb
@@ -55,7 +55,8 @@ class Reviewable < ActiveRecord::Base
:require_reject_reason,
:custom_modal,
:completed_message,
- :penalty_effect
+ :penalty_effect,
+ :dsa_classification_required
def initialize(id, icon = nil, button_class = nil, label = nil)
super(id)
@@ -84,11 +85,13 @@ class Reviewable < ActiveRecord::Base
# id-keyed collection for the whole queue. Two reviewables offering the same
# action would otherwise collapse into a single record, and every one of
# them would render the last copy. Bundle ids are scoped by their callers.
- def add(id, bundle: nil, secondary: false)
+ def add(id, bundle: nil, secondary: false, dsa_classification_required: false)
action_name = [reviewable.target_type&.underscore, id].compact_blank.join("-")
scoped_id = [reviewable.id, action_name].compact_blank.join("-")
action = Actions.common_actions[action_name] || Action.new(scoped_id)
+ action.dsa_classification_required = dsa_classification_required
yield action if block_given?
+ action.dsa_classification_required &&= !reviewable.potentially_illegal?
@content << action
bundle ||= add_bundle(scoped_id, secondary:)
diff --git a/plugins/chat/app/models/chat/reviewable_message.rb b/plugins/chat/app/models/chat/reviewable_message.rb
index 822f91a4b97..dc75b504684 100644
--- a/plugins/chat/app/models/chat/reviewable_message.rb
+++ b/plugins/chat/app/models/chat/reviewable_message.rb
@@ -64,9 +64,21 @@ module Chat
if chat_message.deleted_at?
build_action(actions, :agree_and_restore, icon: "far-eye", bundle: agree)
- build_action(actions, :agree_and_keep_deleted, icon: "thumbs-up", bundle: agree)
+ build_action(
+ actions,
+ :agree_and_keep_deleted,
+ icon: "thumbs-up",
+ bundle: agree,
+ dsa_classification_required: true,
+ )
else
- build_action(actions, :agree_and_delete, icon: "trash-can", bundle: agree)
+ build_action(
+ actions,
+ :agree_and_delete,
+ icon: "trash-can",
+ bundle: agree,
+ dsa_classification_required: true,
+ )
build_action(actions, :agree_and_keep_message, icon: "far-eye", bundle: agree)
end
@@ -77,6 +89,7 @@ module Chat
icon: "ban",
bundle: agree,
client_action: "suspend",
+ dsa_classification_required: true,
)
build_action(
actions,
@@ -84,6 +97,7 @@ module Chat
icon: "microphone-slash",
bundle: agree,
client_action: "silence",
+ dsa_classification_required: true,
)
end
@@ -103,7 +117,13 @@ module Chat
build_action(actions, :ignore, icon: "xmark", bundle: disagree_bundle)
unless chat_message.deleted_at?
- build_action(actions, :delete_and_agree, icon: "trash-can", bundle: disagree_bundle)
+ build_action(
+ actions,
+ :delete_and_agree,
+ icon: "trash-can",
+ bundle: disagree_bundle,
+ dsa_classification_required: true,
+ )
end
build_unsilence_action(actions, guardian)
diff --git a/plugins/chat/spec/models/chat/reviewable_chat_message_spec.rb b/plugins/chat/spec/models/chat/reviewable_chat_message_spec.rb
index 852d5ff3507..a69fc2b48ae 100644
--- a/plugins/chat/spec/models/chat/reviewable_chat_message_spec.rb
+++ b/plugins/chat/spec/models/chat/reviewable_chat_message_spec.rb
@@ -29,6 +29,21 @@ RSpec.describe Chat::ReviewableMessage, type: :model do
expect(notification.url).to eq("/review/#{reviewable.id}")
end
+ describe "#actions_for" do
+ it "requires classification for restrictive chat actions" do
+ reviewable.update!(target_created_by: user)
+
+ actions = reviewable.actions_for(moderator.guardian).to_a
+
+ expect(actions.select(&:dsa_classification_required).map(&:server_action)).to contain_exactly(
+ "agree_and_delete",
+ "delete_and_agree",
+ "agree_and_suspend",
+ "agree_and_silence",
+ )
+ end
+ end
+
describe "#perform" do
it "suspends the author and deletes the flagged message" do
reviewable.update!(target_created_by: user)
@@ -79,6 +94,30 @@ RSpec.describe Chat::ReviewableMessage, type: :model do
}.not_to change(DsaStatementOfRecord, :count)
end
+ it "classifies the statement while deleting the flagged message" do
+ result =
+ reviewable.perform(
+ moderator,
+ :agree_and_delete,
+ dsa_classification: {
+ community_rule: {
+ "ground" => "Be respectful",
+ "explanation" => "Personal attacks are not allowed.",
+ },
+ category: "STATEMENT_CATEGORY_OTHER_VIOLATION_TC",
+ },
+ )
+
+ expect(result).to be_success
+ expect(chat_message.reload.deleted_at).to be_present
+ expect(reviewable.reload).to be_approved
+
+ statement = reviewable.dsa_statement_of_records.sole
+ expect(statement).to be_ready
+ expect(statement.classified_by_id).to eq(moderator.id)
+ expect(statement.payload).to include("incompatible_content_ground" => "Be respectful")
+ end
+
it "records a statement when agree_and_delete handles the chat message reviewable" do
expect { reviewable.perform(moderator, :agree_and_delete) }.to change(
DsaStatementOfRecord,
diff --git a/spec/models/concerns/reviewable_action_builder_spec.rb b/spec/models/concerns/reviewable_action_builder_spec.rb
index 054515a2fb4..4d94c5296d4 100644
--- a/spec/models/concerns/reviewable_action_builder_spec.rb
+++ b/spec/models/concerns/reviewable_action_builder_spec.rb
@@ -51,6 +51,26 @@ RSpec.describe ReviewableActionBuilder do
expect(action.require_reject_reason).to be(true)
end
+ it "allows an extension action to opt into classification while ordinary actions remain optional" do
+ actions = Reviewable::Actions.new(reviewable_user, guardian)
+
+ reviewable_user.build_action(actions, :approve_user)
+ reviewable_user.build_action(actions, :plugin_restrict, dsa_classification_required: true)
+
+ expect(actions.to_a.select(&:dsa_classification_required).map(&:server_action)).to eq(
+ ["plugin_restrict"],
+ )
+ end
+
+ it "keeps potentially illegal reviewables outside classification" do
+ reviewable_user.update!(potentially_illegal: true)
+ actions = Reviewable::Actions.new(reviewable_user, guardian)
+
+ reviewable_user.build_action(actions, :plugin_restrict, dsa_classification_required: true)
+
+ expect(actions.to_a.select(&:dsa_classification_required)).to be_empty
+ end
+
it "adds the action to the provided bundle" do
user_actions = Reviewable::Actions.new(reviewable_user, guardian)
diff --git a/spec/models/reviewable_flagged_post_spec.rb b/spec/models/reviewable_flagged_post_spec.rb
index 5abd5ec032f..b9b6d217542 100644
--- a/spec/models/reviewable_flagged_post_spec.rb
+++ b/spec/models/reviewable_flagged_post_spec.rb
@@ -23,6 +23,25 @@ RSpec.describe ReviewableFlaggedPost, type: :model do
expect(reviewable.reload.potentially_illegal?).to eq(true)
end
+ describe "#actions_for" do
+ it "requires classification for actions that restrict the flagged content or its author" do
+ reviewable = PostActionCreator.spam(user, post).reviewable
+
+ actions = reviewable.actions_for(moderator.guardian).to_a
+
+ expect(actions.select(&:dsa_classification_required).map(&:server_action)).to contain_exactly(
+ "agree_and_hide",
+ "agree_and_edit",
+ "delete_and_agree",
+ "delete_and_ignore",
+ "agree_and_suspend",
+ "agree_and_silence",
+ "delete_user",
+ "delete_user_block",
+ )
+ end
+ end
+
describe "actions" do
let!(:result) { PostActionCreator.spam(user, post) }
let(:reviewable) { result.reviewable }
diff --git a/spec/models/reviewable_post_spec.rb b/spec/models/reviewable_post_spec.rb
index 7e710712a4c..31a0b07eb68 100644
--- a/spec/models/reviewable_post_spec.rb
+++ b/spec/models/reviewable_post_spec.rb
@@ -3,6 +3,21 @@
RSpec.describe ReviewablePost do
fab!(:admin)
+ describe "#actions_for" do
+ it "requires classification for rejecting or restricting the submitted post" do
+ post = Fabricate(:post)
+ reviewable = described_class.queue_for_review(post)
+
+ actions = reviewable.actions_for(admin.guardian).to_a
+
+ expect(actions.select(&:dsa_classification_required).map(&:server_action)).to contain_exactly(
+ "reject_and_delete",
+ "reject_and_suspend",
+ "reject_and_silence",
+ )
+ end
+ end
+
describe "#build_actions" do
let(:post) { Fabricate.build(:post) }
let(:reviewable) { ReviewablePost.new(target: post, target_created_by: post.user) }
diff --git a/spec/models/reviewable_queued_post_spec.rb b/spec/models/reviewable_queued_post_spec.rb
index d27507555fc..1bbc7009a80 100644
--- a/spec/models/reviewable_queued_post_spec.rb
+++ b/spec/models/reviewable_queued_post_spec.rb
@@ -5,6 +5,23 @@ RSpec.describe ReviewableQueuedPost, type: :model do
fab!(:moderator) { Fabricate(:moderator, refresh_auto_groups: true) }
fab!(:admin)
+ describe "#actions_for" do
+ it "requires classification for rejecting queued content or restricting its author" do
+ reviewable = Fabricate(:reviewable_queued_post_topic)
+
+ actions = reviewable.actions_for(admin.guardian).to_a
+
+ expect(actions.select(&:dsa_classification_required).map(&:server_action)).to contain_exactly(
+ "reject_post",
+ "revise_and_reject_post",
+ "reject_and_suspend",
+ "reject_and_silence",
+ "delete_user",
+ "delete_user_block",
+ )
+ end
+ end
+
describe "creating a post" do
let!(:topic) { Fabricate(:topic, category: category) }
let(:reviewable) { Fabricate(:reviewable_queued_post, topic: topic) }
@@ -635,6 +652,44 @@ RSpec.describe ReviewableQueuedPost, type: :model do
end
describe "#perform" do
+ it "retains the classified decision when account deletion removes the queued review" do
+ SiteSetting.dsa_reporting_enabled = true
+ recipient = Fabricate(:user)
+ queued =
+ Fabricate(
+ :reviewable_queued_post_topic,
+ created_by: recipient,
+ target_created_by: recipient,
+ )
+ Fabricate(:reviewable_note, reviewable: queued)
+ rule = { "ground" => "Be respectful", "explanation" => "Personal attacks are not allowed." }
+
+ result =
+ queued.perform(
+ admin,
+ :delete_user,
+ dsa_classification: {
+ community_rule: rule,
+ category: "STATEMENT_CATEGORY_OTHER_VIOLATION_TC",
+ },
+ )
+
+ expect(result).to be_success
+ expect(User.exists?(recipient.id)).to eq(false)
+ expect(Reviewable.exists?(queued.id)).to eq(false)
+ expect(ReviewableNote.where(reviewable_id: queued.id)).to be_empty
+ expect(DsaStatementOfRecord.where(reviewable_id: queued.id).sole).to have_attributes(
+ status: "ready",
+ classified_by_id: admin.id,
+ payload:
+ include(
+ "decision_account" => "DECISION_ACCOUNT_TERMINATED",
+ "incompatible_content_ground" => rule["ground"],
+ "category" => "STATEMENT_CATEGORY_OTHER_VIOLATION_TC",
+ ),
+ )
+ end
+
context "when the dsa_reporting_enabled site setting is enabled" do
let(:reviewable) { Fabricate(:reviewable_queued_post) }
diff --git a/spec/models/reviewable_spec.rb b/spec/models/reviewable_spec.rb
index b6d12fccb0a..f3b27611aea 100644
--- a/spec/models/reviewable_spec.rb
+++ b/spec/models/reviewable_spec.rb
@@ -663,6 +663,70 @@ RSpec.describe Reviewable, type: :model do
fab!(:moderator) { Fabricate(:moderator, refresh_auto_groups: true) }
let(:post) { Fabricate(:post) }
+ context "with DSA classification" do
+ fab!(:admin)
+ fab!(:post)
+
+ fab!(:reviewable) do
+ Fabricate(:reviewable_flagged_post, target: post, target_created_by: post.user)
+ end
+
+ let(:classification) do
+ {
+ community_rule: {
+ "ground" => "Be respectful",
+ "explanation" => "Personal attacks are not allowed.",
+ },
+ category: "STATEMENT_CATEGORY_OTHER_VIOLATION_TC",
+ }
+ end
+
+ before { SiteSetting.dsa_reporting_enabled = true }
+
+ it "classifies the moderation decision and records the acting staff member in its note" do
+ result = reviewable.perform(admin, :delete_and_agree, dsa_classification: classification)
+
+ expect(result).to be_success
+ expect(reviewable.reload).to be_approved
+ expect(post.reload).to be_trashed
+ expect(reviewable.dsa_statement_of_records.sole).to have_attributes(
+ status: "ready",
+ classified_by_id: admin.id,
+ payload:
+ include(
+ "incompatible_content_ground" => classification[:community_rule]["ground"],
+ "incompatible_content_explanation" => classification[:community_rule]["explanation"],
+ "category" => classification[:category],
+ ),
+ )
+ expect(reviewable.reviewable_notes.sole).to have_attributes(
+ user: admin,
+ content: <<~TEXT.chomp,
+ Classified this moderation decision for DSA reporting.
+ Community rule: Be respectful
+ Category: Other violation of terms and conditions
+ TEXT
+ )
+ end
+
+ it "rolls back moderation and classification when the classification note cannot be saved" do
+ TranslationOverride.upsert!(
+ "en",
+ "dsa_statements.classification_note",
+ "x" * (ReviewableNote::MAX_CONTENT_LENGTH + 1),
+ )
+
+ expect {
+ reviewable.perform(admin, :delete_and_agree, dsa_classification: classification)
+ }.to raise_error(ActiveRecord::RecordInvalid)
+
+ expect(reviewable.reload).to be_pending
+ expect(post.reload).not_to be_trashed
+ expect(reviewable.dsa_statement_of_records).to be_empty
+ expect(reviewable.reviewable_notes).to be_empty
+ end
+ end
+
it "hides actions and denies execution for an inaccessible target" do
reviewable = Fabricate(:reviewable_flagged_post)
private_category = Fabricate(:private_category, group: Fabricate(:group))
diff --git a/spec/models/reviewable_user_spec.rb b/spec/models/reviewable_user_spec.rb
index fb929df6b9c..a1dfba034ef 100644
--- a/spec/models/reviewable_user_spec.rb
+++ b/spec/models/reviewable_user_spec.rb
@@ -13,6 +13,30 @@ RSpec.describe ReviewableUser, type: :model do
describe "#actions_for" do
fab!(:reviewable)
+ it "requires classification for suspect account restrictions and avatar removal" do
+ user = Fabricate(:user, uploaded_avatar: Fabricate(:upload))
+ reviewable = Fabricate(:suspect_user_reviewable, target: user)
+
+ actions = reviewable.actions_for(admin.guardian).to_a
+
+ expect(actions.select(&:dsa_classification_required).map(&:server_action)).to contain_exactly(
+ "delete_user",
+ "delete_user_block",
+ "suspend_user",
+ "silence_user",
+ "remove_avatar",
+ )
+ end
+
+ it "keeps registration approval actions outside classification" do
+ user = Fabricate(:user, approved: false, uploaded_avatar: Fabricate(:upload))
+ reviewable = Fabricate(:reviewable_user, target: user)
+
+ actions = reviewable.actions_for(admin.guardian).to_a
+
+ expect(actions.select(&:dsa_classification_required)).to be_empty
+ end
+
it "returns correct actions in the pending state" do
actions = reviewable.actions_for(Guardian.new(moderator))
expect(actions.has?(:approve_user)).to eq(true)
@@ -248,6 +272,53 @@ RSpec.describe ReviewableUser, type: :model do
describe "#perform" do
fab!(:reviewable)
+ it "rejects a registration without creating a statement when classification is supplied" do
+ SiteSetting.dsa_reporting_enabled = true
+ reviewable = Fabricate(:reviewable_user, target: Fabricate(:user, approved: false))
+
+ result =
+ reviewable.perform(
+ admin,
+ :delete_user,
+ reject_reason: "Membership is limited to employees.",
+ dsa_classification: {
+ community_rule: {
+ "ground" => "Be respectful",
+ "explanation" => "No personal attacks.",
+ },
+ category: "STATEMENT_CATEGORY_OTHER_VIOLATION_TC",
+ },
+ )
+
+ expect(result).to be_success
+ expect(reviewable.reload).to be_rejected
+ expect(reviewable.dsa_statement_of_records).to be_empty
+ end
+
+ it "classifies avatar removal while leaving the account review pending" do
+ SiteSetting.dsa_reporting_enabled = true
+ user = Fabricate(:user, uploaded_avatar: Fabricate(:upload))
+ reviewable = Fabricate(:suspect_user_reviewable, target: user)
+
+ result =
+ reviewable.perform(
+ admin,
+ :remove_avatar,
+ dsa_classification: {
+ community_rule: {
+ "ground" => "Be respectful",
+ "explanation" => "No personal attacks.",
+ },
+ category: "STATEMENT_CATEGORY_OTHER_VIOLATION_TC",
+ },
+ )
+
+ expect(result).to be_success
+ expect(user.reload.uploaded_avatar_id).to be_nil
+ expect(reviewable.reload).to be_pending
+ expect(reviewable.dsa_statement_of_records.sole).to be_ready
+ end
+
context "when removing an avatar" do
fab!(:avatar, :upload)
diff --git a/spec/requests/reviewables_controller_spec.rb b/spec/requests/reviewables_controller_spec.rb
index 2fc82ccb8e0..5afa84e8cb1 100644
--- a/spec/requests/reviewables_controller_spec.rb
+++ b/spec/requests/reviewables_controller_spec.rb
@@ -1863,6 +1863,171 @@ RSpec.describe ReviewablesController do
end
describe "#perform" do
+ context "when DSA classification is provided" do
+ fab!(:admin)
+ fab!(:flagged_post, :post)
+
+ fab!(:reviewable) do
+ Fabricate(
+ :reviewable_flagged_post,
+ target: flagged_post,
+ target_created_by: flagged_post.user,
+ topic: flagged_post.topic,
+ category: flagged_post.topic.category,
+ )
+ end
+
+ let(:rule) { { ground: "Be respectful", explanation: "Personal attacks are not allowed." } }
+
+ let(:classification) do
+ {
+ community_rule: DsaStatementOfRecord.community_rules.first.fetch("id"),
+ category: "STATEMENT_CATEGORY_OTHER_VIOLATION_TC",
+ }
+ end
+
+ before do
+ SiteSetting.dsa_reporting_enabled = true
+ SiteSetting.dsa_community_rules = [rule].to_json
+ sign_in(admin)
+ end
+
+ it "classifies the new statement using the configured rule and records a note" do
+ put "/review/#{reviewable.id}/perform/delete_and_agree.json",
+ params: {
+ version: reviewable.version,
+ dsa_classification: classification,
+ }
+
+ expect(response).to have_http_status(:ok)
+ expect(flagged_post.reload).to be_trashed
+ statement = reviewable.dsa_statement_of_records.sole
+ expect(statement).to be_ready
+ expect(statement.payload).to include(
+ "incompatible_content_ground" => rule[:ground],
+ "incompatible_content_explanation" => rule[:explanation],
+ "category" => classification[:category],
+ )
+ expect(reviewable.reviewable_notes.sole.content).to include(rule[:ground])
+ end
+
+ it "rejects an unknown rule before moderation" do
+ put "/review/#{reviewable.id}/perform/delete_and_agree.json",
+ params: {
+ version: reviewable.version,
+ dsa_classification: classification.merge(community_rule: "unknown-rule"),
+ }
+
+ expect(response).to have_http_status(:bad_request)
+ expect(reviewable.reload).to be_pending
+ expect(flagged_post.reload).not_to be_trashed
+ expect(reviewable.dsa_statement_of_records).to be_empty
+ end
+
+ it "rejects a string before moderation" do
+ put "/review/#{reviewable.id}/perform/delete_and_agree.json",
+ params: {
+ version: reviewable.version,
+ dsa_classification: "invalid",
+ }
+
+ expect(response).to have_http_status(:bad_request)
+ expect(reviewable.reload).to be_pending
+ expect(flagged_post.reload).not_to be_trashed
+ expect(reviewable.dsa_statement_of_records).to be_empty
+ end
+
+ it "rejects an invalid category before moderation" do
+ put "/review/#{reviewable.id}/perform/delete_and_agree.json",
+ params: {
+ version: reviewable.version,
+ dsa_classification: classification.merge(category: "unknown-category"),
+ }
+
+ expect(response).to have_http_status(:bad_request)
+ expect(reviewable.reload).to be_pending
+ expect(flagged_post.reload).not_to be_trashed
+ expect(reviewable.dsa_statement_of_records).to be_empty
+ end
+
+ it "preserves optional classification for existing clients" do
+ put "/review/#{reviewable.id}/perform/delete_and_agree.json",
+ params: {
+ version: reviewable.version,
+ }
+
+ expect(response).to have_http_status(:ok)
+ expect(flagged_post.reload).to be_trashed
+ expect(reviewable.dsa_statement_of_records.sole).to be_pending
+ end
+
+ it "rejects classification when reporting has been disabled" do
+ SiteSetting.dsa_reporting_enabled = false
+
+ put "/review/#{reviewable.id}/perform/delete_and_agree.json",
+ params: {
+ version: reviewable.version,
+ dsa_classification: classification,
+ }
+
+ expect(response).to have_http_status(:forbidden)
+ expect(reviewable.reload).to be_pending
+ expect(flagged_post.reload).not_to be_trashed
+ end
+
+ it "lets a category moderator classify an action in their category" do
+ category_moderator = Fabricate(:user)
+ group = Fabricate(:group)
+ group.add(category_moderator)
+ Fabricate(:category_moderation_group, group: group, category: flagged_post.topic.category)
+ SiteSetting.enable_category_group_moderation = true
+ sign_in(category_moderator)
+
+ put "/review/#{reviewable.id}/perform/delete_and_agree.json",
+ params: {
+ version: reviewable.version,
+ dsa_classification: classification,
+ }
+
+ expect(response).to have_http_status(:ok)
+ expect(flagged_post.reload).to be_trashed
+ expect(reviewable.dsa_statement_of_records.sole).to be_ready
+ end
+
+ it "rejects classification with an action outside the moderator's category" do
+ category_moderator = Fabricate(:user)
+ group = Fabricate(:group)
+ group.add(category_moderator)
+ moderated_post = Fabricate(:post, topic: Fabricate(:topic, category: Fabricate(:category)))
+ moderated_reviewable =
+ Fabricate(
+ :reviewable_flagged_post,
+ target: moderated_post,
+ target_created_by: moderated_post.user,
+ topic: moderated_post.topic,
+ category: moderated_post.topic.category,
+ )
+ Fabricate(:category_moderation_group, group: group, category: moderated_post.topic.category)
+ SiteSetting.enable_category_group_moderation = true
+ sign_in(category_moderator)
+
+ get "/review/#{moderated_reviewable.id}.json"
+
+ expect(response).to have_http_status(:ok)
+
+ put "/review/#{reviewable.id}/perform/delete_and_agree.json",
+ params: {
+ version: reviewable.version,
+ dsa_classification: classification,
+ }
+
+ expect(response).to have_http_status(:not_found)
+ expect(reviewable.reload).to be_pending
+ expect(flagged_post.reload).not_to be_trashed
+ expect(reviewable.dsa_statement_of_records).to be_empty
+ end
+ end
+
context "when a reviewable targets a private message" do
include_context "with a private-message reviewable"
diff --git a/spec/system/page_objects/modals/dsa_moderation.rb b/spec/system/page_objects/modals/dsa_moderation.rb
new file mode 100644
index 00000000000..094cd840734
--- /dev/null
+++ b/spec/system/page_objects/modals/dsa_moderation.rb
@@ -0,0 +1,88 @@
+# frozen_string_literal: true
+
+module PageObjects
+ module Modals
+ class DsaModeration < Base
+ MODAL_SELECTOR =
+ ":is(.dsa-moderation-action, .suspend-user-modal, .silence-user-modal, .revise-and-reject-reviewable)"
+
+ def initialize
+ super(modal_selector: MODAL_SELECTOR)
+ end
+
+ def select_rule(ground)
+ within(full_modal_selector) { select(ground, from: "Community rule") }
+ end
+
+ def select_category(category)
+ within(full_modal_selector) { select(category, from: "Category") }
+ end
+
+ def continue
+ within(full_modal_selector) { click_button("Continue", exact: true) }
+ end
+
+ def click_previous_step
+ within(full_modal_selector) { find(".dsa-moderation-steps__back").click }
+ end
+
+ def has_disabled_continue?
+ within(full_modal_selector) { has_button?("Continue", exact: true, disabled: true) }
+ end
+
+ def back
+ within(full_modal_selector) { click_button("Back", exact: true) }
+ end
+
+ def has_cancel_button?
+ within(full_modal_selector) { has_button?("Cancel", exact: true) }
+ end
+
+ def has_no_cancel_button?
+ within(full_modal_selector) { has_no_button?("Cancel", exact: true) }
+ end
+
+ def confirm(label)
+ within(full_modal_selector) { click_button(label, exact: true) }
+ end
+
+ def has_steps?(*labels)
+ has_css?("#{full_modal_selector} .dsa-moderation-steps li", count: labels.size) &&
+ labels.each_with_index.all? do |label, index|
+ has_css?(
+ "#{full_modal_selector} .dsa-moderation-steps li:nth-child(#{index + 1})",
+ text: label,
+ )
+ end
+ end
+
+ def has_action_title?(title)
+ has_css?("#{full_modal_selector} .d-modal__title-text", text: title, exact_text: true)
+ end
+
+ def has_classification?
+ has_css?("#{full_modal_selector} .dsa-moderation-details")
+ end
+
+ def has_confirmation_prompt?(message)
+ within(full_modal_selector) { has_text?(message, normalize_ws: true) }
+ end
+
+ def has_selected_rule?(ground)
+ within(full_modal_selector) { has_select?("Community rule", selected: ground) }
+ end
+
+ def has_selected_category?(category)
+ within(full_modal_selector) { has_select?("Category", selected: category) }
+ end
+
+ def has_focused_step?(label)
+ has_css?("#{full_modal_selector} [aria-current='step']:focus", text: label)
+ end
+
+ def has_required_errors?
+ has_css?("#{full_modal_selector} .form-kit__errors", text: "Required")
+ end
+ end
+ end
+end
diff --git a/spec/system/page_objects/modals/penalize_user.rb b/spec/system/page_objects/modals/penalize_user.rb
index 0b24be5d90b..5e6c4f5e0c1 100644
--- a/spec/system/page_objects/modals/penalize_user.rb
+++ b/spec/system/page_objects/modals/penalize_user.rb
@@ -29,6 +29,10 @@ module PageObjects
find("input.suspend-reason").fill_in with: reason
end
+ def has_suspend_reason?(reason)
+ has_field?(class: "suspend-reason", with: reason)
+ end
+
def fill_in_silence_reason(reason)
find("input.silence-reason").fill_in with: reason
end
diff --git a/spec/system/page_objects/modals/revise_and_reject_post.rb b/spec/system/page_objects/modals/revise_and_reject_post.rb
new file mode 100644
index 00000000000..8dbc3bb4fc4
--- /dev/null
+++ b/spec/system/page_objects/modals/revise_and_reject_post.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+module PageObjects
+ module Modals
+ class ReviseAndRejectPost < Base
+ def initialize
+ super(modal_selector: ".revise-and-reject-reviewable")
+ end
+
+ def fill_reason(reason)
+ find(".revise-and-reject-reviewable__custom-reason").fill_in(with: reason)
+ end
+
+ def fill_feedback(feedback)
+ find(".revise-and-reject-reviewable__feedback").fill_in(with: feedback)
+ end
+
+ def has_reason?(reason)
+ has_field?(class: "revise-and-reject-reviewable__custom-reason", with: reason)
+ end
+
+ def has_feedback?(feedback)
+ has_field?(class: "revise-and-reject-reviewable__feedback", with: feedback)
+ end
+ end
+ end
+end
diff --git a/spec/system/page_objects/pages/admin_user.rb b/spec/system/page_objects/pages/admin_user.rb
index d5b5c45af5f..37e0f077628 100644
--- a/spec/system/page_objects/pages/admin_user.rb
+++ b/spec/system/page_objects/pages/admin_user.rb
@@ -19,6 +19,10 @@ module PageObjects
has_css?(".btn-danger.unsuspend-user")
end
+ def has_suspension_reason?(reason)
+ has_css?(".suspension-info .full-reason", text: reason)
+ end
+
def has_no_suspend_button?
has_no_css?(".btn-danger.suspend-user")
end
diff --git a/spec/system/page_objects/pages/review.rb b/spec/system/page_objects/pages/review.rb
index 6b3bedf46e3..6d511f298d5 100644
--- a/spec/system/page_objects/pages/review.rb
+++ b/spec/system/page_objects/pages/review.rb
@@ -62,6 +62,10 @@ module PageObjects
end
end
+ def has_help_resources?
+ has_css?(".review-item__resources", text: I18n.t("js.review.need_help"))
+ end
+
def has_reviewable_items?(count:)
page.has_css?(".review-item", count: count)
end
@@ -172,6 +176,10 @@ module PageObjects
page.has_css?(".timeline-event__description", text: content, normalize_ws: true)
end
+ def has_no_note?(content)
+ page.has_no_css?(".timeline-event__description", text: content, normalize_ws: true)
+ end
+
def has_claimed_history_item?(user)
page.has_css?(".timeline-event__icon .d-icon-user-plus") && page.has_text?("Claimed by")
end
diff --git a/spec/system/review_dsa_moderation_spec.rb b/spec/system/review_dsa_moderation_spec.rb
new file mode 100644
index 00000000000..37046930104
--- /dev/null
+++ b/spec/system/review_dsa_moderation_spec.rb
@@ -0,0 +1,168 @@
+# frozen_string_literal: true
+
+describe "Classifying reviewable moderation" do
+ fab!(:admin)
+ fab!(:topic, :topic_with_op)
+
+ let(:review_page) { PageObjects::Pages::Review.new }
+ let(:modal) { PageObjects::Modals::DsaModeration.new }
+ let(:composer) { PageObjects::Components::Composer.new }
+ let(:rule) { { ground: "Be respectful", explanation: "Personal attacks are not allowed." } }
+ let(:category) { "Other violation of terms and conditions" }
+
+ let(:note) do
+ "Classified this moderation decision for DSA reporting. Community rule: #{rule[:ground]} Category: #{category}"
+ end
+
+ before do
+ SiteSetting.dsa_reporting_enabled = true
+ SiteSetting.dsa_community_rules = [rule].to_json
+ sign_in(admin)
+ end
+
+ it "preserves suspension details and classification when navigating back, and leaves the review pending if cancelled" do
+ SiteSetting.reviewable_claiming = "disabled"
+ post = Fabricate(:post, topic: topic)
+ flagger = Fabricate(:user, trust_level: TrustLevel[3])
+ reviewable = PostActionCreator.create(flagger, post, :inappropriate).reviewable
+ penalty_modal = PageObjects::Modals::PenalizeUser.new("suspend")
+
+ review_page.visit_reviewable(reviewable)
+
+ expect(review_page).to have_context_question(reviewable, "Is this post inappropriate?")
+
+ review_page.select_bundled_action(reviewable, "post-agree_and_suspend", bundle_index: 1)
+
+ expect(modal).to have_action_title("Suspend User")
+ expect(modal).to have_cancel_button
+ expect(review_page).to have_context_question(reviewable, "Is this post inappropriate?")
+
+ penalty_modal.set_future_date("two_weeks")
+
+ expect(modal).to have_disabled_continue
+
+ penalty_modal.fill_in_suspend_reason("Repeated personal attacks.")
+ modal.continue
+
+ expect(modal).to have_action_title("Suspend User")
+ expect(modal).to have_classification
+ expect(modal).to have_selected_rule(rule[:ground])
+ expect(modal).to have_focused_step("DSA classification")
+ expect(modal).to have_no_cancel_button
+
+ modal.confirm("Suspend")
+
+ expect(modal).to have_required_errors
+
+ modal.select_category(category)
+ modal.close
+ dialog = PageObjects::Components::Dialog.new
+
+ expect(dialog).to be_open
+
+ dialog.click_no
+
+ expect(modal).to have_selected_category(category)
+
+ modal.back
+
+ expect(modal).to have_focused_step("Action details")
+ expect(modal).to have_action_title("Suspend User")
+ expect(penalty_modal).to have_suspend_reason("Repeated personal attacks.")
+
+ modal.continue
+
+ expect(modal).to have_selected_category(category)
+
+ modal.click_previous_step
+
+ expect(modal).to have_focused_step("Action details")
+ expect(penalty_modal).to have_suspend_reason("Repeated personal attacks.")
+
+ modal.continue
+
+ expect(modal).to have_selected_category(category)
+
+ modal.close
+
+ expect(dialog).to be_open
+
+ dialog.click_yes
+
+ expect(modal).to be_closed
+ expect(review_page).to have_reviewable_with_pending_status(reviewable)
+ expect(review_page).to have_no_note(note)
+
+ review_page.select_bundled_action(reviewable, "post-agree_and_suspend", bundle_index: 1)
+ penalty_modal.set_future_date("two_weeks")
+ penalty_modal.fill_in_suspend_reason("Repeated personal attacks.")
+ modal.continue
+ modal.select_category(category)
+ modal.confirm("Suspend")
+
+ expect(modal).to be_closed
+ expect(review_page).to have_reviewable_with_approved_status(reviewable)
+
+ page.refresh
+
+ expect(review_page).to have_note(note)
+
+ admin_user_page = PageObjects::Pages::AdminUser.new
+ admin_user_page.visit(post.user)
+
+ expect(admin_user_page).to have_suspension_reason("Repeated personal attacks.")
+ end
+
+ it "classifies before editing, handling the review only after the edit is saved" do
+ SiteSetting.dsa_community_rules = [
+ rule,
+ { ground: "No advertising", explanation: "Unsolicited advertising is not allowed." },
+ ].to_json
+ post = topic.first_post
+ reviewable =
+ Fabricate(:reviewable_flagged_post, target: post, target_created_by: post.user, topic:)
+
+ review_page.visit_reviewable(reviewable)
+ review_page.select_bundled_action(reviewable, "post-agree_and_edit", bundle_index: 1)
+
+ expect(modal).to have_action_title("Edit post")
+ expect(modal).to have_steps("DSA classification", "Edit post")
+ expect(modal).to have_selected_rule("Choose a community rule")
+
+ modal.select_rule(rule[:ground])
+ modal.select_category(category)
+ modal.confirm("Continue to editor")
+
+ expect(modal).to be_closed
+ expect(composer).to be_opened
+
+ composer.fill_content("A correction that should be discarded.")
+ composer.discard
+ discard_modal = PageObjects::Modals::DiscardDraft.new
+
+ expect(discard_modal).to be_open
+
+ discard_modal.click_discard
+
+ expect(composer).to be_closed
+ expect(review_page).to have_reviewable_with_pending_status(reviewable)
+ expect(review_page).to have_no_note(note)
+
+ review_page.select_bundled_action(reviewable, "post-agree_and_edit", bundle_index: 1)
+ modal.select_rule(rule[:ground])
+ modal.select_category(category)
+ modal.confirm("Continue to editor")
+
+ expect(composer).to be_opened
+
+ composer.fill_content("A corrected contribution to the discussion.")
+ composer.submit
+
+ expect(composer).to be_closed
+ expect(review_page).to have_reviewable_with_approved_status(reviewable)
+
+ page.refresh
+
+ expect(review_page).to have_note(note)
+ end
+end