Skip to content

Commit

Permalink
Merge branch '3.3' into 4.0
Browse files Browse the repository at this point in the history
# Conflicts:
#	Neos.Media.Browser/Resources/Private/Translations/uk/Main.xlf
#	Neos.Neos/Resources/Private/Translations/ar/Main.xlf
  • Loading branch information
kdambekalns committed Nov 9, 2018
2 parents a05d444 + 1fd6d46 commit 382aa7d
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 13 deletions.
12 changes: 12 additions & 0 deletions Classes/Controller/Module/Management/WorkspacesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Neos\Error\Messages\Message;
use Neos\Flow\I18n\Translator;
use Neos\Flow\Mvc\ActionRequest;
use Neos\Flow\Package\PackageManager;
use Neos\Flow\Property\PropertyMapper;
use Neos\Flow\Property\TypeConverter\PersistentObjectConverter;
use Neos\Flow\Security\Context;
Expand Down Expand Up @@ -95,6 +96,12 @@ class WorkspacesController extends AbstractModuleController
*/
protected $translator;

/**
* @var PackageManager
* @Flow\Inject
*/
protected $packageManager;

/**
* @var ContentDimensionPresetSourceInterface
* @Flow\Inject
Expand Down Expand Up @@ -335,6 +342,11 @@ public function rebaseAndRedirectAction(NodeInterface $targetNode, Workspace $ta
$mainRequest = $this->controllerContext->getRequest()->getMainRequest();
/** @var ActionRequest $mainRequest */
$this->uriBuilder->setRequest($mainRequest);

if ($this->packageManager->isPackageAvailable('Neos.Neos.Ui')) {
$this->redirect('index', 'Backend', 'Neos.Neos.Ui', ['node' => $context->getNode($targetNode->getPath())]);
}

$this->redirect('show', 'Frontend\\Node', 'Neos.Neos', ['node' => $context->getNode($targetNode->getPath())]);
}

Expand Down
23 changes: 14 additions & 9 deletions Classes/Domain/Service/UserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use Neos\Neos\Domain\Model\User;
use Neos\Neos\Domain\Repository\UserRepository;
use Neos\Neos\Service\PublishingService;
use Neos\Party\Domain\Model\AbstractParty;
use Neos\Party\Domain\Model\PersonName;
use Neos\Party\Domain\Repository\PartyRepository;
use Neos\Party\Domain\Service\PartyService;
Expand Down Expand Up @@ -168,19 +169,23 @@ public function getUser($username, $authenticationProviderName = null)
$authenticationProviderName = $authenticationProviderName ?: $this->defaultAuthenticationProviderName;
$cacheIdentifier = $authenticationProviderName . '~' . $username;

