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.
This commit is contained in:
Ted Johansson 2024-02-07 10:12:22 +08:00 committed by GitHub
parent 21a830b53d
commit 95a2d285d3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 21 additions and 8 deletions

View File

@ -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

View File

@ -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"

View File

@ -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 <a href="%{base_path}/guidelines">our community guidelines</a>.'
short_description: 'A violation of <a href="%{base_path}/guidelines">our community guidelines</a>'
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."

View File

@ -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]

View File

@ -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