diff --git a/lib/Controller/WorkspaceController.php b/lib/Controller/WorkspaceController.php index 42b7180a2..28681bcb6 100644 --- a/lib/Controller/WorkspaceController.php +++ b/lib/Controller/WorkspaceController.php @@ -32,6 +32,8 @@ use OCA\Workspace\Exceptions\CreateWorkspaceException; use OCA\Workspace\Exceptions\WorkspaceNameExistException; use OCA\Workspace\Folder\RootFolder; +use OCA\Workspace\Group\Admin\AdminGroup; +use OCA\Workspace\Group\Admin\AdminUserGroup; use OCA\Workspace\Helper\GroupfolderHelper; use OCA\Workspace\Service\Group\GroupFormatter; use OCA\Workspace\Service\Group\ManagersWorkspace; @@ -53,6 +55,8 @@ class WorkspaceController extends Controller { public function __construct( IRequest $request, + private AdminGroup $adminGroup, + private AdminUserGroup $adminUserGroup, private GroupfolderHelper $folderHelper, private IGroupManager $groupManager, private RootFolder $rootFolder, @@ -147,17 +151,14 @@ public function createWorkspace(string $spaceName, */ public function destroy(int $spaceId): JSONResponse { $this->logger->debug('Removing GE users from the WorkspacesManagers group if needed.'); - $space = $this->spaceManager->get($spaceId); - $folderId = $space['groupfolder_id']; - - $GEGroup = $this->groupManager->get(WorkspaceManagerGroup::get($spaceId)); - foreach ($GEGroup->getUsers() as $user) { + foreach ($this->adminGroup->getUsers($spaceId) as $user) { if ($this->userService->canRemoveWorkspaceManagers($user)) { - $this->userService->removeGEFromWM($user); + $this->adminUserGroup->removeUser($user); } } // Removes all workspaces groups + $space = $this->spaceManager->get($spaceId); $groups = []; $this->logger->debug('Removing workspaces groups.'); foreach (array_keys($space['groups']) as $group) { @@ -165,7 +166,7 @@ public function destroy(int $spaceId): JSONResponse { $this->groupManager->get($group)->delete(); } - $this->folderHelper->removeFolder($folderId); + $this->spaceManager->remove($spaceId); return new JSONResponse([ 'http' => [ diff --git a/lib/Group/Admin/AdminGroup.php b/lib/Group/Admin/AdminGroup.php index d1a2e6cfd..591776801 100644 --- a/lib/Group/Admin/AdminGroup.php +++ b/lib/Group/Admin/AdminGroup.php @@ -24,7 +24,9 @@ namespace OCA\Workspace\Group\Admin; +use OCP\IGroupManager; use OCP\IUser; +use Psr\Log\LoggerInterface; /** * This class represents a Workspace Manager (GE-) group. @@ -33,7 +35,9 @@ class AdminGroup { public const GID_PREFIX = 'SPACE-GE-'; public function __construct(private AdminUserGroup $adminUserGroup, - private AdminGroupManager $adminGroupManager) { + private AdminGroupManager $adminGroupManager, + private LoggerInterface $logger, + private IGroupManager $groupManager) { } public function addUser(IUser $user, string $gid): bool { @@ -43,4 +47,12 @@ public function addUser(IUser $user, string $gid): bool { return true; } + + /** + * @return IUser[] + */ + public function getUsers(int $spaceId): array { + $group = $this->groupManager->get(self::GID_PREFIX . $spaceId); + return $group->getUsers(); + } } diff --git a/lib/Group/Admin/AdminUserGroup.php b/lib/Group/Admin/AdminUserGroup.php index a936cac92..1b41e3a4b 100644 --- a/lib/Group/Admin/AdminUserGroup.php +++ b/lib/Group/Admin/AdminUserGroup.php @@ -26,6 +26,7 @@ use OCP\IGroupManager; use OCP\IUser; +use Psr\Log\LoggerInterface; /** * This class gathers all users from the @@ -35,7 +36,10 @@ class AdminUserGroup { public const GID = 'WorkspacesManagers'; - public function __construct(private IGroupManager $groupManager) { + public function __construct( + private IGroupManager $groupManager, + private LoggerInterface $logger, + ) { } public function addUser(IUser $user): bool { @@ -49,4 +53,10 @@ public function addUser(IUser $user): bool { return true; } + + public function removeUser(IUser $user): void { + $this->logger->debug('The ' . $user->getUID() . 'User is not manager of any other workspace, removing it from the ' . self::GID . ' group.'); + $workspaceUserGroup = $this->groupManager->get(self::GID); + $workspaceUserGroup->removeUser($user); + } } diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index a70dcc5f6..0b7f10eed 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -160,6 +160,10 @@ public function canRemoveWorkspaceManagers(IUser $user): bool { * * @param IUser $user * @return void + * + * @deprecated + * + * @uses OCA\Workspace\Group\Admin\AdminUserGroup::removeUser */ public function removeGEFromWM(IUser $user): void { $this->logger->debug('User is not manager of any other workspace, removing it from the ' . ManagersWorkspace::WORKSPACES_MANAGERS . ' group.'); diff --git a/lib/Space/SpaceManager.php b/lib/Space/SpaceManager.php index fda7d4473..377dee0a9 100644 --- a/lib/Space/SpaceManager.php +++ b/lib/Space/SpaceManager.php @@ -145,4 +145,10 @@ public function attachGroup(int $folderId, string $gid): void { private function deleteBlankSpaceName(string $spaceName): string { return trim($spaceName); } + + public function remove(string $spaceId): void { + $space = $this->get($spaceId); + $folderId = $space['groupfolder_id']; + $this->folderHelper->removeFolder($folderId); + } }