Skip to content

Commit

Permalink
Remove Neos UI WorkspaceService
Browse files Browse the repository at this point in the history
  • Loading branch information
bwaidelich committed Sep 25, 2024
1 parent 968ca00 commit bd04359
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 231 deletions.
197 changes: 0 additions & 197 deletions Classes/ContentRepository/Service/WorkspaceService.php

This file was deleted.

19 changes: 6 additions & 13 deletions Classes/Domain/Model/Feedback/Operations/UpdateWorkspaceInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Mvc\Controller\ControllerContext;
use Neos\Neos\PendingChangesProjection\ChangeFinder;
use Neos\Neos\Ui\ContentRepository\Service\WorkspaceService;
use Neos\Neos\Domain\Service\WorkspacePublishingService;
use Neos\Neos\Ui\Domain\Model\AbstractFeedback;
use Neos\Neos\Ui\Domain\Model\FeedbackInterface;

Expand All @@ -28,9 +27,9 @@ class UpdateWorkspaceInfo extends AbstractFeedback
{
/**
* @Flow\Inject
* @var WorkspaceService
* @var WorkspacePublishingService
*/
protected $workspaceService;
protected $workspacePublishingService;

/**
* @Flow\Inject
Expand Down Expand Up @@ -104,17 +103,11 @@ public function serializePayload(ControllerContext $controllerContext)
if ($workspace === null) {
return null;
}
/** @var ChangeFinder $changeFinder */
$changeFinder = $contentRepository->projectionState(ChangeFinder::class);
$totalNumberOfChanges = $changeFinder->countByContentStreamId($workspace->currentContentStreamId);

$pendingChanges = $this->workspacePublishingService->pendingWorkspaceChanges($this->contentRepositoryId, $this->workspaceName);
return [
'name' => $this->workspaceName->value,
'totalNumberOfChanges' => $totalNumberOfChanges,
'publishableNodes' => $this->workspaceService->getPublishableNodeInfo(
$this->workspaceName,
$this->contentRepositoryId
),
'totalNumberOfChanges' => $pendingChanges->count(),
'publishableNodes' => $pendingChanges->toPublishableNodeInfo($contentRepository, $workspace->workspaceName),
'baseWorkspace' => $workspace->baseWorkspaceName?->value,
'status' => $workspace->status->value,
];
Expand Down
26 changes: 10 additions & 16 deletions Classes/Fusion/Helper/WorkspaceHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@
use Neos\Flow\Security\Context;
use Neos\Neos\Domain\Service\UserService;
use Neos\Neos\Domain\Service\WorkspacePublishingService;
use Neos\Neos\Domain\Service\WorkspaceService as NeosWorkspaceService;
use Neos\Neos\Ui\ContentRepository\Service\WorkspaceService;
use Neos\Neos\Domain\Service\WorkspaceService;

/**
* @internal implementation detail of the Neos Ui to build its initialState.
* and used for the workspace-info endpoint.
* @internal implementation detail of the Neos Ui to build its initialState {@see \Neos\Neos\Ui\Infrastructure\Configuration\InitialStateProvider}
*
* TODO REMOVE
*/
Expand All @@ -35,12 +33,6 @@ class WorkspaceHelper implements ProtectedContextAwareInterface
*/
protected $contentRepositoryRegistry;

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

/**
* @Flow\Inject
* @var Context
Expand All @@ -61,9 +53,9 @@ class WorkspaceHelper implements ProtectedContextAwareInterface

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

/**
* @return array<string,mixed>
Expand All @@ -74,12 +66,14 @@ public function getPersonalWorkspace(ContentRepositoryId $contentRepositoryId):
if ($currentUser === null) {
return [];
}
$personalWorkspace = $this->neosWorkspaceService->getPersonalWorkspaceForUser($contentRepositoryId, $currentUser->getId());
$personalWorkspacePermissions = $this->neosWorkspaceService->getWorkspacePermissionsForUser($contentRepositoryId, $personalWorkspace->workspaceName, $currentUser);
$contentRepository = $this->contentRepositoryRegistry->get($contentRepositoryId);
$personalWorkspace = $this->workspaceService->getPersonalWorkspaceForUser($contentRepositoryId, $currentUser->getId());
$personalWorkspacePermissions = $this->workspaceService->getWorkspacePermissionsForUser($contentRepositoryId, $personalWorkspace->workspaceName, $currentUser);
$pendingChanges = $this->workspacePublishingService->pendingWorkspaceChanges($contentRepositoryId, $personalWorkspace->workspaceName);
return [
'name' => $personalWorkspace->workspaceName->value,
'totalNumberOfChanges' => $this->workspacePublishingService->countPendingWorkspaceChanges($contentRepositoryId, $personalWorkspace->workspaceName),
'publishableNodes' => $this->workspaceService->getPublishableNodeInfo($personalWorkspace->workspaceName, $contentRepositoryId),
'totalNumberOfChanges' => $pendingChanges->count(),
'publishableNodes' => $pendingChanges->toPublishableNodeInfo($contentRepository, $personalWorkspace->workspaceName),
'baseWorkspace' => $personalWorkspace->baseWorkspaceName?->value,
'readOnly' => !($personalWorkspace->baseWorkspaceName !== null && $personalWorkspacePermissions->write),
'status' => $personalWorkspace->status->value,
Expand Down
33 changes: 28 additions & 5 deletions Classes/Infrastructure/Configuration/ConfigurationProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Configuration\ConfigurationManager;
use Neos\Flow\Mvc\Routing\UriBuilder;
use Neos\Neos\Domain\Model\WorkspaceClassification;
use Neos\Neos\Domain\Service\WorkspaceService;
use Neos\Neos\Service\UserService;
use Neos\Neos\Ui\ContentRepository\Service\WorkspaceService;
use Neos\Neos\Ui\Domain\InitialData\CacheConfigurationVersionProviderInterface;
use Neos\Neos\Ui\Domain\InitialData\ConfigurationProviderInterface;

Expand Down Expand Up @@ -54,10 +55,7 @@ public function getConfiguration(
ConfigurationManager::CONFIGURATION_TYPE_SETTINGS,
'Neos.Neos.userInterface.navigateComponent.structureTree',
),
'allowedTargetWorkspaces' =>
$this->workspaceService->getAllowedTargetWorkspaces(
$contentRepository
),
'allowedTargetWorkspaces' => $this->getAllowedTargetWorkspaces($contentRepository),
'endpoints' => [
'nodeTypeSchema' => $uriBuilder->reset()
->setCreateAbsoluteUri(true)
Expand Down Expand Up @@ -89,4 +87,29 @@ public function getConfiguration(
]
];
}

private function getAllowedTargetWorkspaces(ContentRepository $contentRepository): array
{
$backendUser = $this->userService->getBackendUser();
if ($backendUser === null) {
return [];
}
$result = [];
foreach ($contentRepository->getWorkspaceFinder()->findAll() as $workspace) {
$workspaceMetadata = $this->workspaceService->getWorkspaceMetadata($contentRepository->id, $workspace->workspaceName);
if (!in_array($workspaceMetadata->classification, [WorkspaceClassification::ROOT, WorkspaceClassification::SHARED], true)) {
continue;
}
$workspacePermissions = $this->workspaceService->getWorkspacePermissionsForUser($contentRepository->id, $workspace->workspaceName, $backendUser);
if ($workspacePermissions->read === false) {
continue;
}
$result[$workspace->workspaceName->value] = [
'name' => $workspace->workspaceName->value,
'title' => $workspaceMetadata->title->value,
'readonly' => !$workspacePermissions->write,
];
}
return $result;
}
}

0 comments on commit bd04359

Please sign in to comment.