/**
  * Render user initials or an abbreviated name for a given username. If the account was deleted, use the username as fallback.
  *
  * @param string $format Supported are "fullFirstName" and "initials"
  * @return string
  */
 public function render($format = 'initials')
 {
     if (!in_array($format, array('fullFirstName', 'initials', 'fullName'))) {
         throw new \InvalidArgumentException(sprintf('Format "%s" given to history:userInitials(), only supporting "fullFirstName", "initials" and "fullName".', $format), 1415705861);
     }
     $username = $this->renderChildren();
     /* @var $requestedUser Person */
     $requestedUser = $this->domainUserService->getUser($username);
     if ($requestedUser === null || $requestedUser->getName() === null) {
         return $username;
     }
     $currentUser = $this->userService->getBackendUser();
     if ($currentUser) {
         if ($currentUser === $requestedUser) {
             $translationHelper = new TranslationHelper();
             $you = $translationHelper->translate('you', null, [], 'Main', 'Neos.Neos');
         }
     }
     switch ($format) {
         case 'initials':
             return mb_substr($requestedUser->getName()->getFirstName(), 0, 1) . mb_substr($requestedUser->getName()->getLastName(), 0, 1);
         case 'fullFirstName':
             return isset($you) ? $you : $requestedUser->getName()->getFirstName() . ' ' . mb_substr($requestedUser->getName()->getLastName(), 0, 1) . '.';
         case 'fullName':
             return isset($you) ? $you : $requestedUser->getName()->getFullName();
     }
 }
 /**
  * Returns an array of usage reference objects.
  *
  * @param AssetInterface $asset
  * @return array<\Neos\Neos\Domain\Model\Dto\AssetUsageInNodeProperties>
  * @throws \Neos\ContentRepository\Exception\NodeConfigurationException
  */
 public function getUsageReferences(AssetInterface $asset)
 {
     $assetIdentifier = $this->persistenceManager->getIdentifierByObject($asset);
     if (isset($this->firstlevelCache[$assetIdentifier])) {
         return $this->firstlevelCache[$assetIdentifier];
     }
     $userWorkspace = $this->userService->getPersonalWorkspace();
     $relatedNodes = [];
     foreach ($this->getRelatedNodes($asset) as $relatedNodeData) {
         $accessible = $this->domainUserService->currentUserCanReadWorkspace($relatedNodeData->getWorkspace());
         if ($accessible) {
             $context = $this->createContextMatchingNodeData($relatedNodeData);
         } else {
             $context = $this->createContentContext($userWorkspace->getName());
         }
         $site = $context->getCurrentSite();
         $node = $this->nodeFactory->createFromNodeData($relatedNodeData, $context);
         $flowQuery = new FlowQuery([$node]);
         /** @var \Neos\ContentRepository\Domain\Model\NodeInterface $documentNode */
         $documentNode = $flowQuery->closest('[instanceof Neos.Neos:Document]')->get(0);
         $relatedNodes[] = new AssetUsageInNodeProperties($asset, $site, $documentNode, $node, $accessible);
     }
     $this->firstlevelCache[$assetIdentifier] = $relatedNodes;
     return $this->firstlevelCache[$assetIdentifier];
 }
 /**
  * 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);
 }
 /**
  * Returns TRUE, if the specified user ($value) does not exist yet.
  *
  * If at least one error occurred, the result is FALSE.
  *
  * @param mixed $value The value that should be validated
  * @return void
  * @throws InvalidSubjectException
  */
 protected function isValid($value)
 {
     if (!is_string($value)) {
         throw new InvalidSubjectException('The given username was not a string.', 1325155784);
     }
     if ($this->userService->getUser($value) !== null) {
         $this->addError('The username is already in use.', 1325156008);
     }
 }
 /**
  * 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');
 }
 /**
  * @test
  */
 public function getPersonalWorkspaceNameReturnsTheUsersWorkspaceNameIfAUserIsLoggedIn()
 {
     $mockUser = $this->getMockBuilder(User::class)->disableOriginalConstructor()->getMock();
     $this->mockUserDomainService->expects($this->atLeastOnce())->method('getCurrentUser')->will($this->returnValue($mockUser));
     $this->mockUserDomainService->expects($this->atLeastOnce())->method('getUserName')->with($mockUser)->will($this->returnValue('TheUserName'));
     $this->assertSame('user-TheUserName', $this->userService->getPersonalWorkspaceName());
 }
 /**
  * Delete an electronic address action
  *
  * @param User $user
  * @param ElectronicAddress $electronicAddress
  * @return void
  */
 public function deleteElectronicAddressAction(User $user, ElectronicAddress $electronicAddress)
 {
     $user->removeElectronicAddress($electronicAddress);
     $this->userService->updateUser($user);
     $this->addFlashMessage('The electronic address "%s" (%s) has been deleted for "%s".', 'Electronic address removed', Message::SEVERITY_NOTICE, array(htmlspecialchars($electronicAddress->getIdentifier()), htmlspecialchars($electronicAddress->getType()), htmlspecialchars($user->getName())), 1412374678);
     $this->redirect('edit', null, null, array('user' => $user));
 }
