Add Discord allowed mentions configuration

This commit is contained in:
2026-04-24 17:01:34 +00:00
parent 9958db10b9
commit 55db0ac642
6 changed files with 300 additions and 1 deletions
@@ -106,6 +106,44 @@ class DeliverNotificationActionTest extends TestCase
$this->assertNotNull($deliveryLog->delivered_at);
}
/**
* Ensure Discord deliveries include configured allowed mention parse values.
*/
public function test_discord_delivery_includes_configured_allowed_mentions(): void
{
Http::preventStrayRequests();
Http::fake([
'https://discord.com/api/webhooks/123456/discord-alerts' => Http::response('', 204),
]);
$notificationAction = NotificationAction::factory()->discord()->create([
'delivery_url' => 'https://discord.com/api/webhooks/123456/discord-alerts',
'channel_configuration' => [
'allowed_mentions' => ['users', 'roles', 'users', 'EVERYONE', 'invalid'],
],
'message_template' => '$ticket_key moved to $status_to',
]);
$deliveryLog = $this->createPendingDeliveryLog($notificationAction);
(new DeliverNotificationAction(
notificationActionId: $notificationAction->id,
payload: $this->payload(),
notificationDeliveryLogId: $deliveryLog->id,
))->handle();
Http::assertSentCount(1);
Http::assertSent(function (Request $request): bool {
return $request->method() === 'POST'
&& $request->url() === 'https://discord.com/api/webhooks/123456/discord-alerts'
&& $request->data() === [
'content' => 'CORE-42 moved to Doing',
'allowed_mentions' => [
'parse' => ['users', 'roles', 'everyone'],
],
];
});
}
/**
* Ensure retryable webhook responses release the job and update the delivery log.
*/
@@ -29,6 +29,9 @@ class ProjectNotificationSettingsControllerTest extends TestCase
->for($project)
->create([
'name' => 'Discord alerts',
'channel_configuration' => [
'allowed_mentions' => ['users', 'roles'],
],
]);
$this->syncProjectPermissions($project, $user, ['edit']);
@@ -41,6 +44,8 @@ class ProjectNotificationSettingsControllerTest extends TestCase
->where('project.id', $project->id)
->where('notificationActions.0.name', 'Discord alerts')
->where('notificationActions.0.channel', NotificationChannel::Discord->value)
->where('notificationActions.0.channel_configuration.allowed_mentions.0', 'users')
->where('notificationActions.0.channel_configuration.allowed_mentions.1', 'roles')
->where('notificationActions.0.event_type', NotificationEventType::TicketStatusChanged->value)
->where('notificationActions.0.enabled', true)
->where('notificationActions.0.has_delivery_url', true)
@@ -83,6 +88,9 @@ class ProjectNotificationSettingsControllerTest extends TestCase
'name' => 'Discord alerts',
'event_type' => NotificationEventType::TicketStatusChanged->value,
'channel' => NotificationChannel::Discord->value,
'channel_configuration' => [
'allowed_mentions' => ['users', 'roles'],
],
'enabled' => '1',
'delivery_url' => 'https://discord.com/api/webhooks/123456/discord-alerts',
'message_template' => '$ticket_key moved from $status_from to $status_to by $actor_name: $url',
@@ -95,6 +103,10 @@ class ProjectNotificationSettingsControllerTest extends TestCase
$this->assertSame($project->id, $notificationAction->project_id);
$this->assertSame(NotificationChannel::Discord, $notificationAction->channel);
$this->assertSame(NotificationEventType::TicketStatusChanged, $notificationAction->event_type);
$this->assertSame(
['allowed_mentions' => ['users', 'roles']],
$notificationAction->channel_configuration,
);
$this->assertTrue($notificationAction->enabled);
$this->assertSame(
'https://discord.com/api/webhooks/123456/discord-alerts',
@@ -124,6 +136,9 @@ class ProjectNotificationSettingsControllerTest extends TestCase
'name' => 'Ops escalation alerts',
'event_type' => NotificationEventType::TicketStatusChanged->value,
'channel' => NotificationChannel::Discord->value,
'channel_configuration' => [
'allowed_mentions' => ['users', 'everyone'],
],
'enabled' => '1',
'delivery_url' => '',
'message_template' => '$ticket_key moved to $status_to: $url',
@@ -138,6 +153,10 @@ class ProjectNotificationSettingsControllerTest extends TestCase
'https://discord.com/api/webhooks/123456/original-secret',
$notificationAction->delivery_url,
);
$this->assertSame(
['allowed_mentions' => ['users', 'everyone']],
$notificationAction->channel_configuration,
);
$this->assertSame('$ticket_key moved to $status_to: $url', $notificationAction->message_template);
}
@@ -257,6 +276,9 @@ class ProjectNotificationSettingsControllerTest extends TestCase
'channel' => NotificationChannel::Discord->value,
'enabled' => 'definitely-not-a-boolean',
'delivery_url' => 'not-a-url',
'channel_configuration' => [
'allowed_mentions' => ['not-valid'],
],
'message_template' => '',
])
->assertRedirect(route('projects.settings.notifications', $project))
@@ -265,6 +287,7 @@ class ProjectNotificationSettingsControllerTest extends TestCase
'event_type',
'enabled',
'delivery_url',
'channel_configuration.allowed_mentions.0',
'message_template',
]);
}