diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 7c2ff005f..d40774d16 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -72,6 +72,7 @@ public function index($path = ''): TemplateResponse { $this->initialState->provideInitialState('isSpaceManager', $this->userService->isSpaceManager()); $this->initialState->provideInitialState('aclInheritPerUser', $this->config->getAppValue('groupfolders', 'acl-inherit-per-user', 'false') === 'true'); $this->initialState->provideInitialState('addedGroupDisabled', $this->appConfig->getAppValueBool('added_group_disabled', false)); + $this->initialState->provideInitialState('allowWmWorkspaceCreation', $this->appConfig->getAppValueBool('allow_wm_workspace_creation', false)); $currentUser = $this->session->getUser(); $generalManagerGroup = $this->groupManager->get(ManagersWorkspace::GENERAL_MANAGER); diff --git a/lib/Controller/WorkspaceController.php b/lib/Controller/WorkspaceController.php index 55c20aa5b..61fb6fbc6 100644 --- a/lib/Controller/WorkspaceController.php +++ b/lib/Controller/WorkspaceController.php @@ -27,6 +27,7 @@ use OCA\Workspace\Db\SpaceMapper; use OCA\Workspace\Exceptions\BadRequestException; +use OCA\Workspace\Exceptions\Middleware\ForbiddenException; use OCA\Workspace\Folder\RootFolder; use OCA\Workspace\Helper\GroupfolderHelper; use OCA\Workspace\Service\Formatter\WorkspaceFormatter; @@ -42,6 +43,7 @@ use OCP\AppFramework\Http\Attribute\FrontpageRoute; use OCP\AppFramework\Http\Attribute\NoAdminRequired; use OCP\AppFramework\Http\JSONResponse; +use OCP\AppFramework\Services\IAppConfig; use OCP\IGroupManager; use OCP\IRequest; use OCP\IURLGenerator; @@ -67,6 +69,7 @@ public function __construct( private SpaceManager $spaceManager, private IURLGenerator $urlGenerator, private ConnectedGroupsService $connectedGroups, + private IAppConfig $appConfig, public $AppName, ) { parent::__construct($AppName, $request); @@ -83,12 +86,36 @@ private function deleteBlankSpaceName(string $spaceName): string { /** * @NoAdminRequired - * @GeneralManagerRequired + * @WorkspaceManagerAccessMiddleware * @param string $spaceName */ public function createWorkspace(string $spaceName): JSONResponse { + + $workspaceManagersCanCreateWorkspace = + $this->userService->isSpaceManager() + && $this->appConfig->getAppValueBool('allow_wm_workspace_creation', false) + ; + + if ($this->userService->isSpaceManager()) { + if (false === $workspaceManagersCanCreateWorkspace) { + throw new ForbiddenException('You can not create a workspace.'); + } + } + $workspace = $this->spaceManager->create($spaceName); + if ($workspaceManagersCanCreateWorkspace) { + $spaceId = $workspace['id']; + $this->spaceManager->addUserAsWorkspaceManager( + $spaceId, + $this->userSession->getUser()->getUID() + ); + + $workspace = $this->spaceManager->get($spaceId); + $workspace['id_space'] = $workspace['id']; + $workspace['color'] = $workspace['color_code']; + } + return new JSONResponse( array_merge( $workspace, diff --git a/src/App.vue b/src/App.vue index 92968fbea..1cbf507a4 100644 --- a/src/App.vue +++ b/src/App.vue @@ -44,6 +44,7 @@ export default { const count = loadState('workspace', 'countWorkspaces') const isSpaceManager = loadState('workspace', 'isSpaceManager') const addedGroupDisabled = loadState('workspace', 'addedGroupDisabled') + const allowWmWorkspaceCreation = loadState('workspace', 'allowWmWorkspaceCreation') const canAccessApp = count > 0 this.$root.$data.isUserGeneralAdmin = isUserGeneralAdmin @@ -52,6 +53,7 @@ export default { this.$root.$data.userSession = userSession this.$root.$data.isSpaceManager = isSpaceManager this.$root.$data.addedGroupDisabled = addedGroupDisabled + this.$root.$data.allowWmWorkspaceCreation = allowWmWorkspaceCreation this.$store.dispatch('setCountTotalWorkspaces', { count }) this.$store.dispatch('setCountTotalWorkspacesByQuery', { count }) diff --git a/src/LeftSidebar.vue b/src/LeftSidebar.vue index 2ffdb7611..6b945d21f 100644 --- a/src/LeftSidebar.vue +++ b/src/LeftSidebar.vue @@ -23,7 +23,7 @@