remove app from user organization

This commit is contained in:
Charles 2025-07-25 11:50:06 +02:00
parent fed351b433
commit 8eb5cf433d
1 changed files with 4 additions and 3 deletions

View File

@ -207,15 +207,16 @@ readonly class UserOrganizationService
$uoEntity = $this->entityManager
->getRepository(UsersOrganizations::class)
->findOneBy(['users' => $user, 'organization' => $organization, 'role' => $roleUser]);
// dd($roleUser);
// dd($uoEntity->getApps()->toArray());
// 1. Remove apps that are no longer selected
foreach ($uoEntity->getApps() as $existingApp) {
foreach ($uoEntity->getApps()->toArray() as $existingApp) {
if (!in_array($existingApp->getId(), $selectedApps)) {
$uoEntity->removeApp($existingApp);
}
}
// 2. Add newly selected apps (your existing logic)
// 2. Add newly selected apps
foreach ($selectedApps as $appId) {
$appEntity = $this->entityManager->getRepository(Apps::class)->find($appId);
if ($appEntity && !$uoEntity->getApps()->contains($appEntity)) {