Add canonical user access profile table
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:
@@ -33,9 +33,10 @@ class UserRoleModel extends Model
|
||||
$userId = (int) ($data['data']['user_id'] ?? 0);
|
||||
if ($userId > 0) {
|
||||
service('staffDirectorySync')->syncUser($userId);
|
||||
model(UserAccessProfileModel::class)->syncUser($userId);
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
log_message('error', 'UserRoleModel staff directory sync failed: ' . $e->getMessage());
|
||||
log_message('error', 'UserRoleModel role-derived sync failed: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
return $data;
|
||||
@@ -45,8 +46,9 @@ class UserRoleModel extends Model
|
||||
{
|
||||
try {
|
||||
service('staffDirectorySync')->syncAll();
|
||||
model(UserAccessProfileModel::class)->syncAll();
|
||||
} catch (\Throwable $e) {
|
||||
log_message('error', 'UserRoleModel staff directory delete sync failed: ' . $e->getMessage());
|
||||
log_message('error', 'UserRoleModel role-derived delete sync failed: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
Reference in New Issue
Block a user