replaced allowed mentions with enum
linter / quality (pull_request) Successful in 1m20s
tests / ci (8.4) (pull_request) Failing after 1m31s

This commit is contained in:
2026-04-25 18:55:05 +02:00
parent 55db0ac642
commit e66b798429
9 changed files with 131 additions and 189 deletions
@@ -2,6 +2,7 @@
namespace App\Http\Requests;
use App\Enums\DiscordAllowedMentionType;
use App\Enums\NotificationChannel;
use App\Enums\NotificationEventType;
use Illuminate\Contracts\Validation\ValidationRule;
@@ -10,11 +11,6 @@ use Illuminate\Validation\Rule;
class StoreProjectNotificationActionRequest extends FormRequest
{
/**
* @var list<string>
*/
private const array DISCORD_ALLOWED_MENTION_TYPES = ['everyone', 'roles', 'users'];
/**
* Determine if the user is authorized to make this request.
*/
@@ -32,60 +28,14 @@ class StoreProjectNotificationActionRequest extends FormRequest
{
return [
'name' => ['required', 'string', 'max:255'],
'event_type' => ['required', 'string', Rule::in($this->eventTypes())],
'channel' => ['required', 'string', Rule::in($this->channels())],
'event_type' => ['required', 'string', Rule::in(NotificationEventType::values())],
'channel' => ['required', 'string', Rule::in(NotificationChannel::values())],
'channel_configuration' => ['nullable', 'array'],
'channel_configuration.allowed_mentions' => ['nullable', 'array'],
'channel_configuration.allowed_mentions.*' => $this->allowedMentionRules(),
'channel_configuration.allowed_mentions.*' => ['nullable', 'string', Rule::in(DiscordAllowedMentionType::values())],
'enabled' => ['required', 'boolean'],
'delivery_url' => ['required', 'string', 'max:2048', 'url'],
'message_template' => $this->messageTemplateRules(),
];
}
/**
* @return array<int, string>
*/
private function channels(): array
{
return array_map(
static fn (NotificationChannel $channel): string => $channel->value,
NotificationChannel::cases(),
);
}
/**
* @return array<int, string>
*/
private function eventTypes(): array
{
return array_map(
static fn (NotificationEventType $eventType): string => $eventType->value,
NotificationEventType::cases(),
);
}
/**
* @return array<int, ValidationRule|string>
*/
private function messageTemplateRules(): array
{
if ($this->input('channel') === NotificationChannel::Discord->value) {
return ['required', 'string', 'max:2000'];
}
return ['nullable', 'string', 'max:2000'];
}
/**
* @return array<int, ValidationRule|string>
*/
private function allowedMentionRules(): array
{
return [
'nullable',
'string',
Rule::in(self::DISCORD_ALLOWED_MENTION_TYPES),
'message_template' => [Rule::requiredIf($this->input('channel') === NotificationChannel::Discord->value), 'string', 'max:2000'],
];
}
}
@@ -2,6 +2,7 @@
namespace App\Http\Requests;
use App\Enums\DiscordAllowedMentionType;
use App\Enums\NotificationChannel;
use App\Enums\NotificationEventType;
use Illuminate\Contracts\Validation\ValidationRule;
@@ -10,10 +11,6 @@ use Illuminate\Validation\Rule;
class UpdateProjectNotificationActionRequest extends FormRequest
{
/**
* @var list<string>
*/
private const array DISCORD_ALLOWED_MENTION_TYPES = ['everyone', 'roles', 'users'];
/**
* Determine if the user is authorized to make this request.
@@ -32,60 +29,14 @@ class UpdateProjectNotificationActionRequest extends FormRequest
{
return [
'name' => ['required', 'string', 'max:255'],
'event_type' => ['required', 'string', Rule::in($this->eventTypes())],
'channel' => ['required', 'string', Rule::in($this->channels())],
'event_type' => ['required', 'string', Rule::in(NotificationEventType::values())],
'channel' => ['required', 'string', Rule::in(NotificationChannel::values())],
'channel_configuration' => ['nullable', 'array'],
'channel_configuration.allowed_mentions' => ['nullable', 'array'],
'channel_configuration.allowed_mentions.*' => $this->allowedMentionRules(),
'channel_configuration.allowed_mentions.*' => ['nullable', 'string', Rule::in(DiscordAllowedMentionType::values())],
'enabled' => ['required', 'boolean'],
'delivery_url' => ['nullable', 'string', 'max:2048', 'url'],
'message_template' => $this->messageTemplateRules(),
];
}
/**
* @return array<int, string>
*/
private function channels(): array
{
return array_map(
static fn (NotificationChannel $channel): string => $channel->value,
NotificationChannel::cases(),
);
}
/**
* @return array<int, string>
*/
private function eventTypes(): array
{
return array_map(
static fn (NotificationEventType $eventType): string => $eventType->value,
NotificationEventType::cases(),
);
}
/**
* @return array<int, ValidationRule|string>
*/
private function messageTemplateRules(): array
{
if ($this->input('channel') === NotificationChannel::Discord->value) {
return ['required', 'string', 'max:2000'];
}
return ['nullable', 'string', 'max:2000'];
}
/**
* @return array<int, ValidationRule|string>
*/
private function allowedMentionRules(): array
{
return [
'nullable',
'string',
Rule::in(self::DISCORD_ALLOWED_MENTION_TYPES),
'message_template' => [Rule::requiredIf($this->input('channel') === NotificationChannel::Discord->value), 'string', 'max:2000'],
];
}
}