refactor(support): consolidate remaining ID normalization via toIntIds()
Extends the toIntIds() rollout to service and repository layers: - Drops a third private duplicate (UserCustomFieldValueService::normalizeTenantIds) - Collapses the two-line intval+filter pattern inside UserAssignmentService, UserAuthorizationPolicy, SsoUserLinkService, DepartmentService, and UserCustomFieldValueService - Replaces inline patterns in 4 repositories (RolePermissionRepository, RoleAssignableRoleRepository, UserWriteRepository, DepartmentRepository, UserCustomFieldValueRepository, UserCustomFieldValueOptionRepository) - Simplifies the notifications sanitizeTenantIds trait body Tenant-area files deliberately untouched per parallel ongoing work on the tenant-logo refactor. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -176,8 +176,7 @@ class UserAssignmentService
|
||||
|
||||
public function syncRoles(int $userId, array $roleIds, bool $bumpAuthz = true, int $actorUserId = 0): bool
|
||||
{
|
||||
$ids = array_values(array_unique(array_map('intval', $roleIds)));
|
||||
$ids = array_values(array_filter($ids, static fn ($id) => $id > 0));
|
||||
$ids = toIntIds($roleIds);
|
||||
$validIds = $this->directoryGateway->listActiveRoleIds();
|
||||
if ($validIds) {
|
||||
$validMap = array_fill_keys($validIds, true);
|
||||
@@ -201,16 +200,11 @@ class UserAssignmentService
|
||||
|
||||
public function syncDepartments(int $userId, array $departmentIds, bool $bumpAuthz = true): bool
|
||||
{
|
||||
$ids = array_values(array_unique(array_map('intval', $departmentIds)));
|
||||
$ids = array_values(array_filter($ids, static fn ($id) => $id > 0));
|
||||
$ids = toIntIds($departmentIds);
|
||||
// Important: use the user's assigned tenants directly (no permission bypass),
|
||||
// otherwise privileged users (e.g. admins) would incorrectly allow departments
|
||||
// from tenants that were just removed from their assignments.
|
||||
$userTenantIds = array_values(array_unique(array_map(
|
||||
'intval',
|
||||
$this->userTenantRepository->listTenantIdsByUserId($userId)
|
||||
)));
|
||||
$userTenantIds = array_values(array_filter($userTenantIds, static fn ($id) => $id > 0));
|
||||
$userTenantIds = toIntIds($this->userTenantRepository->listTenantIdsByUserId($userId));
|
||||
if (!$userTenantIds) {
|
||||
$ids = [];
|
||||
} else {
|
||||
@@ -304,14 +298,12 @@ class UserAssignmentService
|
||||
$collect($item);
|
||||
}
|
||||
|
||||
$ids = array_values(array_unique(array_map('intval', $flat)));
|
||||
return array_values(array_filter($ids, static fn ($id) => $id > 0));
|
||||
return toIntIds($flat);
|
||||
}
|
||||
|
||||
public function normalizeTenantIds(array $tenantIds): array
|
||||
{
|
||||
$ids = array_values(array_unique(array_map('intval', $tenantIds)));
|
||||
$ids = array_filter($ids, static fn ($id) => $id > 0);
|
||||
$ids = toIntIds($tenantIds);
|
||||
$validIds = $this->directoryGateway->listTenantIds();
|
||||
if ($validIds) {
|
||||
$validMap = array_fill_keys($validIds, true);
|
||||
|
||||
Reference in New Issue
Block a user