Session 2's PersonProvisioner picked CrowdType::oldest() for the org — silently wrong for multi-crowd_type orgs (Volunteer + Crew + Press are three distinct crowd_types in one org). Schemas now declare their target crowd_type explicitly via form_schemas.default_crowd_type_id. RequiresDefaultCrowdType publish guard prevents misconfigured event_registration schemas from publishing. PersonProvisioner: oldest() fallback removed entirely. Misconfiguration throws no_default_crowd_type at runtime; publish guard prevents it at config time. Migration uses a plain ulid() column without DB-level FK because SQLite's table-rebuild on ALTER ADD FOREIGN KEY cascade-deletes form_fields rows (form_fields.form_schema_id has cascadeOnDelete on form_schemas). Application-level integrity via FormSchema::defaultCrowdType() belongsTo + the publish guard + the runtime failsafe — three load-bearing checks, none of which require the DB-level constraint. Three pre-existing migration backfill tests bumped step counts +1 to account for the new migration sitting between WS-5c and WS-5d: FormFieldBindingMigrationTest (16→17, 14→15), FormFieldConfigBackfillAndDropTest (11→12), FormFieldValidationRuleBackfillTest (14→15), ConditionalLogicBackfillTest (5→6). Six event_registration test fixtures updated to set default_crowd_type_id to satisfy the new publish guard. FormBuilderDevSeeder.resolveDefaultCrowdTypeId() — VOLUNTEER → first-active → create-as-needed fallback chain; documented contract for future seeders. SCHEMA.md updated to v2.7. Refs: RFC-WS-6.md v1.1 §3 Q8 addendum (Task 4 of this session) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
69 lines
2.5 KiB
PHP
69 lines
2.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\FormBuilder\Purposes\Guards;
|
|
|
|
use App\Enums\FormBuilder\FormFieldType;
|
|
use App\FormBuilder\Bindings\BindingTypeRegistry;
|
|
use App\FormBuilder\Publishing\AppendStrategyRequiresCollectionTarget;
|
|
use App\FormBuilder\Publishing\ConditionalRequirement;
|
|
use App\FormBuilder\Publishing\IdentityKeyBindingsOnlyInFirstSection;
|
|
use App\FormBuilder\Publishing\MaxOneIdentityKeyPerTargetEntity;
|
|
use App\FormBuilder\Publishing\NoAmbiguousTrustLevels;
|
|
use App\FormBuilder\Publishing\RequiresFieldType;
|
|
use App\FormBuilder\Publishing\RequiresDefaultCrowdType;
|
|
use App\FormBuilder\Publishing\RequiresIdentityKeyBinding;
|
|
use App\FormBuilder\Publishing\SchemaHasLinkedEvent;
|
|
use App\FormBuilder\Publishing\TagCategoriesConfiguredOnAllPickers;
|
|
use App\FormBuilder\Purposes\PurposeGuardProvider;
|
|
use App\Models\FormBuilder\FormField;
|
|
use App\Models\FormBuilder\FormSchema;
|
|
|
|
final readonly class EventRegistrationGuards implements PurposeGuardProvider
|
|
{
|
|
public function __construct(private BindingTypeRegistry $registry) {}
|
|
|
|
public function publishGuards(): array
|
|
{
|
|
return [
|
|
new RequiresIdentityKeyBinding('person', 'email'),
|
|
new RequiresDefaultCrowdType(),
|
|
new MaxOneIdentityKeyPerTargetEntity(),
|
|
new RequiresFieldType(FormFieldType::EMAIL, 1),
|
|
new ConditionalRequirement(
|
|
predicate: $this->fieldTypePresent(FormFieldType::AVAILABILITY_PICKER),
|
|
subGuard: new SchemaHasLinkedEvent(),
|
|
code: 'availability_picker_requires_event',
|
|
),
|
|
new ConditionalRequirement(
|
|
predicate: $this->fieldTypePresent(FormFieldType::TAG_PICKER),
|
|
subGuard: new TagCategoriesConfiguredOnAllPickers(),
|
|
code: 'tag_picker_requires_tag_categories',
|
|
),
|
|
new AppendStrategyRequiresCollectionTarget($this->registry),
|
|
new NoAmbiguousTrustLevels(),
|
|
new IdentityKeyBindingsOnlyInFirstSection(),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return \Closure(FormSchema): bool
|
|
*/
|
|
private function fieldTypePresent(FormFieldType $type): \Closure
|
|
{
|
|
$value = $type->value;
|
|
|
|
return static function (FormSchema $schema) use ($value): bool {
|
|
/** @var FormField $field */
|
|
foreach ($schema->fields as $field) {
|
|
if ($field->field_type === $value) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
};
|
|
}
|
|
}
|