update api register
This commit is contained in:
@@ -65,6 +65,7 @@ class UserService
|
||||
'profile_photo_file_id',
|
||||
'password',
|
||||
'is_master',
|
||||
'is_platform_staff',
|
||||
'access_level',
|
||||
'status',
|
||||
]);
|
||||
@@ -109,6 +110,7 @@ class UserService
|
||||
'whatsapp_number',
|
||||
'profile_photo_file_id',
|
||||
'is_master',
|
||||
'is_platform_staff',
|
||||
'access_level',
|
||||
'status',
|
||||
]);
|
||||
@@ -176,9 +178,12 @@ class UserService
|
||||
|
||||
protected function syncTenants(User $user, array $rows): void
|
||||
{
|
||||
$existingRoles = $user->userTenants()->pluck('role', 'tenant_id');
|
||||
$normalized = collect($rows)
|
||||
->map(fn ($row) => [
|
||||
'tenant_id' => $row['tenant_id'] ?? null,
|
||||
'role' => $row['role'] ?? $existingRoles->get($row['tenant_id'] ?? null)
|
||||
?? ($user->access_level === UserAccessLevel::STAFF ? 'staff' : 'customer'),
|
||||
'is_default' => (bool) ($row['is_default'] ?? false),
|
||||
])
|
||||
->filter(fn ($row) => ! empty($row['tenant_id']))
|
||||
@@ -186,6 +191,12 @@ class UserService
|
||||
->values()
|
||||
->all();
|
||||
|
||||
if (collect($normalized)->where('role', 'tenant_owner')->count() > 1) {
|
||||
throw ValidationException::withMessages([
|
||||
'user_tenants' => 'Satu user hanya boleh menjadi Tenant Owner pada satu tenant.',
|
||||
]);
|
||||
}
|
||||
|
||||
$defaultSet = false;
|
||||
foreach ($normalized as $index => $row) {
|
||||
if ($row['is_default'] && ! $defaultSet) {
|
||||
@@ -243,6 +254,13 @@ class UserService
|
||||
return;
|
||||
}
|
||||
|
||||
if ($payload['is_platform_staff'] ?? false) {
|
||||
throw ValidationException::withMessages([
|
||||
'is_platform_staff' => 'Hanya Master Admin yang dapat memberikan akses staff platform.',
|
||||
]);
|
||||
}
|
||||
unset($payload['is_platform_staff']);
|
||||
|
||||
if ($target?->isMasterAdmin()) {
|
||||
throw ValidationException::withMessages([
|
||||
'user' => 'Master Admin hanya dapat diubah oleh Master Admin.',
|
||||
@@ -275,6 +293,11 @@ class UserService
|
||||
$key => 'Assignment hanya boleh dibuat untuk tenant yang sedang aktif.',
|
||||
]);
|
||||
}
|
||||
if ($key === 'user_tenants' && ($row['role'] ?? null) === 'tenant_owner') {
|
||||
throw ValidationException::withMessages([
|
||||
$key => 'Tenant Owner tidak dapat memberikan role Tenant Owner.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user