Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
29 changes: 28 additions & 1 deletion lib/Controller/WorkspaceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 })
Expand Down
2 changes: 1 addition & 1 deletion src/LeftSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<NcAppNavigation
aria-label="workspace navigation">
<ul class="ws-navigation-header">
<NcAppNavigationNewItem v-if="$root.$data.isUserGeneralAdmin || $root.$data.isSpaceManager"
<NcAppNavigationNewItem v-if="$root.$data.isUserGeneralAdmin || ($root.$data.isSpaceManager && $root.$data.allowWmWorkspaceCreation)"
class="input-new-item"
:class="isDarkTheme ? 'btn-dark' : 'btn-light'"
icon="icon-add"
Expand Down
Loading