Files
unsupervised-scheduler/src/Policy/Policy.php
T
thatguygriffandClaude Opus 4.8 721c4be1d6
CI / Tests (PHP 8.1) (pull_request) Successful in 49s
CI / Tests (PHP 8.2) (pull_request) Successful in 49s
CI / No Debug Code (pull_request) Successful in 2s
CI / Coding Standards (pull_request) Successful in 2m47s
CI / PHPStan (pull_request) Successful in 3m16s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m41s
CI / Build Plugin Zip (pull_request) Skipped
Fix field-length saves, student wp-admin access, and empty instructor picker
Three bug fixes for the 1.2.1 section:

- Fixed-size fields (question labels, offering titles/notes/e-transfer
  email, policy titles/slugs) no longer silently fail to save when the
  value exceeds its column length. The REST endpoints reject over-long
  values with a 400, the admin controllers refuse to insert them, and the
  form inputs carry a maxlength so the browser blocks over-long entry.
  Limits are MAX_* constants on the value objects, kept in lockstep with
  the schema columns.

- Students are kept out of wp-admin entirely. New StudentAdminGuard
  redirects front-end-only users (no back-office capability) away from the
  dashboard and hides the admin bar for them, while administrators, studio
  admins, and instructors keep full access.

- The Add/Edit Offering instructor picker now includes WordPress
  administrators when they act as instructors (the default single-account
  setup), so a solo studio owner is selectable instead of the dropdown
  being empty.

composer test (618), composer lint, composer cs all pass.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-24 20:22:04 -03:00

67 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
namespace Unsupervised\Schedular\Policy;
use Unsupervised\Schedular\Val;
class Policy {
public const SCOPE_SIGNUP = 'signup';
public const SCOPE_BOOKING = 'booking';
public const SCOPE_BOTH = 'both';
/**
* All valid acceptance scopes — when a policy must be accepted.
*
* @var list<string>
*/
public const VALID_SCOPES = [ self::SCOPE_SIGNUP, self::SCOPE_BOOKING, self::SCOPE_BOTH ];
/** Maximum length of the title, matching the `title` VARCHAR(191) column. */
public const MAX_TITLE_LENGTH = 191;
/** Maximum length of the slug, matching the `slug` VARCHAR(191) column. */
public const MAX_SLUG_LENGTH = 191;
public function __construct(
public readonly string $title,
public readonly string $slug,
public readonly ?int $currentVersionId = null,
public readonly string $acceptanceScope = self::SCOPE_BOOKING,
public readonly ?int $id = null,
) {}
public static function fromRow( \stdClass $row ): self {
return new self(
title: Val::string( $row->title ),
slug: Val::string( $row->slug ),
currentVersionId: Val::intOrNull( $row->current_version_id ),
acceptanceScope: Val::string( $row->acceptance_scope ),
id: Val::int( $row->id ),
);
}
/**
* Whether this policy must be accepted in the given gate (`signup` or `booking`).
*/
public function appliesTo( string $scope ): bool {
return $this->acceptanceScope === $scope || self::SCOPE_BOTH === $this->acceptanceScope;
}
/**
* Returns a plain array representation of the policy.
*
* @return array<string, mixed>
*/
public function toArray(): array {
return [
'id' => $this->id,
'title' => $this->title,
'slug' => $this->slug,
'current_version_id' => $this->currentVersionId,
'acceptance_scope' => $this->acceptanceScope,
];
}
}