Returns the currently logged in user, if any
public getCurrentUser ( ) : |
||
return | The currently logged in user, or null |
/** * Returns the name of the currently logged in user's personal workspace (even if that might not exist at that time). * If no user is logged in this method returns null. * * @return string * @api */ public function getPersonalWorkspaceName() { $currentUser = $this->userDomainService->getCurrentUser(); if (!$currentUser instanceof User) { return null; } $username = $this->userDomainService->getUsername($currentUser); return $username === null ? null : UserUtility::getPersonalWorkspaceNameForUsername($username); }
/** * Update/adds a user preference * * @param string $key The key of the preference to update/add * @param string $value The value of the preference * @return void */ public function updateAction($key, $value) { // TODO: This should be done in an earlier stage (TypeConverter ?) if (strtolower($value) === 'false') { $value = false; } elseif (strtolower($value) === 'true') { $value = true; } $user = $this->userService->getCurrentUser(); $user->getPreferences()->set($key, $value); $this->userService->updateUser($user); $this->throwStatus(204, 'User preferences have been updated'); }
/** * @return void */ protected function initializeAction() { parent::initializeAction(); $translationHelper = new TranslationHelper(); $this->setTitle($translationHelper->translate($this->moduleConfiguration['label']) . ' :: ' . $translationHelper->translate(str_replace('label', 'action.', $this->moduleConfiguration['label']) . $this->request->getControllerActionName())); if ($this->arguments->hasArgument('user')) { $propertyMappingConfigurationForUser = $this->arguments->getArgument('user')->getPropertyMappingConfiguration(); $propertyMappingConfigurationForUserName = $propertyMappingConfigurationForUser->forProperty('user.name'); $propertyMappingConfigurationForPrimaryAccount = $propertyMappingConfigurationForUser->forProperty('user.primaryAccount'); $propertyMappingConfigurationForPrimaryAccount->setTypeConverterOption(PersistentObjectConverter::class, PersistentObjectConverter::CONFIGURATION_TARGET_TYPE, Account::class); /** @var PropertyMappingConfiguration $propertyMappingConfiguration */ foreach (array($propertyMappingConfigurationForUser, $propertyMappingConfigurationForUserName, $propertyMappingConfigurationForPrimaryAccount) as $propertyMappingConfiguration) { $propertyMappingConfiguration->setTypeConverterOption(PersistentObjectConverter::class, PersistentObjectConverter::CONFIGURATION_MODIFICATION_ALLOWED, true); } } $this->currentUser = $this->userService->getCurrentUser(); }
/** * Shows a list of existing workspaces * * @return string */ public function indexAction() { $user = $this->userService->getCurrentUser(); $workspacesArray = []; /** @var Workspace $workspace */ foreach ($this->workspaceRepository->findAll() as $workspace) { // FIXME: This check should be implemented through a specialized Workspace Privilege or something similar if ($workspace->getOwner() !== null && $workspace->getOwner() !== $user) { continue; } $workspaceArray = ['name' => $workspace->getName(), 'title' => $workspace->getTitle(), 'description' => $workspace->getDescription(), 'baseWorkspace' => $workspace->getBaseWorkspace()]; if ($user !== null) { $workspaceArray['readonly'] = !$this->userService->currentUserCanPublishToWorkspace($workspace); } $workspacesArray[] = $workspaceArray; } $this->view->assign('workspaces', $workspacesArray); }
/** * Create a workspace * * @Flow\Validate(argumentName="title", type="\Neos\Flow\Validation\Validator\NotEmptyValidator") * @param string $title Human friendly title of the workspace, for example "Christmas Campaign" * @param Workspace $baseWorkspace Workspace the new workspace should be based on * @param string $visibility Visibility of the new workspace, must be either "internal" or "shared" * @param string $description A description explaining the purpose of the new workspace * @return void */ public function createAction($title, Workspace $baseWorkspace, $visibility, $description = '') { $workspace = $this->workspaceRepository->findOneByTitle($title); if ($workspace instanceof Workspace) { $this->addFlashMessage($this->translator->translateById('workspaces.workspaceWithThisTitleAlreadyExists', [], null, null, 'Modules', 'Neos.Neos'), '', Message::SEVERITY_WARNING); $this->redirect('new'); } $workspaceName = Utility::renderValidNodeName($title) . '-' . substr(base_convert(microtime(false), 10, 36), -5, 5); while ($this->workspaceRepository->findOneByName($workspaceName) instanceof Workspace) { $workspaceName = Utility::renderValidNodeName($title) . '-' . substr(base_convert(microtime(false), 10, 36), -5, 5); } if ($visibility === 'private') { $owner = $this->userService->getCurrentUser(); } else { $owner = null; } $workspace = new Workspace($workspaceName, $baseWorkspace, $owner); $workspace->setTitle($title); $workspace->setDescription($description); $this->workspaceRepository->add($workspace); $this->redirect('index'); }