/**
  * 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', 'TYPO3.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();
     }
 }
 /**
  * @test
  */
 public function getBackendUserReturnsTheCurrentlyLoggedInUserIfSecurityContextIsInitialized()
 {
     $mockUser = $this->getMockBuilder('TYPO3\\Neos\\Domain\\Model\\User')->disableOriginalConstructor()->getMock();
     $this->mockSecurityContext->expects($this->atLeastOnce())->method('canBeInitialized')->will($this->returnValue(TRUE));
     $this->mockSecurityContext->expects($this->atLeastOnce())->method('getPartyByType')->with('TYPO3\\Neos\\Domain\\Model\\User')->will($this->returnValue($mockUser));
     $this->assertSame($mockUser, $this->userService->getBackendUser());
 }
 /**
  * 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);
     }
     $accountIdentifier = $this->renderChildren();
     // TODO: search by credential source is still needed
     /* @var $account \TYPO3\Flow\Security\Account */
     $account = $this->accountRepository->findOneByAccountIdentifier($accountIdentifier);
     if ($account === null) {
         return $accountIdentifier;
     }
     /* @var $requestedUser Person */
     $requestedUser = $account->getParty();
     if ($requestedUser === null || $requestedUser->getName() === null) {
         return $accountIdentifier;
     }
     $currentUser = $this->userService->getBackendUser();
     if ($currentUser) {
         if ($currentUser === $requestedUser) {
             $translationHelper = new TranslationHelper();
             $you = $translationHelper->translateById('you', 'TYPO3.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();
     }
 }
 /**
  * Get the current rendering mode (editPreviewMode).
  * Will return a live mode when not in backend.
  *
  * @return UserInterfaceMode
  */
 public function findModeByCurrentUser()
 {
     if ($this->userService->getBackendUser() === NULL || !$this->privilegeManager->isPrivilegeTargetGranted('TYPO3.Neos:Backend.GeneralAccess')) {
         return $this->findModeByName('live');
     }
     /** @var \TYPO3\Neos\Domain\Model\User $user */
     $editPreviewMode = $this->userService->getUserPreference('contentEditing.editPreviewMode');
     if ($editPreviewMode === NULL) {
         $editPreviewMode = $this->defaultEditPreviewMode;
     }
     $mode = $this->findModeByName($editPreviewMode);
     return $mode;
 }
 /**
  * If the specified workspace or its root node does not exist yet, the workspace and root node will be created.
  *
  * This method is basically a safeguard for legacy and potentially broken websites where users might not have
  * their own workspace yet. In a normal setup, the Domain User Service is responsible for creating and deleting
  * user workspaces.
  *
  * @param string $workspaceName Name of the workspace
  * @return void
  */
 protected function createWorkspaceAndRootNodeIfNecessary($workspaceName)
 {
     $workspace = $this->workspaceRepository->findOneByName($workspaceName);
     if ($workspace === null) {
         $liveWorkspace = $this->workspaceRepository->findOneByName('live');
         $owner = $this->userService->getBackendUser();
         $workspace = new Workspace($workspaceName, $liveWorkspace, $owner);
         $this->workspaceRepository->add($workspace);
         $this->persistenceManager->whitelistObject($workspace);
     }
     $contentContext = $this->createContext($workspaceName);
     $rootNode = $contentContext->getRootNode();
     $this->persistenceManager->whitelistObject($rootNode);
     $this->persistenceManager->whitelistObject($rootNode->getNodeData());
     $this->persistenceManager->persistAll(true);
 }
 /**
  * Returns a specific URI string to redirect to after the login; or NULL if there is none.
  *
  * @param ActionRequest $actionRequest
  * @return string
  */
 public function getAfterLoginRedirectionUri(ActionRequest $actionRequest)
 {
     $user = $this->userService->getBackendUser();
     if ($user === NULL) {
         return NULL;
     }
     $workspaceName = $this->userService->getUserWorkspaceName();
     $this->createWorkspaceAndRootNodeIfNecessary($workspaceName);
     $uriBuilder = new UriBuilder();
     $uriBuilder->setRequest($actionRequest);
     $uriBuilder->setFormat('html');
     $uriBuilder->setCreateAbsoluteUri(TRUE);
     $contentContext = $this->createContext($workspaceName);
     $lastVisitedNode = $this->getLastVisitedNode($workspaceName);
     if ($lastVisitedNode !== NULL) {
         return $uriBuilder->uriFor('show', array('node' => $lastVisitedNode), 'Frontend\\Node', 'TYPO3.Neos');
     }
     return $uriBuilder->uriFor('show', array('node' => $contentContext->getCurrentSiteNode()), 'Frontend\\Node', 'TYPO3.Neos');
 }
 /**
  * Displays the backend interface
  *
  * @param NodeInterface $node The node that will be displayed on the first tab
  * @return void
  */
 public function indexAction(NodeInterface $node = null)
 {
     $this->contentCache->flush();
     $this->session->start();
     $this->session->putData('__cheEnabled__', true);
     if ($user = $this->userService->getBackendUser()) {
         $workspaceName = $this->userService->getPersonalWorkspaceName();
         $contentContext = $this->createContext($workspaceName);
         $contentContext->getWorkspace();
         $this->persistenceManager->persistAll();
         $siteNode = $contentContext->getCurrentSiteNode();
         if ($node === null) {
             $node = $siteNode;
         }
         $this->view->assign('user', $user);
         $this->view->assign('documentNode', $node);
         $this->view->assign('site', $node);
         $this->view->assign('translations', $this->xliffService->getCachedJson(new Locale($this->userService->getInterfaceLanguage())));
         return;
     }
     $this->redirectToUri($this->uriBuilder->uriFor('index', array(), 'Login', 'TYPO3.Neos'));
 }
 /**
  * @test
  */
 public function getBackendUserReturnsTheCurrentlyLoggedInUser()
 {
     $mockUser = $this->getMockBuilder('TYPO3\\Neos\\Domain\\Model\\User')->disableOriginalConstructor()->getMock();
     $this->mockUserDomainService->expects($this->atLeastOnce())->method('getCurrentUser')->will($this->returnValue($mockUser));
     $this->assertSame($mockUser, $this->userService->getBackendUser());
 }
 /**
  * Get data
  *
  * @param NodeInterface $node The node that is currently edited (optional)
  * @param array $arguments Additional arguments (key / value)
  * @return mixed JSON serializable data
  * @api
  */
 public function getData(NodeInterface $node = NULL, array $arguments)
 {
     return array('name' => $this->userService->getBackendUser()->getName()->getFullName());
 }