Add canonical user access profile table
Deploy to Shared Hosting / Shared hosting deploy (push) Failing after 47s
Tests / PHPUnit (push) Successful in 1m20s

Create user_access_profiles as a denormalized access index over the existing roles and user_roles tables. Store primary_category plus is_admin, is_teacher, and is_parent flags so permission checks can use a single canonical source for broad user groups.

Classify teacher and teacher_assistant/TA roles as teacher access, parent as parent access, and every other active staff role as admin access. Backfill all existing users during migration and keep profiles synchronized when role assignments are inserted, updated, or deleted.

Expose the computed access profile in web sessions and auth API responses while preserving the existing detailed roles array and route-filter behavior. Add unit coverage for TA, staff-admin, and multi-role parent/teacher classification.
This commit is contained in:
root
2026-08-29 23:20:40 -04:00
parent 48ae2805d3
commit 0f8ad86b4f
5 changed files with 429 additions and 8 deletions
@@ -0,0 +1,43 @@
<?php
namespace Tests\App\Models;
use App\Models\UserAccessProfileModel;
use CodeIgniter\Test\CIUnitTestCase;
final class UserAccessProfileModelTest extends CIUnitTestCase
{
public function testTeacherAssistantCountsAsTeacher(): void
{
$flags = UserAccessProfileModel::flagsForRoles([
['name' => 'teacher_assistant', 'slug' => 'teacher_assistant'],
]);
$this->assertFalse($flags['is_admin']);
$this->assertTrue($flags['is_teacher']);
$this->assertFalse($flags['is_parent']);
$this->assertSame('teacher', UserAccessProfileModel::primaryCategory($flags));
}
public function testAnyNonTeacherStaffRoleCountsAsAdmin(): void
{
$flags = UserAccessProfileModel::flagsForRoles([
['name' => 'head of fa', 'slug' => 'head_of_fa'],
]);
$this->assertTrue($flags['is_admin']);
$this->assertFalse($flags['is_teacher']);
$this->assertFalse($flags['is_parent']);
$this->assertSame('admin', UserAccessProfileModel::primaryCategory($flags));
}
public function testMultiRoleUserKeepsAllAccessFlags(): void
{
$flags = UserAccessProfileModel::flagsForRoles(['parent', 'teacher']);
$this->assertFalse($flags['is_admin']);
$this->assertTrue($flags['is_teacher']);
$this->assertTrue($flags['is_parent']);
$this->assertSame('teacher', UserAccessProfileModel::primaryCategory($flags));
}
}