Skip to content

Commit

Permalink
Stricter validation for uuid and integer
Browse files Browse the repository at this point in the history
  • Loading branch information
korridor committed Oct 15, 2024
1 parent 2b1da88 commit 62018ea
Show file tree
Hide file tree
Showing 31 changed files with 187 additions and 122 deletions.
2 changes: 1 addition & 1 deletion app/Actions/Fortify/CreateNewUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function create(array $input): User
'string',
'email',
'max:255',
new UniqueEloquent(User::class, 'email', function (Builder $builder): Builder {
UniqueEloquent::make(User::class, 'email', function (Builder $builder): Builder {
/** @var Builder<User> $builder */
return $builder->where('is_placeholder', '=', false);
}),
Expand Down
2 changes: 1 addition & 1 deletion app/Actions/Fortify/UpdateUserProfileInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function update(User $user, array $input): void
'required',
'email',
'max:255',
(new UniqueEloquent(User::class, 'email'))->ignore($user->id)->query(function (Builder $query) {
UniqueEloquent::make(User::class, 'email')->ignore($user->id)->query(function (Builder $query) {
/** @var Builder<User> $query */
return $query->where('is_placeholder', '=', false);
}),
Expand Down
4 changes: 2 additions & 2 deletions app/Actions/Jetstream/AddOrganizationMember.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ protected function rules(): array
'email' => [
'required',
'email',
(new ExistsEloquent(User::class, 'email', function (Builder $builder) {
ExistsEloquent::make(User::class, 'email', function (Builder $builder) {
/** @var Builder<User> $builder */
return $builder->where('is_placeholder', '=', false);
}))->withMessage(__('We were unable to find a registered user with this email address.')),
})->withMessage(__('We were unable to find a registered user with this email address.')),
],
'role' => [
'required',
Expand Down
1 change: 1 addition & 0 deletions app/Filament/Resources/OrganizationResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public static function form(Form $form): Form
'nullable',
'integer',
'gt:0',
'max:2147483647',
])
->numeric(),
Forms\Components\DateTimePicker::make('created_at')
Expand Down
1 change: 1 addition & 0 deletions app/Filament/Resources/ProjectMemberResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public static function form(Form $form): Form
'nullable',
'integer',
'gt:0',
'max:2147483647',
])
->numeric(),
Forms\Components\Select::make('user_id')
Expand Down
1 change: 1 addition & 0 deletions app/Filament/Resources/ProjectResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public static function form(Form $form): Form
'nullable',
'integer',
'gt:0',
'max:2147483647',
])
->numeric(),
Forms\Components\Select::make('organization_id')
Expand Down
1 change: 1 addition & 0 deletions app/Http/Requests/V1/Client/ClientIndexRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function rules(): array
'page' => [
'integer',
'min:1',
'max:2147483647',
],
'archived' => [
'string',
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Requests/V1/Client/ClientStoreRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public function rules(): array
'string',
'min:1',
'max:255',
(new UniqueEloquent(Client::class, 'name', function (Builder $builder): Builder {
UniqueEloquent::make(Client::class, 'name', function (Builder $builder): Builder {
/** @var Builder<Client> $builder */
return $builder->whereBelongsTo($this->organization, 'organization');
}))->withCustomTranslation('validation.client_name_already_exists'),
})->withCustomTranslation('validation.client_name_already_exists'),
],
];
}
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Requests/V1/Client/ClientUpdateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ public function rules(): array
'string',
'min:1',
'max:255',
(new UniqueEloquent(Client::class, 'name', function (Builder $builder): Builder {
UniqueEloquent::make(Client::class, 'name', function (Builder $builder): Builder {
/** @var Builder<Client> $builder */
return $builder->whereBelongsTo($this->organization, 'organization');
}))->ignore($this->client?->getKey())->withCustomTranslation('validation.client_name_already_exists'),
})->ignore($this->client?->getKey())->withCustomTranslation('validation.client_name_already_exists'),
],
'is_archived' => [
'boolean',
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Requests/V1/Invitation/InvitationStoreRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public function rules(): array
'email' => [
'required',
'email',
(new UniqueEloquent(OrganizationInvitation::class, 'email', function (Builder $builder): Builder {
UniqueEloquent::make(OrganizationInvitation::class, 'email', function (Builder $builder): Builder {
/** @var Builder<OrganizationInvitation> $builder */
return $builder->whereBelongsTo($this->organization, 'organization');
}))->withCustomTranslation('validation.invitation_already_exists'),
})->withCustomTranslation('validation.invitation_already_exists'),
],
'role' => [
'required',
Expand Down
1 change: 1 addition & 0 deletions app/Http/Requests/V1/Member/MemberUpdateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function rules(): array
'nullable',
'integer',
'min:0',
'max:2147483647',
],
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function rules(): array
'nullable',
'integer',
'min:0',
'max:2147483647',
],
'employees_can_see_billable_rates' => [
'boolean',
Expand Down
1 change: 1 addition & 0 deletions app/Http/Requests/V1/Project/ProjectIndexRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function rules(): array
'page' => [
'integer',
'min:1',
'max:2147483647',
],
'archived' => [
'string',
Expand Down
10 changes: 6 additions & 4 deletions app/Http/Requests/V1/Project/ProjectStoreRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public function rules(): array
'string',
'min:1',
'max:255',
(new UniqueEloquent(Project::class, 'name', function (Builder $builder): Builder {
UniqueEloquent::make(Project::class, 'name', function (Builder $builder): Builder {
/** @var Builder<Project> $builder */
return $builder->whereBelongsTo($this->organization, 'organization');
}))->withCustomTranslation('validation.project_name_already_exists'),
})->withCustomTranslation('validation.project_name_already_exists'),
],
'color' => [
'required',
Expand All @@ -51,20 +51,22 @@ public function rules(): array
'nullable',
'integer',
'min:0',
'max:2147483647',
],
// ID of the client
'client_id' => [
'nullable',
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(),
],
// Estimated time in seconds
'estimated_time' => [
'nullable',
'integer',
'min:0',
'max:2147483647',
],
];
}
Expand Down
10 changes: 6 additions & 4 deletions app/Http/Requests/V1/Project/ProjectUpdateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public function rules(): array
'required',
'string',
'max:255',
(new UniqueEloquent(Project::class, 'name', function (Builder $builder): Builder {
UniqueEloquent::make(Project::class, 'name', function (Builder $builder): Builder {
/** @var Builder<Project> $builder */
return $builder->whereBelongsTo($this->organization, 'organization');
}))->ignore($this->project?->getKey())->withCustomTranslation('validation.project_name_already_exists'),
})->ignore($this->project?->getKey())->withCustomTranslation('validation.project_name_already_exists'),
],
'color' => [
'required',
Expand All @@ -52,21 +52,23 @@ public function rules(): array
],
'client_id' => [
'nullable',
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(),
],
'billable_rate' => [
'nullable',
'integer',
'min:0',
'max:2147483647',
],
// Estimated time in seconds
'estimated_time' => [
'nullable',
'integer',
'min:0',
'max:2147483647',
],
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ public function rules(): array
return [
'member_id' => [
'required',
'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(),
],
'billable_rate' => [
'nullable',
'integer',
'min:0',
'max:2147483647',
],
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function rules(): array
'nullable',
'integer',
'min:0',
'max:2147483647',
],
];
}
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Requests/V1/Tag/TagStoreRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public function rules(): array
'string',
'min:1',
'max:255',
(new UniqueEloquent(Tag::class, 'name', function (Builder $builder): Builder {
UniqueEloquent::make(Tag::class, 'name', function (Builder $builder): Builder {
/** @var Builder<Tag> $builder */
return $builder->whereBelongsTo($this->organization, 'organization');
}))->withCustomTranslation('validation.tag_name_already_exists'),
})->withCustomTranslation('validation.tag_name_already_exists'),
],
];
}
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Requests/V1/Tag/TagUpdateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public function rules(): array
'string',
'min:1',
'max:255',
(new UniqueEloquent(Tag::class, 'name', function (Builder $builder): Builder {
UniqueEloquent::make(Tag::class, 'name', function (Builder $builder): Builder {
/** @var Builder<Tag> $builder */
return $builder->whereBelongsTo($this->organization, 'organization');
}))->ignore($this->tag?->getKey())->withCustomTranslation('validation.tag_name_already_exists'),
})->ignore($this->tag?->getKey())->withCustomTranslation('validation.tag_name_already_exists'),
],
];
}
Expand Down
5 changes: 2 additions & 3 deletions app/Http/Requests/V1/Task/TaskIndexRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public function rules(): array
{
return [
'project_id' => [
'uuid',
new ExistsEloquent(Project::class, null, function (Builder $builder): Builder {
ExistsEloquent::make(Project::class, null, function (Builder $builder): Builder {
/** @var Builder<Project> $builder */
$builder = $builder->whereBelongsTo($this->organization, 'organization');

Expand All @@ -37,7 +36,7 @@ public function rules(): array
}

return $builder;
}),
})->uuid(),
],
'done' => [
'string',
Expand Down
9 changes: 5 additions & 4 deletions app/Http/Requests/V1/Task/TaskStoreRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,24 @@ public function rules(): array
'string',
'min:1',
'max:255',
(new UniqueEloquent(Task::class, 'name', function (Builder $builder): Builder {
UniqueEloquent::make(Task::class, 'name', function (Builder $builder): Builder {
/** @var Builder<Task> $builder */
return $builder->where('project_id', '=', $this->input('project_id'));
}))->withCustomTranslation('validation.task_name_already_exists'),
})->withCustomTranslation('validation.task_name_already_exists'),
],
'project_id' => [
'required',
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(),
],
// Estimated time in seconds
'estimated_time' => [
'nullable',
'integer',
'min:0',
'max:2147483647',
],
];
}
Expand Down
5 changes: 3 additions & 2 deletions app/Http/Requests/V1/Task/TaskUpdateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public function rules(): array
'string',
'min:1',
'max:255',
(new UniqueEloquent(Task::class, 'name', function (Builder $builder): Builder {
UniqueEloquent::make(Task::class, 'name', function (Builder $builder): Builder {
/** @var Builder<Task> $builder */
return $builder->where('project_id', '=', $this->task->project_id);
}))->ignore($this->task?->getKey())->withCustomTranslation('validation.task_name_already_exists'),
})->ignore($this->task?->getKey())->withCustomTranslation('validation.task_name_already_exists'),
],
'is_done' => [
'boolean',
Expand All @@ -43,6 +43,7 @@ public function rules(): array
'nullable',
'integer',
'min:0',
'max:2147483647',
],
];
}
Expand Down
Loading

0 comments on commit 62018ea

Please sign in to comment.