2022-06-25 14:24:14 +02:00
|
|
|
<?php
|
2023-09-20 06:36:43 +02:00
|
|
|
|
2022-06-25 14:24:14 +02:00
|
|
|
/*
|
2023-09-20 06:17:56 +02:00
|
|
|
* StoreRequest.php
|
|
|
|
* Copyright (c) 2023 james@firefly-iii.org
|
2022-06-25 14:24:14 +02:00
|
|
|
*
|
|
|
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2023-09-20 06:36:43 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2023-09-20 06:17:56 +02:00
|
|
|
namespace FireflyIII\Api\V2\Request\UserGroup;
|
2022-10-16 19:22:26 +02:00
|
|
|
|
2023-09-21 11:29:09 +02:00
|
|
|
use FireflyIII\Enums\UserRoleEnum;
|
2023-09-20 06:17:56 +02:00
|
|
|
use FireflyIII\Support\Request\ChecksLogin;
|
|
|
|
use FireflyIII\Support\Request\ConvertsDataTypes;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
2022-06-25 14:24:14 +02:00
|
|
|
|
2023-09-20 06:36:43 +02:00
|
|
|
/**
|
|
|
|
* Class StoreRequest
|
|
|
|
*/
|
2023-09-20 06:17:56 +02:00
|
|
|
class StoreRequest extends FormRequest
|
2022-06-25 14:24:14 +02:00
|
|
|
{
|
2023-09-20 06:17:56 +02:00
|
|
|
use ChecksLogin;
|
|
|
|
use ConvertsDataTypes;
|
2023-10-28 15:03:33 +02:00
|
|
|
|
2023-09-21 11:32:56 +02:00
|
|
|
protected array $acceptedRoles = [UserRoleEnum::OWNER, UserRoleEnum::FULL];
|
2023-09-20 06:17:56 +02:00
|
|
|
|
|
|
|
public function getAll(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'title' => $this->convertString('title'),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function rules(): array
|
|
|
|
{
|
2024-11-23 19:19:46 +01:00
|
|
|
$roles = [];
|
|
|
|
foreach (UserRoleEnum::cases() as $role) {
|
2024-11-23 16:14:47 +01:00
|
|
|
$roles[] = $role->value;
|
|
|
|
}
|
|
|
|
$string = implode(',', $roles);
|
|
|
|
|
2023-09-20 06:17:56 +02:00
|
|
|
return [
|
2024-11-23 16:14:47 +01:00
|
|
|
'title' => 'unique:user_groups,title|required|min:1|max:255',
|
|
|
|
'members' => 'required|min:1',
|
|
|
|
'members.*.user_email' => 'email|missing_with:members.*.user_id',
|
2024-11-23 19:19:46 +01:00
|
|
|
'members.*.user_id' => 'integer|exists:users,id|missing_with:members.*.user_email',
|
|
|
|
'members.*.roles' => 'required|array|min:1',
|
|
|
|
'members.*.roles.*' => sprintf('required|in:%s', $string),
|
2023-09-20 06:17:56 +02:00
|
|
|
];
|
|
|
|
}
|
2022-07-16 09:25:10 +02:00
|
|
|
}
|