Files
unsupervised-scheduler/src/Policy/PolicyService.php
T
thatguygriff 9c900d6553
CI / Tests (PHP 8.1) (pull_request) Successful in 47s
CI / No Debug Code (pull_request) Successful in 2s
CI / Build Plugin Zip (pull_request) Has been skipped
CI / Coding Standards (pull_request) Successful in 52s
CI / PHPStan (pull_request) Successful in 1m1s
CI / Tests (PHP 8.2) (pull_request) Successful in 48s
CI / Tests (PHP 8.3) (pull_request) Successful in 45s
Add account registration with signup policy acceptance
Implements #16: invite-only student self-registration through a front-end
page, accepting signup-scoped policies at account creation.

Policy domain:
- us_policies.acceptance_scope (signup/booking/both); Policy::appliesTo();
  PolicyRepository::findForScope(); scope threaded through PolicyService,
  the REST create, the admin controller, and the Policies form.
- PolicyAcceptance::REG_ACCOUNT (registration_id = the new user's ID).

Auth:
- Invite value object + InviteRepository; us_invites table.
- RegistrationController + Invites admin page (manage_students): invite an
  email, share the registration link, revoke.
- RegistrationPage ([us_student_register] shortcode): validates the invite
  token, collects name/password, renders signup-scoped published policies
  with required acceptance, creates the us_student user, records account-type
  acceptances, marks the invite accepted, and logs the user in.
- RoleManager: manage_students cap added to STUDIO_ADMIN_CAPS.

Invite-only is implemented; the us_registration_mode self_approval path is a
documented future seam.

Docs: docs/features/account-registration.md; policies.md updated.
Tests: tests/Unit/Auth/ (Invite, InviteRepository) plus Policy scope
updates. composer test (104), cs, and PHPStan level 6 all pass.

Refs #16

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-05 16:39:39 -03:00

59 lines
1.8 KiB
PHP

<?php
declare(strict_types=1);
namespace Unsupervised\Schedular\Policy;
/**
* Orchestrates policy operations that span the policies and versions tables.
*/
class PolicyService {
public function __construct(
private PolicyRepository $policies,
private PolicyVersionRepository $versions,
) {}
public function createPolicy( string $title, string $slug, string $scope = Policy::SCOPE_BOOKING ): int {
return $this->policies->insert( new Policy( $title, $slug, acceptanceScope: $scope ) );
}
/**
* Add a new draft version to a policy, numbered after the latest existing one.
*/
public function addDraftVersion( int $policyId, ?string $body ): int {
$next = $this->versions->maxVersionNumber( $policyId ) + 1;
return $this->versions->insert(
new PolicyVersion(
policyId: $policyId,
versionNumber: $next,
body: $body,
status: PolicyVersion::STATUS_DRAFT,
)
);
}
/**
* Publish a version: archive the policy's previously current version, mark
* the new one published, and point the policy at it. Returns false if the
* version does not belong to the policy.
*/
public function publishVersion( int $policyId, int $versionId ): bool {
$policy = $this->policies->findById( $policyId );
$version = $this->versions->findById( $versionId );
if ( null === $policy || null === $version || $version->policyId !== $policyId ) {
return false;
}
if ( null !== $policy->currentVersionId && $policy->currentVersionId !== $versionId ) {
$this->versions->updateStatus( $policy->currentVersionId, PolicyVersion::STATUS_ARCHIVED );
}
$this->versions->updateStatus( $versionId, PolicyVersion::STATUS_PUBLISHED, current_time( 'mysql' ) );
$this->policies->updateCurrentVersion( $policyId, $versionId );
return true;
}
}