From 1abad18bb084f6cb2981421ab79c6851f667b0c8 Mon Sep 17 00:00:00 2001 From: Baptiste Fotia Date: Mon, 29 May 2023 17:14:56 +0200 Subject: [PATCH 1/3] refactor(PHP): Apply the polymorpishm for Groups I applied the polymorphism principle for the main groups for a Workspace (WM- and U-). Signed-off-by: Baptiste Fotia --- lib/Controller/GroupController.php | 18 ++++---- lib/Controller/WorkspaceController.php | 44 +++++++++--------- lib/Service/Group/GroupsWorkspace.php | 47 ++++++++------------ lib/Service/Group/GroupsWorkspaceService.php | 16 ++++--- lib/Service/Group/IGroupWorkspace.php | 37 +++++++++++++++ lib/Service/Group/UserGroup.php | 38 +++++++--------- lib/Service/Group/WorkspaceManagerGroup.php | 45 ++++++++----------- lib/Service/UserService.php | 12 ++--- lib/Service/WorkspaceService.php | 10 +++-- lib/Upgrade/UpgradeV300.php | 12 +++-- 10 files changed, 152 insertions(+), 127 deletions(-) create mode 100644 lib/Service/Group/IGroupWorkspace.php diff --git a/lib/Controller/GroupController.php b/lib/Controller/GroupController.php index 51bd7f3a4..0b3332681 100644 --- a/lib/Controller/GroupController.php +++ b/lib/Controller/GroupController.php @@ -50,11 +50,13 @@ class GroupController extends Controller { public function __construct( private GroupsWorkspaceService $groupsWorkspace, private IGroupManager $groupManager, - private LoggerInterface $logger, private IUserManager $userManager, + private LoggerInterface $logger, private UserFormatter $userFormatter, private UserService $userService, - private UserWorkspace $userWorkspace + private UserWorkspace $userWorkspace, + private UserGroup $userGroup, + private WorkspaceManagerGroup $workspaceManagerGroup ) { } @@ -207,7 +209,7 @@ public function addUser(string $spaceId, string $gid, string $user): JSONRespons $NCGroup->addUser($NCUser); // Adds the user to the application manager group when we are adding a workspace manager - if ($gid === WorkspaceManagerGroup::get($spaceId)) { + if ($gid === $this->workspaceManagerGroup->get($spaceId)) { $workspaceUsersGroup = $this->groupManager->get(ManagersWorkspace::WORKSPACES_MANAGERS); if (!is_null($workspaceUsersGroup)) { $workspaceUsersGroup->addUser($NCUser); @@ -220,7 +222,7 @@ public function addUser(string $spaceId, string $gid, string $user): JSONRespons // Adds user to workspace user group // This must be the last action done, when all other previous actions have succeeded - $UGroup = $this->groupManager->get(UserGroup::get($spaceId)); + $UGroup = $this->groupManager->get($this->userGroup->get($spaceId)); $UGroup->addUser($NCUser); return new JSONResponse(['message' => 'The user ' . $user . ' is added in the ' . $gid . ' group'], Http::STATUS_CREATED); @@ -258,8 +260,8 @@ public function removeUser(array|string $space, // Removes user from group(s) $NCUser = $this->userManager->get($user); $groups = []; - if ($gid === WorkspaceManagerGroup::get($space['id']) - || $gid === UserGroup::get($space['id'])) { + if ($gid === $this->workspaceManagerGroup->get($space['id']) + || $gid === $this->userGroup->get($space['id'])) { // Removing user from a U- group $this->logger->debug('Removing user from a workspace, removing it from all the workspace subgroups too.'); $users = (array)$space['users']; @@ -268,7 +270,7 @@ public function removeUser(array|string $space, $NCGroup->removeUser($NCUser); $groups[] = $NCGroup->getGID(); $this->logger->debug('User removed from group: ' . $NCGroup->getDisplayName()); - if ($groupId === WorkspaceManagerGroup::get($space['id'])) { + if ($groupId === $this->workspaceManagerGroup->get($space['id'])) { $this->logger->debug('Removing user from a workspace manager group, removing it from the WorkspacesManagers group if needed.'); $this->userService->removeGEFromWM($NCUser, $space); } @@ -278,7 +280,7 @@ public function removeUser(array|string $space, $groups[] = $gid; $NCGroup->removeUser($NCUser); $this->logger->debug('User removed from group: ' . $NCGroup->getDisplayName()); - if ($gid === WorkspaceManagerGroup::get($space['id'])) { + if ($gid === $this->workspaceManagerGroup->get($space['id'])) { // Removing user from a GE- group $this->logger->debug('Removing user from a workspace manager group, removing it from the WorkspacesManagers group if needed.'); $this->userService->removeGEFromWM($NCUser, $space); diff --git a/lib/Controller/WorkspaceController.php b/lib/Controller/WorkspaceController.php index 4f0519f18..bfbc634a0 100644 --- a/lib/Controller/WorkspaceController.php +++ b/lib/Controller/WorkspaceController.php @@ -25,26 +25,27 @@ namespace OCA\Workspace\Controller; +use OCP\IRequest; +use OCP\IUserManager; +use OCP\IGroupManager; +use OCP\AppFramework\Http; +use OCA\Workspace\Db\Space; +use Psr\Log\LoggerInterface; +use OCP\AppFramework\Controller; +use OCA\Workspace\Db\SpaceMapper; use OCA\Workspace\BadRequestException; +use OCA\Workspace\Service\UserService; use OCA\Workspace\CreateGroupException; +use OCA\Workspace\Service\SpaceService; +use OCP\AppFramework\Http\JSONResponse; +use OCA\Workspace\Service\Group\UserGroup; use OCA\Workspace\CreateWorkspaceException; -use OCA\Workspace\Db\Space; -use OCA\Workspace\Db\SpaceMapper; +use OCA\Workspace\Service\WorkspaceService; use OCA\Workspace\Service\Group\GroupFormatter; +use OCA\Workspace\Service\Group\GroupsWorkspace; use OCA\Workspace\Service\Group\ManagersWorkspace; -use OCA\Workspace\Service\Group\UserGroup; use OCA\Workspace\Service\Group\WorkspaceManagerGroup; -use OCA\Workspace\Service\SpaceService; -use OCA\Workspace\Service\UserService; use OCA\Workspace\Service\Workspace\WorkspaceCheckService; -use OCA\Workspace\Service\WorkspaceService; -use OCP\AppFramework\Controller; -use OCP\AppFramework\Http; -use OCP\AppFramework\Http\JSONResponse; -use OCP\IGroupManager; -use OCP\IRequest; -use OCP\IUserManager; -use Psr\Log\LoggerInterface; class WorkspaceController extends Controller { public function __construct( @@ -54,12 +55,13 @@ public function __construct( private LoggerInterface $logger, private SpaceMapper $spaceMapper, private SpaceService $spaceService, + private UserGroup $userGroup, private UserService $userService, private WorkspaceCheckService $workspaceCheck, - private WorkspaceService $workspaceService, - private UserGroup $userGroup, private WorkspaceManagerGroup $workspaceManagerGroup, - public $AppName + private WorkspaceService $workspaceService, + public $AppName, + private GroupsWorkspace $groupsWorkspace ) { parent::__construct($AppName, $request); } @@ -107,8 +109,8 @@ public function createWorkspace(string $spaceName, } // #2 create groups - $newSpaceManagerGroup = $this->workspaceManagerGroup->create($space); - $newSpaceUsersGroup = $this->userGroup->create($space); + $newSpaceManagerGroup = $this->groupsWorkspace->create($this->workspaceManagerGroup, $space); + $newSpaceUsersGroup = $this->groupsWorkspace->create($this->userGroup, $space); // #3 Returns result return new JSONResponse([ @@ -135,7 +137,7 @@ public function createWorkspace(string $spaceName, */ public function destroy(array $workspace): JSONResponse { $this->logger->debug('Removing GE users from the WorkspacesManagers group if needed.'); - $GEGroup = $this->groupManager->get(WorkspaceManagerGroup::get($workspace['id'])); + $GEGroup = $this->groupManager->get($this->workspaceManagerGroup->get($workspace['id'])); foreach ($GEGroup->getUsers() as $user) { $this->userService->removeGEFromWM($user, $workspace); } @@ -240,7 +242,7 @@ public function changeUserRole(array|string $space, } $user = $this->userManager->get($userId); - $GEgroup = $this->groupManager->get(WorkspaceManagerGroup::get($space['id'])); + $GEgroup = $this->groupManager->get($this->workspaceManagerGroup->get($space['id'])); if ($GEgroup->inGroup($user)) { // Changing a user's role from admin to user $GEgroup->removeUser($user); @@ -248,7 +250,7 @@ public function changeUserRole(array|string $space, $this->userService->removeGEFromWM($user, $space); } else { // Changing a user's role from user to admin - $this->groupManager->get(WorkspaceManagerGroup::get($space['id']))->addUser($user); + $this->groupManager->get($this->workspaceManagerGroup->get($space['id']))->addUser($user); $this->groupManager->get(ManagersWorkspace::WORKSPACES_MANAGERS)->addUser($user); } diff --git a/lib/Service/Group/GroupsWorkspace.php b/lib/Service/Group/GroupsWorkspace.php index 39cf005e7..a652c211d 100644 --- a/lib/Service/Group/GroupsWorkspace.php +++ b/lib/Service/Group/GroupsWorkspace.php @@ -23,43 +23,32 @@ namespace OCA\Workspace\Service\Group; +use OCA\Workspace\CreateGroupException; use OCA\Workspace\Db\Space; +use OCP\AppFramework\Http; use OCP\AppFramework\Services\IAppConfig; use OCP\IGroup; +use OCP\IGroupManager; -abstract class GroupsWorkspace { - private const GID_SPACE_MANAGER = 'GE-'; - private const GID_SPACE_USERS = 'U-'; - private const GID_SPACE = 'SPACE-'; - - protected const PREFIX_GID_MANAGERS = self::GID_SPACE . self::GID_SPACE_MANAGER; - protected const PREFIX_GID_USERS = self::GID_SPACE . self::GID_SPACE_USERS; - - protected static string $DISPLAY_PREFIX_MANAGER_GROUP; - protected static string $DISPLAY_PREFIX_USER_GROUP; - - public function __construct(IAppConfig $appConfig) { - self::$DISPLAY_PREFIX_MANAGER_GROUP = $appConfig->getAppValue('DISPLAY_PREFIX_MANAGER_GROUP'); - self::$DISPLAY_PREFIX_USER_GROUP = $appConfig->getAppValue('DISPLAY_PREFIX_USER_GROUP'); - } - - public static function getDisplayPrefixManagerGroup(): string { - return self::$DISPLAY_PREFIX_MANAGER_GROUP; - } - - public static function getDisplayPrefixUserGroup(): string { - return self::$DISPLAY_PREFIX_USER_GROUP; +class GroupsWorkspace { + + public function __construct(private IAppConfig $appConfig, + private IGroupManager $groupManager) { } /** - * @return string - Just the GID with the spaceId. + * Use the OCA\Workspace\Db\Space to get its spaceId and spaceName. */ - abstract public static function get(int $spaceId): string; + public function create(IGroupWorkspace $groupWorkspace, Space $space): IGroup { + $group = $this->groupManager->createGroup($groupWorkspace->getGidPrefix() . $space->getId()); - abstract public static function getPrefix(): string; + if (is_null($group)) { + throw new CreateGroupException('Error to create a Space Manager group.', Http::STATUS_CONFLICT); + } + + $group->setDisplayName($groupWorkspace->getDisplayPrefix() . $space->getSpaceName()); + + return $group; + } - /** - * Use the OCA\Workspace\Db\Space to get its spaceId and spaceName. - */ - abstract public function create(Space $space): IGroup; } diff --git a/lib/Service/Group/GroupsWorkspaceService.php b/lib/Service/Group/GroupsWorkspaceService.php index 2b01c06bf..1e2313ce5 100644 --- a/lib/Service/Group/GroupsWorkspaceService.php +++ b/lib/Service/Group/GroupsWorkspaceService.php @@ -24,15 +24,17 @@ namespace OCA\Workspace\Service\Group; -use OCA\Workspace\GroupException; -use OCA\Workspace\UserGroup; -use OCA\Workspace\WorkspaceManagerGroup; +use OCP\IUser; use OCP\IGroup; use OCP\IGroupManager; -use OCP\IUser; +use OCA\Workspace\Exceptions\GroupException; +use OCA\Workspace\Service\Group\UserGroup; +use OCA\Workspace\Service\Group\WorkspaceManagerGroup; class GroupsWorkspaceService { - public function __construct(private IGroupManager $groupManager) { + public function __construct(private IGroupManager $groupManager, + private WorkspaceManagerGroup $workspaceManagerGroup, + private UserGroup $userGroup) { } /** @@ -40,7 +42,7 @@ public function __construct(private IGroupManager $groupManager) { */ public function getWorkspaceManagerGroup(string $spaceId): IGroup { $groupSpaceManager = $this->groupManager->get( - WorkspaceManagerGroup::get($spaceId) + $this->workspaceManagerGroup->get($spaceId) ); if (is_null($groupSpaceManager)) { @@ -55,7 +57,7 @@ public function getWorkspaceManagerGroup(string $spaceId): IGroup { */ public function getUserGroup(string $spaceId): IGroup { $groupUser = $this->groupManager->get( - UserGroup::get($spaceId) + $this->userGroup->get($spaceId) ); if (is_null($groupUser)) { diff --git a/lib/Service/Group/IGroupWorkspace.php b/lib/Service/Group/IGroupWorkspace.php new file mode 100644 index 000000000..82881a864 --- /dev/null +++ b/lib/Service/Group/IGroupWorkspace.php @@ -0,0 +1,37 @@ + + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCA\Workspace\Service\Group; + +interface IGroupWorkspace { + + /** + * @return string - Just the GID with the spaceId. + */ + public function get(int $spaceId): string; + + public function getDisplayPrefix(): string; + + public function getGidPrefix(): string; + +} diff --git a/lib/Service/Group/UserGroup.php b/lib/Service/Group/UserGroup.php index 6295757a2..ec8695f87 100644 --- a/lib/Service/Group/UserGroup.php +++ b/lib/Service/Group/UserGroup.php @@ -23,38 +23,30 @@ namespace OCA\Workspace\Service\Group; -use OCA\Workspace\CreateGroupException; -use OCA\Workspace\Db\Space; -use OCP\AppFramework\Http; use OCP\AppFramework\Services\IAppConfig; -use OCP\IGroup; -use OCP\IGroupManager; +use OCA\Workspace\Service\Group\IGroupWorkspace; -class UserGroup extends GroupsWorkspace { - private IGroupManager $groupManager; +class UserGroup implements IGroupWorkspace { - public function __construct(IGroupManager $groupManager, IAppConfig $appConfig) { - parent::__construct($appConfig); - $this->groupManager = $groupManager; + private const GID_SPACE = 'SPACE-'; + private const PREFIX_GID_USERS = self::GID_SPACE . 'U-'; + private string $DISPLAY_PREFIX_USER_GROUP; + + + public function __construct(IAppConfig $appConfig) { + $this->DISPLAY_PREFIX_USER_GROUP = $appConfig->getAppValue('DISPLAY_PREFIX_USER_GROUP'); } - public static function get(int $spaceId): string { + public function get(int $spaceId): string { return self::PREFIX_GID_USERS . $spaceId; } - public static function getPrefix(): string { + public function getGidPrefix(): string { return self::PREFIX_GID_USERS; } - public function create(Space $space): IGroup { - $group = $this->groupManager->createGroup(self::PREFIX_GID_USERS . $space->getId()); - - if (is_null($group)) { - throw new CreateGroupException('Error to create a Space Manager group.', Http::STATUS_CONFLICT); - } - - $group->setDisplayName(self::getDisplayPrefixUserGroup() . $space->getSpaceName()); - - return $group; - } + public function getDisplayPrefix(): string + { + return $this->DISPLAY_PREFIX_USER_GROUP; + } } diff --git a/lib/Service/Group/WorkspaceManagerGroup.php b/lib/Service/Group/WorkspaceManagerGroup.php index 6baf744c1..3ee7a1805 100644 --- a/lib/Service/Group/WorkspaceManagerGroup.php +++ b/lib/Service/Group/WorkspaceManagerGroup.php @@ -23,38 +23,29 @@ namespace OCA\Workspace\Service\Group; -use OCA\Workspace\CreateGroupException; -use OCA\Workspace\Db\Space; -use OCP\AppFramework\Http; use OCP\AppFramework\Services\IAppConfig; -use OCP\IGroup; -use OCP\IGroupManager; +use OCA\Workspace\Service\Group\IGroupWorkspace; -class WorkspaceManagerGroup extends GroupsWorkspace { - private IGroupManager $groupManager; +class WorkspaceManagerGroup implements IGroupWorkspace { - public function __construct(IGroupManager $groupManager, IAppConfig $appConfig) { - parent::__construct($appConfig); - $this->groupManager = $groupManager; - } - - public static function get(int $spaceId): string { - return self::PREFIX_GID_MANAGERS . $spaceId; - } + private const GID_SPACE = 'SPACE-'; + private const PREFIX_GID_MANAGERS = self::GID_SPACE . 'GE-'; + private string $DISPLAY_PREFIX_MANAGER_GROUP; - public static function getPrefix(): string { - return self::PREFIX_GID_MANAGERS; - } - - public function create(Space $space): IGroup { - $group = $this->groupManager->createGroup(self::PREFIX_GID_MANAGERS . $space->getId()); + public function __construct(IAppConfig $appConfig) { + $this->DISPLAY_PREFIX_MANAGER_GROUP = $appConfig->getAppValue('DISPLAY_PREFIX_MANAGER_GROUP'); + } - if (is_null($group)) { - throw new CreateGroupException('Error to create a Space Manager group.', Http::STATUS_CONFLICT); - } + public function get(int $spaceId): string { + return self::PREFIX_GID_MANAGERS . $spaceId; + } - $group->setDisplayName(self::getDisplayPrefixManagerGroup() . $space->getSpaceName()); + public function getGidPrefix(): string { + return self::PREFIX_GID_MANAGERS; + } - return $group; - } + public function getDisplayPrefix(): string + { + return $this->DISPLAY_PREFIX_MANAGER_GROUP; + } } diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 585d3f6a3..6a32b3fff 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -37,7 +37,9 @@ class UserService { public function __construct( private IGroupManager $groupManager, private IUserSession $userSession, - private LoggerInterface $logger + private LoggerInterface $logger, + private UserGroup $userGroup, + private WorkspaceManagerGroup $workspaceManagerGroup ) { } @@ -92,7 +94,7 @@ public function isUserGeneralAdmin(): bool { * @return boolean true if user is a space manager, false otherwise */ public function isSpaceManager(): bool { - $workspaceAdminGroups = $this->groupManager->search(WorkspaceManagerGroup::getPrefix()); + $workspaceAdminGroups = $this->groupManager->search($this->workspaceManagerGroup->getGidPrefix()); foreach ($workspaceAdminGroups as $group) { if ($this->groupManager->isInGroup($this->userSession->getUser()->getUID(), $group->getGID())) { return true; @@ -117,7 +119,7 @@ public function canAccessApp(): bool { * @return boolean true if user is space manager of the specified workspace, false otherwise */ public function isSpaceManagerOfSpace(array $space): bool { - if ($this->groupManager->isInGroup($this->userSession->getUser()->getUID(), WorkspaceManagerGroup::get($space['id']))) { + if ($this->groupManager->isInGroup($this->userSession->getUser()->getUID(), $this->workspaceManagerGroup->get($space['id']))) { return true; } return false; @@ -133,8 +135,8 @@ public function removeGEFromWM(IUser $user, array|object $space): void { // Checks if the user is member of the GE- group of another workspace foreach ($groups as $group) { $gid = $group->getGID(); - if (strpos($gid, WorkspaceManagerGroup::get($space['id'])) === 0 && - $gid !== UserGroup::get($space['id']) + if (strpos($gid, $this->workspaceManagerGroup->get($space['id'])) === 0 && + $gid !== $this->userGroup->get($space['id']) ) { $found = true; break; diff --git a/lib/Service/WorkspaceService.php b/lib/Service/WorkspaceService.php index fe1071cf0..40396c46e 100644 --- a/lib/Service/WorkspaceService.php +++ b/lib/Service/WorkspaceService.php @@ -43,7 +43,9 @@ public function __construct( private IUserSession $userSession, private LoggerInterface $logger, private SpaceMapper $spaceMapper, - private UserService $userService + private UserGroup $userGroup, + private UserService $userService, + private WorkspaceManagerGroup $workspaceManagerGroup ) { } @@ -133,7 +135,7 @@ public function autoComplete(string $term, array|string $space): array { $role = 'user'; if ($this->groupManager->isInGroup( $user->getUID(), - WorkspaceManagerGroup::get($space['id'])) + $this->workspaceManagerGroup->get($space['id'])) ) { $role = 'admin'; } @@ -169,7 +171,7 @@ public function addUsersInfo(string|array $workspace): array { // from the workspace's manager group, as users may be members of both groups $this->logger->debug('Adding users information to workspace'); $users = array(); - $group = $this->groupManager->get(UserGroup::get($workspace['id'])); + $group = $this->groupManager->get($this->userGroup->get($workspace['id'])); // TODO Handle is_null($group) better (remove workspace from list?) if (!is_null($group)) { foreach ($group->getUsers() as $user) { @@ -177,7 +179,7 @@ public function addUsersInfo(string|array $workspace): array { }; } // TODO Handle is_null($group) better (remove workspace from list?) - $group = $this->groupManager->get(WorkspaceManagerGroup::get($workspace['id'])); + $group = $this->groupManager->get($this->workspaceManagerGroup->get($workspace['id'])); if (!is_null($group)) { foreach ($group->getUsers() as $user) { $users[$user->getUID()] = $this->userService->formatUser($user, $workspace, 'admin'); diff --git a/lib/Upgrade/UpgradeV300.php b/lib/Upgrade/UpgradeV300.php index 174d29ad2..cca30feb4 100644 --- a/lib/Upgrade/UpgradeV300.php +++ b/lib/Upgrade/UpgradeV300.php @@ -36,16 +36,22 @@ class UpgradeV300 implements UpgradeInterface { private IAppConfig $appConfig; private IGroupManager $groupManager; private SpaceMapper $spaceMapper; + private UserGroup $userGroup; + private WorkspaceManagerGroup $workspaceManagerGroup; public function __construct( GroupFoldersGroupsMapper $groupfoldersGroupsMapper, IAppConfig $appConfig, IGroupManager $groupManager, - SpaceMapper $spaceMapper) { + SpaceMapper $spaceMapper, + UserGroup $userGroup, + WorkspaceManagerGroup $workspaceManagerGroup) { $this->appConfig = $appConfig; $this->groupfoldersGroupsMapper = $groupfoldersGroupsMapper; $this->groupManager = $groupManager; $this->spaceMapper = $spaceMapper; + $this->userGroup = $userGroup; + $this->workspaceManagerGroup = $workspaceManagerGroup; } public function upgrade(): void { @@ -72,7 +78,7 @@ private function changeConventionForSubgroups(): void { } private function changePrefixForWorkspaceManagerGroups(): void { - $workspaceManagerGroups = $this->groupManager->search(WorkspaceManagerGroup::getPrefix()); + $workspaceManagerGroups = $this->groupManager->search($this->workspaceManagerGroup->getGidPrefix()); foreach ($workspaceManagerGroups as $group) { $groupname = $group->getGID(); $groupnameSplitted = explode('-', $groupname); @@ -85,7 +91,7 @@ private function changePrefixForWorkspaceManagerGroups(): void { } private function changePrefixForWorkspaceUserGroups(): void { - $userGroups = $this->groupManager->search(UserGroup::getPrefix()); + $userGroups = $this->groupManager->search($this->userGroup->getGidPrefix()); foreach ($userGroups as $group) { $groupname = $group->getGID(); $groupnameSplitted = explode('-', $groupname); From b7935801888fcfcf0234fbc829cc494095d74cd2 Mon Sep 17 00:00:00 2001 From: Baptiste Fotia Date: Mon, 10 Jul 2023 10:51:26 +0200 Subject: [PATCH 2/3] refactor(): Move group files in the Groups folder I moved the group files in the new Groups folder and the namespace that wear the same name. Signed-off-by: Baptiste Fotia --- lib/Controller/GroupController.php | 6 +++--- lib/Controller/WorkspaceController.php | 6 +++--- lib/{Service/Group => Groups}/GroupFormatter.php | 2 +- .../GroupWorkspaceInterface.php} | 4 ++-- lib/{Service/Group => Groups/Workspace}/UserGroup.php | 6 +++--- .../Group => Groups/Workspace}/WorkspaceManagerGroup.php | 6 +++--- lib/Service/Group/GroupsWorkspace.php | 3 ++- lib/Service/Group/GroupsWorkspaceService.php | 4 ++-- lib/Service/UserService.php | 4 ++-- lib/Service/WorkspaceService.php | 4 ++-- lib/Upgrade/UpgradeV300.php | 4 ++-- 11 files changed, 25 insertions(+), 24 deletions(-) rename lib/{Service/Group => Groups}/GroupFormatter.php (96%) rename lib/{Service/Group/IGroupWorkspace.php => Groups/GroupWorkspaceInterface.php} (93%) rename lib/{Service/Group => Groups/Workspace}/UserGroup.php (90%) rename lib/{Service/Group => Groups/Workspace}/WorkspaceManagerGroup.php (90%) diff --git a/lib/Controller/GroupController.php b/lib/Controller/GroupController.php index 0b3332681..447fee486 100644 --- a/lib/Controller/GroupController.php +++ b/lib/Controller/GroupController.php @@ -26,11 +26,11 @@ namespace OCA\Workspace\Controller; use OCA\Workspace\Service\Group\GroupFolder\GroupFolderManage; -use OCA\Workspace\Service\Group\GroupFormatter; +use OCA\Workspace\Groups\GroupFormatter; use OCA\Workspace\Service\Group\GroupsWorkspaceService; use OCA\Workspace\Service\Group\ManagersWorkspace; -use OCA\Workspace\Service\Group\UserGroup; -use OCA\Workspace\Service\Group\WorkspaceManagerGroup; +use OCA\Workspace\Groups\Workspace\UserGroup; +use OCA\Workspace\Groups\Workspace\WorkspaceManagerGroup; use OCA\Workspace\Service\User\UserFormatter; use OCA\Workspace\Service\User\UserWorkspace; use OCA\Workspace\Service\UserService; diff --git a/lib/Controller/WorkspaceController.php b/lib/Controller/WorkspaceController.php index bfbc634a0..57ab9eefd 100644 --- a/lib/Controller/WorkspaceController.php +++ b/lib/Controller/WorkspaceController.php @@ -38,13 +38,13 @@ use OCA\Workspace\CreateGroupException; use OCA\Workspace\Service\SpaceService; use OCP\AppFramework\Http\JSONResponse; -use OCA\Workspace\Service\Group\UserGroup; +use OCA\Workspace\Groups\Workspace\UserGroup; use OCA\Workspace\CreateWorkspaceException; use OCA\Workspace\Service\WorkspaceService; -use OCA\Workspace\Service\Group\GroupFormatter; +use OCA\Workspace\Groups\GroupFormatter; use OCA\Workspace\Service\Group\GroupsWorkspace; use OCA\Workspace\Service\Group\ManagersWorkspace; -use OCA\Workspace\Service\Group\WorkspaceManagerGroup; +use OCA\Workspace\Groups\Workspace\WorkspaceManagerGroup; use OCA\Workspace\Service\Workspace\WorkspaceCheckService; class WorkspaceController extends Controller { diff --git a/lib/Service/Group/GroupFormatter.php b/lib/Groups/GroupFormatter.php similarity index 96% rename from lib/Service/Group/GroupFormatter.php rename to lib/Groups/GroupFormatter.php index 4295a068e..9636b8353 100644 --- a/lib/Service/Group/GroupFormatter.php +++ b/lib/Groups/GroupFormatter.php @@ -22,7 +22,7 @@ * */ -namespace OCA\Workspace\Service\Group; +namespace OCA\Workspace\Groups; use OCP\IGroup; diff --git a/lib/Service/Group/IGroupWorkspace.php b/lib/Groups/GroupWorkspaceInterface.php similarity index 93% rename from lib/Service/Group/IGroupWorkspace.php rename to lib/Groups/GroupWorkspaceInterface.php index 82881a864..aaae7e197 100644 --- a/lib/Service/Group/IGroupWorkspace.php +++ b/lib/Groups/GroupWorkspaceInterface.php @@ -21,9 +21,9 @@ * */ -namespace OCA\Workspace\Service\Group; +namespace OCA\Workspace\Groups; -interface IGroupWorkspace { +interface GroupWorkspaceInterface { /** * @return string - Just the GID with the spaceId. diff --git a/lib/Service/Group/UserGroup.php b/lib/Groups/Workspace/UserGroup.php similarity index 90% rename from lib/Service/Group/UserGroup.php rename to lib/Groups/Workspace/UserGroup.php index ec8695f87..6fbb9a7ce 100644 --- a/lib/Service/Group/UserGroup.php +++ b/lib/Groups/Workspace/UserGroup.php @@ -21,12 +21,12 @@ * */ -namespace OCA\Workspace\Service\Group; +namespace OCA\Workspace\Groups\Workspace; use OCP\AppFramework\Services\IAppConfig; -use OCA\Workspace\Service\Group\IGroupWorkspace; +use OCA\Workspace\Groups\GroupWorkspaceInterface; -class UserGroup implements IGroupWorkspace { +class UserGroup implements GroupWorkspaceInterface { private const GID_SPACE = 'SPACE-'; private const PREFIX_GID_USERS = self::GID_SPACE . 'U-'; diff --git a/lib/Service/Group/WorkspaceManagerGroup.php b/lib/Groups/Workspace/WorkspaceManagerGroup.php similarity index 90% rename from lib/Service/Group/WorkspaceManagerGroup.php rename to lib/Groups/Workspace/WorkspaceManagerGroup.php index 3ee7a1805..e1d4a9b6a 100644 --- a/lib/Service/Group/WorkspaceManagerGroup.php +++ b/lib/Groups/Workspace/WorkspaceManagerGroup.php @@ -21,12 +21,12 @@ * */ -namespace OCA\Workspace\Service\Group; +namespace OCA\Workspace\Groups\Workspace; use OCP\AppFramework\Services\IAppConfig; -use OCA\Workspace\Service\Group\IGroupWorkspace; +use OCA\Workspace\Groups\GroupWorkspaceInterface; -class WorkspaceManagerGroup implements IGroupWorkspace { +class WorkspaceManagerGroup implements GroupWorkspaceInterface { private const GID_SPACE = 'SPACE-'; private const PREFIX_GID_MANAGERS = self::GID_SPACE . 'GE-'; diff --git a/lib/Service/Group/GroupsWorkspace.php b/lib/Service/Group/GroupsWorkspace.php index a652c211d..8bee1c22a 100644 --- a/lib/Service/Group/GroupsWorkspace.php +++ b/lib/Service/Group/GroupsWorkspace.php @@ -25,6 +25,7 @@ use OCA\Workspace\CreateGroupException; use OCA\Workspace\Db\Space; +use OCA\Workspace\Groups\GroupWorkspaceInterface; use OCP\AppFramework\Http; use OCP\AppFramework\Services\IAppConfig; use OCP\IGroup; @@ -39,7 +40,7 @@ public function __construct(private IAppConfig $appConfig, /** * Use the OCA\Workspace\Db\Space to get its spaceId and spaceName. */ - public function create(IGroupWorkspace $groupWorkspace, Space $space): IGroup { + public function create(GroupWorkspaceInterface $groupWorkspace, Space $space): IGroup { $group = $this->groupManager->createGroup($groupWorkspace->getGidPrefix() . $space->getId()); if (is_null($group)) { diff --git a/lib/Service/Group/GroupsWorkspaceService.php b/lib/Service/Group/GroupsWorkspaceService.php index 1e2313ce5..011fd88d7 100644 --- a/lib/Service/Group/GroupsWorkspaceService.php +++ b/lib/Service/Group/GroupsWorkspaceService.php @@ -28,8 +28,8 @@ use OCP\IGroup; use OCP\IGroupManager; use OCA\Workspace\Exceptions\GroupException; -use OCA\Workspace\Service\Group\UserGroup; -use OCA\Workspace\Service\Group\WorkspaceManagerGroup; +use OCA\Workspace\Groups\Workspace\UserGroup; +use OCA\Workspace\Groups\Workspace\WorkspaceManagerGroup; class GroupsWorkspaceService { public function __construct(private IGroupManager $groupManager, diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 6a32b3fff..ca20d6c87 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -26,8 +26,8 @@ namespace OCA\Workspace\Service; use OCA\Workspace\Service\Group\ManagersWorkspace; -use OCA\Workspace\Service\Group\UserGroup; -use OCA\Workspace\Service\Group\WorkspaceManagerGroup; +use OCA\Workspace\Groups\Workspace\UserGroup; +use OCA\Workspace\Groups\Workspace\WorkspaceManagerGroup; use OCP\IGroupManager; use OCP\IUser; use OCP\IUserSession; diff --git a/lib/Service/WorkspaceService.php b/lib/Service/WorkspaceService.php index 40396c46e..cf4d8b4d6 100644 --- a/lib/Service/WorkspaceService.php +++ b/lib/Service/WorkspaceService.php @@ -26,8 +26,8 @@ namespace OCA\Workspace\Service; use OCA\Workspace\Db\SpaceMapper; -use OCA\Workspace\Service\Group\UserGroup; -use OCA\Workspace\Service\Group\WorkspaceManagerGroup; +use OCA\Workspace\Groups\Workspace\UserGroup; +use OCA\Workspace\Groups\Workspace\WorkspaceManagerGroup; use OCP\IGroupManager; use OCP\IUser; use OCP\IUserManager; diff --git a/lib/Upgrade/UpgradeV300.php b/lib/Upgrade/UpgradeV300.php index cca30feb4..1b82b4936 100644 --- a/lib/Upgrade/UpgradeV300.php +++ b/lib/Upgrade/UpgradeV300.php @@ -26,8 +26,8 @@ use OCA\Workspace\Db\GroupFoldersGroupsMapper; use OCA\Workspace\Db\SpaceMapper; -use OCA\Workspace\Service\Group\UserGroup; -use OCA\Workspace\Service\Group\WorkspaceManagerGroup; +use OCA\Workspace\Groups\Workspace\UserGroup; +use OCA\Workspace\Groups\Workspace\WorkspaceManagerGroup; use OCP\AppFramework\Services\IAppConfig; use OCP\IGroupManager; From 763340c73f95e79f7707163914e2f3ec11d86914 Mon Sep 17 00:00:00 2001 From: Baptiste Fotia Date: Mon, 10 Jul 2023 14:41:32 +0200 Subject: [PATCH 3/3] refactor(): Rename and move GroupsWorkspaceService I renamed GroupsWorkspaceService to GroupManager and moved in the lib/Groups folder and its namespace is "OCA\Workspace\Groups" now. Signed-off-by: Baptiste Fotia --- lib/Controller/GroupController.php | 18 +++++++++--------- .../GroupManager.php} | 4 ++-- lib/Service/User/UserFormatter.php | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) rename lib/{Service/Group/GroupsWorkspaceService.php => Groups/GroupManager.php} (97%) diff --git a/lib/Controller/GroupController.php b/lib/Controller/GroupController.php index 447fee486..98bc95990 100644 --- a/lib/Controller/GroupController.php +++ b/lib/Controller/GroupController.php @@ -27,7 +27,7 @@ use OCA\Workspace\Service\Group\GroupFolder\GroupFolderManage; use OCA\Workspace\Groups\GroupFormatter; -use OCA\Workspace\Service\Group\GroupsWorkspaceService; +use OCA\Workspace\Groups\GroupManager; use OCA\Workspace\Service\Group\ManagersWorkspace; use OCA\Workspace\Groups\Workspace\UserGroup; use OCA\Workspace\Groups\Workspace\WorkspaceManagerGroup; @@ -48,7 +48,7 @@ class GroupController extends Controller { ]; public function __construct( - private GroupsWorkspaceService $groupsWorkspace, + private GroupManager $groupWorkspaceManager, private IGroupManager $groupManager, private IUserManager $userManager, private LoggerInterface $logger, @@ -311,8 +311,8 @@ public function transferUsersToGroups(string $spaceId, $groups = GroupFormatter::formatGroups( array_merge( [ - $this->groupsWorkspace->getWorkspaceManagerGroup($spaceId), - $this->groupsWorkspace->getUserGroup($spaceId) + $this->groupWorkspaceManager->getWorkspaceManagerGroup($spaceId), + $this->groupWorkspaceManager->getUserGroup($spaceId) ], array_map(function ($groupName) { return $this->groupManager->get($groupName); @@ -325,11 +325,11 @@ public function transferUsersToGroups(string $spaceId, $allUsers = $this->userWorkspace->getUsersFromGroup($groupsName); $usersFromAdvancedPermissions = $this->userWorkspace->getUsersFromGroup($groupsNameFromAdvancedPermissions); - $this->groupsWorkspace - ->transferUsersToGroup($allUsers, $this->groupsWorkspace->getUserGroup($spaceId)); - $this->groupsWorkspace - ->transferUsersToGroup($usersFromAdvancedPermissions, $this->groupsWorkspace->getWorkspaceManagerGroup($spaceId)); - $this->groupsWorkspace + $this->groupWorkspaceManager + ->transferUsersToGroup($allUsers, $this->groupWorkspaceManager->getUserGroup($spaceId)); + $this->groupWorkspaceManager + ->transferUsersToGroup($usersFromAdvancedPermissions, $this->groupWorkspaceManager->getWorkspaceManagerGroup($spaceId)); + $this->groupWorkspaceManager ->transferUsersToGroup($usersFromAdvancedPermissions, $this->groupManager->get(ManagersWorkspace::WORKSPACES_MANAGERS)); $users = $this->userFormatter->formatUsers($allUsers, $groupfolder, $spaceId); diff --git a/lib/Service/Group/GroupsWorkspaceService.php b/lib/Groups/GroupManager.php similarity index 97% rename from lib/Service/Group/GroupsWorkspaceService.php rename to lib/Groups/GroupManager.php index 011fd88d7..a0f798012 100644 --- a/lib/Service/Group/GroupsWorkspaceService.php +++ b/lib/Groups/GroupManager.php @@ -22,7 +22,7 @@ * */ -namespace OCA\Workspace\Service\Group; +namespace OCA\Workspace\Groups; use OCP\IUser; use OCP\IGroup; @@ -31,7 +31,7 @@ use OCA\Workspace\Groups\Workspace\UserGroup; use OCA\Workspace\Groups\Workspace\WorkspaceManagerGroup; -class GroupsWorkspaceService { +class GroupManager { public function __construct(private IGroupManager $groupManager, private WorkspaceManagerGroup $workspaceManagerGroup, private UserGroup $userGroup) { diff --git a/lib/Service/User/UserFormatter.php b/lib/Service/User/UserFormatter.php index a46970d56..e8e77e297 100644 --- a/lib/Service/User/UserFormatter.php +++ b/lib/Service/User/UserFormatter.php @@ -25,11 +25,11 @@ namespace OCA\Workspace\Service\User; use OCA\Workspace\Roles; -use OCA\Workspace\Service\Group\GroupsWorkspaceService; +use OCA\Workspace\Groups\GroupManager; use OCP\IUser; class UserFormatter { - public function __construct(private GroupsWorkspaceService $groupsWorkspace) { + public function __construct(private GroupManager $groupsWorkspace) { } /**