A platform for community discussion. Free, open, simple.
DEV: Add appeal instructions to moderation notices when DSA is enabled (#44884)
Alan Guo Xiang Tan575d631684bf
diff --git a/app/mailers/user_notifications.rb b/app/mailers/user_notifications.rbindex c6066f6df43..e490f2bb4a0 100644--- a/app/mailers/user_notifications.rb+++ b/app/mailers/user_notifications.rb@@ -56,6 +56,7 @@ class UserNotifications < ActionMailer::Basebuild_email(user.email,template: "user_notifications.post_approved",+ **Dsa::AppealInstructions.message_options,locale: locale,base_url: Discourse.base_url,post_url: post_url,@@ -68,6 +69,7 @@ class UserNotifications < ActionMailer::Basebuild_email(user.email,template: "user_notifications.signup_after_reject",+ **Dsa::AppealInstructions.message_options,locale: locale,reject_reason: opts[:reject_reason],recipient_user: user,@@ -179,6 +181,7 @@ class UserNotifications < ActionMailer::Basebuild_email(user.email,template: "user_notifications.account_silenced_forever",+ **Dsa::AppealInstructions.message_options,locale:,reason: user_history.details,recipient_user: user,@@ -191,6 +194,7 @@ class UserNotifications < ActionMailer::Basebuild_email(user.email,template: "user_notifications.account_silenced",+ **Dsa::AppealInstructions.message_options,locale:,reason: user_history.details,silenced_till:@@ -219,7 +223,12 @@ class UserNotifications < ActionMailer::Baseflag_reason ||= I18n.t("flag_reasons.spam")- build_email(email, template: "user_notifications.account_deleted", flag_reason: flag_reason)+ build_email(+ email,+ template: "user_notifications.account_deleted",+ **Dsa::AppealInstructions.message_options,+ flag_reason: flag_reason,+ )enddef account_suspended(user, opts = nil)@@ -233,6 +242,7 @@ class UserNotifications < ActionMailer::Basebuild_email(user.email,template: "user_notifications.account_suspended_forever",+ **Dsa::AppealInstructions.message_options,locale:,reason: user_history.details,recipient_user: user,@@ -245,6 +255,7 @@ class UserNotifications < ActionMailer::Basebuild_email(user.email,template: "user_notifications.account_suspended",+ **Dsa::AppealInstructions.message_options,locale:,reason: user_history.details,suspended_till:diff --git a/app/models/post.rb b/app/models/post.rbindex 9dd804c9ae0..c896054553f 100644--- a/app/models/post.rb+++ b/app/models/post.rb@@ -719,6 +719,7 @@ class Post < ActiveRecord::Base# inform userif user.present?options = {+ **Dsa::AppealInstructions.message_options,url: url,edit_delay: SiteSetting.cooldown_minutes_after_hiding_posts,flag_reason:diff --git a/app/models/reviewable_flagged_post.rb b/app/models/reviewable_flagged_post.rbindex a2a7bb50953..da0bfae5a7f 100644--- a/app/models/reviewable_flagged_post.rb+++ b/app/models/reviewable_flagged_post.rb@@ -502,6 +502,7 @@ class ReviewableFlaggedPost < Reviewableuser_id: post.user_id,message_type: "flags_disagreed",message_options: {+ **Dsa::AppealInstructions.message_options,flagged_post_raw_content: post.raw,url: post.url,},diff --git a/app/models/reviewable_queued_post.rb b/app/models/reviewable_queued_post.rbindex d6b7fba5f6b..b12cd30bdb0 100644--- a/app/models/reviewable_queued_post.rb+++ b/app/models/reviewable_queued_post.rb@@ -190,6 +190,7 @@ class ReviewableQueuedPost < Reviewableendpm_translation_args = {+ **Dsa::AppealInstructions.message_options,topic_title: topic&.title || payload["title"],topic_url: topic&.url,reason: args[:revise_custom_reason].presence || args[:revise_reason],diff --git a/app/services/user_silencer.rb b/app/services/user_silencer.rbindex 58c2f679d4e..dc4fe16a84d 100644--- a/app/services/user_silencer.rb+++ b/app/services/user_silencer.rb@@ -44,7 +44,7 @@ class UserSilencer@user_history = StaffActionLogger.new(@by_user).log_silence_user(@user, log_params)end- silence_message_params = {}+ silence_message_params = Dsa::AppealInstructions.message_optionsDiscourseEvent.trigger(:user_silenced,user: @user,@@ -102,7 +102,7 @@ class UserSilencer@user.silenced_till = nilif @user.saveDiscourseEvent.trigger(:user_unsilenced, user: @user, by_user: @by_user)- SystemMessage.create(@user, :unsilenced)+ SystemMessage.create(@user, :unsilenced, Dsa::AppealInstructions.message_options)if @by_userStaffActionLogger.new(@by_user).log_unsilence_user(@user,diff --git a/config/locales/server.en.yml b/config/locales/server.en.ymlindex 436f9eeb170..89d99e18600 100644--- a/config/locales/server.en.yml+++ b/config/locales/server.en.yml@@ -2148,6 +2148,7 @@ en:site_settings:dsa_notice_group: "Group receiving illegal content notices when {{setting:dsa_reporting_enabled}} is enabled. Members can read notices and reporter contact details. Defaults to admins, which also receives notices if the selected group is missing or empty."+ dsa_moderation_appeal_email: "Users can appeal moderation decisions by emailing this address. Leave blank to omit appeal instructions. Requires {{setting:dsa_reporting_enabled}} to be turned on."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"@@ -4023,6 +4024,7 @@ en:private_topic_title: "Topic #%{id}"contents_hidden: "Please visit the post to see its contents."+ moderation_appeal_instructions: "To appeal this decision, contact %{email}"post_hidden:title: "Post Hidden"diff --git a/config/site_settings.yml b/config/site_settings.ymlindex 7032942c1a7..12f9d8cab8f 100644--- a/config/site_settings.yml+++ b/config/site_settings.yml@@ -4910,6 +4910,10 @@ experimental:default: falsehidden: truearea: "experimental"+ dsa_moderation_appeal_email:+ default: ""+ type: email+ hidden: truedsa_community_rules:type: objectsdefault: []diff --git a/lib/dsa/appeal_instructions.rb b/lib/dsa/appeal_instructions.rbnew file mode 100644index 00000000000..27b8dcd7c09--- /dev/null+++ b/lib/dsa/appeal_instructions.rb@@ -0,0 +1,14 @@+# frozen_string_literal: true++module Dsa+ module AppealInstructions+ def self.message_options+ return {} unless SiteSetting.dsa_reporting_enabled++ email = SiteSetting.dsa_moderation_appeal_email.presence+ return {} unless email++ { body_suffix_key: "system_messages.moderation_appeal_instructions", email: }+ end+ end+enddiff --git a/lib/email/message_builder.rb b/lib/email/message_builder.rbindex 4cc6d9b6fd3..d3d8e1d8e56 100644--- a/lib/email/message_builder.rb+++ b/lib/email/message_builder.rb@@ -224,6 +224,11 @@ module Emailbody = @opts[:body].dupend+ if key = @template_args[:body_suffix_key]+ paragraph = I18n.t(key, @template_args)+ body = "#{body.rstrip}\n\n#{paragraph}"+ end+if @template_args[:unsubscribe_instructions].present?body << "\n"body << @template_args[:unsubscribe_instructions]diff --git a/lib/post_destroyer.rb b/lib/post_destroyer.rbindex 463c31c157d..39553919f1b 100644--- a/lib/post_destroyer.rb+++ b/lib/post_destroyer.rb@@ -469,6 +469,7 @@ class PostDestroyerend),message_options: {+ **Dsa::AppealInstructions.message_options,flagged_post_raw_content: notify_responders ? options[:parent_post].raw : @post.raw,flagged_post_response_raw_content: @post.raw,url: notify_responders ? options[:parent_post].url : @post.url,diff --git a/lib/system_message.rb b/lib/system_message.rbindex dd0557ba9c5..9eabdb116b2 100644--- a/lib/system_message.rb+++ b/lib/system_message.rb@@ -39,6 +39,11 @@ class SystemMessageI18n.t("system_messages.#{type}.text_body_template", params)end+ if key = params[:body_suffix_key]+ paragraph = I18n.with_locale(@recipient.effective_locale) { I18n.t(key, params) }+ raw = "#{raw.rstrip}\n\n#{paragraph}"+ end+if from_systemuser = Discourse.system_userelsediff --git a/spec/lib/dsa/appeal_instructions_spec.rb b/spec/lib/dsa/appeal_instructions_spec.rbnew file mode 100644index 00000000000..25ec32f7620--- /dev/null+++ b/spec/lib/dsa/appeal_instructions_spec.rb@@ -0,0 +1,45 @@+# frozen_string_literal: true++RSpec.describe Dsa::AppealInstructions do+ describe ".message_options" do+ before do+ SiteSetting.dsa_moderation_appeal_email = ""+ SiteSetting.contact_email = ""+ end++ context "when the dsa_reporting_enabled site setting is enabled" do+ before { SiteSetting.dsa_reporting_enabled = true }++ it "uses the DSA appeal address" do+ SiteSetting.dsa_moderation_appeal_email = "[email protected]"+ SiteSetting.contact_email = "[email protected]"++ expect(described_class.message_options).to eq(+ body_suffix_key: "system_messages.moderation_appeal_instructions",+ email: "[email protected]",+ )+ end++ it "omits instructions when only the site contact email is configured" do+ SiteSetting.contact_email = "[email protected]"++ expect(described_class.message_options).to eq({})+ end++ it "returns no paragraph when the DSA appeal address is blank" do+ expect(described_class.message_options).to eq({})+ end+ end++ context "when the dsa_reporting_enabled site setting is disabled" do+ before { SiteSetting.dsa_reporting_enabled = false }++ it "returns no paragraph when DSA reporting is disabled" do+ SiteSetting.dsa_moderation_appeal_email = "[email protected]"+ SiteSetting.contact_email = "[email protected]"++ expect(described_class.message_options).to eq({})+ end+ end+ end+enddiff --git a/spec/lib/email/message_builder_spec.rb b/spec/lib/email/message_builder_spec.rbindex cc46595cf94..012762e755a 100644--- a/spec/lib/email/message_builder_spec.rb+++ b/spec/lib/email/message_builder_spec.rb@@ -30,6 +30,60 @@ RSpec.describe Email::MessageBuilder doexpect(builder.body).to eq(body)end+ context "with an appended paragraph" do+ let(:builder) do+ Email::MessageBuilder.new(+ to_address,+ subject: email_subject,+ body:,+ body_suffix_key: "system_messages.private_topic_title",+ id: 42,+ )+ end++ it "interpolates the paragraph after the supplied body" do+ expect(builder.body).to eq("#{body}\n\nTopic #42")+ end++ it "uses the same locale as the email template" do+ TranslationOverride.upsert!(:fr, "system_messages.private_topic_title", "Sujet %{id}")+ TranslationOverride.upsert!(+ :fr,+ "system_messages.welcome_invite.text_body_template",+ "Bienvenue %{username}.",+ )+ localized_builder =+ Email::MessageBuilder.new(+ to_address,+ template: "system_messages.welcome_invite",+ username: "Jake",+ locale: :fr,+ body_suffix_key: "system_messages.private_topic_title",+ id: 42,+ )++ expect(localized_builder.body).to eq("Bienvenue Jake.\n\nSujet 42")+ end++ it "places the paragraph before unsubscribe instructions and the body modifier" do+ modifier = ->(rendered, *) { "#{rendered}\nModified." }+ plugin_instance = Plugin::Instance.new+ plugin_instance.register_modifier(:message_builder_body, &modifier)+ footer_builder =+ Email::MessageBuilder.new(+ to_address,+ body:,+ body_suffix_key: "system_messages.private_topic_title",+ id: 42,+ unsubscribe_instructions: "Unsubscribe here.",+ )++ expect(footer_builder.body).to eq("#{body}\n\nTopic #42\nUnsubscribe here.\nModified.")+ ensure+ DiscoursePluginRegistry.unregister_modifier(plugin_instance, :message_builder_body, &modifier)+ end+ end+it "uses the message_builder subject modifier properly" doplugin_instance = Plugin::Instance.newplugin_instance.register_modifier(:message_builder_subject, &subject_modifier_block)diff --git a/spec/lib/post_destroyer_spec.rb b/spec/lib/post_destroyer_spec.rbindex 9bf819ec919..dfe09eaf19a 100644--- a/spec/lib/post_destroyer_spec.rb+++ b/spec/lib/post_destroyer_spec.rb@@ -1131,6 +1131,21 @@ RSpec.describe PostDestroyer dobefore { Jobs::SendSystemMessage.clear }+ context "when the dsa_reporting_enabled site setting is enabled" do+ before do+ SiteSetting.dsa_reporting_enabled = true+ SiteSetting.dsa_moderation_appeal_email = "[email protected]"+ end++ it "includes appeal instructions in the deletion notice" do+ PostDestroyer.new(moderator, second_post).destroy+ args = Jobs::SendSystemMessage.jobs.last["args"][0].with_indifferent_access+ Jobs::SendSystemMessage.new.execute(args)++ expect(Post.last.raw).to include("To appeal this decision, contact [email protected]")+ end+ end+it "deletes public post actions and agrees with flags" dourl = second_post.urlPostDestroyer.new(moderator, second_post).destroydiff --git a/spec/lib/system_message_spec.rb b/spec/lib/system_message_spec.rbindex 0bf960c9f80..14120d8904c 100644--- a/spec/lib/system_message_spec.rb+++ b/spec/lib/system_message_spec.rb@@ -10,6 +10,28 @@ RSpec.describe SystemMessage dobefore { SiteSetting.site_contact_username = admin.username }+ it "appends a paragraph in the recipient locale to a custom body before the plugin event" do+ SiteSetting.allow_user_locale = true+ user.update!(locale: "fr")+ TranslationOverride.upsert!(:fr, "system_messages.private_topic_title", "Sujet %{id}")+ expected_raw = "Custom outcome.\n\nSujet 42"++ event =+ DiscourseEvent.track(:before_system_message_sent) do+ SystemMessage.create(+ user,+ :plugin_notice,+ message_title: "Custom notice",+ message_raw: "Custom outcome.",+ body_suffix_key: "system_messages.private_topic_title",+ id: 42,+ )+ end++ expect(Post.last.raw).to eq(expected_raw)+ expect(event[:params].first[:post_creator_args].last[:raw]).to eq(expected_raw)+ end+it "creates the expected post" dosystem_message = SystemMessage.new(user)post = system_message.create(:welcome_invite)diff --git a/spec/mailers/user_notifications_spec.rb b/spec/mailers/user_notifications_spec.rbindex 375eb071b2d..ee26d4dc298 100644--- a/spec/mailers/user_notifications_spec.rb+++ b/spec/mailers/user_notifications_spec.rb@@ -131,6 +131,17 @@ RSpec.describe UserNotifications doexpect(email.body).to be_presentend+ context "when the dsa_reporting_enabled site setting is enabled" do+ before do+ SiteSetting.dsa_reporting_enabled = true+ SiteSetting.dsa_moderation_appeal_email = "[email protected]"+ end++ it "omits appeal instructions from the password reset email" do+ expect(email.body.decoded).not_to include(SiteSetting.dsa_moderation_appeal_email)+ end+ end+it "shows the correct preview text in forgot password" dopreview_text = I18n.t("user_notifications.forgot_password.preview")expect(Email::Renderer.new(email).html.scan(/#{preview_text}/).count).to eq(1)@@ -147,6 +158,19 @@ RSpec.describe UserNotifications dodescribe ".post_approved" dofab!(:post)+ context "when the dsa_reporting_enabled site setting is enabled" do+ before do+ SiteSetting.dsa_reporting_enabled = true+ SiteSetting.dsa_moderation_appeal_email = "[email protected]"+ end++ it "includes appeal instructions when DSA reporting and an appeal address are configured" do+ mail = UserNotifications.post_approved(user, notification_data_hash: { post_url: post.url })++ expect(mail.body.decoded).to include("To appeal this decision, contact [email protected]")+ end+ end+it "addresses the post approval email to the user with a subject and body" dosubject =UserNotifications.post_approved(user, { notification_data_hash: { post_url: post.url } })@@ -1539,6 +1563,43 @@ RSpec.describe UserNotifications dolet(:user) { Fabricate(:user) }let(:notification) { Fabricate(:private_message_notification, user: user, post: response) }+ context "when the dsa_reporting_enabled site setting is enabled" do+ before do+ SiteSetting.dsa_reporting_enabled = true+ SiteSetting.dsa_moderation_appeal_email = "[email protected]"+ end++ it "includes the stored moderation appeal once in each email part" do+ moderation_post =+ SystemMessage.create_from_system_user(+ user,+ :silenced_by_staff,+ message_title: "Moderation notice",+ message_raw: "Moderation outcome.",+ **Dsa::AppealInstructions.message_options,+ )+ moderation_notification =+ Fabricate(:private_message_notification, user:, post: moderation_post)+ appeal =+ I18n.t(+ "system_messages.moderation_appeal_instructions",+ email: SiteSetting.dsa_moderation_appeal_email,+ )++ mail =+ UserNotifications.user_private_message(+ user,+ post: moderation_post,+ notification_type: moderation_notification.notification_type,+ notification_data_hash: moderation_notification.data_hash,+ )++ html_text = Nokogiri::HTML5.fragment(mail.html_part.body.decoded).text+ expect(html_text.scan(appeal).size).to eq(1)+ expect(mail.text_part.body.decoded.scan(appeal).size).to eq(1)+ end+ end+it "generates a correct email" doSiteSetting.enable_names = truemail =@@ -2427,6 +2488,25 @@ RSpec.describe UserNotifications dodescribe ".account_silenced" dofab!(:user_history) { Fabricate(:user_history, action: UserHistory.actions[:silence_user]) }+ context "when the dsa_reporting_enabled site setting is enabled" do+ before do+ SiteSetting.dsa_reporting_enabled = true+ SiteSetting.dsa_moderation_appeal_email = "[email protected]"+ end++ it "includes appeal instructions for temporary and permanent silences without a reviewable" do+ [1.day.from_now, 1000.years.from_now].each do |deadline|+ user.silenced_till = deadline++ mail = UserNotifications.account_silenced(user, user_history:)++ expect(mail.body.decoded).to include(+ "To appeal this decision, contact [email protected]",+ )+ end+ end+ end+it "adds the silenced_till date in user's timezone" douser.user_option.timezone = "Asia/Tbilisi" # GMT+4user.silenced_till = DateTime.parse("May 25, 2020, 12:00pm")@@ -2522,6 +2602,19 @@ RSpec.describe UserNotifications dodescribe ".account_deleted" dofab!(:reviewable) { Fabricate(:reviewable_flagged_post, reviewable_scores: []) }+ context "when the dsa_reporting_enabled site setting is enabled" do+ before do+ SiteSetting.dsa_reporting_enabled = true+ SiteSetting.dsa_moderation_appeal_email = "[email protected]"+ end++ it "includes appeal instructions in account deletion emails" do+ mail = UserNotifications.account_deleted("[email protected]", reviewable)++ expect(mail.body.decoded).to include("To appeal this decision, contact [email protected]")+ end+ end+it "includes flag reason for standard flags" doFabricate(:reviewable_score,@@ -2591,6 +2684,25 @@ RSpec.describe UserNotifications dodescribe ".account_suspended" dofab!(:user_history) { Fabricate(:user_history, action: UserHistory.actions[:suspend_user]) }+ context "when the dsa_reporting_enabled site setting is enabled" do+ before do+ SiteSetting.dsa_reporting_enabled = true+ SiteSetting.dsa_moderation_appeal_email = "[email protected]"+ end++ it "includes appeal instructions for temporary and permanent suspensions without a reviewable" do+ [1.day.from_now, 1000.years.from_now].each do |deadline|+ user.suspended_till = deadline++ mail = UserNotifications.account_suspended(user, user_history:)++ expect(mail.body.decoded).to include(+ "To appeal this decision, contact [email protected]",+ )+ end+ end+ end+it "adds the suspended_till date in user's timezone" douser.user_option.timezone = "Asia/Tbilisi" # GMT+4user.suspended_till = DateTime.parse("May 25, 2020, 12:00pm")@@ -2678,6 +2790,21 @@ RSpec.describe UserNotifications doendend+ describe ".signup_after_reject" do+ context "when the dsa_reporting_enabled site setting is enabled" do+ before do+ SiteSetting.dsa_reporting_enabled = true+ SiteSetting.dsa_moderation_appeal_email = "[email protected]"+ end++ it "includes the DSA appeal address in signup rejection emails" do+ mail = UserNotifications.signup_after_reject(user, reject_reason: "Account not approved.")++ expect(mail.body.decoded).to include("To appeal this decision, contact [email protected]")+ end+ end+ end+describe "improved email subject templates" dodef assert_improved_template_format(base_key)original = I18n.t("user_notifications.#{base_key}.subject_template")diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rbindex 56c608d4b99..b5ee97d8e6a 100644--- a/spec/models/post_spec.rb+++ b/spec/models/post_spec.rb@@ -1623,6 +1623,25 @@ RSpec.describe Post docustom_flag.destroy!end+ context "when the dsa_reporting_enabled site setting is enabled" do+ before do+ SiteSetting.dsa_reporting_enabled = true+ SiteSetting.dsa_moderation_appeal_email = "[email protected]"+ end++ it "includes appeal instructions in the hidden post notice" do+ custom_flag = Fabricate(:flag, name: "custom flag")+ post.hide!(PostActionType.types[:custom_custom_flag])++ jobs = Jobs::SendSystemMessage.jobs++ Jobs::SendSystemMessage.new.execute(jobs[0]["args"][0].with_indifferent_access)+ expect(Post.last.raw).to include("To appeal this decision, contact [email protected]")++ custom_flag.destroy!+ end+ end+it "decreases user_stat topic_count for the first post" doexpect do post.hide!(PostActionType.types[:off_topic]) end.to change {post.user.user_stat.reload.topic_countdiff --git a/spec/models/reviewable_flagged_post_spec.rb b/spec/models/reviewable_flagged_post_spec.rbindex e314ec50e8c..68a57aba9ef 100644--- a/spec/models/reviewable_flagged_post_spec.rb+++ b/spec/models/reviewable_flagged_post_spec.rb@@ -1470,6 +1470,28 @@ RSpec.describe ReviewableFlaggedPost, type: :model doassert_pm_creation_enqueued(reviewable.post.user_id, "flags_disagreed")end+ context "when the dsa_reporting_enabled site setting is enabled" do+ before do+ SiteSetting.dsa_reporting_enabled = true+ SiteSetting.dsa_moderation_appeal_email = "[email protected]"+ end++ it "includes appeal instructions in the restored post notice" do+ reviewable = Fabricate(:reviewable_flagged_post)+ reviewable.post.update(+ hidden: true,+ hidden_at: Time.zone.now,+ hidden_reason_id: PostActionType.types[:spam],+ )++ reviewable.perform(moderator, :disagree_and_restore)++ args = Jobs::SendSystemMessage.jobs.last["args"][0].with_indifferent_access+ Jobs::SendSystemMessage.new.execute(args)+ expect(Post.last.raw).to include("To appeal this decision, contact [email protected]")+ end+ end+it "unsilences the user if they were silenced for the post" doreviewable = Fabricate(:reviewable_flagged_post)target_user = reviewable.post.userdiff --git a/spec/models/reviewable_queued_post_spec.rb b/spec/models/reviewable_queued_post_spec.rbindex b0888034f01..d27507555fc 100644--- a/spec/models/reviewable_queued_post_spec.rb+++ b/spec/models/reviewable_queued_post_spec.rb@@ -161,6 +161,24 @@ RSpec.describe ReviewableQueuedPost, type: :model doexpect(Post.public_posts.count).to eq(post_count)end+ context "when the dsa_reporting_enabled site setting is enabled" do+ before do+ SiteSetting.dsa_reporting_enabled = true+ SiteSetting.dsa_moderation_appeal_email = "[email protected]"+ end++ it "includes appeal instructions in the feedback message" do+ reviewable.perform(+ moderator,+ :revise_and_reject_post,+ revise_reason: "Duplicate",+ revise_feedback: "This is old news",+ )++ expect(Post.last.raw).to include("To appeal this decision, contact [email protected]")+ end+ end+it "creates a private message to the creator of the post" doargs = { revise_reason: "Duplicate", revise_feedback: "This is old news" }expect { reviewable.perform(moderator, :revise_and_reject_post, args) }.to change {diff --git a/spec/services/user_silencer_spec.rb b/spec/services/user_silencer_spec.rbindex aa538e30088..5fa59fc9779 100644--- a/spec/services/user_silencer_spec.rb+++ b/spec/services/user_silencer_spec.rb@@ -140,6 +140,26 @@ RSpec.describe UserSilencer doexpect(post.topic.title).to eq("override title")expect(post.raw).to eq("override raw")end++ context "when the dsa_reporting_enabled site setting is enabled" do+ before do+ SiteSetting.dsa_reporting_enabled = true+ SiteSetting.dsa_moderation_appeal_email = "[email protected]"+ end++ it "includes appeal instructions in plugin customized messages" do+ UserSilencer.silence(user, admin, message: :plugin_silence_notice)+ # force a reload in case instance has no posts+ system_user = User.find(Discourse::SYSTEM_USER_ID)++ post = system_user.posts.order("posts.id desc").first++ expect(post.topic.title).to eq("override title")+ expect(post.raw).to eq(+ "override raw\n\nTo appeal this decision, contact [email protected]",+ )+ end+ endendend@@ -165,6 +185,22 @@ RSpec.describe UserSilencer doexpect(count).to eq(1)end+ context "when the dsa_reporting_enabled site setting is enabled" do+ before do+ SiteSetting.dsa_reporting_enabled = true+ SiteSetting.dsa_moderation_appeal_email = "[email protected]"+ end++ it "includes appeal instructions in the unsilence notice" do+ user.update!(silenced_till: 1.year.from_now)++ UserSilencer.unsilence(user, admin)++ pm = user.topics_allowed.order("topics.id desc").first+ expect(pm.first_post.raw).to include("To appeal this decision, contact [email protected]")+ end+ end+it "does nothing when the user is not silenced" doexpect(UserSilencer.unsilence(user, admin)).to eq(false)