From 95a2d285d397edf0c31ac7ac96dac7d3d0f200d3 Mon Sep 17 00:00:00 2001 From: Ted Johansson Date: Wed, 7 Feb 2024 10:12:22 +0800 Subject: [PATCH] FEATURE: Add new 'illegal' flag reason (#25498) To comply with Digital Services Act we need a way for users to flag a post as potentially illegal. This PR adds that functionality. --- app/models/post_action_type.rb | 3 +++ config/locales/client.en.yml | 3 +++ config/locales/server.en.yml | 6 ++++++ lib/post_action_creator.rb | 7 ++++--- spec/models/post_action_spec.rb | 10 +++++----- 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/app/models/post_action_type.rb b/app/models/post_action_type.rb index 3f2f8d7e977..9b49575e3b7 100644 --- a/app/models/post_action_type.rb +++ b/app/models/post_action_type.rb @@ -100,6 +100,9 @@ class PostActionType < ActiveRecord::Base notify_type: true, custom_type: true, ) + @flag_settings.add(10, :illegal, topic_type: true, notify_type: true, custom_type: true) + # When adding a new ID here, check that it doesn't clash with any added in + # `ReviewableScore.types`. You can thank me later. end end diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 4c87b0ba699..7e5ce546c04 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -3658,6 +3658,7 @@ en: off_topic: "You flagged this as off-topic" spam: "You flagged this as spam" inappropriate: "You flagged this as inappropriate" + illegal: "You flagged this as illegal" notify_moderators: "You flagged this for moderation" notify_user: "You sent a message to this user" @@ -3940,10 +3941,12 @@ en: off_topic: "It's Off-Topic" inappropriate: "It's Inappropriate" spam: "It's Spam" + illegal: "It's Illegal" custom_placeholder_notify_user: "Be specific, be constructive, and always be kind." notify_user_textarea_label: "Message for the user" custom_placeholder_notify_moderators: "Let us know specifically what you are concerned about, and provide relevant links and examples where possible." notify_moderators_textarea_label: "Message for the moderators" + custom_placeholder_illegal: "Let us know specifically why you believe this post is illegal, and provide relevant links and examples where possible." custom_message: at_least: one: "enter at least %{count} character" diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 928fd630fe8..4e6248832ba 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -964,6 +964,12 @@ en: title: "Inappropriate" description: 'This post contains content that a reasonable person would consider offensive, abusive, to be hateful conduct or a violation of our community guidelines.' short_description: 'A violation of our community guidelines' + illegal: + title: "It's Illegal" + description: "This post requires staff attention because I believe it contains content that is illegal." + short_description: "This is illegal" + email_title: 'A post in "%{title}" requires staff attention' + email_body: "%{link}\n\n%{message}" notify_user: title: "Send @%{username} a message" description: "I want to talk to this person directly and personally about their post." diff --git a/lib/post_action_creator.rb b/lib/post_action_creator.rb index 7eda9c95567..df36e57af43 100644 --- a/lib/post_action_creator.rb +++ b/lib/post_action_creator.rb @@ -32,7 +32,7 @@ class PostActionCreator create(created_by, post, action, silent: silent) end end - %i[notify_moderators notify_user].each do |action| + %i[notify_moderators notify_user illegal].each do |action| define_method(action) do |created_by, post, message = nil| create(created_by, post, action, message: message) end @@ -114,7 +114,8 @@ class PostActionCreator end # create meta topic / post if needed - if @message.present? && %i[notify_moderators notify_user spam].include?(@post_action_name) + if @message.present? && + %i[notify_moderators notify_user spam illegal].include?(@post_action_name) creator = create_message_creator # We need to check if the creator exists because it's possible `create_message_creator` returns nil # in the event that a `post_action_notify_user_handler` evaluated to false, haulting the post creation. @@ -334,7 +335,7 @@ class PostActionCreator raw: body, } - if %i[notify_moderators spam].include?(@post_action_name) + if %i[notify_moderators spam illegal].include?(@post_action_name) create_args[:subtype] = TopicSubtype.notify_moderators create_args[:target_group_names] = [Group[:moderators].name] diff --git a/spec/models/post_action_spec.rb b/spec/models/post_action_spec.rb index 88454419f6b..ad311caa914 100644 --- a/spec/models/post_action_spec.rb +++ b/spec/models/post_action_spec.rb @@ -755,11 +755,11 @@ RSpec.describe PostAction do end end - it "prevents user to act twice at the same time" do - # flags are already being tested - all_types_except_flags = - PostActionType.types.except(*PostActionType.flag_types_without_custom.keys) - all_types_except_flags.values.each do |action| + # flags are already being tested + all_types_except_flags = + PostActionType.types.except(*PostActionType.flag_types_without_custom.keys) + all_types_except_flags.values.each do |action| + it "prevents user to act twice at the same time" do expect(PostActionCreator.new(eviltrout, post, action).perform).to be_success expect(PostActionCreator.new(eviltrout, post, action).perform).to be_failed end