trypost/app/Http/Requests/App/Invite/StoreWorkspaceInviteRequest.php
Paulo Castellano 6c47bac1b8 fix(members): preserve invited role on accept and surface viewer in role menu
AcceptInviteController attached invited users with a hardcoded member role,
ignoring the invite's role entirely (a viewer invite joined as member). Use the
invite's role on accept, require role on invite creation (no silent default),
and drop the role from the request/CreateInvite defaults. Add the Viewer option
to the member role dropdown (now iterates all roles), hide the dropdown on the
current user's own row, and require the member's email to confirm removal.
Covered by tests asserting the accepted role matches the invited role for
viewer/admin/member, plus invite role validation.
2026-06-22 14:24:19 -03:00

48 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Http\Requests\App\Invite;
use App\Enums\UserWorkspace\Role as WorkspaceRole;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class StoreWorkspaceInviteRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'email' => ['required', 'email', 'max:255'],
'role' => ['required', Rule::in(array_column(WorkspaceRole::cases(), 'value'))],
];
}
/**
* Get custom messages for validation errors.
*
* @return array<string, string>
*/
public function messages(): array
{
return [
'email.required' => __('validation.required', ['attribute' => 'email']),
'email.email' => __('validation.email', ['attribute' => 'email']),
'email.max' => __('validation.max.string', ['attribute' => 'email', 'max' => 255]),
];
}
}