Stricter validation for uuid and integer

This commit is contained in:
Constantin Graf
2024-10-15 10:59:53 +02:00
committed by Constantin Graf
parent 2b1da883fb
commit 69d3ff4f7b
31 changed files with 187 additions and 122 deletions

View File

@@ -45,11 +45,10 @@ class TimeEntryAggregateRequest extends FormRequest
// Filter by member ID
'member_id' => [
'string',
'uuid',
new ExistsEloquent(Member::class, null, function (Builder $builder): Builder {
ExistsEloquent::make(Member::class, null, function (Builder $builder): Builder {
/** @var Builder<Member> $builder */
return $builder->whereBelongsTo($this->organization, 'organization');
}),
})->uuid(),
],
// Filter by multiple member IDs, member IDs are OR combined, but AND combined with the member_id parameter
'member_ids' => [
@@ -58,21 +57,19 @@ class TimeEntryAggregateRequest extends FormRequest
],
'member_ids.*' => [
'string',
'uuid',
new ExistsEloquent(Member::class, null, function (Builder $builder): Builder {
ExistsEloquent::make(Member::class, null, function (Builder $builder): Builder {
/** @var Builder<Member> $builder */
return $builder->whereBelongsTo($this->organization, 'organization');
}),
})->uuid(),
],
// Filter by user ID
'user_id' => [
'string',
'uuid',
new ExistsEloquent(User::class, null, function (Builder $builder): Builder {
ExistsEloquent::make(User::class, null, function (Builder $builder): Builder {
/** @var Builder<User> $builder */
return $builder->belongsToOrganization($this->organization);
}),
})->uuid(),
],
// Filter by project IDs, project IDs are OR combined
'project_ids' => [
@@ -81,11 +78,10 @@ class TimeEntryAggregateRequest extends FormRequest
],
'project_ids.*' => [
'string',
'uuid',
new ExistsEloquent(Project::class, null, function (Builder $builder): Builder {
ExistsEloquent::make(Project::class, null, function (Builder $builder): Builder {
/** @var Builder<Project> $builder */
return $builder->whereBelongsTo($this->organization, 'organization');
}),
})->uuid(),
],
// Filter by client IDs, client IDs are OR combined
'client_ids' => [
@@ -94,11 +90,10 @@ class TimeEntryAggregateRequest extends FormRequest
],
'client_ids.*' => [
'string',
'uuid',
new ExistsEloquent(Client::class, null, function (Builder $builder): Builder {
ExistsEloquent::make(Client::class, null, function (Builder $builder): Builder {
/** @var Builder<Client> $builder */
return $builder->whereBelongsTo($this->organization, 'organization');
}),
})->uuid(),
],
// Filter by tag IDs, tag IDs are AND combined
'tag_ids' => [
@@ -107,11 +102,10 @@ class TimeEntryAggregateRequest extends FormRequest
],
'tag_ids.*' => [
'string',
'uuid',
new ExistsEloquent(Tag::class, null, function (Builder $builder): Builder {
ExistsEloquent::make(Tag::class, null, function (Builder $builder): Builder {
/** @var Builder<Tag> $builder */
return $builder->whereBelongsTo($this->organization, 'organization');
}),
})->uuid(),
],
// Filter by task IDs, task IDs are OR combined
'task_ids' => [
@@ -120,10 +114,9 @@ class TimeEntryAggregateRequest extends FormRequest
],
'task_ids.*' => [
'string',
'uuid',
new ExistsEloquent(Task::class, null, function (Builder $builder): Builder {
ExistsEloquent::make(Task::class, null, function (Builder $builder): Builder {
return $builder->whereBelongsTo($this->organization, 'organization');
}),
})->uuid(),
],
// Filter only time entries that have a start date after the given timestamp in UTC (example: 2021-01-01T00:00:00Z)
'start' => [

View File

@@ -31,11 +31,10 @@ class TimeEntryIndexRequest extends FormRequest
// Filter by member ID
'member_id' => [
'string',
'uuid',
new ExistsEloquent(Member::class, null, function (Builder $builder): Builder {
ExistsEloquent::make(Member::class, null, function (Builder $builder): Builder {
/** @var Builder<Member> $builder */
return $builder->whereBelongsTo($this->organization, 'organization');
}),
})->uuid(),
],
// Filter by multiple member IDs, member IDs are OR combined, but AND combined with the member_id parameter
'member_ids' => [
@@ -44,11 +43,10 @@ class TimeEntryIndexRequest extends FormRequest
],
'member_ids.*' => [
'string',
'uuid',
new ExistsEloquent(Member::class, null, function (Builder $builder): Builder {
ExistsEloquent::make(Member::class, null, function (Builder $builder): Builder {
/** @var Builder<Member> $builder */
return $builder->whereBelongsTo($this->organization, 'organization');
}),
})->uuid(),
],
// Filter by client IDs, client IDs are OR combined
'client_ids' => [
@@ -57,11 +55,10 @@ class TimeEntryIndexRequest extends FormRequest
],
'client_ids.*' => [
'string',
'uuid',
new ExistsEloquent(Client::class, null, function (Builder $builder): Builder {
ExistsEloquent::make(Client::class, null, function (Builder $builder): Builder {
/** @var Builder<Client> $builder */
return $builder->whereBelongsTo($this->organization, 'organization');
}),
})->uuid(),
],
// Filter by project IDs, project IDs are OR combined
'project_ids' => [
@@ -70,11 +67,10 @@ class TimeEntryIndexRequest extends FormRequest
],
'project_ids.*' => [
'string',
'uuid',
new ExistsEloquent(Project::class, null, function (Builder $builder): Builder {
ExistsEloquent::make(Project::class, null, function (Builder $builder): Builder {
/** @var Builder<Project> $builder */
return $builder->whereBelongsTo($this->organization, 'organization');
}),
})->uuid(),
],
// Filter by tag IDs, tag IDs are AND combined
'tag_ids' => [
@@ -83,11 +79,10 @@ class TimeEntryIndexRequest extends FormRequest
],
'tag_ids.*' => [
'string',
'uuid',
new ExistsEloquent(Tag::class, null, function (Builder $builder): Builder {
ExistsEloquent::make(Tag::class, null, function (Builder $builder): Builder {
/** @var Builder<Tag> $builder */
return $builder->whereBelongsTo($this->organization, 'organization');
}),
})->uuid(),
],
// Filter by task IDs, task IDs are OR combined
'task_ids' => [
@@ -96,11 +91,10 @@ class TimeEntryIndexRequest extends FormRequest
],
'task_ids.*' => [
'string',
'uuid',
new ExistsEloquent(Task::class, null, function (Builder $builder): Builder {
ExistsEloquent::make(Task::class, null, function (Builder $builder): Builder {
/** @var Builder<Task> $builder */
return $builder->whereBelongsTo($this->organization, 'organization');
}),
})->uuid(),
],
// Filter only time entries that have a start date after the given timestamp in UTC (example: 2021-01-01T00:00:00Z)
'start' => [
@@ -135,6 +129,7 @@ class TimeEntryIndexRequest extends FormRequest
'offset' => [
'integer',
'min:0',
'max:2147483647',
],
// Filter makes sure that only time entries of a whole date are returned
'only_full_dates' => [

View File

@@ -31,36 +31,33 @@ class TimeEntryStoreRequest extends FormRequest
'member_id' => [
'required',
'string',
'uuid',
new ExistsEloquent(Member::class, null, function (Builder $builder): Builder {
ExistsEloquent::make(Member::class, null, function (Builder $builder): Builder {
/** @var Builder<Member> $builder */
return $builder->whereBelongsTo($this->organization, 'organization');
}),
})->uuid(),
],
'project_id' => [
'nullable',
'string',
'uuid',
'required_with:task_id',
new ExistsEloquent(Project::class, null, function (Builder $builder): Builder {
ExistsEloquent::make(Project::class, null, function (Builder $builder): Builder {
/** @var Builder<Project> $builder */
return $builder->whereBelongsTo($this->organization, 'organization');
}),
})->uuid(),
],
// ID of the task that the time entry should belong to
'task_id' => [
'nullable',
'string',
'uuid',
new ExistsEloquent(Task::class, null, function (Builder $builder): Builder {
ExistsEloquent::make(Task::class, null, function (Builder $builder): Builder {
/** @var Builder<Task> $builder */
return $builder->whereBelongsTo($this->organization, 'organization');
}),
(new ExistsEloquent(Task::class, null, function (Builder $builder): Builder {
})->uuid(),
ExistsEloquent::make(Task::class, null, function (Builder $builder): Builder {
/** @var Builder<Task> $builder */
return $builder->whereBelongsTo($this->organization, 'organization')
->where('project_id', $this->input('project_id'));
}))->withMessage(__('validation.task_belongs_to_project')),
})->uuid()->withMessage(__('validation.task_belongs_to_project')),
],
// Start of time entry (ISO 8601 format, UTC timezone)
'start' => [
@@ -90,12 +87,10 @@ class TimeEntryStoreRequest extends FormRequest
'array',
],
'tags.*' => [
'string',
'uuid',
new ExistsEloquent(Tag::class, null, function (Builder $builder): Builder {
ExistsEloquent::make(Tag::class, null, function (Builder $builder): Builder {
/** @var Builder<Tag> $builder */
return $builder->whereBelongsTo($this->organization, 'organization');
}),
})->uuid(),
],
];
}

View File

@@ -42,37 +42,34 @@ class TimeEntryUpdateMultipleRequest extends FormRequest
// ID of the organization member that the time entry should belong to
'changes.member_id' => [
'string',
'uuid',
new ExistsEloquent(Member::class, null, function (Builder $builder): Builder {
ExistsEloquent::make(Member::class, null, function (Builder $builder): Builder {
/** @var Builder<Member> $builder */
return $builder->whereBelongsTo($this->organization, 'organization');
}),
})->uuid(),
],
// ID of the project that the time entry should belong to
'changes.project_id' => [
'nullable',
'string',
'uuid',
'required_with:task_id',
new ExistsEloquent(Project::class, null, function (Builder $builder): Builder {
ExistsEloquent::make(Project::class, null, function (Builder $builder): Builder {
/** @var Builder<Project> $builder */
return $builder->whereBelongsTo($this->organization, 'organization');
}),
})->uuid(),
],
// ID of the task that the time entry should belong to
'changes.task_id' => [
'nullable',
'string',
'uuid',
new ExistsEloquent(Task::class, null, function (Builder $builder): Builder {
ExistsEloquent::make(Task::class, null, function (Builder $builder): Builder {
/** @var Builder<Task> $builder */
return $builder->whereBelongsTo($this->organization, 'organization');
}),
(new ExistsEloquent(Task::class, null, function (Builder $builder): Builder {
})->uuid(),
ExistsEloquent::make(Task::class, null, function (Builder $builder): Builder {
/** @var Builder<Task> $builder */
return $builder->whereBelongsTo($this->organization, 'organization')
->where('project_id', $this->input('changes.project_id'));
}))->withMessage(__('validation.task_belongs_to_project')),
})->uuid()->withMessage(__('validation.task_belongs_to_project')),
],
// Whether time entry is billable
'changes.billable' => [
@@ -91,11 +88,10 @@ class TimeEntryUpdateMultipleRequest extends FormRequest
],
'changes.tags.*' => [
'string',
'uuid',
new ExistsEloquent(Tag::class, null, function (Builder $builder): Builder {
ExistsEloquent::make(Tag::class, null, function (Builder $builder): Builder {
/** @var Builder<Tag> $builder */
return $builder->whereBelongsTo($this->organization, 'organization');
}),
})->uuid(),
],
];
}