示例#8
0
 /**
  * Creates an array of user names and their respective labels which are possible owners for a workspace.
  *
  * @return array
  */
 protected function prepareOwnerOptions()
 {
     $ownerOptions = ['' => '-'];
     foreach ($this->userService->getUsers() as $user) {
         /** @var User $user */
         $ownerOptions[$this->persistenceManager->getIdentifierByObject($user)] = $user->getLabel();
     }
     return $ownerOptions;
 }
 /**
  * Create a workspace
  *
  * @param string $workspaceName
  * @param Workspace $baseWorkspace
  * @param string $ownerAccountIdentifier
  * @return string
  */
 public function createAction($workspaceName, Workspace $baseWorkspace, $ownerAccountIdentifier = null)
 {
     $existingWorkspace = $this->workspaceRepository->findByIdentifier($workspaceName);
     if ($existingWorkspace !== null) {
         $this->throwStatus(409, 'Workspace already exists', '');
     }
     if ($ownerAccountIdentifier !== null) {
         $owner = $this->userService->getUser($ownerAccountIdentifier);
         if ($owner === null) {
             $this->throwStatus(422, 'Requested owner account does not exist', '');
         }
     } else {
         $owner = null;
     }
     $workspace = new Workspace($workspaceName, $baseWorkspace, $owner);
     $this->workspaceRepository->add($workspace);
     $this->throwStatus(201, 'Workspace created', '');
 }
 /**
  * Prepares a table row for output with data of the given User
  *
  * @param User $user The user
  * @return array
  */
 protected function getTableRowForUser(User $user)
 {
     $roleNames = array();
     $accountIdentifiers = array();
     foreach ($user->getAccounts() as $account) {
         /** @var Account $account */
         $authenticationProviderName = $account->getAuthenticationProviderName();
         if ($authenticationProviderName !== $this->userService->getDefaultAuthenticationProviderName()) {
             $authenticationProviderLabel = ' (' . (isset($this->authenticationProviderSettings[$authenticationProviderName]['label']) ? $this->authenticationProviderSettings[$authenticationProviderName]['label'] : $authenticationProviderName) . ')';
         } else {
             $authenticationProviderLabel = '';
         }
         $accountIdentifiers[] = $account->getAccountIdentifier() . $authenticationProviderLabel;
         foreach ($account->getRoles() as $role) {
             /** @var Role $role */
             $roleNames[] = $role->getIdentifier();
         }
     }
     return array($user->getName()->getFullName(), $user->getPrimaryElectronicAddress(), implode(', ', $accountIdentifiers), implode(', ', $roleNames), $user->isActive() ? 'yes' : 'no');
 }
 /**
  * Create a new workspace
  *
  * This command creates a new workspace.
  *
  * @param string $workspace Name of the workspace, for example "christmas-campaign"
  * @param string $baseWorkspace Name of the base workspace. If none is specified, "live" is assumed.
  * @param string $title Human friendly title of the workspace, for example "Christmas Campaign"
  * @param string $description A description explaining the purpose of the new workspace
  * @param string $owner The identifier of a User to own the workspace
  * @return void
  */
 public function createCommand($workspace, $baseWorkspace = 'live', $title = null, $description = null, $owner = '')
 {
     $workspaceName = $workspace;
     $workspace = $this->workspaceRepository->findOneByName($workspaceName);
     if ($workspace instanceof Workspace) {
         $this->outputLine('Workspace "%s" already exists', [$workspaceName]);
         $this->quit(1);
     }
     $baseWorkspaceName = $baseWorkspace;
     $baseWorkspace = $this->workspaceRepository->findOneByName($baseWorkspaceName);
     if (!$baseWorkspace instanceof Workspace) {
         $this->outputLine('The base workspace "%s" does not exist', [$baseWorkspaceName]);
         $this->quit(2);
     }
     if ($owner === '') {
         $owningUser = null;
     } else {
         $owningUser = $this->userService->getUser($owner);
         if ($owningUser === null) {
             $this->outputLine('The user "%s" specified as owner does not exist', [$owner]);
             $this->quit(3);
         }
     }
     if ($title === null) {
         $title = $workspaceName;
     }
     $workspace = new Workspace($workspaceName, $baseWorkspace, $owningUser);
     $workspace->setTitle($title);
     $workspace->setDescription($description);
     $this->workspaceRepository->add($workspace);
     if ($owningUser instanceof User) {
         $this->outputLine('Created a new workspace "%s", based on workspace "%s", owned by "%s".', [$workspaceName, $baseWorkspaceName, $owner]);
     } else {
         $this->outputLine('Created a new workspace "%s", based on workspace "%s".', [$workspaceName, $baseWorkspaceName]);
     }
 }
 /**
  * This method is called when the form of this step has been submitted
  *
  * @param array $formValues
  * @return void
  */
 public function postProcessFormValues(array $formValues)
 {
     $this->userService->createUser($formValues['username'], $formValues['password'], $formValues['firstName'], $formValues['lastName'], array('Neos.Neos:Administrator'));
 }