/api/v1/projects, /members and /services: create, list, show, update, delete and restore, with the panel's own rules — so the MCP server can load the collective's work, people and offer without anyone retyping them into forms. The MCP server picks the tools up from openapi.yaml. - Relations travel as ids and are replaced whole when sent, left alone when not: a project's technology_ids, service_ids and members with each one's role; a member's technology_ids; a service's technology_ids and project_ids. Record and relations are saved in one transaction. - Publishing stays a permission of its own. Without projects.publish or services.publish, published_at, unpublish_at and is_published are refused — the fields the panel disables for the same people. - MemberPolicy still lets someone edit their own profile. - Uploads accept `for: projects` and `for: members`, landing where the panel's own upload fields put them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
67 lines
2.3 KiB
PHP
67 lines
2.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Requests\Api\V1;
|
|
|
|
use App\Models\Member;
|
|
use App\Rules\Translatable;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
/**
|
|
* The panel's member form, as rules. A name is a person's, the same in every
|
|
* language, and so is the slug built from it; only the headline and the bio
|
|
* are translatable.
|
|
*
|
|
* `links` is a label → URL map (`{"github": "https://…"}`). `technology_ids`
|
|
* is replaced whole when sent. Which projects someone is on is set from the
|
|
* project, where the role belongs.
|
|
*/
|
|
class MemberRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
$member = $this->route('member');
|
|
$creating = ! $member instanceof Member;
|
|
$sometimes = $creating ? 'required' : 'sometimes';
|
|
|
|
return [
|
|
'name' => [$sometimes, 'string', 'max:255'],
|
|
'slug' => [
|
|
$sometimes,
|
|
'string',
|
|
'max:255',
|
|
'alpha_dash:ascii',
|
|
Rule::unique('members', 'slug')->ignore($member?->id),
|
|
],
|
|
'headline' => ['sometimes', 'nullable', new Translatable(max: 255)],
|
|
'bio' => ['sometimes', 'nullable', new Translatable],
|
|
|
|
'avatar' => ['sometimes', 'nullable', 'string', 'max:2048'],
|
|
// Never shown on the site; the panel keeps it for the collective.
|
|
'email' => ['sometimes', 'nullable', 'email', 'max:255'],
|
|
'github_username' => ['sometimes', 'nullable', 'string', 'max:120'],
|
|
'links' => ['sometimes', 'nullable', 'array', 'max:10'],
|
|
'links.*' => ['nullable', 'url', 'max:2048'],
|
|
|
|
'is_public' => ['sometimes', 'boolean'],
|
|
'is_founder' => ['sometimes', 'boolean'],
|
|
'joined_at' => ['sometimes', 'nullable', 'date'],
|
|
'left_at' => ['sometimes', 'nullable', 'date', 'after_or_equal:joined_at'],
|
|
'position' => ['sometimes', 'integer', 'min:0'],
|
|
|
|
'technology_ids' => ['sometimes', 'array'],
|
|
'technology_ids.*' => ['integer', 'distinct', Rule::exists('technologies', 'id')],
|
|
];
|
|
}
|
|
}
|