FEATURE: auto_action_type field for flags (#29306)

Allow admins to specify if the flag should be `auto_action_type`. If yes, then when an admin flags a post,  it is automatically actioned.

Meta: https://meta.discourse.org/t/allow-creation-of-custom-flags-which-auto-hide-content-similar-to-spam-and-inapproriate/329894
This commit is contained in:
Krzysztof Kotlarek 2024-10-22 10:56:31 +11:00 committed by GitHub
parent 08911eac8f
commit 644e6c7f46
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 60 additions and 6 deletions

View File

@ -30,11 +30,13 @@ export default class AdminFlagsForm extends Component {
appliesTo: this.args.flag.applies_to,
requireMessage: this.args.flag.require_message,
enabled: this.args.flag.enabled,
autoActionType: this.args.flag.auto_action_type,
};
} else {
return {
enabled: true,
requireMessage: false,
autoActionType: false,
};
}
}
@ -68,7 +70,14 @@ export default class AdminFlagsForm extends Component {
}
@action
save({ name, description, appliesTo, requireMessage, enabled }) {
save({
name,
description,
appliesTo,
requireMessage,
enabled,
autoActionType,
}) {
const createOrUpdate = this.isUpdate ? this.update : this.create;
const data = {
name,
@ -76,6 +85,7 @@ export default class AdminFlagsForm extends Component {
enabled,
applies_to: appliesTo,
require_message: requireMessage,
auto_action_type: autoActionType,
};
createOrUpdate(data);
}
@ -107,6 +117,7 @@ export default class AdminFlagsForm extends Component {
this.args.flag.applies_to = response.flag.applies_to;
this.args.flag.require_message = response.flag.require_message;
this.args.flag.enabled = response.flag.enabled;
this.args.flag.auto_action_type = response.flag.auto_action_type;
this.router.transitionTo("adminConfig.flags");
} catch (error) {
popupAjaxError(error);
@ -183,6 +194,20 @@ export default class AdminFlagsForm extends Component {
>
<field.Checkbox />
</checkboxGroup.Field>
<checkboxGroup.Field
@name="autoActionType"
@title={{i18n
"admin.config_areas.flags.form.auto_action_type"
}}
as |field|
>
<field.Checkbox>
{{i18n
"admin.config_areas.flags.form.auto_action_type_description"
}}
</field.Checkbox>
</checkboxGroup.Field>
</form.CheckboxGroup>
<form.Alert @icon="info-circle">

View File

@ -12,7 +12,8 @@ class FlagSerializer < ApplicationSerializer
:enabled,
:is_flag,
:applies_to,
:is_used
:is_used,
:auto_action_type
def i18n_prefix
"#{@options[:target] || "post_action"}_types.#{object.name_key}"

View File

@ -10,6 +10,7 @@ class Flags::CreateFlag
attribute :require_message, :boolean
attribute :enabled, :boolean
attribute :applies_to
attribute :auto_action_type, :boolean
validates :name, presence: true
validates :description, presence: true

View File

@ -10,6 +10,7 @@ class Flags::UpdateFlag
attribute :require_message, :boolean
attribute :enabled, :boolean
attribute :applies_to
attribute :auto_action_type, :boolean
validates :id, presence: true
validates :name, presence: true

View File

@ -5679,6 +5679,8 @@ en:
non_deletable: "You cannot delete this flag because it is a system flag or has already been used in the review system, however you can still disable it."
require_message: "Prompt users to provide additional reasons"
require_message_description: "When this flag is selected, a text field will be displayed for the user to provide additional detail about why they are flagging the content"
auto_action_type: "Auto action type"
auto_action_type_description: "When a post is flagged by a staff member it is automatically hidden"
more_options:
title: "More options"
move_up: "Move up"

View File

@ -368,6 +368,9 @@
},
"position": {
"type": "integer"
},
"auto_action_type": {
"type": "boolean"
}
},
"required": [
@ -380,7 +383,8 @@
"require_message",
"enabled",
"applies_to",
"is_used"
"is_used",
"auto_action_type"
]
}
},
@ -423,6 +427,9 @@
},
"position": {
"type": "integer"
},
"auto_action_type": {
"type": "boolean"
}
},
"required": [
@ -435,7 +442,8 @@
"require_message",
"enabled",
"applies_to",
"is_used"
"is_used",
"auto_action_type"
]
}
},

View File

@ -14,13 +14,16 @@ RSpec.describe(Flags::CreateFlag) do
fab!(:current_user) { Fabricate(:admin) }
let(:params) { { name:, description:, applies_to:, require_message:, enabled: } }
let(:params) do
{ name:, description:, applies_to:, require_message:, enabled:, auto_action_type: }
end
let(:dependencies) { { guardian: current_user.guardian } }
let(:name) { "custom flag name" }
let(:description) { "custom flag description" }
let(:applies_to) { ["Topic"] }
let(:enabled) { true }
let(:require_message) { true }
let(:auto_action_type) { true }
context "when user is not allowed to perform the action" do
fab!(:current_user) { Fabricate(:user) }
@ -62,6 +65,7 @@ RSpec.describe(Flags::CreateFlag) do
require_message: true,
enabled: true,
notify_type: true,
auto_action_type: true,
)
end

View File

@ -16,7 +16,17 @@ RSpec.describe(Flags::UpdateFlag) do
fab!(:current_user) { Fabricate(:admin) }
let(:flag) { Fabricate(:flag) }
let(:params) { { id: flag_id, name:, description:, applies_to:, require_message:, enabled: } }
let(:params) do
{
id: flag_id,
name:,
description:,
applies_to:,
require_message:,
enabled:,
auto_action_type:,
}
end
let(:dependencies) { { guardian: current_user.guardian } }
let(:flag_id) { flag.id }
let(:name) { "edited custom flag name" }
@ -24,6 +34,7 @@ RSpec.describe(Flags::UpdateFlag) do
let(:applies_to) { ["Topic"] }
let(:require_message) { true }
let(:enabled) { false }
let(:auto_action_type) { true }
context "when contract is invalid" do
let(:name) { nil }
@ -72,6 +83,7 @@ RSpec.describe(Flags::UpdateFlag) do
applies_to: ["Topic"],
require_message: true,
enabled: false,
auto_action_type: true,
)
end