`taskstream: true` on POST /v1/projects also creates the project in TaskStream, public, as the caller (their Pireon token is passed on), and the answer carries `taskstream_key` and `taskstream_url`. The key is `taskstream_key` or one made from the default-language slug. The board is opened before the project is saved: if TaskStream refuses it, nothing is created here and the reason comes back as a validation error (502 when TaskStream does not answer). Machine tokens need the server's own TASKSTREAM_TOKEN. Updates ignore the flag, and duplicates do not inherit the link. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
93 lines
4.0 KiB
PHP
93 lines
4.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Requests\Api\V1;
|
|
|
|
use App\Enums\ProjectStatus;
|
|
use App\Http\Requests\Api\V1\Concerns\GuardsPublication;
|
|
use App\Models\Project;
|
|
use App\Rules\Translatable;
|
|
use App\Rules\UniqueTranslatedSlug;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
use Illuminate\Validation\Validator;
|
|
|
|
/**
|
|
* The panel's project form, as rules. On update every field is optional
|
|
* (PATCH semantics) but keeps the same shape.
|
|
*
|
|
* Relations travel as ids and are replaced whole when sent: `technology_ids`,
|
|
* `service_ids`, and `members` with each one's role on the project.
|
|
*
|
|
* `taskstream` (on creation only) opens a public board in TaskStream for the
|
|
* project, keyed `taskstream_key` or one derived from the slug.
|
|
*/
|
|
class ProjectRequest extends FormRequest
|
|
{
|
|
use GuardsPublication;
|
|
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
$project = $this->route('project');
|
|
$creating = ! $project instanceof Project;
|
|
$sometimes = $creating ? 'required' : 'sometimes';
|
|
|
|
return [
|
|
'title' => [$sometimes, new Translatable(requireDefaultLocale: $creating, max: 255)],
|
|
'slug' => [
|
|
$sometimes,
|
|
new Translatable(requireDefaultLocale: $creating, max: 255),
|
|
new UniqueTranslatedSlug(Project::class, $project?->id),
|
|
],
|
|
'tagline' => ['sometimes', 'nullable', new Translatable(max: 300)],
|
|
'description' => ['sometimes', 'nullable', new Translatable],
|
|
'decisions' => ['sometimes', 'nullable', new Translatable],
|
|
'postmortem' => ['sometimes', 'nullable', new Translatable],
|
|
'meta_title' => ['sometimes', 'nullable', new Translatable(max: 60)],
|
|
'meta_description' => ['sometimes', 'nullable', new Translatable(max: 160)],
|
|
|
|
'status' => ['sometimes', Rule::enum(ProjectStatus::class)],
|
|
'is_featured' => ['sometimes', 'boolean'],
|
|
'needs_help' => ['sometimes', 'boolean'],
|
|
'demo_url' => ['sometimes', 'nullable', 'url', 'max:2048'],
|
|
'cover_image' => ['sometimes', 'nullable', 'string', 'max:2048'],
|
|
'cover_image_alt' => ['sometimes', 'nullable', new Translatable(max: 255)],
|
|
'started_at' => ['sometimes', 'nullable', 'date'],
|
|
'ended_at' => ['sometimes', 'nullable', 'date', 'after_or_equal:started_at'],
|
|
'published_at' => ['sometimes', 'nullable', 'date'],
|
|
'unpublish_at' => ['sometimes', 'nullable', 'date', 'after:published_at'],
|
|
'position' => ['sometimes', 'integer', 'min:0'],
|
|
|
|
'client_id' => ['sometimes', 'nullable', 'integer', Rule::exists('clients', 'id')->whereNull('deleted_at')],
|
|
'lead_member_id' => ['sometimes', 'nullable', 'integer', Rule::exists('members', 'id')->whereNull('deleted_at')],
|
|
|
|
'technology_ids' => ['sometimes', 'array'],
|
|
'technology_ids.*' => ['integer', 'distinct', Rule::exists('technologies', 'id')],
|
|
'service_ids' => ['sometimes', 'array'],
|
|
'service_ids.*' => ['integer', 'distinct', Rule::exists('services', 'id')->whereNull('deleted_at')],
|
|
'members' => ['sometimes', 'array'],
|
|
'members.*.id' => ['required', 'integer', 'distinct', Rule::exists('members', 'id')->whereNull('deleted_at')],
|
|
'members.*.role' => ['nullable', 'string', 'max:120'],
|
|
|
|
// Only when creating; a client PATCHing back what it read sends
|
|
// the key it got, which is ignored rather than refused.
|
|
'taskstream' => [$creating ? 'sometimes' : 'exclude', 'boolean'],
|
|
'taskstream_key' => [$creating ? 'sometimes' : 'exclude', 'nullable', 'string', 'regex:/^[A-Za-z][A-Za-z0-9]{1,9}$/'],
|
|
];
|
|
}
|
|
|
|
public function withValidator(Validator $validator): void
|
|
{
|
|
$this->guardPublication($validator, 'projects.publish', ['published_at', 'unpublish_at']);
|
|
}
|
|
}
|