View File

@@ -30,37 +30,34 @@ class TimeEntryUpdateRequest extends FormRequest
// ID of the organization member that the time entry should belong to
'member_id' => [
'string',
'uuid',
new ExistsEloquent(Member::class, null, function (Builder $builder): Builder {
ExistsEloquent::make(Member::class, null, function (Builder $builder): Builder {
/** @var Builder<Member> $builder */
return $builder->whereBelongsTo($this->organization, 'organization');
}),
})->uuid(),
],
// ID of the project that the time entry should belong to
'project_id' => [
'nullable',
'string',
'uuid',
'required_with:task_id',
new ExistsEloquent(Project::class, null, function (Builder $builder): Builder {
ExistsEloquent::make(Project::class, null, function (Builder $builder): Builder {
/** @var Builder<Project> $builder */
return $builder->whereBelongsTo($this->organization, 'organization');
}),
})->uuid(),
],
// ID of the task that the time entry should belong to
'task_id' => [
'nullable',
'string',
'uuid',
new ExistsEloquent(Task::class, null, function (Builder $builder): Builder {
ExistsEloquent::make(Task::class, null, function (Builder $builder): Builder {
/** @var Builder<Task> $builder */
return $builder->whereBelongsTo($this->organization, 'organization');
}),
(new ExistsEloquent(Task::class, null, function (Builder $builder): Builder {
})->uuid(),
ExistsEloquent::make(Task::class, null, function (Builder $builder): Builder {
/** @var Builder<Task> $builder */
return $builder->whereBelongsTo($this->organization, 'organization')
->where('project_id', $this->input('project_id'));
}))->withMessage(__('validation.task_belongs_to_project')),
})->uuid()->withMessage(__('validation.task_belongs_to_project')),
],
// Start of time entry (ISO 8601 format, UTC timezone)
'start' => [
@@ -89,11 +86,10 @@ class TimeEntryUpdateRequest extends FormRequest
],
'tags.*' => [
'string',
'uuid',
new ExistsEloquent(Tag::class, null, function (Builder $builder): Builder {
ExistsEloquent::make(Tag::class, null, function (Builder $builder): Builder {
/** @var Builder<Tag> $builder */
return $builder->whereBelongsTo($this->organization, 'organization');
}),
})->uuid(),
],
];
}