Skip to content

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

DEV: Let staff classify DSA statements from the review queue (#44512)

Alan Guo Xiang Tan6f5643427d10
diff --git a/app/assets/stylesheets/common/base/_index.scss b/app/assets/stylesheets/common/base/_index.scss
index bc669291fc2..df4cab9233a 100644
--- a/app/assets/stylesheets/common/base/_index.scss
+++ b/app/assets/stylesheets/common/base/_index.scss
@@ -44,6 +44,7 @@
@import "reorder-categories";
@import "review";
@import "reviewables";
+@import "dsa-classification";
@import "revise-and-reject-post-reviewable";
@import "rtl";
@import "search";
diff --git a/app/assets/stylesheets/common/base/dsa-classification.scss b/app/assets/stylesheets/common/base/dsa-classification.scss
new file mode 100644
index 00000000000..f63e149fff3
--- /dev/null
+++ b/app/assets/stylesheets/common/base/dsa-classification.scss
@@ -0,0 +1,48 @@
+.dsa-classification {
+ min-width: 0;
+ overflow-wrap: anywhere;
+
+ &__heading {
+ display: flex;
+ align-items: center;
+ gap: 0.5em;
+ margin-block-end: 0.5em;
+ }
+
+ h2 {
+ font-size: var(--font-up-2);
+ margin: 0;
+ }
+}
+
+.dsa-classification-confirmation {
+ &__label {
+ font-weight: bold;
+ }
+
+ &__value {
+ margin: 0 0 var(--space-4);
+ overflow-wrap: anywhere;
+ }
+}
+
+.review-item__aside.--dsa-classification {
+ padding-block-start: 0;
+}
+
+.review-item__classify {
+ margin-block-end: var(--space-4);
+ margin-inline-start: var(--review-item-padding);
+
+ &.--pending-notice {
+ inline-size: calc(100% - 2 * var(--review-item-padding));
+ justify-content: flex-start;
+ background: var(--highlight-low);
+ color: var(--primary);
+ border: 1px solid var(--highlight-medium);
+ }
+}
+
+.dsa-classification-modal__help {
+ margin-inline-end: auto;
+}
diff --git a/app/assets/stylesheets/common/base/review.scss b/app/assets/stylesheets/common/base/review.scss
index 770dd6d8d1d..4582010ed6d 100644
--- a/app/assets/stylesheets/common/base/review.scss
+++ b/app/assets/stylesheets/common/base/review.scss
@@ -602,6 +602,9 @@
}
&__description {
+ &.--note {
+ white-space: pre-line;
+ }
color: var(--primary-high);
font-size: var(--font-down-1);
overflow-wrap: anywhere;
diff --git a/app/controllers/dsa_statements_controller.rb b/app/controllers/dsa_statements_controller.rb
new file mode 100644
index 00000000000..513a3feaea5
--- /dev/null
+++ b/app/controllers/dsa_statements_controller.rb
@@ -0,0 +1,44 @@
+# frozen_string_literal: true
+
+class DsaStatementsController < ApplicationController
+ requires_login
+
+ def classify
+ DsaStatementOfRecord::Classify.call(service_params) do
+ on_success do |reviewable:|
+ statement_ids =
+ reviewable.dsa_statement_of_records.pending.order(:created_at, :id).pluck(:id)
+ notes = reviewable.reviewable_notes.preload(:user).to_a
+
+ render_json_dump(
+ dsa_classification: {
+ statement_ids:,
+ },
+ reviewable_notes:
+ serialize_data(
+ notes,
+ ReviewableNoteSerializer,
+ root: false,
+ reviewable_note_mention_usernames:
+ PlaintextMentions.known_usernames(notes.map(&:content)),
+ ),
+ )
+ end
+ on_failed_policy(:staff) { raise Discourse::InvalidAccess }
+ on_failed_policy(:classification_enabled) { raise Discourse::InvalidAccess }
+ on_model_not_found(:reviewable) { raise Discourse::NotFound }
+ on_model_not_found(:statements) do
+ render_json_error(I18n.t("dsa_statements.errors.statements_changed"), status: :conflict)
+ end
+ on_failed_policy(:current_statements) do
+ render_json_error(I18n.t("dsa_statements.errors.statements_changed"), status: :conflict)
+ end
+ on_failed_contract do |contract|
+ render_json_error(contract.errors.full_messages, status: :unprocessable_entity)
+ end
+ on_failure do
+ render_json_error(I18n.t("dsa_statements.errors.failed"), status: :unprocessable_entity)
+ end
+ end
+ end
+end
diff --git a/app/controllers/reviewables_controller.rb b/app/controllers/reviewables_controller.rb
index 90809bf8b08..06e01bee57a 100644
--- a/app/controllers/reviewables_controller.rb
+++ b/app/controllers/reviewables_controller.rb
@@ -95,7 +95,14 @@ class ReviewablesController < ApplicationController
end
json.merge!(hash)
- render_json_dump(json, rest_serializer: true)
+ render_json_dump(
+ json,
+ rest_serializer: true,
+ extras: {
+ dsa_classification:
+ DsaClassificationSerializer.new({}, scope: guardian, root: false).as_json,
+ },
+ )
end
def user_menu_list
@@ -172,6 +179,10 @@ class ReviewablesController < ApplicationController
rest_serializer: true,
claimed_topics: ReviewableClaimedTopic.claimed_hash([reviewable.topic_id]),
root: "reviewable",
+ extras: {
+ dsa_classification:
+ DsaClassificationSerializer.new({}, scope: guardian, root: false).as_json,
+ },
meta: {
types: meta_types,
},
diff --git a/app/models/dsa_statement_of_record.rb b/app/models/dsa_statement_of_record.rb
index e80ae24a5c4..972ca7a2e42 100644
--- a/app/models/dsa_statement_of_record.rb
+++ b/app/models/dsa_statement_of_record.rb
@@ -34,19 +34,71 @@ class DsaStatementOfRecord < ActiveRecord::Base
SK
].freeze
- enum :status, { pending: 0 }
+ enum :status, { pending: 0, ready: 1 }
+
+ CATEGORIES =
+ %w[
+ ANIMAL_WELFARE
+ CONSUMER_INFORMATION
+ CYBER_VIOLENCE
+ CYBER_VIOLENCE_AGAINST_WOMEN
+ DATA_PROTECTION_AND_PRIVACY_VIOLATIONS
+ ILLEGAL_OR_HARMFUL_SPEECH
+ INTELLECTUAL_PROPERTY_INFRINGEMENTS
+ NEGATIVE_EFFECTS_ON_CIVIC_DISCOURSE_OR_ELECTIONS
+ NOT_SPECIFIED_NOTICE
+ OTHER_VIOLATION_TC
+ PROTECTION_OF_MINORS
+ RISK_FOR_PUBLIC_SECURITY
+ SCAMS_AND_FRAUD
+ SELF_HARM
+ UNSAFE_AND_PROHIBITED_PRODUCTS
+ VIOLENCE
+ ].map { |category| "STATEMENT_CATEGORY_#{category}" }.freeze
+
+ class << self
+ def community_rules
+ JSON
+ .parse(SiteSetting.dsa_community_rules)
+ .map do |rule|
+ rule.merge(
+ "id" => Digest::SHA256.hexdigest([rule["ground"], rule["explanation"]].to_json),
+ )
+ end
+ end
+
+ def classification_enabled?
+ SiteSetting.dsa_reporting_enabled && JSON.parse(SiteSetting.dsa_community_rules).present?
+ end
+ end
+
+ def classify!(community_rule:, category:, classified_by:)
+ update!(
+ payload:
+ payload.merge(
+ "incompatible_content_ground" => community_rule.fetch("ground"),
+ "incompatible_content_explanation" => community_rule.fetch("explanation"),
+ "category" => category,
+ ),
+ status: :ready,
+ classified_by_id: classified_by.id,
+ classified_at: Time.current,
+ )
+ end
end
# == Schema Information
#
# Table name: dsa_statement_of_records
#
-# id :uuid not null, primary key
-# payload :jsonb not null
-# status :integer default("pending"), not null
-# created_at :datetime not null
-# updated_at :datetime not null
-# reviewable_id :bigint not null
+# id :uuid not null, primary key
+# classified_at :datetime
+# payload :jsonb not null
+# status :integer default("pending"), not null
+# created_at :datetime not null
+# updated_at :datetime not null
+# classified_by_id :bigint
+# reviewable_id :bigint not null
#
# Indexes
#
diff --git a/app/models/reviewable.rb b/app/models/reviewable.rb
index c196aabfd9d..1dfd2dce4a4 100644
--- a/app/models/reviewable.rb
+++ b/app/models/reviewable.rb
@@ -34,6 +34,7 @@ class Reviewable < ActiveRecord::Base
has_many :reviewable_histories, dependent: :destroy
has_many :reviewable_scores, -> { order(created_at: :desc) }, dependent: :destroy
has_many :reviewable_notes, -> { order(created_at: :asc) }, dependent: :destroy
+ has_many :dsa_statement_of_records
enum :status, { pending: 0, approved: 1, rejected: 2, ignored: 3, deleted: 4 }
diff --git a/app/serializers/dsa_classification_serializer.rb b/app/serializers/dsa_classification_serializer.rb
new file mode 100644
index 00000000000..1a7aec32758
--- /dev/null
+++ b/app/serializers/dsa_classification_serializer.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+class DsaClassificationSerializer < ApplicationSerializer
+ attributes :community_rules, :categories
+
+ def community_rules
+ DsaStatementOfRecord.community_rules.map { |rule| rule.slice("id", "ground") }
+ end
+
+ def categories
+ DsaStatementOfRecord::CATEGORIES.map do |category|
+ { id: category, name: I18n.t("dsa_statements.categories.#{category}") }
+ end
+ end
+
+ def include_community_rules?
+ scope.is_staff? && DsaStatementOfRecord.classification_enabled?
+ end
+
+ alias_method :include_categories?, :include_community_rules?
+end
diff --git a/app/serializers/reviewable_serializer.rb b/app/serializers/reviewable_serializer.rb
index d79a70619ac..61cc494335b 100644
--- a/app/serializers/reviewable_serializer.rb
+++ b/app/serializers/reviewable_serializer.rb
@@ -26,6 +26,17 @@ class ReviewableSerializer < ApplicationSerializer
attribute :status_for_database, key: :status
+ attribute :dsa_classification
+
+ def dsa_classification
+ { statement_ids: object.dsa_statement_of_records.select(&:pending?).map(&:id) }
+ end
+
+ def include_dsa_classification?
+ scope.is_staff? && DsaStatementOfRecord.classification_enabled? &&
+ object.dsa_statement_of_records.present?
+ end
+
has_one :target_created_by, root: "users"
has_one :created_by, serializer: UserWithCustomFieldsSerializer, root: "users"
has_one :target_deleted_by, serializer: BasicUserSerializer, root: "users"
diff --git a/app/services/dsa_statement_of_record/classify.rb b/app/services/dsa_statement_of_record/classify.rb
new file mode 100644
index 00000000000..dd3a757e3ae
--- /dev/null
+++ b/app/services/dsa_statement_of_record/classify.rb
@@ -0,0 +1,83 @@
+# frozen_string_literal: true
+
+class DsaStatementOfRecord::Classify
+ include Service::Base
+
+ policy :staff
+ policy :classification_enabled
+
+ params 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 }
+ end
+
+ model :community_rule
+
+ transaction do
+ model :reviewable
+ model :statements
+ policy :current_statements
+ step :classify
+ model :reviewable_note, :save_note
+ end
+
+ private
+
+ def staff(guardian:)
+ guardian.is_staff?
+ end
+
+ def classification_enabled
+ DsaStatementOfRecord.classification_enabled?
+ end
+
+ def fetch_community_rule(params:)
+ DsaStatementOfRecord.community_rules.find { |rule| rule["id"] == params.community_rule }
+ end
+
+ def fetch_reviewable(params:, guardian:)
+ reviewable =
+ Reviewable.viewable_by(guardian.user, preload: false).find_by(id: params.reviewable_id)
+
+ reviewable&.lock!
+ end
+
+ def fetch_statements(reviewable:)
+ reviewable.dsa_statement_of_records.pending.order(:id).lock.to_a
+ end
+
+ def current_statements(statements:, params:)
+ params.statement_ids.map(&:to_s).sort == statements.map(&:id).sort
+ end
+
+ def classify(statements:, community_rule:, params:, guardian:)
+ statements.each do |statement|
+ statement.classify!(community_rule:, category: params.category, classified_by: guardian.user)
+ end
+ end
+
+ def save_note(reviewable:, community_rule:, params:, 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
+ end
+end
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 590de9486e8..f623634ca40 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -981,6 +981,20 @@ en:
search: "Search for a Message"
placeholder: "type the message title, url or id here"
+ dsa_statements:
+ title: "DSA classification"
+ help_title: "About DSA classification"
+ help: "Select the community rule and category that explain this moderation decision. These are saved with its Digital Services Act statement of reasons."
+ rule: "Community rule"
+ rule_prompt: "Choose a community rule"
+ category: "Category"
+ category_prompt: "Choose a category"
+ pending: "DSA classification pending"
+ confirm_title: "Save DSA classification?"
+ confirm_message: "Check the community rule and category. This classification cannot be changed after saving."
+ save: "Save classification"
+ saving: "Saving…"
+ saved: "Classification saved"
review:
show_more: "Show more"
show_less: "Show less"
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index 7b91045817b..9d84793fa69 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -1,4 +1,26 @@
en:
+ dsa_statements:
+ classification_note: "Classified this moderation decision for DSA reporting.\nCommunity rule: %{ground}\nCategory: %{category}"
+ errors:
+ statements_changed: "The statements for this review have changed. Reload the page to see their current classification."
+ failed: "Classification could not be saved. Please try again."
+ categories:
+ STATEMENT_CATEGORY_ANIMAL_WELFARE: "Animal welfare"
+ STATEMENT_CATEGORY_CONSUMER_INFORMATION: "Consumer information infringements"
+ STATEMENT_CATEGORY_CYBER_VIOLENCE: "Cyber violence"
+ STATEMENT_CATEGORY_CYBER_VIOLENCE_AGAINST_WOMEN: "Cyber violence against women"
+ STATEMENT_CATEGORY_DATA_PROTECTION_AND_PRIVACY_VIOLATIONS: "Data protection and privacy violations"
+ STATEMENT_CATEGORY_ILLEGAL_OR_HARMFUL_SPEECH: "Illegal or harmful speech"
+ STATEMENT_CATEGORY_INTELLECTUAL_PROPERTY_INFRINGEMENTS: "Intellectual property infringements"
+ STATEMENT_CATEGORY_NEGATIVE_EFFECTS_ON_CIVIC_DISCOURSE_OR_ELECTIONS: "Negative effects on civic discourse or elections"
+ STATEMENT_CATEGORY_NOT_SPECIFIED_NOTICE: "Type of alleged illegal content not specified by the notifier"
+ STATEMENT_CATEGORY_OTHER_VIOLATION_TC: "Other violation of terms and conditions"
+ STATEMENT_CATEGORY_PROTECTION_OF_MINORS: "Protection of minors"
+ STATEMENT_CATEGORY_RISK_FOR_PUBLIC_SECURITY: "Risk for public security"
+ STATEMENT_CATEGORY_SCAMS_AND_FRAUD: "Scams and fraud"
+ STATEMENT_CATEGORY_SELF_HARM: "Self harm"
+ STATEMENT_CATEGORY_UNSAFE_AND_PROHIBITED_PRODUCTS: "Unsafe or prohibited products"
+ STATEMENT_CATEGORY_VIOLENCE: "Violence"
markdown_endpoints:
latest: "Latest"
categories: "Categories"
@@ -2094,6 +2116,7 @@ en:
unavailable: "A random username could not be generated. Check the random username word lists in your site settings."
site_settings:
+ dsa_community_rules: "Community rules available for DSA classification when {{setting:dsa_reporting_enabled}} is enabled. Each rule needs an exact contractual reference (up to 500 characters) and an explanation (up to 2000 characters). Leave empty to disable classification."
allow_bulk_invite: "Allow bulk invites by uploading a CSV file"
disabled: "disabled"
display_local_time_in_user_card: "Display the local time based on a user's timezone when their user card is opened."
diff --git a/config/routes.rb b/config/routes.rb
index e94c02fd048..bbebe0267a3 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -618,6 +618,10 @@ Discourse::Application.routes.draw do
get "review/settings" => "reviewables#settings"
get "review/user-menu-list" => "reviewables#user_menu_list", :format => :json
put "review/settings" => "reviewables#settings"
+ put "review/:reviewable_id/dsa-classification" => "dsa_statements#classify",
+ :constraints => {
+ reviewable_id: /\d+/,
+ }
put "review/:reviewable_id/perform/:action_id" => "reviewables#perform",
:constraints => {
reviewable_id: /\d+/,
diff --git a/config/site_settings.yml b/config/site_settings.yml
index 5d8f8c6751e..d8ce6114b7f 100644
--- a/config/site_settings.yml
+++ b/config/site_settings.yml
@@ -4900,6 +4900,23 @@ experimental:
default: false
hidden: true
area: "experimental"
+ dsa_community_rules:
+ type: objects
+ default: []
+ area: "experimental"
+ schema:
+ name: community_rule
+ properties:
+ ground:
+ type: string
+ required: true
+ validations:
+ max_length: 500
+ explanation:
+ type: string
+ required: true
+ validations:
+ max_length: 2000
experimental_impersonation_time_limit_minutes:
default: 15
hidden: true
diff --git a/db/migrate/20261013062937_add_classification_to_dsa_statement_of_records.rb b/db/migrate/20261013062937_add_classification_to_dsa_statement_of_records.rb
new file mode 100644
index 00000000000..bcd313d465c
--- /dev/null
+++ b/db/migrate/20261013062937_add_classification_to_dsa_statement_of_records.rb
@@ -0,0 +1,8 @@
+# frozen_string_literal: true
+
+class AddClassificationToDsaStatementOfRecords < ActiveRecord::Migration[8.1]
+ def change
+ add_column :dsa_statement_of_records, :classified_by_id, :bigint
+ add_column :dsa_statement_of_records, :classified_at, :datetime
+ end
+end
diff --git a/db/structure.sql b/db/structure.sql
index 92adc5f272e..589fb0c6983 100644
--- a/db/structure.sql
+++ b/db/structure.sql
@@ -5992,7 +5992,9 @@ CREATE TABLE public.dsa_statement_of_records (
status integer DEFAULT 0 NOT NULL,
payload jsonb NOT NULL,
created_at timestamp(6) without time zone NOT NULL,
- updated_at timestamp(6) without time zone NOT NULL
+ updated_at timestamp(6) without time zone NOT NULL,
+ classified_by_id bigint,
+ classified_at timestamp(6) without time zone
);
@@ -25925,6 +25927,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20261014065735'),
('20261013222431'),
('20261013183208'),
+('20261013062937'),
('20261013010026'),
('20261013010022'),
('20261012021959'),
diff --git a/frontend/discourse/app/components/dialog-messages/dsa-classification-confirmation.gjs b/frontend/discourse/app/components/dialog-messages/dsa-classification-confirmation.gjs
new file mode 100644
index 00000000000..e38c7b4fa93
--- /dev/null
+++ b/frontend/discourse/app/components/dialog-messages/dsa-classification-confirmation.gjs
@@ -0,0 +1,17 @@
+import { i18n } from "discourse-i18n";
+
+const DsaClassificationConfirmation = <template>
+ <p>{{i18n "dsa_statements.confirm_message"}}</p>
+ <dl class="dsa-classification-confirmation">
+ <dt class="dsa-classification-confirmation__label">{{i18n
+ "dsa_statements.rule"
+ }}</dt>
+ <dd class="dsa-classification-confirmation__value">{{@model.rule}}</dd>
+ <dt class="dsa-classification-confirmation__label">{{i18n
+ "dsa_statements.category"
+ }}</dt>
+ <dd class="dsa-classification-confirmation__value">{{@model.category}}</dd>
+ </dl>
+</template>;
+
+export default DsaClassificationConfirmation;
diff --git a/frontend/discourse/app/components/dsa-statement-classification.gjs b/frontend/discourse/app/components/dsa-statement-classification.gjs
new file mode 100644
index 00000000000..110235e4fe7
--- /dev/null
+++ b/frontend/discourse/app/components/dsa-statement-classification.gjs
@@ -0,0 +1,172 @@
+import Component from "@glimmer/component";
+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 Form from "discourse/components/form";
+import { ajax } from "discourse/lib/ajax";
+import { popupAjaxError } from "discourse/lib/ajax-error";
+import DButton from "discourse/ui-kit/d-button";
+import { i18n } from "discourse-i18n";
+
+export default class DsaStatementClassification extends Component {
+ @service dialog;
+ @service toasts;
+
+ @tracked saving = false;
+
+ formData = {};
+
+ get classification() {
+ return this.args.reviewable.dsa_classification;
+ }
+
+ get classificationOptions() {
+ return this.args.reviewable.extras.dsa_classification;
+ }
+
+ @action
+ cancel() {
+ this.args.onCancel?.();
+ }
+
+ @action
+ showHelp() {
+ this.dialog.alert(i18n("dsa_statements.help"));
+ }
+
+ @action
+ async save(data) {
+ const reviewable = this.args.reviewable;
+
+ const statementIds = [...this.classification.statement_ids];
+ const rule = this.classificationOptions.community_rules.find(
+ (entry) => entry.id === data.community_rule
+ );
+ const category = this.classificationOptions.categories.find(
+ (entry) => entry.id === data.category
+ );
+ const confirmed = await this.dialog.confirm({
+ title: i18n("dsa_statements.confirm_title"),
+ bodyComponent: DsaClassificationConfirmation,
+ bodyComponentModel: { rule: rule.ground, category: category.name },
+ confirmButtonLabel: "dsa_statements.save",
+ });
+
+ if (!confirmed || this.isDestroying) {
+ return;
+ }
+
+ this.saving = true;
+ this.args.onSavingChange?.(true);
+
+ try {
+ const response = await ajax(
+ `/review/${reviewable.id}/dsa-classification`,
+ {
+ type: "PUT",
+ data: {
+ ...data,
+ statement_ids: statementIds,
+ },
+ }
+ );
+ reviewable.set("reviewable_notes", response.reviewable_notes);
+
+ if (!this.isDestroying) {
+ this.cancel();
+ }
+
+ reviewable.set("dsa_classification", response.dsa_classification);
+ this.toasts.success({
+ duration: "short",
+ data: { message: i18n("dsa_statements.saved") },
+ });
+ } catch (error) {
+ popupAjaxError(error);
+ } finally {
+ this.saving = false;
+ this.args.onSavingChange?.(false);
+ }
+ }
+
+ <template>
+ <section class="dsa-classification" ...attributes>
+ {{#unless @hideHeading}}
+ <div class="dsa-classification__heading">
+ <h2>{{i18n "dsa_statements.title"}}</h2>
+ <DButton
+ class="btn-transparent"
+ @action={{this.showHelp}}
+ @icon="circle-question"
+ @title="dsa_statements.help_title"
+ />
+ </div>
+ {{/unless}}
+
+ {{#if this.classification.statement_ids.length}}
+ <Form @data={{this.formData}} @onSubmit={{this.save}} as |form|>
+ <form.Field
+ @disabled={{this.saving}}
+ @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 this.classificationOptions.community_rules as |rule|}}
+ <select.Option
+ @value={{rule.id}}
+ >{{rule.ground}}</select.Option>
+ {{/each}}
+ </field.Control>
+ </form.Field>
+
+ <form.Field
+ @disabled={{this.saving}}
+ @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 this.classificationOptions.categories as |category|}}
+ <select.Option
+ @value={{category.id}}
+ >{{category.name}}</select.Option>
+ {{/each}}
+ </field.Control>
+ </form.Field>
+
+ <form.Actions>
+ <form.Submit
+ @disabled={{this.saving}}
+ @label={{if
+ this.saving
+ "dsa_statements.saving"
+ "dsa_statements.save"
+ }}
+ />
+ {{#if @showCancel}}
+ <DButton
+ @action={{this.cancel}}
+ @disabled={{this.saving}}
+ @label="cancel"
+ />
+ {{/if}}
+ </form.Actions>
+ </Form>
+ {{/if}}
+ </section>
+ </template>
+}
diff --git a/frontend/discourse/app/components/modal/dsa-classification.gjs b/frontend/discourse/app/components/modal/dsa-classification.gjs
new file mode 100644
index 00000000000..be2792ee4b7
--- /dev/null
+++ b/frontend/discourse/app/components/modal/dsa-classification.gjs
@@ -0,0 +1,52 @@
+import Component from "@glimmer/component";
+import { tracked } from "@glimmer/tracking";
+import { action } from "@ember/object";
+import { service } from "@ember/service";
+import DsaStatementClassification from "discourse/components/dsa-statement-classification";
+import { not } from "discourse/truth-helpers";
+import DButton from "discourse/ui-kit/d-button";
+import DModal from "discourse/ui-kit/d-modal";
+import { i18n } from "discourse-i18n";
+
+export default class DsaClassificationModal extends Component {
+ @service dialog;
+
+ @tracked saving = false;
+
+ @action
+ savingChanged(saving) {
+ this.saving = saving;
+ }
+
+ @action
+ showHelp() {
+ this.dialog.alert(i18n("dsa_statements.help"));
+ }
+
+ <template>
+ <DModal
+ class="dsa-classification-modal"
+ @closeModal={{@closeModal}}
+ @dismissable={{not this.saving}}
+ @title={{i18n "dsa_statements.title"}}
+ >
+ <:headerBelowTitle>
+ <DButton
+ class="btn-transparent dsa-classification-modal__help"
+ @action={{this.showHelp}}
+ @icon="circle-question"
+ @title="dsa_statements.help_title"
+ />
+ </:headerBelowTitle>
+ <:body>
+ <DsaStatementClassification
+ @hideHeading={{true}}
+ @onCancel={{@closeModal}}
+ @onSavingChange={{this.savingChanged}}
+ @reviewable={{@model.reviewable}}
+ @showCancel={{true}}
+ />
+ </:body>
+ </DModal>
+ </template>
+}
diff --git a/frontend/discourse/app/components/reviewable/item.gjs b/frontend/discourse/app/components/reviewable/item.gjs
index 623f9ca1795..ac4742b259c 100644
--- a/frontend/discourse/app/components/reviewable/item.gjs
+++ b/frontend/discourse/app/components/reviewable/item.gjs
@@ -1,6 +1,6 @@
import Component from "@glimmer/component";
import { cached, tracked } from "@glimmer/tracking";
-import { fn, get } from "@ember/helper";
+import { array, fn, get } from "@ember/helper";
import { on } from "@ember/modifier";
import { action } from "@ember/object";
import { getOwner } from "@ember/owner";
@@ -8,6 +8,8 @@ import { trackedObject } from "@ember/reactive/collections";
import { service } from "@ember/service";
import { classify, dasherize } from "@ember/string";
import ScrubRejectedUserModal from "discourse/admin/components/modal/scrub-rejected-user";
+import DsaStatementClassification from "discourse/components/dsa-statement-classification";
+import DsaClassificationModal from "discourse/components/modal/dsa-classification";
import RejectReasonReviewableModal from "discourse/components/modal/reject-reason-reviewable";
import ReviseAndRejectPostReviewable from "discourse/components/modal/revise-and-reject-post-reviewable";
import ReviewableFlagReason from "discourse/components/reviewable/flag-reason";
@@ -39,7 +41,7 @@ import Composer from "discourse/models/composer";
import { PENDING } from "discourse/models/reviewable";
import { CLAIMED, UNCLAIMED } from "discourse/models/reviewable-history";
import Topic from "discourse/models/topic";
-import { eq, not, or } from "discourse/truth-helpers";
+import { and, eq, not, or } from "discourse/truth-helpers";
import DAsyncContent from "discourse/ui-kit/d-async-content";
import DButton from "discourse/ui-kit/d-button";
import DHorizontalOverflowNav from "discourse/ui-kit/d-horizontal-overflow-nav";
@@ -101,6 +103,7 @@ export function registerReviewableTypeLabel(reviewableType, labelKey) {
export default class ReviewableItem extends Component {
@service dialog;
+ @service capabilities;
@service modal;
@service siteSettings;
@service currentUser;
@@ -304,6 +307,13 @@ export default class ReviewableItem extends Component {
return resolveReviewableComponent(getOwner(this), type);
}
+ @action
+ openClassification() {
+ this.modal.show(DsaClassificationModal, {
+ model: { reviewable: this.args.reviewable },
+ });
+ }
+
@action
clientScrub() {
this.modal.show(ScrubRejectedUserModal, {
@@ -798,6 +808,21 @@ export default class ReviewableItem extends Component {
{{/if}}
</div>
+ {{#if
+ (and
+ (not this.capabilities.viewport.sm)
+ @reviewable.dsa_classification.statement_ids.length
+ )
+ }}
+ <DButton
+ class="review-item__classify --pending-notice"
+ @action={{this.openClassification}}
+ @icon="clock"
+ @label="dsa_statements.pending"
+ @suffixIcon="chevron-right"
+ />
+ {{/if}}
+
<div class="review-item__insights">
<div class="d-nav-submenu">
<DHorizontalOverflowNav
@@ -849,7 +874,12 @@ export default class ReviewableItem extends Component {
</div>
</div>
- <div class="review-item__aside">
+ <div
+ class={{dConcatClass
+ "review-item__aside"
+ (if @reviewable.dsa_classification "--dsa-classification")
+ }}
+ >
{{#unless @reviewable.last_performing_username}}
{{#if this.canPerform}}
@@ -936,7 +966,16 @@ export default class ReviewableItem extends Component {
</div>
{{/if}}
- {{#if @showHelp}}
+ {{#if
+ (and
+ this.capabilities.viewport.sm
+ @reviewable.dsa_classification.statement_ids.length
+ )
+ }}
+ {{#each (array @reviewable) as |reviewable|}}
+ <DsaStatementClassification @reviewable={{reviewable}} />
+ {{/each}}
+ {{else if (and @showHelp (not @reviewable.dsa_classification))}}
<ReviewableHelpResources />
{{/if}}
</div>
diff --git a/frontend/discourse/app/components/reviewable/timeline.gjs b/frontend/discourse/app/components/reviewable/timeline.gjs
index 283496a10f2..fe04a28961b 100644
--- a/frontend/discourse/app/components/reviewable/timeline.gjs
+++ b/frontend/discourse/app/components/reviewable/timeline.gjs
@@ -279,7 +279,11 @@ export default class ReviewableTimeline extends Component {
</div>
{{#if event.description}}
<DDecoratedHtml
- @className="timeline-event__description"
+ @className={{if
+ (eq event.type "note")
+ "timeline-event__description --note"
+ "timeline-event__description"
+ }}
@html={{event.description}}
/>
{{/if}}
diff --git a/frontend/discourse/app/models/reviewable.js b/frontend/discourse/app/models/reviewable.js
index 062278d08fc..4ff0cb84551 100644
--- a/frontend/discourse/app/models/reviewable.js
+++ b/frontend/discourse/app/models/reviewable.js
@@ -33,6 +33,7 @@ export default class Reviewable extends RestModel {
@tracked created_by;
@tracked created_from_flag;
@tracked deleted_at;
+ @tracked dsa_classification;
@tracked editable_fields;
@tracked fancy_title;
@tracked id;
diff --git a/spec/fabricators/dsa_statement_of_record_fabricator.rb b/spec/fabricators/dsa_statement_of_record_fabricator.rb
new file mode 100644
index 00000000000..d6e1ae3d107
--- /dev/null
+++ b/spec/fabricators/dsa_statement_of_record_fabricator.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+Fabricator(:dsa_statement_of_record) do
+ reviewable_id { Fabricate(:reviewable_flagged_post).id }
+ payload do
+ {
+ "decision_visibility" => ["DECISION_VISIBILITY_CONTENT_REMOVED"],
+ "decision_ground" => "DECISION_GROUND_INCOMPATIBLE_CONTENT",
+ "decision_facts" => "The flagged post was removed.",
+ "content_type" => ["CONTENT_TYPE_TEXT"],
+ "content_date" => "2026-10-01",
+ "application_date" => "2026-10-02",
+ "territorial_scope" => DsaStatementOfRecord::TERRITORIAL_SCOPE,
+ "source_type" => "SOURCE_VOLUNTARY",
+ "automated_detection" => "No",
+ "automated_decision" => "AUTOMATED_DECISION_NOT_AUTOMATED",
+ }
+ end
+end
diff --git a/spec/models/site_setting_spec.rb b/spec/models/site_setting_spec.rb
index 9c824c9ba8b..2e1023edb61 100644
--- a/spec/models/site_setting_spec.rb
+++ b/spec/models/site_setting_spec.rb
@@ -1,6 +1,40 @@
# frozen_string_literal: true
RSpec.describe SiteSetting do
+ describe ".dsa_community_rules=" do
+ let(:rule) { { ground: "Terms, section 3", explanation: "Personal attacks are prohibited." } }
+
+ it "accepts a 500 character contractual ground and rejects 501 characters" do
+ rule[:ground] = "é" * 500
+
+ SiteSetting.dsa_community_rules = [rule].to_json
+
+ expect(JSON.parse(SiteSetting.dsa_community_rules).sole.fetch("ground")).to eq(rule[:ground])
+
+ rule[:ground] << "é"
+
+ expect { SiteSetting.dsa_community_rules = [rule].to_json }.to raise_error(
+ Discourse::InvalidParameters,
+ )
+ end
+
+ it "accepts a 2000 character explanation and rejects 2001 characters" do
+ rule[:explanation] = "é" * 2000
+
+ SiteSetting.dsa_community_rules = [rule].to_json
+
+ expect(JSON.parse(SiteSetting.dsa_community_rules).sole.fetch("explanation")).to eq(
+ rule[:explanation],
+ )
+
+ rule[:explanation] << "é"
+
+ expect { SiteSetting.dsa_community_rules = [rule].to_json }.to raise_error(
+ Discourse::InvalidParameters,
+ )
+ end
+ end
+
describe "topic_title_length" do
it "returns a range of min/max topic title length" do
expect(SiteSetting.topic_title_length).to eq(
diff --git a/spec/requests/dsa_statements_controller_spec.rb b/spec/requests/dsa_statements_controller_spec.rb
new file mode 100644
index 00000000000..51944cde1f2
--- /dev/null
+++ b/spec/requests/dsa_statements_controller_spec.rb
@@ -0,0 +1,91 @@
+# frozen_string_literal: true
+
+RSpec.describe DsaStatementsController do
+ describe "#classify" do
+ fab!(:moderator)
+ fab!(:reviewable, :reviewable_flagged_post)
+ fab!(:statement) { Fabricate(:dsa_statement_of_record, reviewable_id: reviewable.id) }
+
+ let(:params) do
+ {
+ community_rule: DsaStatementOfRecord.community_rules.first.fetch("id"),
+ category: "STATEMENT_CATEGORY_ILLEGAL_OR_HARMFUL_SPEECH",
+ statement_ids: [statement.id],
+ }
+ end
+
+ before do
+ SiteSetting.dsa_reporting_enabled = true
+ SiteSetting.dsa_community_rules = [
+ {
+ ground: "Terms, section 3",
+ explanation: "The content targets another person with insults.",
+ },
+ ].to_json
+ end
+
+ it "returns forbidden when a nonstaff user classifies a flagged post" do
+ sign_in(Fabricate(:user))
+
+ put("/review/#{reviewable.id}/dsa-classification.json", params:)
+
+ expect(response).to have_http_status(:forbidden)
+ end
+
+ it "allows a full moderator to classify a flagged post they can review" do
+ sign_in(moderator)
+
+ put("/review/#{reviewable.id}/dsa-classification.json", params:)
+
+ note = reviewable.reviewable_notes.last
+
+ expect(response).to have_http_status(:ok)
+ expect(response.parsed_body["dsa_classification"]).to eq("statement_ids" => [])
+ expect(response.parsed_body["reviewable_notes"].sole).to include(
+ "id" => note.id,
+ "content" => note.content,
+ "user" => include("id" => moderator.id),
+ )
+ end
+
+ it "returns not found for an unknown reviewable" do
+ sign_in(moderator)
+
+ put("/review/0/dsa-classification.json", params:)
+
+ expect(response).to have_http_status(:not_found)
+ end
+
+ it "returns a generic error for an unknown community rule" do
+ sign_in(moderator)
+ params[:community_rule] = "unknown"
+
+ put("/review/#{reviewable.id}/dsa-classification.json", params:)
+
+ expect(response).to have_http_status(:unprocessable_entity)
+ expect(response.parsed_body["errors"]).to include(I18n.t("dsa_statements.errors.failed"))
+ end
+
+ it "returns validation errors for an invalid category" do
+ sign_in(moderator)
+ params[:category] = "unknown"
+
+ put("/review/#{reviewable.id}/dsa-classification.json", params:)
+
+ expect(response).to have_http_status(:unprocessable_entity)
+ expect(response.parsed_body["errors"]).to include(a_string_matching(/Category/))
+ end
+
+ it "rejects a second classification of the same statement" do
+ sign_in(moderator)
+ statement.update!(status: :ready)
+
+ put("/review/#{reviewable.id}/dsa-classification.json", params:)
+
+ expect(response).to have_http_status(:conflict)
+ expect(response.parsed_body["errors"]).to include(
+ I18n.t("dsa_statements.errors.statements_changed"),
+ )
+ end
+ end
+end
diff --git a/spec/requests/reviewables_controller_spec.rb b/spec/requests/reviewables_controller_spec.rb
index 29542e9f082..0ba1d1d337e 100644
--- a/spec/requests/reviewables_controller_spec.rb
+++ b/spec/requests/reviewables_controller_spec.rb
@@ -43,6 +43,43 @@ RSpec.describe ReviewablesController do
before { sign_in(admin) }
describe "#index" do
+ it "includes DSA classification for flagged posts without loading each statement separately" do
+ SiteSetting.dsa_reporting_enabled = true
+ SiteSetting.dsa_community_rules = [
+ { ground: "Terms, section 3", explanation: "Personal attacks are prohibited." },
+ ].to_json
+ first_reviewable = Fabricate(:reviewable_flagged_post)
+ second_reviewable = Fabricate(:reviewable_flagged_post)
+ first_statement = Fabricate(:dsa_statement_of_record, reviewable_id: first_reviewable.id)
+ second_statement = Fabricate(:dsa_statement_of_record, reviewable_id: second_reviewable.id)
+
+ queries = track_sql_queries { get "/review.json" }
+
+ expect(response).to have_http_status(:ok)
+ reviewables = response.parsed_body["reviewables"].index_by { |reviewable| reviewable["id"] }
+ expect(reviewables[first_reviewable.id]["dsa_classification"]).to eq(
+ "statement_ids" => [first_statement.id],
+ )
+ expect(reviewables[second_reviewable.id]["dsa_classification"]).to eq(
+ "statement_ids" => [second_statement.id],
+ )
+
+ options = response.parsed_body["extras"]["dsa_classification"]
+ expect(options["community_rules"]).to eq(
+ [
+ {
+ "id" => DsaStatementOfRecord.community_rules.first["id"],
+ "ground" => "Terms, section 3",
+ },
+ ],
+ )
+ expect(options["categories"]).to include(
+ "id" => "STATEMENT_CATEGORY_ILLEGAL_OR_HARMFUL_SPEECH",
+ "name" => "Illegal or harmful speech",
+ )
+ expect(queries.count { |sql| sql.include?('FROM "dsa_statement_of_records"') }).to eq(1)
+ end
+
it "returns empty JSON when nothing to review" do
get "/review.json"
expect(response.code).to eq("200")
@@ -604,6 +641,57 @@ RSpec.describe ReviewablesController do
end
describe "#show" do
+ context "when dsa_reporting_enabled is enabled" do
+ fab!(:reviewable, :reviewable_flagged_post)
+ fab!(:statement) { Fabricate(:dsa_statement_of_record, reviewable_id: reviewable.id) }
+
+ before do
+ sign_in(Fabricate(:moderator))
+ SiteSetting.dsa_reporting_enabled = true
+ SiteSetting.dsa_community_rules = [
+ { ground: "Terms, section 3", explanation: "Personal attacks are prohibited." },
+ ].to_json
+ end
+
+ it "includes pending statement IDs and shared classification options for a flagged post" do
+ get "/review/#{reviewable.id}.json"
+
+ expect(response.parsed_body["reviewable"]["dsa_classification"]).to eq(
+ "statement_ids" => [statement.id],
+ )
+
+ options = response.parsed_body["extras"]["dsa_classification"]
+ expect(options["community_rules"]).to eq(
+ [
+ {
+ "id" => DsaStatementOfRecord.community_rules.first["id"],
+ "ground" => "Terms, section 3",
+ },
+ ],
+ )
+ expect(options["categories"]).to include(
+ "id" => "STATEMENT_CATEGORY_ILLEGAL_OR_HARMFUL_SPEECH",
+ "name" => "Illegal or harmful speech",
+ )
+ end
+
+ it "omits classification when community rules are empty" do
+ SiteSetting.dsa_community_rules = "[]"
+
+ get "/review/#{reviewable.id}.json"
+
+ expect(response.parsed_body["reviewable"]).not_to have_key("dsa_classification")
+ end
+
+ it "omits classification when dsa_reporting_enabled is disabled" do
+ SiteSetting.dsa_reporting_enabled = false
+
+ get "/review/#{reviewable.id}.json"
+
+ expect(response.parsed_body["reviewable"]).not_to have_key("dsa_classification")
+ end
+ end
+
context "with basics" do
fab!(:reviewable)
before { sign_in(Fabricate(:moderator)) }
diff --git a/spec/services/dsa_statement_of_record/classify_spec.rb b/spec/services/dsa_statement_of_record/classify_spec.rb
new file mode 100644
index 00000000000..299c6b7d16d
--- /dev/null
+++ b/spec/services/dsa_statement_of_record/classify_spec.rb
@@ -0,0 +1,197 @@
+# frozen_string_literal: true
+
+RSpec.describe DsaStatementOfRecord::Classify do
+ describe ".call" do
+ subject(:result) { described_class.call(params:, **dependencies) }
+
+ fab!(:acting_user, :admin)
+ fab!(:reviewable, :reviewable_flagged_post)
+ fab!(:statement) { Fabricate(:dsa_statement_of_record, reviewable_id: reviewable.id) }
+
+ let(:dependencies) { { guardian: acting_user.guardian } }
+ let(:rule) do
+ {
+ "ground" => "Terms of Service, section 3: Personal attacks",
+ "explanation" => "The content targets another person with insults.",
+ }
+ end
+ let(:params) do
+ {
+ reviewable_id: reviewable.id,
+ community_rule: DsaStatementOfRecord.community_rules.first.fetch("id"),
+ category: "STATEMENT_CATEGORY_ILLEGAL_OR_HARMFUL_SPEECH",
+ statement_ids: [statement.id],
+ }
+ end
+
+ before do
+ SiteSetting.dsa_reporting_enabled = true
+ SiteSetting.dsa_community_rules = [rule].to_json
+ end
+
+ it "classifies a flagged post removal and records the staff member's decision in a note" do
+ original_payload = statement.payload
+ freeze_time
+
+ expect { result }.to change { reviewable.reviewable_notes.count }.by(1)
+
+ expect(result).to run_successfully
+ expect(statement.reload).to have_attributes(
+ status: "ready",
+ classified_by_id: acting_user.id,
+ classified_at: eq_time(Time.current),
+ payload:
+ original_payload.merge(
+ "incompatible_content_ground" => rule["ground"],
+ "incompatible_content_explanation" => rule["explanation"],
+ "category" => "STATEMENT_CATEGORY_ILLEGAL_OR_HARMFUL_SPEECH",
+ ),
+ )
+ expect(reviewable.reviewable_notes.last).to have_attributes(
+ user: acting_user,
+ content: <<~TEXT.chomp,
+ Classified this moderation decision for DSA reporting.
+ Community rule: Terms of Service, section 3: Personal attacks
+ Category: Illegal or harmful speech
+ TEXT
+ )
+ end
+
+ it "classifies a flagged post removal and account suspension with one moderation note" do
+ account_statement =
+ Fabricate(
+ :dsa_statement_of_record,
+ reviewable_id: reviewable.id,
+ payload: {
+ "decision_account" => "DECISION_ACCOUNT_SUSPENDED",
+ "decision_ground" => "DECISION_GROUND_INCOMPATIBLE_CONTENT",
+ "decision_facts" => "The reviewed account was suspended.",
+ },
+ )
+ params[:statement_ids] << account_statement.id
+
+ expect { result }.to change { reviewable.reviewable_notes.count }.by(1)
+
+ expect(result).to run_successfully
+ expect(statement.reload).to be_ready
+ expect(account_statement.reload).to be_ready
+ expect(account_statement.payload).to include(
+ "incompatible_content_ground" => rule["ground"],
+ "category" => params[:category],
+ "decision_facts" => "The reviewed account was suspended.",
+ )
+ end
+
+ it "leaves an existing classification unchanged when classifying a pending statement" do
+ prior_payload = statement.payload.merge("incompatible_content_ground" => "Previous terms")
+ earlier =
+ Fabricate(
+ :dsa_statement_of_record,
+ reviewable_id: reviewable.id,
+ status: :ready,
+ payload: prior_payload,
+ )
+
+ expect(result).to run_successfully
+ expect(statement.reload).to be_ready
+ expect(earlier.reload.payload).to eq(prior_payload)
+ end
+
+ context "when the classification note is invalid" do
+ before do
+ TranslationOverride.upsert!(
+ "en",
+ "dsa_statements.classification_note",
+ "x" * (ReviewableNote::MAX_CONTENT_LENGTH + 1),
+ )
+ end
+
+ it "rolls back the classification without adding a note" do
+ original_payload = statement.payload
+
+ expect { result }.not_to change { reviewable.reviewable_notes.count }
+
+ expect(result).to fail_with_an_invalid_model(:reviewable_note)
+ expect(statement.reload).to have_attributes(
+ status: "pending",
+ payload: original_payload,
+ classified_by_id: nil,
+ classified_at: nil,
+ )
+ end
+ end
+
+ context "when the actor is not staff" do
+ fab!(:acting_user, :user)
+
+ it { is_expected.to fail_a_policy(:staff) }
+ end
+
+ context "when the flagged post is outside the moderator's visible categories" do
+ fab!(:acting_user, :moderator)
+
+ before { reviewable.update!(category: Fabricate(:private_category, group: Group[:admins])) }
+
+ it "rejects classification without changing the statement or adding a note" do
+ original_payload = statement.payload
+
+ expect { result }.not_to change { reviewable.reviewable_notes.count }
+
+ expect(result).to fail_to_find_a_model(:reviewable)
+ expect(statement.reload).to be_pending
+ expect(statement.payload).to eq(original_payload)
+ end
+ end
+
+ context "when dsa_reporting_enabled is disabled" do
+ before { SiteSetting.dsa_reporting_enabled = false }
+
+ it { is_expected.to fail_a_policy(:classification_enabled) }
+ end
+
+ context "when community rules are empty" do
+ before do
+ params
+ SiteSetting.dsa_community_rules = "[]"
+ end
+
+ it { is_expected.to fail_a_policy(:classification_enabled) }
+ end
+
+ context "when the category is invalid" do
+ before { params[:category] = "anything" }
+
+ it { is_expected.to fail_a_contract }
+ end
+
+ context "when the selected rule has changed" do
+ before do
+ params
+ SiteSetting.dsa_community_rules = [
+ rule.merge("explanation" => "Updated explanation"),
+ ].to_json
+ end
+
+ it { is_expected.to fail_to_find_a_model(:community_rule) }
+ end
+
+ context "when no pending statements remain" do
+ before { statement.update!(status: :ready) }
+
+ it "preserves the saved classification without adding another note" do
+ original_payload = statement.payload
+
+ expect { result }.not_to change { reviewable.reviewable_notes.count }
+
+ expect(result).to fail_to_find_a_model(:statements)
+ expect(statement.reload.payload).to eq(original_payload)
+ end
+ end
+
+ context "when another decision adds a statement after the form opened" do
+ before { Fabricate(:dsa_statement_of_record, reviewable_id: reviewable.id) }
+
+ it { is_expected.to fail_a_policy(:current_statements) }
+ end
+ end
+end
diff --git a/spec/system/page_objects/components/dsa_classification.rb b/spec/system/page_objects/components/dsa_classification.rb
new file mode 100644
index 00000000000..24bdcf11cf1
--- /dev/null
+++ b/spec/system/page_objects/components/dsa_classification.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+module PageObjects
+ module Components
+ class DsaClassification < PageObjects::Components::Base
+ def select_rule(ground)
+ within(".dsa-classification") { select(ground, from: "Community rule") }
+ end
+
+ def select_category(category)
+ within(".dsa-classification") { select(category, from: "Category") }
+ end
+
+ def save
+ within(".dsa-classification") { click_button("Save classification") }
+ end
+
+ def has_selected_rule?(ground)
+ within(".dsa-classification") { has_select?("Community rule", selected: ground) }
+ end
+
+ def has_selected_category?(category)
+ within(".dsa-classification") { has_select?("Category", selected: category) }
+ end
+
+ def has_no_sidebar?
+ has_no_css?(".dsa-classification")
+ end
+ end
+ end
+end
diff --git a/spec/system/page_objects/pages/review.rb b/spec/system/page_objects/pages/review.rb
index 3a1bd9cc547..6b3bedf46e3 100644
--- a/spec/system/page_objects/pages/review.rb
+++ b/spec/system/page_objects/pages/review.rb
@@ -168,6 +168,10 @@ module PageObjects
page.has_css?(".timeline-event", count: count)
end
+ def has_note?(content)
+ page.has_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/viewing_reviewable_spec.rb b/spec/system/viewing_reviewable_spec.rb
index 6b53d9eed2a..f4ec8642aa1 100644
--- a/spec/system/viewing_reviewable_spec.rb
+++ b/spec/system/viewing_reviewable_spec.rb
@@ -21,6 +21,66 @@ describe "Viewing reviewable item" do
sign_in(admin)
end
+ context "when dsa_reporting_enabled is enabled" do
+ let(:classification) { PageObjects::Components::DsaClassification.new }
+ let(:toasts) { PageObjects::Components::Toasts.new }
+ let(:rule) do
+ {
+ ground: "Terms of Service, section 3: Personal attacks",
+ explanation: "The content targets another person with insults.",
+ }
+ end
+
+ let(:other_rule) do
+ {
+ ground: "Terms of Service, section 4: Unsolicited advertising",
+ explanation: "The content promotes unrelated products.",
+ }
+ end
+
+ before do
+ SiteSetting.dsa_reporting_enabled = true
+ SiteSetting.dsa_community_rules = [rule, other_rule].to_json
+ reviewable_flagged_post.perform(admin, :delete_and_agree)
+ end
+
+ it "lets staff double check and confirm the DSA classification of a flagged post removal" do
+ dialog = PageObjects::Components::Dialog.new
+ note =
+ "Classified this moderation decision for DSA reporting. Community rule: #{other_rule[:ground]} Category: Other violation of terms and conditions"
+ review_page.visit_reviewable(reviewable_flagged_post)
+ classification.select_rule(rule[:ground])
+ classification.select_category("Illegal or harmful speech")
+ classification.save
+
+ expect(dialog).to have_content(rule[:ground])
+ expect(dialog).to have_content("Illegal or harmful speech")
+
+ dialog.click_no
+
+ expect(classification).to have_selected_rule(rule[:ground])
+ expect(classification).to have_selected_category("Illegal or harmful speech")
+
+ classification.select_rule(other_rule[:ground])
+ classification.select_category("Other violation of terms and conditions")
+ classification.save
+
+ expect(dialog).to have_content(other_rule[:ground])
+ expect(dialog).to have_content("Other violation of terms and conditions")
+
+ dialog.click_yes
+
+ expect(toasts).to have_success(I18n.t("js.dsa_statements.saved"))
+ expect(classification).to have_no_sidebar
+ expect(review_page).to have_note(note)
+
+ page.refresh
+
+ expect(classification).to have_no_sidebar
+ expect(review_page).to have_note(note)
+ end
+ end
+
describe "when the reviewable item is a flagged post" do
it "shows the new reviewable UI" do
review_page.visit_reviewable(reviewable_flagged_post)