Skip to content

Commit

Permalink
Draft: FEATURE: Extract workspace metadata and user-assignment to Neos
Browse files Browse the repository at this point in the history
  • Loading branch information
bwaidelich committed Aug 9, 2024
1 parent 7638e49 commit d588fbc
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 140 deletions.
3 changes: 0 additions & 3 deletions Classes/Application/ReloadNodes/ReloadNodesQueryHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Mvc\ActionRequest;
use Neos\Neos\Domain\Service\NodeTypeNameFactory;
use Neos\Neos\Domain\Workspace\WorkspaceProvider;
use Neos\Neos\FrontendRouting\NodeAddressFactory;
use Neos\Neos\Ui\Fusion\Helper\NodeInfoHelper;

Expand All @@ -36,8 +35,6 @@
#[Flow\Scope("singleton")]
final class ReloadNodesQueryHandler
{
#[Flow\Inject]
protected WorkspaceProvider $workspaceProvider;

#[Flow\Inject]
protected ContentRepositoryRegistry $contentRepositoryRegistry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Flow\Annotations as Flow;
use Neos\Neos\Domain\NodeLabel\NodeLabelGeneratorInterface;
use Neos\Neos\Domain\Workspace\WorkspaceProvider;
use Neos\Neos\Domain\Service\WorkspacePublishingService;

/**
* The application layer level command handler to for rebasing the workspace
Expand All @@ -32,20 +32,19 @@ final class SyncWorkspaceCommandHandler
protected ContentRepositoryRegistry $contentRepositoryRegistry;

#[Flow\Inject]
protected WorkspaceProvider $workspaceProvider;
protected WorkspacePublishingService $workspacePublishingService;

#[Flow\Inject]
protected NodeLabelGeneratorInterface $nodeLabelGenerator;

public function handle(SyncWorkspaceCommand $command): void
{
try {
$workspace = $this->workspaceProvider->provideForWorkspaceName(
$this->workspacePublishingService->rebaseWorkspace(
$command->contentRepositoryId,
$command->workspaceName
$command->workspaceName,
$command->rebaseErrorHandlingStrategy
);

$workspace->rebase($command->rebaseErrorHandlingStrategy);
} catch (WorkspaceRebaseFailed $e) {
$conflictsBuilder = Conflicts::builder(
contentRepository: $this->contentRepositoryRegistry
Expand Down
12 changes: 11 additions & 1 deletion Classes/ContentRepository/Service/WorkspaceService.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ class WorkspaceService
*/
protected $domainUserService;

/**
* @Flow\Inject
* @var \Neos\Neos\Domain\Service\WorkspaceService
*/
protected $neosWorkspaceService;

/**
* Get all publishable node context paths for a workspace
*
Expand Down Expand Up @@ -132,6 +138,9 @@ public function getPublishableNodeInfo(WorkspaceName $workspaceName, ContentRepo
public function getAllowedTargetWorkspaces(ContentRepository $contentRepository): array
{
$user = $this->domainUserService->getCurrentUser();
if ($user === null) {
return [];
}

$workspacesArray = [];
foreach ($contentRepository->getWorkspaceFinder()->findAll() as $workspace) {
Expand All @@ -149,12 +158,13 @@ public function getAllowedTargetWorkspaces(ContentRepository $contentRepository)
// Skip other personal workspaces
continue;
}
$workspacePermissions = $this->neosWorkspaceService->getWorkspacePermissionsForUser($contentRepository->id, $workspace->workspaceName, $user);

$workspaceArray = [
'name' => $workspace->workspaceName->jsonSerialize(),
'title' => $workspace->workspaceTitle->jsonSerialize(),
'description' => $workspace->workspaceDescription->jsonSerialize(),
'readonly' => !$this->domainUserService->currentUserCanPublishToWorkspace($workspace)
'readonly' => !$workspacePermissions->write,
];
$workspacesArray[$workspace->workspaceName->jsonSerialize()] = $workspaceArray;
}
Expand Down
23 changes: 9 additions & 14 deletions Classes/Controller/BackendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Mvc\Controller\ActionController;
use Neos\Flow\Persistence\PersistenceManagerInterface;
use Neos\Flow\Security\Context;
use Neos\Neos\Domain\Repository\DomainRepository;
use Neos\Neos\Domain\Repository\SiteRepository;
use Neos\Neos\Domain\Service\NodeTypeNameFactory;
use Neos\Neos\Domain\Service\WorkspaceNameBuilder;
use Neos\Neos\Domain\Service\WorkspaceService;
use Neos\Neos\FrontendRouting\NodeAddressFactory;
use Neos\Neos\FrontendRouting\NodeUriBuilderFactory;
use Neos\Neos\FrontendRouting\SiteDetection\SiteDetectionResult;
Expand Down Expand Up @@ -78,12 +77,6 @@ class BackendController extends ActionController
*/
protected $contentRepositoryRegistry;

/**
* @Flow\Inject
* @var Context
*/
protected $securityContext;

/**
* @Flow\Inject
* @var ConfigurationProviderInterface
Expand Down Expand Up @@ -126,6 +119,12 @@ class BackendController extends ActionController
*/
protected $nodeUriBuilderFactory;

/**
* @Flow\Inject
* @var WorkspaceService
*/
protected $workspaceService;

/**
* Displays the backend interface
*
Expand All @@ -138,23 +137,19 @@ public function indexAction(string $node = null)
$contentRepository = $this->contentRepositoryRegistry->get($siteDetectionResult->contentRepositoryId);

$nodeAddress = $node !== null ? NodeAddressFactory::create($contentRepository)->createFromUriString($node) : null;
unset($node);
$user = $this->userService->getBackendUser();

if ($user === null) {
$this->redirectToUri($this->uriBuilder->uriFor('index', [], 'Login', 'Neos.Neos'));
}

$currentAccount = $this->securityContext->getAccount();
assert($currentAccount !== null);
$workspaceName = WorkspaceNameBuilder::fromAccountIdentifier($currentAccount->getAccountIdentifier());

try {
$contentGraph = $contentRepository->getContentGraph($workspaceName);
$workspace = $this->workspaceService->getPersonalWorkspaceForUser($siteDetectionResult->contentRepositoryId, $user->getId());
} catch (WorkspaceDoesNotExist) {
// todo will cause infinite loop: https://github.com/neos/neos-development-collection/issues/4401
$this->redirectToUri($this->uriBuilder->uriFor('index', [], 'Login', 'Neos.Neos'));
}
$contentGraph = $contentRepository->getContentGraph($workspace->workspaceName);

$backendControllerInternals = $this->contentRepositoryRegistry->buildService(
$siteDetectionResult->contentRepositoryId,
Expand Down
Loading

0 comments on commit d588fbc

Please sign in to comment.