if (!array_key_exists($cacheIdentifier, $this->runtimeUserCache)) {
$user = $this->findUserForAccount($username, $authenticationProviderName);
$this->runtimeUserCache[$cacheIdentifier] = $user === null ? null : $this->persistenceManager->getIdentifierByObject($user);
return $user;
if (array_key_exists($cacheIdentifier, $this->runtimeUserCache)) {
$userIdentifier = $this->runtimeUserCache[$cacheIdentifier];
return $this->partyRepository->findByIdentifier($userIdentifier);
}

$userIdentifier = $this->runtimeUserCache[$cacheIdentifier];
if ($userIdentifier === null) {
return null;
$user = $this->findUserForAccount($username, $authenticationProviderName);

if ($user instanceof AbstractParty) {
$userIdentifier = $this->persistenceManager->getIdentifierByObject($user);
}

$user = $this->partyRepository->findByIdentifier($userIdentifier);
return $user;
if (isset($userIdentifier) && (string)$userIdentifier !== '') {
$this->runtimeUserCache[$cacheIdentifier] = $userIdentifier;
return $this->partyRepository->findByIdentifier($userIdentifier);
}

return null;
}

/**
Expand Down
16 changes: 15 additions & 1 deletion Classes/Fusion/DimensionsMenuImplementation.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected function buildItems()
$nodeInDimensions = $this->findAcceptableNode($allowedCombination, $allDimensionPresets);
}

if ($nodeInDimensions !== null && $this->isNodeHidden($nodeInDimensions)) {
if ($nodeInDimensions !== null && ($this->isNodeHidden($nodeInDimensions) || $this->hasHiddenNodeParent($nodeInDimensions))) {
$nodeInDimensions = null;
}

Expand Down Expand Up @@ -209,4 +209,18 @@ protected function calculateTargetDimensionsForCombination(array $dimensionCombi

return $targetDimensions;
}

/**
* Returns TRUE if the node has a inaccessible parent.
*
* @param NodeInterface $node
* @return bool
*/
protected function hasHiddenNodeParent(NodeInterface $node): bool
{
$rootNode = $node->getContext()->getRootNode();
$nodesOnPath = $node->getContext()->getNodesOnPath($rootNode, $node);

return count($nodesOnPath) < $node->getDepth();
}
}
2 changes: 1 addition & 1 deletion Resources/Private/Styles/Login.scss
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ html,
.neos-actions {
bottom: 0;
width: 100%;
height: $unit;
min-height: $unit;

button {
height: $unit;
Expand Down
2 changes: 1 addition & 1 deletion Resources/Public/Styles/Login.css
Original file line number Diff line number Diff line change
Expand Up @@ -5353,7 +5353,7 @@ html,
.neos .neos-login-box .neos-actions {
bottom: 0;
width: 100%;
height: 40px;
min-height: 40px;
}
.neos .neos-login-box .neos-actions button {
height: 40px;
Expand Down
111 changes: 110 additions & 1 deletion Tests/Unit/Service/UserServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@
* source code.
*/

use Neos\Flow\Reflection\ObjectAccess;
use Neos\Flow\Tests\UnitTestCase;
use Neos\Neos\Domain\Model\User;
use Neos\Neos\Domain\Service\UserService as UserDomainService;
use Neos\Flow\Persistence\PersistenceManagerInterface;
use Neos\Neos\Service\UserService;
use Neos\Party\Domain\Repository\PartyRepository;
use Neos\ContentRepository\Domain\Model\Workspace;
use Neos\ContentRepository\Domain\Repository\WorkspaceRepository;
use Neos\Flow\Security\AccountRepository;
use Neos\Party\Domain\Service\PartyService;
use Neos\Flow\Security\Account;

/**
* Test case for the UserService
Expand All @@ -34,19 +40,62 @@ class UserServiceTest extends UnitTestCase
protected $mockUserDomainService;

/**
* @var WorkspaceRepository
* @var UserDomainService
*/
protected $userDomainService;

/**
* @var WorkspaceRepository | \PHPUnit_Framework_MockObject_MockObject
*/
protected $mockWorkspaceRepository;

/**
* @var AccountRepository | \PHPUnit_Framework_MockObject_MockObject
*/
protected $mockAccountRepository;

/**
* @var PartyService | \PHPUnit_Framework_MockObject_MockObject
*/
protected $mockPartyService;

/**
* @var PartyRepository | \PHPUnit_Framework_MockObject_MockObject
*/
protected $mockPartyRepository;

/**
* @var PersistenceManagerInterface
*/
protected $persistenceManager;

/**
* @var PersistenceManagerInterface
*/
protected $mockPersistenceManager;

public function setUp()
{
$this->userService = new UserService();
$this->userDomainService = new UserDomainService();

$this->mockUserDomainService = $this->getMockBuilder(UserDomainService::class)->getMock();
$this->inject($this->userService, 'userDomainService', $this->mockUserDomainService);

$this->mockWorkspaceRepository = $this->getMockBuilder(WorkspaceRepository::class)->disableOriginalConstructor()->setMethods(array('findOneByName'))->getMock();
$this->inject($this->userService, 'workspaceRepository', $this->mockWorkspaceRepository);

$this->mockAccountRepository = $this->getMockBuilder(AccountRepository::class)->getMock();
$this->inject($this->userDomainService, 'accountRepository', $this->mockAccountRepository);

$this->mockPersistenceManager = $this->getMockBuilder(PersistenceManagerInterface::class)->getMock();
$this->inject($this->userDomainService, 'persistenceManager', $this->mockPersistenceManager);

$this->mockPartyService = $this->getMockBuilder(PartyService::class)->getMock();
$this->inject($this->userDomainService, 'partyService', $this->mockPartyService);

$this->mockPartyRepository = $this->getMockBuilder(PartyRepository::class)->getMock();
$this->inject($this->userDomainService, 'partyRepository', $this->mockPartyRepository);
}

/**
Expand Down Expand Up @@ -103,4 +152,64 @@ public function getPersonalWorkspaceNameReturnsTheUsersWorkspaceNameIfAUserIsLog
$this->mockUserDomainService->expects($this->atLeastOnce())->method('getUserName')->with($mockUser)->will($this->returnValue('TheUserName'));
$this->assertSame('user-TheUserName', $this->userService->getPersonalWorkspaceName());
}

/**
* @test
*/
public function getUserReturnsNullForInvalidUser()
{
$this->assertNull($this->mockUserDomainService->getUser('NonExistantUser'));
}

/**
* @test
*/
public function getUsersWillReturnUserOnSecondCall()
{
$mockUser = $this->getMockBuilder(User::class)->disableOriginalConstructor()->getMock();
$mockAccount = $this->getMockBuilder(Account::class)->disableOriginalConstructor()->getMock();

$this->setUpGetUser($mockUser);

$this->mockAccountRepository->expects(self::any())
->method('findByAccountIdentifierAndAuthenticationProviderName')
->will($this->onConsecutiveCalls(null, $mockAccount));

$this->userDomainService->getUser('test-user');

$this->assertSame($mockUser, $this->userDomainService->getUser('test-user'));
}

/**
* @test
*/
public function getUserReturnsUserForValidUser()
{
$mockUser = $this->getMockBuilder(User::class)->disableOriginalConstructor()->getMock();
$mockAccount = $this->getMockBuilder(Account::class)->disableOriginalConstructor()->getMock();

$this->setUpGetUser($mockUser);

$this->mockAccountRepository->expects(self::atLeastOnce())
->method('findByAccountIdentifierAndAuthenticationProviderName')
->willReturn($mockAccount);

$this->assertSame($mockUser, $this->userDomainService->getUser('test-user'));
}

protected function setUpGetUser($mockUser)
{
$this->mockPartyService->expects(self::atLeastOnce())
->method('getAssignedPartyOfAccount')
->willReturn($mockUser);

$this->mockPersistenceManager->expects(self::atLeastOnce())
->method('getIdentifierByObject')
->with($mockUser)
->willReturn('8eb663bd-6886-4b90-a77e-8c3bbc2868f0');

$this->mockPartyRepository->expects(self::atLeastOnce())
->method('findByIdentifier')
->willReturn($mockUser);
}
}

0 comments on commit 382aa7d

Please sign in to comment.