Skip to content

Commit

Permalink
Merge pull request flownative#35 from flownative/task/flow-8-compatib…
Browse files Browse the repository at this point in the history
…ility

Flow 8 compatibility
  • Loading branch information
kdambekalns committed Jun 2, 2022
2 parents 6661b2c + 93ccd87 commit 4bd4cd5
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 55 deletions.
18 changes: 9 additions & 9 deletions Classes/Command/HashTokenCommandController.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php
declare(strict_types=1);

namespace Flownative\WorkspacePreview\Command;

use Flownative\WorkspacePreview\WorkspacePreviewTokenFactory;
use Neos\ContentRepository\Domain\Model\Workspace;
use Neos\ContentRepository\Domain\Repository\WorkspaceRepository;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Cli\CommandController;
use Neos\Flow\Persistence\PersistenceManagerInterface;
use Neos\ContentRepository\Domain\Model\Workspace;
use Neos\ContentRepository\Domain\Repository\WorkspaceRepository;
use Flownative\TokenAuthentication\Security\Model\HashAndRoles;
use Flownative\WorkspacePreview\WorkspacePreviewTokenFactory;

/**
*
Expand Down Expand Up @@ -37,7 +38,7 @@ class HashTokenCommandController extends CommandController
*
* @param string $workspaceName
*/
public function createWorkspacePreviewTokenCommand(string $workspaceName)
public function createWorkspacePreviewTokenCommand(string $workspaceName): void
{
$this->createAndOutputWorkspacePreviewToken($workspaceName);
$this->persistenceManager->persistAll();
Expand All @@ -46,7 +47,7 @@ public function createWorkspacePreviewTokenCommand(string $workspaceName)
/**
* Create preview tokens for all internal and private workspaces (not personal though)
*/
public function createForAllPossibleWorkspacesCommand()
public function createForAllPossibleWorkspacesCommand(): void
{
/** @var Workspace $workspace */
foreach ($this->workspaceRepository->findAll() as $workspace) {
Expand All @@ -61,12 +62,11 @@ public function createForAllPossibleWorkspacesCommand()
* Creates a token and outputs information.
*
* @param string $workspaceName
* @return HashAndRoles
* @return void
*/
private function createAndOutputWorkspacePreviewToken($workspaceName)
private function createAndOutputWorkspacePreviewToken(string $workspaceName): void
{
$tokenmetadata = $this->workspacePreviewTokenFactory->create($workspaceName);
$this->outputLine('Created token for "%s" with hash "%s"', [$workspaceName, $tokenmetadata->getHash()]);
return $tokenmetadata;
}
}
24 changes: 7 additions & 17 deletions Classes/Controller/HashTokenLoginController.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
<?php
declare(strict_types=1);

namespace Flownative\WorkspacePreview\Controller;

use Flownative\TokenAuthentication\Security\Repository\HashAndRolesRepository;
use Neos\ContentRepository\Domain\Model\NodeInterface;
use Neos\ContentRepository\Domain\Service\ContextFactoryInterface;
use Neos\Eel\FlowQuery\FlowQuery;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Mvc\ActionRequest;
use Neos\Flow\Mvc\Controller\Argument;
use Neos\Flow\Mvc\Exception\StopActionException;
use Neos\Flow\Security\Authentication\Controller\AbstractAuthenticationController;
use Neos\Neos\Domain\Service\ContentContext;
use Flownative\TokenAuthentication\Security\Repository\HashAndRolesRepository;

/**
*
Expand All @@ -28,19 +31,6 @@ class HashTokenLoginController extends AbstractAuthenticationController
*/
protected $contextFactory;

protected function errorAction()
{
return parent::errorAction();
}

/**
* @return string
*/
public function authenticateAction()
{
return parent::authenticateAction();
}

/**
* @param ActionRequest|null $originalRequest
*/
Expand All @@ -66,7 +56,7 @@ protected function onAuthenticationSuccess(ActionRequest $originalRequest = null
*
* @return NodeInterface|null
*/
protected function getNodeArgumentValue()
protected function getNodeArgumentValue(): ?NodeInterface
{
if (!$this->request->hasArgument('node')) {
return null;
Expand All @@ -80,9 +70,9 @@ protected function getNodeArgumentValue()
/**
* @param string $workspaceName
* @param NodeInterface|null $nodeToRedirectTo
* @throws \Neos\Flow\Mvc\Exception\StopActionException
* @throws StopActionException
*/
protected function redirectToWorkspace(string $workspaceName, NodeInterface $nodeToRedirectTo = null)
protected function redirectToWorkspace(string $workspaceName, NodeInterface $nodeToRedirectTo = null): void
{
/** @var ContentContext $context */
$context = $this->contextFactory->create(['workspaceName' => $workspaceName]);
Expand Down
6 changes: 4 additions & 2 deletions Classes/Controller/HashTokenRefreshController.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?php
declare(strict_types=1);

namespace Flownative\WorkspacePreview\Controller;

use Flownative\WorkspacePreview\WorkspacePreviewTokenFactory;
use Neos\ContentRepository\Domain\Model\Workspace;
use Neos\Error\Messages\Message;
use Neos\Flow\Annotations as Flow;
use Neos\ContentRepository\Domain\Model\Workspace;
use Neos\Flow\Mvc\Controller\ActionController;
use Flownative\WorkspacePreview\WorkspacePreviewTokenFactory;

/**
* Service controller to refresh a preview token for a given workspace.
Expand Down
29 changes: 15 additions & 14 deletions Classes/DataSource/PreviewLinkViewDataSource.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<?php
declare(strict_types=1);

namespace Flownative\WorkspacePreview\DataSource;

use Flownative\TokenAuthentication\Security\Model\HashAndRoles;
use Flownative\TokenAuthentication\Security\Repository\HashAndRolesRepository;
use Neos\Flow\Annotations as Flow;
use Neos\ContentRepository\Domain\Model\NodeInterface;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Mvc\Controller\ControllerContext;
use Neos\Flow\Mvc\Routing\Exception\MissingActionNameException;
use Neos\Neos\Service\DataSource\DataSourceInterface;
use Neos\Neos\Service\UserService;

/**
*
Expand All @@ -26,7 +29,7 @@ class PreviewLinkViewDataSource implements DataSourceInterface

/**
* @Flow\Inject
* @var \Neos\Neos\Service\UserService
* @var UserService
*/
protected $userService;

Expand All @@ -39,23 +42,23 @@ class PreviewLinkViewDataSource implements DataSourceInterface
/**
* @param ControllerContext $controllerContext
*/
public function setControllerContext(ControllerContext $controllerContext)
public function setControllerContext(ControllerContext $controllerContext): void
{
$this->controllerContext = $controllerContext;
}

public static function getIdentifier()
public static function getIdentifier(): string
{
return 'PreviewLinkView';
return 'PreviewLinkView';
}

/**
* @param NodeInterface|null $node
* @param array $arguments
* @return array|mixed
* @return array
* @throws MissingActionNameException
*/
public function getData(NodeInterface $node = null, array $arguments = [])
public function getData(NodeInterface $node = null, array $arguments = []): array
{
$link = $this->getLink($node, $error);
return [
Expand All @@ -68,7 +71,7 @@ public function getData(NodeInterface $node = null, array $arguments = [])

/**
* @param NodeInterface|null $node
* @param string $error
* @param string|null $error
* @return string
* @throws MissingActionNameException
*/
Expand Down Expand Up @@ -96,9 +99,9 @@ protected function getLink(NodeInterface $node = null, string &$error = null): s

$url = $this->controllerContext->getUriBuilder()->reset()->setCreateAbsoluteUri(true)
->uriFor('authenticate', [
'_authenticationHashToken' => $hashAndRoles->getHash(),
'node' => $contextPath
], 'HashTokenLogin', 'Flownative.WorkspacePreview', null);
'_authenticationHashToken' => $hashAndRoles->getHash(),
'node' => $contextPath
], 'HashTokenLogin', 'Flownative.WorkspacePreview');
$error = self::ERROR_NONE;
return $url;
}
Expand All @@ -111,15 +114,13 @@ protected function getHashTokenForWorkspace(string $workspaceName): ?HashAndRole
{
$possibleTokens = $this->hashAndRolesRepository->findByRoles(['Flownative.WorkspacePreview:WorkspacePreviewer']);

$hashAndRoles = array_reduce($possibleTokens->toArray(), static function ($foundToken, HashAndRoles $currentToken) use ($workspaceName) {
return array_reduce($possibleTokens->toArray(), static function ($foundToken, HashAndRoles $currentToken) use ($workspaceName) {
$currentWorkspaceName = $currentToken->getSettings()['workspaceName'] ?? null;
if ($currentWorkspaceName === $workspaceName) {
return $currentToken;
}

return $foundToken;
}, null);

return $hashAndRoles;
}
}
11 changes: 7 additions & 4 deletions Classes/Fusion/ConvertUrisImplementation.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<?php
declare(strict_types=1);

namespace Flownative\WorkspacePreview\Fusion;

use Neos\Flow\Annotations as Flow;
use Neos\Neos\Domain\Exception as DomainException;
use Neos\Neos\Domain\Service\UserInterfaceModeService;
use Neos\Neos\Fusion\ConvertUrisImplementation as OriginalImplementation;
use Neos\Flow\Annotations as Flow;

class ConvertUrisImplementation extends OriginalImplementation
{
Expand All @@ -16,16 +19,16 @@ class ConvertUrisImplementation extends OriginalImplementation

/**
* @return string
* @throws \Neos\Neos\Domain\Exception
* @throws DomainException
*/
public function evaluate()
public function evaluate(): string
{
$currentRenderingMode = $this->interfaceRenderModeService->findModeByCurrentUser();
$forceConversionPathPart = 'forceConversion';

if ($currentRenderingMode->isEdit() === false && $this->fusionValue($forceConversionPathPart) !== false) {
$fullPath = $this->path . '/' . $forceConversionPathPart;
$this->tsValueCache[$fullPath] = true;
$this->fusionValueCache[$fullPath] = true;
}

return parent::evaluate();
Expand Down
18 changes: 13 additions & 5 deletions Classes/ViewHelpers/GetHashTokenForWorkspaceViewHelper.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<?php
declare(strict_types=1);

namespace Flownative\WorkspacePreview\ViewHelpers;

use Flownative\TokenAuthentication\Security\Model\HashAndRoles;
use Flownative\TokenAuthentication\Security\Repository\HashAndRolesRepository;
use Neos\ContentRepository\Domain\Model\Workspace;
use Neos\FluidAdaptor\Core\Rendering\RenderingContext;
use Neos\FluidAdaptor\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use Flownative\TokenAuthentication\Security\Repository\HashAndRolesRepository;

/**
* A viewhelper to get a preview token by workspace
Expand All @@ -20,7 +23,10 @@ public function initializeArguments()
$this->registerArgument('workspace', Workspace::class, 'The workspace to get a token for.', true);
}

public function render()
/**
* @return HashAndRoles|null
*/
public function render(): ?HashAndRoles
{
return self::renderStatic($this->arguments, $this->buildRenderChildrenClosure(), $this->renderingContext);
}
Expand All @@ -29,15 +35,15 @@ public function render()
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
* @return mixed
* @return HashAndRoles|null
*/
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): ?HashAndRoles
{
$workspace = $arguments['workspace'];
$workspaceName = $workspace->getName();

/** @var $renderingContext RenderingContext */
$objectManager = $renderingContext->getObjectManager();
$objectManager = $renderingContext->getObjectManager();
$tokenRepository = $objectManager->get(HashAndRolesRepository::class);

$tokens = $tokenRepository->findByRoles(['Flownative.WorkspacePreview:WorkspacePreviewer']);
Expand All @@ -47,5 +53,7 @@ public static function renderStatic(array $arguments, \Closure $renderChildrenCl
return $token;
}
}

return null;
}
}
8 changes: 5 additions & 3 deletions Classes/WorkspacePreviewTokenFactory.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php
declare(strict_types=1);

namespace Flownative\WorkspacePreview;

use Neos\Flow\Annotations as Flow;
use Neos\Flow\Utility\Algorithms;
use Flownative\TokenAuthentication\Security\Model\HashAndRoles;
use Flownative\TokenAuthentication\Security\Repository\HashAndRolesRepository;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Utility\Algorithms;

/**
* Factory to quickly create tokens to preview specific workspaces.
Expand Down Expand Up @@ -52,7 +54,7 @@ public function refresh(string $workspaceName): HashAndRoles
* @param string $workspaceName
* @return void
*/
protected function removeExistingWorkspacePreviewFor(string $workspaceName)
protected function removeExistingWorkspacePreviewFor(string $workspaceName): void
{
$allWorkspacePreviewTokens = $this->hashAndRolesRepository->findByRoles(['Flownative.WorkspacePreview:WorkspacePreviewer']);
/** @var HashAndRoles $workspacePreviewToken */
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"require": {
"flownative/token-authentication": "^2.2.1",
"neos/neos": "^5.3 || ^7.0"
"neos/neos": "^5.3 || ^7.0 || ^8.0"
},
"autoload": {
"psr-4": {
Expand Down

0 comments on commit 4bd4cd5

Please sign in to comment.