Skip to content

Commit

Permalink
FEATURE: Add new 'illegal' flag reason (discourse#25498)
Browse files Browse the repository at this point in the history
To comply with Digital Services Act we need a way for users to flag a post as potentially illegal. This PR adds that functionality.
  • Loading branch information
Drenmi authored Feb 7, 2024
1 parent 21a830b commit 95a2d28
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
3 changes: 3 additions & 0 deletions app/models/post_action_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ def initialize_flag_settings
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

Expand Down
3 changes: 3 additions & 0 deletions config/locales/client.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions config/locales/server.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
7 changes: 4 additions & 3 deletions lib/post_action_creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def create(
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
Expand Down Expand Up @@ -114,7 +114,8 @@ def perform
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.
Expand Down Expand Up @@ -334,7 +335,7 @@ def create_message_creator
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]

Expand Down
10 changes: 5 additions & 5 deletions spec/models/post_action_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -755,11 +755,11 @@ def value_for(user_id, dt)
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
Expand Down

0 comments on commit 95a2d28

Please sign in to comment.