/** * Delete a workspace * * @param Workspace $workspace A workspace to delete * @return void */ public function deleteAction(Workspace $workspace) { if ($workspace->isPersonalWorkspace()) { $this->redirect('index'); } $dependentWorkspaces = $this->workspaceRepository->findByBaseWorkspace($workspace); if (count($dependentWorkspaces) > 0) { $dependentWorkspaceTitles = []; /** @var Workspace $dependentWorkspace */ foreach ($dependentWorkspaces as $dependentWorkspace) { $dependentWorkspaceTitles[] = $dependentWorkspace->getTitle(); } $message = $this->translator->translateById('workspaces.workspaceCannotBeDeletedBecauseOfDependencies', [$workspace->getTitle(), implode(', ', $dependentWorkspaceTitles)], null, null, 'Modules', 'Neos.Neos'); $this->addFlashMessage($message, '', Message::SEVERITY_WARNING); $this->redirect('index'); } $nodesCount = 0; try { $nodesCount = $this->publishingService->getUnpublishedNodesCount($workspace); } catch (\Exception $exception) { $message = $this->translator->translateById('workspaces.notDeletedErrorWhileFetchingUnpublishedNodes', [$workspace->getTitle()], null, null, 'Modules', 'Neos.Neos'); $this->addFlashMessage($message, '', Message::SEVERITY_WARNING); $this->redirect('index'); } if ($nodesCount > 0) { $message = $this->translator->translateById('workspaces.workspaceCannotBeDeletedBecauseOfUnpublishedNodes', [$workspace->getTitle(), $nodesCount], $nodesCount, null, 'Modules', 'Neos.Neos'); $this->addFlashMessage($message, '', Message::SEVERITY_WARNING); $this->redirect('index'); } $this->workspaceRepository->remove($workspace); $this->addFlashMessage($message = $this->translator->translateById('workspaces.workspaceHasBeenRemoved', [$workspace->getTitle()], null, null, 'Modules', 'Neos.Neos')); $this->redirect('index'); }
/** * Checks if the current user may transfer ownership of the given workspace * * In future versions, this logic may be implemented in Neos in a more generic way (for example, by means of an * ACL object), but for now, this method exists in order to at least centralize and encapsulate the required logic. * * @param Workspace $workspace The workspace * @return boolean */ public function currentUserCanTransferOwnershipOfWorkspace(Workspace $workspace) { if ($workspace->isPersonalWorkspace()) { return false; } // The privilege to manage shared workspaces is needed, because regular editors should not change ownerships // of their internal workspaces, even if it was technically possible, because they wouldn't be able to change // ownership back to themselves. return $this->privilegeManager->isPrivilegeTargetGranted('Neos.Neos:Backend.Module.Management.Workspaces.ManageInternalWorkspaces'); }
/** * @test */ public function isPersonalWorkspaceChecksIfTheWorkspaceNameStartsWithUser() { $liveWorkspace = new Workspace('live'); $personalWorkspace = new Workspace('user-admin', $liveWorkspace); $this->assertFalse($liveWorkspace->isPersonalWorkspace()); $this->assertTrue($personalWorkspace->isPersonalWorkspace()); }