Skip to content

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

UX: Use the DSA form for illegal content reports (#44989)

Alan Guo Xiang Tanb4e34022d330
diff --git a/app/assets/stylesheets/common/base/dsa-notice.scss b/app/assets/stylesheets/common/base/dsa-notice.scss
index 0491d636fd7..e8ff78a4a5f 100644
--- a/app/assets/stylesheets/common/base/dsa-notice.scss
+++ b/app/assets/stylesheets/common/base/dsa-notice.scss
@@ -1,3 +1,63 @@
+@use "lib/viewport";
+
.dsa-notice {
padding-block-end: var(--space-6);
+
+ &__form {
+ max-inline-size: var(--form-kit-max-input);
+ }
+}
+
+.dsa-notice-modal {
+ --modal-max-width: 45rem;
+
+ .d-modal__container {
+ width: 45rem;
+ }
+
+ .d-modal__body {
+ display: flex;
+ overflow: hidden;
+ padding: 0;
+ }
+
+ .dsa-notice,
+ .dsa-notice__form {
+ display: flex;
+ flex-direction: column;
+ flex: 1;
+ min-height: 0;
+ max-inline-size: none;
+ padding: 0;
+ gap: 0;
+ }
+
+ .dsa-notice__fields,
+ .dsa-notice__confirmation,
+ .dsa-notice__actions {
+ box-sizing: border-box;
+ }
+
+ .dsa-notice__fields,
+ .dsa-notice__confirmation {
+ overflow-y: auto;
+ padding: var(--space-6);
+ min-height: 0;
+ }
+
+ .dsa-notice__actions {
+ flex-shrink: 0;
+ margin-top: auto;
+ padding: var(--space-4) var(--space-6);
+ border-top: 1px solid var(--primary-low);
+ }
+
+ @include viewport.until(sm) {
+ .d-modal__container {
+ width: 100%;
+ height: calc(var(--composer-vh, 1dvh) * 100);
+ max-height: calc(var(--composer-vh, 1dvh) * 100);
+ border-radius: 0;
+ }
+ }
}
diff --git a/app/controllers/dsa_notices_controller.rb b/app/controllers/dsa_notices_controller.rb
index c06f5b62413..b832d881444 100644
--- a/app/controllers/dsa_notices_controller.rb
+++ b/app/controllers/dsa_notices_controller.rb
@@ -22,7 +22,17 @@ class DsaNoticesController < ApplicationController
end
def create
- Dsa::SubmitNotice.call(service_params) do
+ submission = service_params
+ if account_email = Dsa::Notice.verified_account_email(current_user)
+ Dsa::NoticeRateLimiter.perform(
+ email: account_email,
+ ip_address: request.remote_ip,
+ user_id: current_user.id,
+ )
+ submission = submission.deep_merge(params: { notice: { email: account_email } })
+ end
+
+ Dsa::SubmitNotice.call(submission) do
on_success { |notice:| render json: { reference: notice.reference }, status: :created }
on_failed_contract do |contract|
render_json_error(contract.errors.full_messages, status: 422)
diff --git a/app/models/dsa/notice.rb b/app/models/dsa/notice.rb
index 185b28b6eec..10bb4025b06 100644
--- a/app/models/dsa/notice.rb
+++ b/app/models/dsa/notice.rb
@@ -6,6 +6,12 @@ module Dsa
belongs_to :post, -> { with_deleted }, optional: true
+ def self.verified_account_email(user)
+ return unless user&.active? && !user.anonymous_user_master && user.email_confirmed?
+
+ user.email
+ end
+
def self.create_with_post!(attributes:, group:)
transaction do
notice = create!(attributes)
diff --git a/app/serializers/current_user_serializer.rb b/app/serializers/current_user_serializer.rb
index 7bb7c212608..a1f1a1e9ad3 100644
--- a/app/serializers/current_user_serializer.rb
+++ b/app/serializers/current_user_serializer.rb
@@ -89,7 +89,8 @@ class CurrentUserSerializer < BasicUserSerializer
:impersonation_expires_at,
:can_change_post_owner,
:show_site_owner_onboarding,
- :can_run_design_wizard
+ :can_run_design_wizard,
+ :can_use_dsa_account_email
delegate :user_stat, to: :object, private: true
delegate :any_posts, :draft_count, :pending_posts_count, :read_faq?, to: :user_stat
@@ -105,6 +106,14 @@ class CurrentUserSerializer < BasicUserSerializer
options[:include_status] = true
end
+ def can_use_dsa_account_email
+ Dsa::Notice.verified_account_email(object).present?
+ end
+
+ def include_can_use_dsa_account_email?
+ SiteSetting.dsa_reporting_enabled
+ end
+
def login_method
@options[:login_method]
end
diff --git a/app/services/dsa/request_notice_verification.rb b/app/services/dsa/request_notice_verification.rb
index f9ed3e09ee8..d30cd6f7949 100644
--- a/app/services/dsa/request_notice_verification.rb
+++ b/app/services/dsa/request_notice_verification.rb
@@ -29,18 +29,7 @@ module Dsa
private
def rate_limit_notice(params:, options:)
- if options.ip_address.present?
- RateLimiter.new(nil, "dsa-notice-ip-#{options.ip_address}", 5, 1.hour).performed!
- end
- email_key = Digest::SHA256.hexdigest(params.email)
- email_limiter = RateLimiter.new(nil, "dsa-notice-email-#{email_key}", 3, 1.day)
- email_limiter.performed!
- begin
- RateLimiter.new(nil, "dsa-notice-global", 100, 1.hour).performed!
- rescue RateLimiter::LimitExceeded
- email_limiter.rollback!
- raise
- end
+ Dsa::NoticeRateLimiter.perform(email: params.email, ip_address: options.ip_address)
end
def create_verification(params:)
diff --git a/app/services/dsa/submit_notice.rb b/app/services/dsa/submit_notice.rb
index 995ca3506ff..ccbd6242e74 100644
--- a/app/services/dsa/submit_notice.rb
+++ b/app/services/dsa/submit_notice.rb
@@ -62,7 +62,7 @@ module Dsa
attribute :token, :string
validates :notice, presence: true
- validates :token, presence: true, length: { is: 64 }
+ validates :token, length: { is: 64 }, allow_blank: true
end
model :verification
@@ -72,7 +72,11 @@ module Dsa
private
- def fetch_verification(params:)
+ def fetch_verification(guardian:, params:)
+ if params.notice.email == Dsa::Notice.verified_account_email(guardian.user)
+ return { email: params.notice.email }
+ end
+
Dsa::NoticeVerification.consume(token: params.token, email: params.notice.email)
end
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 8fe56d5bb79..9de1b9da4b4 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -1,6 +1,9 @@
en:
js:
dsa_notice:
+ choice_title: "It's Illegal"
+ choice_description: "Submit a detailed report explaining why this content is illegal."
+ go_back: "Go back"
title: "Report illegal content"
content_url: "Exact URL of the content"
explanation: "Why do you believe this content is illegal?"
@@ -8,7 +11,7 @@ en:
name: "Full name or organization name"
email: "Email address"
declaration_section: "Declaration"
- declaration: "I confirm that I have a bona fide belief that the information and allegations in this notice are accurate and complete."
+ declaration: "I honestly believe that the facts and claims in this report are true and complete"
submit: "Submit report"
get_email_code: "Get email code"
resend_email_code: "Resend code"
diff --git a/frontend/discourse/app/components/dsa-notice-form.gjs b/frontend/discourse/app/components/dsa-notice-form.gjs
index 372e0bf1967..17f16082fb2 100644
--- a/frontend/discourse/app/components/dsa-notice-form.gjs
+++ b/frontend/discourse/app/components/dsa-notice-form.gjs
@@ -5,17 +5,18 @@ import { action } from "@ember/object";
import { service } from "@ember/service";
import { trustHTML } from "@ember/template";
import Form from "discourse/components/form";
-import FKContainer from "discourse/form-kit/components/fk/container";
import FKErrors from "discourse/form-kit/components/fk/errors";
import { ajax } from "discourse/lib/ajax";
import { extractError, popupAjaxError } from "discourse/lib/ajax-error";
import { emailValid, escapeExpression } from "discourse/lib/utilities";
+import DButton from "discourse/ui-kit/d-button";
import DOtp from "discourse/ui-kit/d-otp";
import dLoadingSpinner from "discourse/ui-kit/helpers/d-loading-spinner";
import dAutoFocus from "discourse/ui-kit/modifiers/d-auto-focus";
import { i18n } from "discourse-i18n";
export default class DsaNoticeForm extends Component {
+ @service currentUser;
@service siteSettings;
@tracked result;
@@ -27,6 +28,10 @@ export default class DsaNoticeForm extends Component {
#form;
+ get canSubmit() {
+ return !this.requiresEmailVerification || this.emailVerified;
+ }
+
get emailCodeDisabled() {
const email = this.#form?.get("email")?.trim();
return (
@@ -47,6 +52,10 @@ export default class DsaNoticeForm extends Component {
: "dsa_notice.get_email_code";
}
+ get requiresEmailVerification() {
+ return !this.currentUser?.can_use_dsa_account_email;
+ }
+
@cached
get initialData() {
return {
@@ -116,7 +125,9 @@ export default class DsaNoticeForm extends Component {
type: "POST",
data: { notice, token: this.verificationToken },
});
- window.scrollTo(0, 0);
+ if (!this.args.inModal) {
+ window.scrollTo(0, 0);
+ }
} catch (error) {
if (error.jqXHR?.responseJSON?.error_type === "verification_required") {
this.emailVerified = false;
@@ -166,30 +177,44 @@ export default class DsaNoticeForm extends Component {
<template>
<div class="dsa-notice" ...attributes>
{{#if this.result}}
- <h1 tabindex="-1" {{dAutoFocus}}>{{i18n "dsa_notice.received"}}</h1>
- <p>{{i18n
- "dsa_notice.received_description"
- site=this.siteSettings.title
- }}</p>
- <p class="dsa-notice__reference">
- {{trustHTML
- (i18n
- "dsa_notice.reference"
- reference=(escapeExpression this.result.reference)
- )
- }}
- </p>
- <p>{{i18n "dsa_notice.contact_confirmation"}}</p>
+ <div class="dsa-notice__confirmation">
+ {{#if @inModal}}
+ <h2 tabindex="-1" {{dAutoFocus}}>{{i18n "dsa_notice.received"}}</h2>
+ {{else}}
+ <h1 tabindex="-1" {{dAutoFocus}}>{{i18n "dsa_notice.received"}}</h1>
+ {{/if}}
+ <p>{{i18n
+ "dsa_notice.received_description"
+ site=this.siteSettings.title
+ }}</p>
+ <p class="dsa-notice__reference">
+ {{trustHTML
+ (i18n
+ "dsa_notice.reference"
+ reference=(escapeExpression this.result.reference)
+ )
+ }}
+ </p>
+ <p>{{i18n "dsa_notice.contact_confirmation"}}</p>
+ </div>
+ {{#if @inModal}}
+ <div class="dsa-notice__actions">
+ <DButton class="btn-primary" @action={{@onClose}} @label="close" />
+ </div>
+ {{/if}}
{{else}}
- <h1>{{i18n "dsa_notice.title"}}</h1>
- <FKContainer @direction="column" @format="max">
- <Form
- @data={{this.initialData}}
- @onRegisterApi={{this.registerForm}}
- @onSubmit={{this.submit}}
- as |form|
- >
- <form.Section>
+ {{#unless @inModal}}
+ <h1>{{i18n "dsa_notice.title"}}</h1>
+ {{/unless}}
+ <Form
+ class="dsa-notice__form"
+ @data={{this.initialData}}
+ @onRegisterApi={{this.registerForm}}
+ @onSubmit={{this.submit}}
+ as |form|
+ >
+ <form.Section class="dsa-notice__fields">
+ {{#if this.requiresEmailVerification}}
<form.Fieldset
aria-busy={{or this.requestingCode this.verifyingCode}}
aria-label={{i18n "dsa_notice.email"}}
@@ -261,60 +286,67 @@ export default class DsaNoticeForm extends Component {
</form.Field>
{{/if}}
</form.Fieldset>
- <form.Field
- @disabled={{not this.emailVerified}}
- @format="full"
- @name="name"
- @title={{i18n "dsa_notice.name"}}
- @type="input"
- @validation="required:trim|length:1,200"
- as |field|
- >
- <field.Control autocomplete="name" />
- </form.Field>
- <form.Field
- @disabled={{not this.emailVerified}}
- @format="full"
- @name="content_url"
- @title={{i18n "dsa_notice.content_url"}}
- @type="input-url"
- @validation="required|url"
- as |field|
- >
- <field.Control />
- </form.Field>
- <form.Field
- @description={{i18n "dsa_notice.explanation_help"}}
- @disabled={{not this.emailVerified}}
- @format="full"
- @name="explanation"
- @title={{i18n "dsa_notice.explanation"}}
- @type="textarea"
- @validation="required:trim|length:50,20000"
- as |field|
- >
- <field.Control rows="6" />
- </form.Field>
- <form.Field
- @disabled={{not this.emailVerified}}
- @format="full"
- @name="declaration"
- @title={{i18n "dsa_notice.declaration_section"}}
- @type="checkbox"
- @validation="accepted"
- as |field|
- >
- <field.Control @title={{i18n "dsa_notice.declaration"}} />
- </form.Field>
- <form.Actions>
- <form.Submit
- @disabled={{not this.emailVerified}}
- @label="dsa_notice.submit"
- />
- </form.Actions>
- </form.Section>
- </Form>
- </FKContainer>
+ {{/if}}
+ <form.Field
+ @disabled={{not this.canSubmit}}
+ @format="full"
+ @name="name"
+ @title={{i18n "dsa_notice.name"}}
+ @type="input"
+ @validation="required:trim|length:1,200"
+ as |field|
+ >
+ <field.Control autocomplete="name" />
+ </form.Field>
+ <form.Field
+ @disabled={{not this.canSubmit}}
+ @format="full"
+ @name="content_url"
+ @title={{i18n "dsa_notice.content_url"}}
+ @type="input-url"
+ @validation="required|url"
+ as |field|
+ >
+ <field.Control />
+ </form.Field>
+ <form.Field
+ @description={{i18n "dsa_notice.explanation_help"}}
+ @disabled={{not this.canSubmit}}
+ @format="full"
+ @name="explanation"
+ @title={{i18n "dsa_notice.explanation"}}
+ @type="textarea"
+ @validation="required:trim|length:50,20000"
+ as |field|
+ >
+ <field.Control rows="6" />
+ </form.Field>
+ <form.Field
+ @disabled={{not this.canSubmit}}
+ @format="full"
+ @name="declaration"
+ @title={{i18n "dsa_notice.declaration_section"}}
+ @type="checkbox"
+ @validation="accepted"
+ as |field|
+ >
+ <field.Control @title={{i18n "dsa_notice.declaration"}} />
+ </form.Field>
+ </form.Section>
+ <form.Actions class="dsa-notice__actions">
+ <form.Submit
+ @disabled={{not this.canSubmit}}
+ @label="dsa_notice.submit"
+ />
+ {{#if @inModal}}
+ <DButton
+ class="btn-flat"
+ @action={{or @onBack @onClose}}
+ @label={{if @onBack "dsa_notice.go_back" "cancel"}}
+ />
+ {{/if}}
+ </form.Actions>
+ </Form>
{{/if}}
</div>
</template>
diff --git a/frontend/discourse/app/components/modal/flag.gjs b/frontend/discourse/app/components/modal/flag.gjs
index 96044ee9bbd..df4ad87a48c 100644
--- a/frontend/discourse/app/components/modal/flag.gjs
+++ b/frontend/discourse/app/components/modal/flag.gjs
@@ -6,22 +6,35 @@ import { action } from "@ember/object";
import { service } from "@ember/service";
import { trustHTML } from "@ember/template";
import FlagActionType from "discourse/components/flag-action-type";
-import FlagSelection from "discourse/components/flag-selection";
+import ReportIllegalContentModal from "discourse/components/modal/report-illegal-content";
import PluginOutlet from "discourse/components/plugin-outlet";
import ReviewableBundledAction from "discourse/components/reviewable-bundled-action";
import lazyHash from "discourse/helpers/lazy-hash";
import { reload } from "discourse/helpers/page-reloader";
+import { getAbsoluteURL } from "discourse/lib/get-url";
import { MAX_MESSAGE_LENGTH } from "discourse/models/post-action-type";
import User from "discourse/models/user";
import DButton from "discourse/ui-kit/d-button";
import DModal from "discourse/ui-kit/d-modal";
import { i18n } from "discourse-i18n";
+function reportingChoices(flags, includeIllegalReport) {
+ const choices = flags.map((flag) => ({ kind: "flag", flag }));
+ if (includeIllegalReport) {
+ const index = choices.findIndex(
+ ({ flag }) => flag.name_key === "notify_moderators"
+ );
+ choices.splice(index < 0 ? choices.length : index, 0, { kind: "dsa" });
+ }
+ return choices;
+}
+
export default class Flag extends Component {
@service adminTools;
@service currentUser;
@service siteSettings;
@service appEvents;
+ @service modal;
// eslint-disable-next-line discourse/no-unused-services
@service site; // FIXME: used by flag-target objects
@@ -29,6 +42,7 @@ export default class Flag extends Component {
@tracked message;
@tracked isConfirmed = false;
@tracked spammerDetails;
+ @tracked dsaSelected = false;
constructor() {
super(...arguments);
@@ -37,7 +51,7 @@ export default class Flag extends Component {
?.checkSpammer(this.args.model.flagModel.user_id)
.then((result) => (this.spammerDetails = result));
- if (this.flagsAvailable.length === 1) {
+ if (this.flagsAvailable.length === 1 && !this.canReportIllegalContent) {
this.selected = this.flagsAvailable[0];
}
}
@@ -79,6 +93,19 @@ export default class Flag extends Component {
);
}
+ get canReportIllegalContent() {
+ return (
+ this.siteSettings.dsa_reporting_enabled &&
+ this.args.model.allowIllegalContentReport === true
+ );
+ }
+
+ get contentUrl() {
+ const content = this.args.model.flagModel;
+ const url = content.urlWithNumber || content.url;
+ return url ? getAbsoluteURL(url) : "";
+ }
+
get showDeleteSpammer() {
return this.spammerDetails?.canDelete && this.selected?.name_key === "spam";
}
@@ -102,7 +129,7 @@ export default class Flag extends Component {
}
get staffFlagsAvailable() {
- return this.flagsAvailable.length > 1;
+ return this.flagsAvailable.length > 1 || this.canReportIllegalContent;
}
get submitEnabled() {
@@ -135,6 +162,16 @@ export default class Flag extends Component {
@action
onKeydown(event) {
+ if (
+ this.dsaSelected &&
+ event.key === "Enter" &&
+ (event.ctrlKey || event.metaKey)
+ ) {
+ event.preventDefault();
+ this.reportIllegalContent();
+ return false;
+ }
+
if (
this.submitEnabled &&
event.key === "Enter" &&
@@ -216,6 +253,24 @@ export default class Flag extends Component {
@action
changePostActionType(actionType) {
this.selected = actionType;
+ this.dsaSelected = false;
+ }
+
+ @action
+ selectIllegalReport() {
+ this.selected = null;
+ this.dsaSelected = true;
+ }
+
+ @action
+ reportIllegalContent() {
+ const model = this.args.model;
+ this.modal.show(ReportIllegalContentModal, {
+ model: {
+ contentUrl: this.contentUrl,
+ onBack: () => this.modal.show(Flag, { model }),
+ },
+ });
}
async #createFlagAndHide(opts) {
@@ -242,19 +297,48 @@ export default class Flag extends Component {
@outletArgs={{lazyHash [email protected]}}
/>
<form>
- <FlagSelection @flags={{this.flagsAvailable}} as |f|>
- <FlagActionType
- @changePostActionType={{this.changePostActionType}}
- @flag={{f}}
- @isConfirmed={{this.isConfirmed}}
- @message={{this.message}}
- @onChangeConfirmed={{fn (mut this.isConfirmed)}}
- @onChangeMessage={{fn (mut this.message)}}
- @selectedFlag={{this.selected}}
- @staffFlagsAvailable={{this.staffFlagsAvailable}}
- @username={{@model.flagModel.username}}
- />
- </FlagSelection>
+ {{#each
+ (reportingChoices this.flagsAvailable this.canReportIllegalContent)
+ as |choice|
+ }}
+ {{#if (eq choice.kind "flag")}}
+ <FlagActionType
+ @changePostActionType={{this.changePostActionType}}
+ @flag={{choice.flag}}
+ @isConfirmed={{this.isConfirmed}}
+ @message={{this.message}}
+ @onChangeConfirmed={{fn (mut this.isConfirmed)}}
+ @onChangeMessage={{fn (mut this.message)}}
+ @selectedFlag={{this.selected}}
+ @staffFlagsAvailable={{this.staffFlagsAvailable}}
+ @username={{@model.flagModel.username}}
+ />
+ {{else}}
+ <div class="illegal-content-report-choice flag-action-type">
+ <div class="controls">
+ <label class="radio checkbox-label">
+ <input
+ checked={{this.dsaSelected}}
+ id="radio_dsa_report"
+ name="post_action_type_index"
+ type="radio"
+ {{on "click" this.selectIllegalReport}}
+ />
+ <div class="flag-action-type-details">
+ <strong class="flag-name">{{i18n
+ "dsa_notice.choice_title"
+ }}</strong>
+ <div class="description">{{i18n
+ "dsa_notice.choice_description"
+ }}</div>
+ </div>
+ </label>
+ </div>
+ </div>
+ {{/if}}
+ {{else}}
+ {{i18n "flagging.cant"}}
+ {{/each}}
</form>
<PluginOutlet
@connectorTagName="div"
@@ -263,50 +347,58 @@ export default class Flag extends Component {
/>
</:body>
<:footer>
- <DButton
- class="btn-primary flag-modal__create-flag"
- @action={{this.createFlag}}
- @disabled={{not this.submitEnabled}}
- @icon={{if this.selected.require_message "envelope" "flag"}}
- @label={{this.submitLabel}}
- @title="flagging.submit_tooltip"
- />
-
- {{#if this.canSendWarning}}
+ {{#if this.dsaSelected}}
<DButton
- class="btn-danger flag-modal__send-warning"
- @action={{this.createFlagAsWarning}}
- @disabled={{not this.submitEnabled}}
- @icon="triangle-exclamation"
- @label="flagging.official_warning"
- />
- {{/if}}
-
- {{#if this.canTakeAction}}
- <ReviewableBundledAction
- class="flag-modal__take-action"
- @bundle={{this.flagActions}}
- @performAction={{this.takeAction}}
- @reviewableUpdating={{not this.submitEnabled}}
+ class="btn-primary flag-modal__continue"
+ @action={{this.reportIllegalContent}}
+ @label="continue"
/>
-
+ {{else}}
<DButton
- class="btn-danger flag-modal__flag-for-review"
- @action={{this.flagForReview}}
+ class="btn-primary flag-modal__create-flag"
+ @action={{this.createFlag}}
@disabled={{not this.submitEnabled}}
- @icon="triangle-exclamation"
- @label="flagging.flag_for_review"
+ @icon={{if this.selected.require_message "envelope" "flag"}}
+ @label={{this.submitLabel}}
+ @title="flagging.submit_tooltip"
/>
- {{/if}}
- {{#if this.showDeleteSpammer}}
- <DButton
- class="btn-danger delete-spammer flag-modal__delete-spammer"
- @action={{this.deleteSpammer}}
- @disabled={{not this.submitEnabled}}
- @icon="triangle-exclamation"
- @label="flagging.delete_spammer"
- />
+ {{#if this.canSendWarning}}
+ <DButton
+ class="btn-danger flag-modal__send-warning"
+ @action={{this.createFlagAsWarning}}
+ @disabled={{not this.submitEnabled}}
+ @icon="triangle-exclamation"
+ @label="flagging.official_warning"
+ />
+ {{/if}}
+
+ {{#if this.canTakeAction}}
+ <ReviewableBundledAction
+ class="flag-modal__take-action"
+ @bundle={{this.flagActions}}
+ @performAction={{this.takeAction}}
+ @reviewableUpdating={{not this.submitEnabled}}
+ />
+
+ <DButton
+ class="btn-danger flag-modal__flag-for-review"
+ @action={{this.flagForReview}}
+ @disabled={{not this.submitEnabled}}
+ @icon="triangle-exclamation"
+ @label="flagging.flag_for_review"
+ />
+ {{/if}}
+
+ {{#if this.showDeleteSpammer}}
+ <DButton
+ class="btn-danger delete-spammer flag-modal__delete-spammer"
+ @action={{this.deleteSpammer}}
+ @disabled={{not this.submitEnabled}}
+ @icon="triangle-exclamation"
+ @label="flagging.delete_spammer"
+ />
+ {{/if}}
{{/if}}
</:footer>
</DModal>
diff --git a/frontend/discourse/app/components/modal/report-illegal-content.gjs b/frontend/discourse/app/components/modal/report-illegal-content.gjs
new file mode 100644
index 00000000000..e8a9f9ac3e1
--- /dev/null
+++ b/frontend/discourse/app/components/modal/report-illegal-content.gjs
@@ -0,0 +1,21 @@
+import DsaNoticeForm from "discourse/components/dsa-notice-form";
+import DModal from "discourse/ui-kit/d-modal";
+import { i18n } from "discourse-i18n";
+
+export default <template>
+ <DModal
+ class="dsa-notice-modal"
+ @closeModal={{@closeModal}}
+ @submitOnEnter={{false}}
+ @title={{i18n "dsa_notice.title"}}
+ >
+ <:body>
+ <DsaNoticeForm
+ @contentUrl={{@model.contentUrl}}
+ @inModal={{true}}
+ @onBack={{@model.onBack}}
+ @onClose={{@closeModal}}
+ />
+ </:body>
+ </DModal>
+</template>
diff --git a/frontend/discourse/app/components/post/menu/buttons/flag.gjs b/frontend/discourse/app/components/post/menu/buttons/flag.gjs
index 695ee47010a..20c3f2681db 100644
--- a/frontend/discourse/app/components/post/menu/buttons/flag.gjs
+++ b/frontend/discourse/app/components/post/menu/buttons/flag.gjs
@@ -10,9 +10,10 @@ export default class PostMenuFlagButton extends Component {
const { post } = args;
const { reviewable_id, canFlag, hidden } = post;
- let show =
+ const show =
reviewable_id ||
(canFlag && !hidden) ||
+ helper.siteSettings.dsa_reporting_enabled ||
(helper.siteSettings.allow_all_users_to_flag_illegal_content &&
!helper.currentUser);
diff --git a/frontend/discourse/app/routes/topic.js b/frontend/discourse/app/routes/topic.js
index 4f25ea17cd2..07d1c040bbe 100644
--- a/frontend/discourse/app/routes/topic.js
+++ b/frontend/discourse/app/routes/topic.js
@@ -15,8 +15,10 @@ import HistoryModal from "discourse/components/modal/history";
import MoveToTopicModal from "discourse/components/modal/move-to-topic";
import PublishPageModal from "discourse/components/modal/publish-page";
import RawEmailModal from "discourse/components/modal/raw-email";
+import ReportIllegalContentModal from "discourse/components/modal/report-illegal-content";
import PostFlag from "discourse/lib/flag-targets/post-flag";
import TopicFlag from "discourse/lib/flag-targets/topic-flag";
+import { getAbsoluteURL } from "discourse/lib/get-url";
import discourseLater from "discourse/lib/later";
import { setTopicId } from "discourse/lib/topic-list-tracker";
import topicTitleToken from "discourse/lib/topic-title-token";
@@ -30,8 +32,8 @@ const SCROLL_DELAY = 500;
export default class TopicRoute extends DiscourseRoute {
@service a11y;
@service composer;
- @service screenTrack;
@service currentUser;
+ @service screenTrack;
@service modal;
@service router;
@@ -83,16 +85,15 @@ export default class TopicRoute extends DiscourseRoute {
@action
showFlags(model) {
if (!this.currentUser && this.siteSettings.dsa_reporting_enabled) {
- this.router.transitionTo("report-illegal-content", {
- queryParams: {
- content_url: window.location.origin + model.urlWithNumber,
- },
+ this.modal.show(ReportIllegalContentModal, {
+ model: { contentUrl: getAbsoluteURL(model.urlWithNumber) },
});
return;
}
this.modal.show(this.currentUser ? FlagModal : AnonymousFlagModal, {
model: {
+ allowIllegalContentReport: true,
flagTarget: new PostFlag(),
flagModel: model,
setHidden: () => model.set("hidden", true),
@@ -105,6 +106,7 @@ export default class TopicRoute extends DiscourseRoute {
const model = this.modelFor("topic");
this.modal.show(FlagModal, {
model: {
+ allowIllegalContentReport: true,
flagTarget: new TopicFlag(),
flagModel: model,
setHidden: () => model.set("hidden", true),
diff --git a/lib/dsa/notice_rate_limiter.rb b/lib/dsa/notice_rate_limiter.rb
new file mode 100644
index 00000000000..9b44d6a8c40
--- /dev/null
+++ b/lib/dsa/notice_rate_limiter.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+module Dsa
+ class NoticeRateLimiter
+ MAX_REQUESTS_PER_REPORTER_PER_DAY = 3
+
+ def self.perform(email:, ip_address:, user_id: nil)
+ prefix = user_id ? "dsa-notice-submission" : "dsa-notice"
+ if ip_address.present?
+ RateLimiter.new(nil, "#{prefix}-ip-#{ip_address}", 5, 1.hour).performed!
+ end
+ reporter_key = user_id ? "user-#{user_id}" : "email-#{Digest::SHA256.hexdigest(email)}"
+ reporter_limiter =
+ RateLimiter.new(nil, "#{prefix}-#{reporter_key}", MAX_REQUESTS_PER_REPORTER_PER_DAY, 1.day)
+ reporter_limiter.performed!
+ begin
+ RateLimiter.new(nil, "#{prefix}-global", 100, 1.hour).performed!
+ rescue RateLimiter::LimitExceeded
+ reporter_limiter.rollback!
+ raise
+ end
+ end
+ end
+end
diff --git a/lib/guardian/post_guardian.rb b/lib/guardian/post_guardian.rb
index 55e84a3a4a8..5cd8abf4ce4 100644
--- a/lib/guardian/post_guardian.rb
+++ b/lib/guardian/post_guardian.rb
@@ -25,6 +25,7 @@ module PostGuardian
# Can the user act on the post in a particular way.
# taken_actions = the list of actions the user has already taken
def post_can_act?(post, action_key, opts: {}, can_see_post: nil)
+ return false if action_key == :illegal && SiteSetting.dsa_reporting_enabled
return false if !(can_see_post.nil? && can_see_post?(post)) && !can_see_post
# no warnings except for staff
diff --git a/plugins/chat/app/serializers/chat/message_serializer.rb b/plugins/chat/app/serializers/chat/message_serializer.rb
index 8368a132b2b..3709852ec79 100644
--- a/plugins/chat/app/serializers/chat/message_serializer.rb
+++ b/plugins/chat/app/serializers/chat/message_serializer.rb
@@ -185,10 +185,12 @@ module Chat
return [] if reviewable_id.present? && user_flag_status == ReviewableScore.statuses[:pending]
if scope.can_only_flag_chat_messages_as_illegal?
+ return [] unless scope.can_flag_message_as?(object, ReviewableScore.types[:illegal], {})
return PostActionType.flag_types.slice(:illegal).keys
end
- PostActionType.flag_types.map do |sym, id|
+ PostActionType.flag_types.filter_map do |sym, id|
+ next unless scope.can_flag_message_as?(object, id, {})
if channel_object.direct_message_channel? && %i[notify_moderators notify_user].include?(sym)
next
end
diff --git a/plugins/chat/assets/javascripts/discourse/lib/chat-message-interactor.js b/plugins/chat/assets/javascripts/discourse/lib/chat-message-interactor.js
index 76e733f50eb..900f0cbd417 100644
--- a/plugins/chat/assets/javascripts/discourse/lib/chat-message-interactor.js
+++ b/plugins/chat/assets/javascripts/discourse/lib/chat-message-interactor.js
@@ -7,10 +7,11 @@ import EmojiPickerDetached from "discourse/components/emoji-picker/detached";
import AnonymousFlagModal from "discourse/components/modal/anonymous-flag";
import BookmarkModal from "discourse/components/modal/bookmark";
import FlagModal from "discourse/components/modal/flag";
+import ReportIllegalContentModal from "discourse/components/modal/report-illegal-content";
import { popupAjaxError } from "discourse/lib/ajax-error";
import { BookmarkFormData } from "discourse/lib/bookmark-form-data";
import { bind } from "discourse/lib/decorators";
-import getURL from "discourse/lib/get-url";
+import getURL, { getAbsoluteURL } from "discourse/lib/get-url";
import { clipboardCopy } from "discourse/lib/utilities";
import Bookmark from "discourse/models/bookmark";
import { DEFAULT_DIVERSITY } from "discourse/services/emoji-store";
@@ -132,6 +133,15 @@ export default class ChatMessageInteractor {
return this.canInteractWithMessage && this.siteSettings.enable_emoji;
}
+ get canReportMessage() {
+ return (
+ this.canFlagMessage ||
+ (this.siteSettings.dsa_reporting_enabled &&
+ !this.message?.chatWebhookEvent &&
+ !this.message?.deletedAt)
+ );
+ }
+
get canFlagMessage() {
if (!this.currentUser) {
return (
@@ -237,7 +247,7 @@ export default class ChatMessageInteractor {
});
}
- if (this.canFlagMessage) {
+ if (this.canReportMessage) {
buttons.push({
id: "flag",
name: i18n("chat.flag"),
@@ -290,7 +300,7 @@ export default class ChatMessageInteractor {
});
}
- if (this.canFlagMessage) {
+ if (this.canReportMessage) {
buttons.push({ id: "flag", name: i18n("chat.flag"), icon: "flag" });
}
@@ -433,11 +443,22 @@ export default class ChatMessageInteractor {
@action
flag() {
+ if (!this.currentUser && this.siteSettings.dsa_reporting_enabled) {
+ this.modal.show(ReportIllegalContentModal, {
+ model: { contentUrl: getAbsoluteURL(this.message.url) },
+ });
+ return;
+ }
+
const model = new ChatMessage(this.message.channel, this.message);
+ if (!this.canFlagMessage) {
+ model.availableFlags = [];
+ }
model.username = this.message.user?.username;
model.user_id = this.message.user?.id;
this.modal.show(this.currentUser ? FlagModal : AnonymousFlagModal, {
model: {
+ allowIllegalContentReport: true,
flagTarget: new ChatMessageFlag(getOwner(this)),
flagModel: model,
setHidden: () => model.set("hidden", true),
diff --git a/plugins/chat/lib/chat/guardian_extensions.rb b/plugins/chat/lib/chat/guardian_extensions.rb
index b9604676065..894af89da1d 100644
--- a/plugins/chat/lib/chat/guardian_extensions.rb
+++ b/plugins/chat/lib/chat/guardian_extensions.rb
@@ -230,6 +230,10 @@ module Chat
end
def can_flag_message_as?(chat_message, flag_type_id, opts)
+ if flag_type_id == ReviewableScore.types[:illegal] && SiteSetting.dsa_reporting_enabled
+ return false
+ end
+
return false if !is_staff? && (opts[:take_action] || opts[:queue_for_review])
if can_only_flag_chat_messages_as_illegal? && flag_type_id != ReviewableScore.types[:illegal]
diff --git a/plugins/chat/spec/requests/chat/api/channels_messages_flags_controller_spec.rb b/plugins/chat/spec/requests/chat/api/channels_messages_flags_controller_spec.rb
index 02c750774a5..777012c4eb2 100644
--- a/plugins/chat/spec/requests/chat/api/channels_messages_flags_controller_spec.rb
+++ b/plugins/chat/spec/requests/chat/api/channels_messages_flags_controller_spec.rb
@@ -14,6 +14,32 @@ RSpec.describe Chat::Api::ChannelsMessagesFlagsController do
end
describe "#create" do
+ it "requires the DSA form for illegal reports only when DSA reporting is enabled" do
+ SiteSetting.dsa_reporting_enabled = true
+
+ expect do
+ post "/chat/api/channels/#{message_1.chat_channel.id}/messages/#{message_1.id}/flags",
+ params: {
+ flag_type_id: ReviewableScore.types[:illegal],
+ }
+ end.not_to change(ReviewableScore, :count)
+
+ expect(response).to be_not_found
+ expect(Reviewable.exists?(target: message_1)).to eq(false)
+
+ SiteSetting.dsa_reporting_enabled = false
+
+ post "/chat/api/channels/#{message_1.chat_channel.id}/messages/#{message_1.id}/flags",
+ params: {
+ flag_type_id: ReviewableScore.types[:illegal],
+ }
+
+ expect(response).to be_successful
+ expect(
+ Reviewable.find_by!(target: message_1).reviewable_scores.pluck(:reviewable_score_type),
+ ).to eq([ReviewableScore.types[:illegal]])
+ end
+
it "ratelimits flagging" do
RateLimiter.enable
diff --git a/plugins/chat/spec/serializer/chat/chat_message_serializer_spec.rb b/plugins/chat/spec/serializer/chat/chat_message_serializer_spec.rb
index 9323495da38..e05e8dc916e 100644
--- a/plugins/chat/spec/serializer/chat/chat_message_serializer_spec.rb
+++ b/plugins/chat/spec/serializer/chat/chat_message_serializer_spec.rb
@@ -191,6 +191,14 @@ describe Chat::MessageSerializer do
context "when flagging on a regular channel" do
let(:options) { { scope: guardian, root: nil, chat_channel: message_1.chat_channel } }
+ it "omits the illegal flag when DSA reporting is enabled" do
+ SiteSetting.dsa_reporting_enabled = true
+
+ expect(serializer.as_json[:available_flags]).to contain_exactly(
+ *PostActionType.flag_types.keys.reject { |name| name == :illegal },
+ )
+ end
+
it "returns an empty list if the user already flagged the message" do
reviewable = Fabricate(:chat_reviewable_message, target: message_1)
diff --git a/plugins/chat/spec/system/flag_message_spec.rb b/plugins/chat/spec/system/flag_message_spec.rb
index a0b833d55b0..2279df54269 100644
--- a/plugins/chat/spec/system/flag_message_spec.rb
+++ b/plugins/chat/spec/system/flag_message_spec.rb
@@ -5,6 +5,8 @@ RSpec.describe "Flag message" do
let(:chat) { PageObjects::Pages::Chat.new }
let(:channel) { PageObjects::Pages::ChatChannel.new }
+ let(:reporting_modal) { PageObjects::Modals::Flag.new }
+ let(:notice_modal) { PageObjects::Modals::DsaNotice.new }
before do
chat_system_bootstrap
@@ -17,16 +19,28 @@ RSpec.describe "Flag message" do
before { category_channel_1.add(current_user) }
- it "allows to flag a message" do
+ it "lets a user flag a message and then report illegal content" do
+ SiteSetting.dsa_reporting_enabled = true
+ SiteSetting.allow_all_users_to_flag_illegal_content = false
+ current_user.activate
chat.visit_channel(category_channel_1)
channel.messages.flag(message_1)
- expect(page).to have_css(".flag-modal")
-
- choose("radio_spam")
- click_button(I18n.t("js.chat.flagging.action"))
+ expect(reporting_modal).to be_open
+ reporting_modal.choose_type(:spam)
+ reporting_modal.confirm_flag
+ expect(channel.messages.find(id: message_1.id)).to have_flag
- expect(channel.message_by_id(message_1.id)).to have_css(".chat-message-info__flag")
+ channel.messages.flag(message_1)
+ expect(reporting_modal).to be_open
+ reporting_modal.report_illegal_content
+ expect(notice_modal).to be_open
+ expect(notice_modal).to have_no_email_input
+
+ notice_modal.go_back
+ expect(reporting_modal).to have_no_selected_illegal_report
+ expect(reporting_modal).to have_no_message_input
+ expect(reporting_modal).to have_no_confirmation
end
end
diff --git a/plugins/chat/spec/system/page_objects/chat/components/message.rb b/plugins/chat/spec/system/page_objects/chat/components/message.rb
index 42b730df9ea..900ca9b3839 100644
--- a/plugins/chat/spec/system/page_objects/chat/components/message.rb
+++ b/plugins/chat/spec/system/page_objects/chat/components/message.rb
@@ -21,6 +21,10 @@ module PageObjects
component.hover
end
+ def has_flag?
+ component.has_css?(".chat-message-info__flag")
+ end
+
def open_more_menu
hover
page.find(".chat-message-actions-container")
diff --git a/plugins/discourse-post-voting/app/serializers/post_voting_comment_serializer.rb b/plugins/discourse-post-voting/app/serializers/post_voting_comment_serializer.rb
index 9dc6bd47236..ec5ce816807 100644
--- a/plugins/discourse-post-voting/app/serializers/post_voting_comment_serializer.rb
+++ b/plugins/discourse-post-voting/app/serializers/post_voting_comment_serializer.rb
@@ -11,7 +11,8 @@ class PostVotingCommentSerializer < ApplicationSerializer
:post_voting_vote_count,
:user_voted,
:available_flags,
- :reviewable_id
+ :reviewable_id,
+ :url
attr_accessor :comments_user_voted
@@ -27,6 +28,10 @@ class PostVotingCommentSerializer < ApplicationSerializer
object.user&.username
end
+ def url
+ "#{Discourse.base_path}/p/#{object.post_id}#post-voting-comment-#{object.id}"
+ end
+
def user_voted
if @comments_user_voted
@comments_user_voted[object.id]
@@ -46,7 +51,9 @@ class PostVotingCommentSerializer < ApplicationSerializer
return [] if !scope.can_flag_post_voting_comment?(object)
return [] if reviewable_id.present? && user_flag_status == ReviewableScore.statuses[:pending]
- PostActionType.flag_types.map { |sym, id| sym }
+ PostActionType.flag_types.filter_map do |name, id|
+ name if scope.can_flag_post_voting_comment_as?(object, id, {})
+ end
end
def post_voting_vote_count
diff --git a/plugins/discourse-post-voting/assets/javascripts/discourse/components/post-voting-comment-actions.gjs b/plugins/discourse-post-voting/assets/javascripts/discourse/components/post-voting-comment-actions.gjs
index 7a4605d482e..4f64c16d8b3 100644
--- a/plugins/discourse-post-voting/assets/javascripts/discourse/components/post-voting-comment-actions.gjs
+++ b/plugins/discourse-post-voting/assets/javascripts/discourse/components/post-voting-comment-actions.gjs
@@ -60,6 +60,7 @@ export default class PostVotingCommentActions extends Component {
this.comment.availableFlags = this.comment.available_flags;
this.modal.show(FlagModal, {
model: {
+ allowIllegalContentReport: true,
flagTarget: new PostVotingFlag(),
flagModel: this.comment,
setHidden: () => (this.comment.hidden = true),
diff --git a/plugins/discourse-post-voting/lib/post_voting/guardian_extension.rb b/plugins/discourse-post-voting/lib/post_voting/guardian_extension.rb
index cbc60bd19aa..85860bdc60e 100644
--- a/plugins/discourse-post-voting/lib/post_voting/guardian_extension.rb
+++ b/plugins/discourse-post-voting/lib/post_voting/guardian_extension.rb
@@ -49,6 +49,10 @@ module PostVoting
end
def can_flag_post_voting_comment_as?(comment, flag_type_id, opts)
+ if flag_type_id == ReviewableScore.types[:illegal] && SiteSetting.dsa_reporting_enabled
+ return false
+ end
+
return false if !is_staff? && (opts[:take_action] || opts[:queue_for_review])
if flag_type_id == ReviewableScore.types[:notify_user]
diff --git a/plugins/discourse-post-voting/spec/requests/post_voting/comments_controller_spec.rb b/plugins/discourse-post-voting/spec/requests/post_voting/comments_controller_spec.rb
index 4607ec8ab12..b54b87467b6 100644
--- a/plugins/discourse-post-voting/spec/requests/post_voting/comments_controller_spec.rb
+++ b/plugins/discourse-post-voting/spec/requests/post_voting/comments_controller_spec.rb
@@ -459,6 +459,34 @@ RSpec.describe PostVoting::CommentsController do
before { sign_in(flagger) }
+ it "requires the DSA form for illegal reports only when DSA reporting is enabled" do
+ SiteSetting.dsa_reporting_enabled = true
+
+ expect do
+ put "/post_voting/comments/flag.json",
+ params: {
+ comment_id: comment.id,
+ flag_type_id: ReviewableScore.types[:illegal],
+ }
+ end.not_to change(ReviewableScore, :count)
+
+ expect(response).to be_forbidden
+ expect(Reviewable.exists?(target: comment)).to eq(false)
+
+ SiteSetting.dsa_reporting_enabled = false
+
+ put "/post_voting/comments/flag.json",
+ params: {
+ comment_id: comment.id,
+ flag_type_id: ReviewableScore.types[:illegal],
+ }
+
+ expect(response).to be_successful
+ expect(
+ Reviewable.find_by!(target: comment).reviewable_scores.pluck(:reviewable_score_type),
+ ).to eq([ReviewableScore.types[:illegal]])
+ end
+
it "returns 403 when flagging a comment on an inaccessible post" do
category.set_permissions(group => :full)
category.save!
diff --git a/plugins/discourse-post-voting/spec/serializers/post_voting/comment_serializer_spec.rb b/plugins/discourse-post-voting/spec/serializers/post_voting/comment_serializer_spec.rb
index 8a77fb0697f..7f3d5d43fb0 100644
--- a/plugins/discourse-post-voting/spec/serializers/post_voting/comment_serializer_spec.rb
+++ b/plugins/discourse-post-voting/spec/serializers/post_voting/comment_serializer_spec.rb
@@ -11,6 +11,20 @@ describe PostVotingCommentSerializer do
PostVoting::VoteManager.vote(comment, post.user)
end
+ it "omits the illegal flag when DSA reporting is enabled" do
+ SiteSetting.dsa_reporting_enabled = true
+ SiteSetting.flag_posts_voting_comments_allowed_groups = Group::AUTO_GROUPS[:everyone]
+
+ serialized = described_class.new(comment, scope: user.guardian).as_json[:post_voting_comment]
+
+ expect(serialized[:available_flags]).to contain_exactly(
+ *PostActionType.flag_types.keys.reject { |name| name == :illegal },
+ )
+ expect(serialized[:url]).to eq(
+ "#{Discourse.base_path}/p/#{post.id}#post-voting-comment-#{comment.id}",
+ )
+ end
+
context "with a comment user" do
it "returns the right attributes for an anonymous user" do
serializer = described_class.new(comment, scope: Guardian.new)
diff --git a/spec/requests/dsa_notices_controller_spec.rb b/spec/requests/dsa_notices_controller_spec.rb
index 31269fe6dd0..0f475155697 100644
--- a/spec/requests/dsa_notices_controller_spec.rb
+++ b/spec/requests/dsa_notices_controller_spec.rb
@@ -150,6 +150,85 @@ RSpec.describe DsaNoticesController do
expect(response.parsed_body["reference"]).to start_with("DSA-")
end
+ it "uses the signed in reporter's account email regardless of the submitted address" do
+ reporter = Fabricate(:user)
+ reporter.activate
+ sign_in(reporter)
+
+ post "/dsa/report-illegal-content.json", params: { notice:, token: "" }
+
+ expect(response.status).to eq(201)
+ saved_notice = Dsa::Notice.last
+ expect(response.parsed_body["reference"]).to eq(saved_notice.reference)
+ expect(saved_notice.email).to eq(reporter.email)
+ end
+
+ it "limits account submissions independently of email verification requests" do
+ reporter = Fabricate(:user)
+ reporter.activate
+ RateLimiter.enable
+
+ stub_const(Dsa::NoticeRateLimiter, :MAX_REQUESTS_PER_REPORTER_PER_DAY, 1) do
+ post "/dsa/report-illegal-content/verify-email.json", params: { email: reporter.email }
+ expect(response.status).to eq(202)
+
+ sign_in(reporter)
+
+ post "/dsa/report-illegal-content.json", params: { notice:, token: "" }
+ expect(response.status).to eq(201)
+
+ expect do
+ post "/dsa/report-illegal-content.json", params: { notice:, token: "" }
+ end.not_to change(Dsa::Notice, :count)
+
+ expect(response.status).to eq(429)
+ end
+ end
+
+ it "lets an anonymous mode reporter submit only with a verified contact email" do
+ SiteSetting.allow_anonymous_mode = true
+ SiteSetting.anonymous_posting_allowed_groups = Group::AUTO_GROUPS[:trust_level_1].to_s
+ reporter = Fabricate(:user, trust_level: TrustLevel[3])
+ sign_in(AnonymousShadowCreator.get(reporter))
+ SiteSetting.allow_anonymous_mode = false
+
+ expect do
+ post "/dsa/report-illegal-content.json", params: { notice:, token: "" }
+ end.not_to change(Dsa::Notice, :count)
+
+ expect(response.status).to eq(422)
+ expect(response.parsed_body["error_type"]).to eq("verification_required")
+
+ post "/dsa/report-illegal-content.json", params: params
+
+ expect(response.status).to eq(201)
+ expect(Dsa::Notice.last.email).to eq(email)
+ end
+
+ it "requires verification when the signed in reporter's account email is unconfirmed" do
+ reporter = Fabricate(:user)
+ sign_in(reporter)
+ Fabricate(:email_token, user: reporter)
+
+ expect do post "/dsa/report-illegal-content.json", params: { notice: } end.not_to change(
+ Dsa::Notice,
+ :count,
+ )
+
+ expect(response.status).to eq(422)
+ expect(response.parsed_body["error_type"]).to eq("verification_required")
+ end
+
+ it "requires email verification for an anonymous report without a token" do
+ expect do post "/dsa/report-illegal-content.json", params: { notice: } end.not_to change(
+ Dsa::Notice,
+ :count,
+ )
+
+ expect(response.status).to eq(422)
+ expect(response.parsed_body["error_type"]).to eq("verification_required")
+ end
+
it "returns not found when disabled" do
SiteSetting.dsa_reporting_enabled = false
post "/dsa/report-illegal-content.json", params: params
diff --git a/spec/requests/post_actions_controller_spec.rb b/spec/requests/post_actions_controller_spec.rb
index 542542c2643..54296780ed4 100644
--- a/spec/requests/post_actions_controller_spec.rb
+++ b/spec/requests/post_actions_controller_spec.rb
@@ -103,6 +103,30 @@ RSpec.describe PostActionsController do
expect(response.status).to eq(403)
end
+ it "forbids illegal flags when DSA reporting is enabled" do
+ SiteSetting.dsa_reporting_enabled = true
+ sign_in(user)
+ target_post = Fabricate(:post, user: coding_horror)
+ reviewable =
+ PostActionCreator.off_topic(
+ Fabricate(:user, refresh_auto_groups: true),
+ target_post,
+ ).reviewable
+
+ post "/post_actions.json",
+ params: {
+ id: target_post.id,
+ post_action_type_id: PostActionType.types[:illegal],
+ message: "This content appears to be illegal.",
+ }
+
+ expect(response).to be_forbidden
+ expect(reviewable.reload.potentially_illegal?).to eq(false)
+ expect(
+ PostAction.where(post: target_post, post_action_type_id: PostActionType.types[:illegal]),
+ ).not_to exist
+ end
+
it "does not reveal private post existence" do
sign_in(user)
pm = Fabricate(:private_message_post, user: coding_horror)
diff --git a/spec/serializers/current_user_serializer_spec.rb b/spec/serializers/current_user_serializer_spec.rb
index 43aac0e7432..670753b7fd0 100644
--- a/spec/serializers/current_user_serializer_spec.rb
+++ b/spec/serializers/current_user_serializer_spec.rb
@@ -6,6 +6,40 @@ RSpec.describe CurrentUserSerializer do
let(:guardian) { user.guardian }
+ describe "#can_use_dsa_account_email" do
+ before { SiteSetting.dsa_reporting_enabled = true }
+
+ it "allows a reporter to use their confirmed account email" do
+ user.activate
+
+ expect(serializer.as_json[:can_use_dsa_account_email]).to eq(true)
+ end
+
+ it "requires email verification when the account email is unconfirmed" do
+ Fabricate(:email_token, user:)
+
+ expect(serializer.as_json[:can_use_dsa_account_email]).to eq(false)
+ end
+
+ it "requires a contact email for a shadow account after anonymous mode is disabled" do
+ SiteSetting.allow_anonymous_mode = true
+ SiteSetting.anonymous_posting_allowed_groups = Group::AUTO_GROUPS[:trust_level_1].to_s
+ reporter = Fabricate(:user, trust_level: TrustLevel[3])
+ shadow = AnonymousShadowCreator.get(reporter)
+ SiteSetting.allow_anonymous_mode = false
+
+ payload = described_class.new(shadow, scope: shadow.guardian, root: false).as_json
+
+ expect(payload[:can_use_dsa_account_email]).to eq(false)
+ end
+
+ it "omits the capability when DSA reporting is disabled" do
+ SiteSetting.dsa_reporting_enabled = false
+
+ expect(serializer.as_json).not_to have_key(:can_use_dsa_account_email)
+ end
+ end
+
it "includes notification types with remaining read or unread notifications" do
expect(serializer.as_json[:available_notification_types]).to eq([])
notification =
diff --git a/spec/services/dsa/submit_notice_spec.rb b/spec/services/dsa/submit_notice_spec.rb
index 28d8a4c535a..6cd4afb81d6 100644
--- a/spec/services/dsa/submit_notice_spec.rb
+++ b/spec/services/dsa/submit_notice_spec.rb
@@ -65,13 +65,13 @@ RSpec.describe Dsa::SubmitNotice do
context "with verification fields" do
subject(:contract) { described_class.new(notice:, token: "a" * 64) }
- it { is_expected.to validate_presence_of(:token) }
+ it { is_expected.to allow_values(nil, "").for(:token) }
it { is_expected.to validate_length_of(:token).is_equal_to(64) }
end
end
describe ".call" do
- subject(:result) { described_class.call(params:) }
+ subject(:result) { described_class.call(params:, **dependencies) }
fab!(:admin)
fab!(:group)
@@ -83,18 +83,70 @@ RSpec.describe Dsa::SubmitNotice do
pending_token
end
let(:params) { { notice:, token: } }
+ let(:dependencies) { { guardian: Guardian.new } }
before do
SiteSetting.dsa_notice_group = group.id.to_s
group.add(admin)
end
- context "when the token is invalid" do
- let(:token) { nil }
+ context "when the token is malformed" do
+ let(:token) { "invalid" }
it { is_expected.to fail_a_contract }
end
+ context "when an anonymous reporter has no verification token" do
+ let(:token) { nil }
+
+ it { is_expected.to fail_to_find_a_model(:verification) }
+ end
+
+ context "when a signed in reporter uses their confirmed account email" do
+ fab!(:reporter, :user)
+
+ let(:dependencies) { { guardian: reporter.guardian } }
+ let(:token) { nil }
+
+ before do
+ reporter.activate
+ notice[:email] = " #{reporter.email.upcase} "
+ end
+
+ it "accepts the report without an email verification token" do
+ expect(result).to run_successfully
+ expect(result.notice.email).to eq(reporter.email)
+ end
+ end
+
+ context "when a signed in reporter uses another email without a token" do
+ fab!(:reporter, :user)
+
+ let(:dependencies) { { guardian: reporter.guardian } }
+ let(:token) { nil }
+
+ before { reporter.activate }
+
+ it { is_expected.to fail_to_find_a_model(:verification) }
+ end
+
+ context "when an anonymous mode reporter uses their shadow account email without a token" do
+ fab!(:reporter) { Fabricate(:user, trust_level: TrustLevel[3]) }
+
+ let(:dependencies) { { guardian: shadow.guardian } }
+ let(:shadow) { AnonymousShadowCreator.get(reporter) }
+ let(:token) { nil }
+
+ before do
+ SiteSetting.allow_anonymous_mode = true
+ SiteSetting.anonymous_posting_allowed_groups = Group::AUTO_GROUPS[:trust_level_1].to_s
+ notice[:email] = shadow.email
+ SiteSetting.allow_anonymous_mode = false
+ end
+
+ it { is_expected.to fail_to_find_a_model(:verification) }
+ end
+
context "when the verification has expired" do
let(:token) { "a" * 64 }
@@ -112,7 +164,7 @@ RSpec.describe Dsa::SubmitNotice do
end
context "when the verification has already been used" do
- before { described_class.call(params:) }
+ before { described_class.call(params:, **dependencies) }
it "creates no duplicate notice" do
expect { result }.not_to change(Dsa::Notice, :count)
diff --git a/spec/system/dsa_notice_spec.rb b/spec/system/dsa_notice_spec.rb
index 5adae9dcba8..32012fe33d6 100644
--- a/spec/system/dsa_notice_spec.rb
+++ b/spec/system/dsa_notice_spec.rb
@@ -3,41 +3,103 @@
RSpec.describe "Illegal content notices" do
fab!(:topic)
fab!(:reported_post) { Fabricate(:post, topic:) }
+ fab!(:reporter) { Fabricate(:user, refresh_auto_groups: true) }
+ let(:reporting_modal) { PageObjects::Modals::Flag.new }
let(:explanation) do
"This listing advertises counterfeit goods as authentic and asks buyers to pay outside the marketplace. The product description and payment instructions appear intended to deceive buyers."
end
+ let(:notice_modal) { PageObjects::Modals::DsaNotice.new }
let(:notice_page) { PageObjects::Pages::DsaNotice.new }
let(:topic_page) { PageObjects::Pages::Topic.new }
before do
+ SiteSetting.post_menu_hidden_items = ""
SiteSetting.contact_email = "[email protected]"
SiteSetting.dsa_reporting_enabled = true
SiteSetting.disable_emails = "no"
- SiteSetting.allow_all_users_to_flag_illegal_content = true
+ SiteSetting.allow_all_users_to_flag_illegal_content = false
Jobs.run_immediately!
end
- it "lets a reporter verify their email and submit an illegal content report" do
+ it "lets a logged in reporter submit a notice using their account email" do
+ reporter.activate
+ sign_in(reporter)
+ topic_page.visit_topic(topic)
+ topic_page.click_post_action_button(reported_post, :flag)
+ expect(reporting_modal).to be_open
+ reporting_modal.report_illegal_content
+ expect(notice_modal).to be_open
+ expect(notice_modal).to have_post_url(reported_post)
+ expect(notice_modal).to have_no_email_input
+
+ notice_modal.go_back
+ expect(reporting_modal).to be_open
+ expect(reporting_modal).to have_no_selected_illegal_report
+ expect(reporting_modal).to have_no_message_input
+ expect(reporting_modal).to have_no_confirmation
+
+ topic_page.visit_topic(topic)
+ topic_page.open_flag_topic_modal
+ reporting_modal.report_illegal_content
+ expect(notice_modal).to be_open
+ expect(notice_modal).to have_topic_url(topic)
+ expect(notice_modal).to have_no_email_input
+
+ notice_modal.enter_report(name: "Alex Morgan", explanation:)
+ notice_modal.accept_declaration
+ notice_modal.submit_report
+ expect(notice_modal).to have_confirmation
+ expect(ActionMailer::Base.deliveries.last.to).to eq([reporter.email])
+
+ topic_page.visit_topic(topic)
+ topic_page.click_post_action_button(reported_post, :flag)
+ reporting_modal.choose_type(:off_topic)
+ reporting_modal.confirm_flag
+ expect(topic_page).to have_post_flagged(post: reported_post, type: :off_topic)
+
topic_page.visit_topic(topic)
topic_page.click_post_action_button(reported_post, :flag)
+ expect(reporting_modal).to be_open
+ reporting_modal.report_illegal_content
+ expect(notice_modal).to be_open
+ expect(notice_modal).to have_post_url(reported_post)
+ expect(notice_modal).to have_no_email_input
+
+ notice_modal.go_back
+ expect(reporting_modal).to have_no_selected_illegal_report
+
+ notice_page.visit_form
expect(notice_page).to have_notice_form
- expect(notice_page.form.field("content_url").value).to end_with(reported_post.url)
- expect(page).to have_button("Submit report", disabled: true)
+ notice_page.submit_report(
+ content_url: URI.join(page.current_url, reported_post.url).to_s,
+ name: "Alex Morgan",
+ explanation:,
+ )
+ expect(notice_page).to have_confirmation
+ end
+
+ it "lets a reporter verify their email and submit an illegal content report" do
+ topic_page.visit_topic(topic)
+ topic_page.click_post_action_button(reported_post, :flag)
+ expect(notice_modal).to be_open
+ expect(notice_modal).to have_post_url(reported_post)
+ expect(notice_modal).to have_disabled_submit
- notice_page.form.field("email").fill_in("[email protected]")
- notice_page.request_email_code
- expect(notice_page.form).to have_field_with_name("verification_code")
+ notice_modal.enter_email("[email protected]")
+ notice_modal.request_email_code
+ expect(notice_modal).to have_verification_code_input
code = ActionMailer::Base.deliveries.last.text_part.decoded[/\b[0-9]{6}\b/]
- notice_page.fill_verification_code(code)
- expect(notice_page).to have_verified_email
- expect(page).to have_field("Email address", disabled: true)
-
- notice_page.form.field("name").fill_in("Alex Morgan")
- notice_page.form.field("explanation").fill_in(explanation)
- notice_page.form.field("declaration").check
- notice_page.form.submit
- expect(notice_page).to have_confirmation
+ notice_modal.fill_verification_code(code)
+ expect(notice_modal).to have_verified_email
+
+ notice_modal.enter_report(name: "Alex Morgan", explanation:)
+ expect(notice_modal).to have_declaration(
+ "I honestly believe that the facts and claims in this report are true and complete",
+ )
+ notice_modal.accept_declaration
+ notice_modal.submit_report
+ expect(notice_modal).to have_confirmation
end
end
diff --git a/spec/system/page_objects/modals/dsa_notice.rb b/spec/system/page_objects/modals/dsa_notice.rb
new file mode 100644
index 00000000000..82a85ea105e
--- /dev/null
+++ b/spec/system/page_objects/modals/dsa_notice.rb
@@ -0,0 +1,95 @@
+# frozen_string_literal: true
+
+module PageObjects
+ module Modals
+ class DsaNotice < Base
+ MODAL_SELECTOR = ".dsa-notice-modal"
+
+ def initialize
+ super(modal_selector: MODAL_SELECTOR)
+ end
+
+ def go_back
+ find(full_modal_selector).click_button("Go back")
+ end
+
+ def enter_email(email)
+ form.field("email").fill_in(email)
+ end
+
+ def request_email_code
+ find(full_modal_selector).click_button("Get email code")
+ end
+
+ def fill_verification_code(code)
+ page.driver.with_playwright_page do |browser_page|
+ browser_page.locator("#{full_modal_selector} .d-otp-input").fill(code)
+ end
+ end
+
+ def enter_report(name:, explanation:)
+ form.field("name").fill_in(name)
+ form.field("explanation").fill_in(explanation)
+ end
+
+ def accept_declaration
+ form.field("declaration").check
+ end
+
+ def submit_report
+ form.submit
+ end
+
+ def has_post_url?(post)
+ within(full_modal_selector) do
+ has_field?(
+ "Exact URL of the content",
+ with: URI.join(page.current_url, post.url).to_s,
+ disabled: :all,
+ )
+ end
+ end
+
+ def has_topic_url?(topic)
+ within(full_modal_selector) do
+ has_field?(
+ "Exact URL of the content",
+ with: URI.join(page.current_url, topic.relative_url).to_s,
+ disabled: :all,
+ )
+ end
+ end
+
+ def has_disabled_submit?
+ has_css?("#{full_modal_selector} button[type='submit']:disabled", text: "Submit report")
+ end
+
+ def has_verification_code_input?
+ has_css?("#{full_modal_selector} .d-otp-input")
+ end
+
+ def has_no_email_input?
+ has_no_css?("#{full_modal_selector} input[name='email']")
+ end
+
+ def has_verified_email?
+ has_css?("#{full_modal_selector} button:disabled", text: "Verified") &&
+ has_css?("#{full_modal_selector} input[name='email']:disabled")
+ end
+
+ def has_declaration?(text)
+ has_css?("#{full_modal_selector} .form-kit__field[data-name='declaration']", text:)
+ end
+
+ def has_confirmation?
+ has_css?("#{full_modal_selector} .dsa-notice__confirmation", text: "Report received")
+ end
+
+ private
+
+ def form
+ PageObjects::Components::FormKit.new("#{full_modal_selector} .form-kit")
+ end
+ end
+ end
+end
diff --git a/spec/system/page_objects/modals/flag.rb b/spec/system/page_objects/modals/flag.rb
index 983b240fcde..0e3f4281604 100644
--- a/spec/system/page_objects/modals/flag.rb
+++ b/spec/system/page_objects/modals/flag.rb
@@ -10,6 +10,23 @@ module PageObjects
body.find("#radio_#{type}").click
end
+ def report_illegal_content
+ body.choose("radio_dsa_report")
+ footer.click_button("Continue")
+ end
+
+ def has_no_selected_illegal_report?
+ body.has_unchecked_field?("radio_dsa_report")
+ end
+
+ def has_no_message_input?
+ body.has_no_css?(".flag-message")
+ end
+
+ def has_no_confirmation?
+ body.has_no_css?(".flag-confirmation")
+ end
+
def confirm_flag
click_primary_button
end
diff --git a/spec/system/page_objects/pages/dsa_notice.rb b/spec/system/page_objects/pages/dsa_notice.rb
index 4681628b4a8..81fc2f2f4fc 100644
--- a/spec/system/page_objects/pages/dsa_notice.rb
+++ b/spec/system/page_objects/pages/dsa_notice.rb
@@ -3,6 +3,11 @@
module PageObjects
module Pages
class DsaNotice < Base
+ def visit_form
+ visit("/dsa/report-illegal-content")
+ self
+ end
+
def form
PageObjects::Components::FormKit.new(".dsa-notice .form-kit")
end
@@ -28,6 +33,14 @@ module PageObjects
def has_confirmation?
has_css?(".dsa-notice h1", text: "Report received")
end
+
+ def submit_report(content_url:, name:, explanation:)
+ form.field("content_url").fill_in(content_url)
+ form.field("name").fill_in(name)
+ form.field("explanation").fill_in(explanation)
+ form.field("declaration").check
+ form.submit
+ end
end
end
end
diff --git a/spec/system/page_objects/pages/topic.rb b/spec/system/page_objects/pages/topic.rb
index 4de0731ff91..cc83c2bfe14 100644
--- a/spec/system/page_objects/pages/topic.rb
+++ b/spec/system/page_objects/pages/topic.rb
@@ -117,6 +117,10 @@ module PageObjects
within_post(post) { has_css?(".show-more-actions") }
end
+ def has_post_flagged?(post:, type:)
+ within_post(post) { has_text?(I18n.t("js.post.actions.by_you.#{type}")) }
+ end
+
def has_post_bookmarked?(post, with_reminder: false)
is_post_bookmarked(post, bookmarked: true, with_reminder: with_reminder)
end