Skip to content

Commit

Permalink
Re-add UI WorkspaceService for now
Browse files Browse the repository at this point in the history
  • Loading branch information
bwaidelich committed Sep 27, 2024
1 parent bd04359 commit a398e65
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 16 deletions.
131 changes: 131 additions & 0 deletions Classes/ContentRepository/Service/WorkspaceService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?php
namespace Neos\Neos\Ui\ContentRepository\Service;

/*
* This file is part of the Neos.Neos.Ui package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/

use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindClosestNodeFilter;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepository\Core\Projection\ContentGraph\VisibilityConstraints;
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Flow\Annotations as Flow;
use Neos\Neos\Domain\Service\NodeTypeNameFactory;
use Neos\Neos\Domain\Service\WorkspacePublishingService;
use Neos\Neos\FrontendRouting\NodeAddress;
use Neos\Neos\FrontendRouting\NodeAddressFactory;
use Neos\Neos\PendingChangesProjection\Change;
use Neos\Neos\Utility\NodeTypeWithFallbackProvider;

/**
* @internal
* @Flow\Scope("singleton")
*/
class WorkspaceService
{
private const NODE_HAS_BEEN_CREATED = 0b0001;
private const NODE_HAS_BEEN_CHANGED = 0b0010;
private const NODE_HAS_BEEN_MOVED = 0b0100;
private const NODE_HAS_BEEN_DELETED = 0b1000;

use NodeTypeWithFallbackProvider;

#[Flow\Inject]
protected ContentRepositoryRegistry $contentRepositoryRegistry;

#[Flow\Inject]
protected WorkspacePublishingService $workspacePublishingService;

/**
* Get all publishable node context paths for a workspace
*
* @return array{contextPath:string,documentContextPath:string,typeOfChange:int}[]
*/
public function getPublishableNodeInfo(WorkspaceName $workspaceName, ContentRepositoryId $contentRepositoryId): array
{
$contentRepository = $this->contentRepositoryRegistry->get($contentRepositoryId);
$pendingChanges = $this->workspacePublishingService->pendingWorkspaceChanges($contentRepositoryId, $workspaceName);
/** @var array{contextPath:string,documentContextPath:string,typeOfChange:int}[] $unpublishedNodes */
$unpublishedNodes = [];
foreach ($pendingChanges as $change) {
if ($change->removalAttachmentPoint) {
$nodeAddress = new NodeAddress(
$change->contentStreamId,
$change->originDimensionSpacePoint->toDimensionSpacePoint(),
$change->nodeAggregateId,
$workspaceName
);

/**
* See {@see Remove::apply} -> Removal Attachment Point == closest document node.
*/
$documentNodeAddress = new NodeAddress(
$change->contentStreamId,
$change->originDimensionSpacePoint->toDimensionSpacePoint(),
$change->removalAttachmentPoint,
$workspaceName
);

$unpublishedNodes[] = [
'contextPath' => $nodeAddress->serializeForUri(),
'documentContextPath' => $documentNodeAddress->serializeForUri(),
'typeOfChange' => $this->getTypeOfChange($change)
];
} else {
$subgraph = $contentRepository->getContentGraph($workspaceName)->getSubgraph(
$change->originDimensionSpacePoint->toDimensionSpacePoint(),
VisibilityConstraints::withoutRestrictions()
);
$node = $subgraph->findNodeById($change->nodeAggregateId);

if ($node instanceof Node) {
$documentNode = $subgraph->findClosestNode($node->aggregateId, FindClosestNodeFilter::create(nodeTypes: NodeTypeNameFactory::NAME_DOCUMENT));
if ($documentNode instanceof Node) {
$nodeAddressFactory = NodeAddressFactory::create($contentRepository);
$unpublishedNodes[] = [
'contextPath' => $nodeAddressFactory->createFromNode($node)->serializeForUri(),
'documentContextPath' => $nodeAddressFactory->createFromNode($documentNode)
->serializeForUri(),
'typeOfChange' => $this->getTypeOfChange($change)
];
}
}
}
}

return array_values(array_filter($unpublishedNodes, function ($item) {
return (bool)$item;
}));
}

private function getTypeOfChange(Change $change): int
{
$result = 0;

if ($change->created) {
$result = $result | self::NODE_HAS_BEEN_CREATED;
}

if ($change->changed) {
$result = $result | self::NODE_HAS_BEEN_CHANGED;
}

if ($change->moved) {
$result = $result | self::NODE_HAS_BEEN_MOVED;
}

if ($change->deleted) {
$result = $result | self::NODE_HAS_BEEN_DELETED;
}

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

Expand All @@ -27,15 +27,15 @@ class UpdateWorkspaceInfo extends AbstractFeedback
{
/**
* @Flow\Inject
* @var WorkspacePublishingService
* @var ContentRepositoryRegistry
*/
protected $workspacePublishingService;
protected $contentRepositoryRegistry;

/**
* @Flow\Inject
* @var ContentRepositoryRegistry
* @var UiWorkspaceService
*/
protected $contentRepositoryRegistry;
protected $uiWorkspaceService;

/**
* UpdateWorkspaceInfo constructor.
Expand Down Expand Up @@ -103,11 +103,11 @@ public function serializePayload(ControllerContext $controllerContext)
if ($workspace === null) {
return null;
}
$pendingChanges = $this->workspacePublishingService->pendingWorkspaceChanges($this->contentRepositoryId, $this->workspaceName);
$publishableNodes = $this->uiWorkspaceService->getPublishableNodeInfo($workspace->workspaceName, $contentRepository->id);
return [
'name' => $this->workspaceName->value,
'totalNumberOfChanges' => $pendingChanges->count(),
'publishableNodes' => $pendingChanges->toPublishableNodeInfo($contentRepository, $workspace->workspaceName),
'totalNumberOfChanges' => count($publishableNodes),
'publishableNodes' => $publishableNodes,
'baseWorkspace' => $workspace->baseWorkspaceName?->value,
'status' => $workspace->status->value,
];
Expand Down
14 changes: 6 additions & 8 deletions Classes/Fusion/Helper/WorkspaceHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Security\Context;
use Neos\Neos\Domain\Service\UserService;
use Neos\Neos\Domain\Service\WorkspacePublishingService;
use Neos\Neos\Domain\Service\WorkspaceService;
use Neos\Neos\Ui\ContentRepository\Service\WorkspaceService as UiWorkspaceService;

/**
* @internal implementation detail of the Neos Ui to build its initialState {@see \Neos\Neos\Ui\Infrastructure\Configuration\InitialStateProvider}
*
* TODO REMOVE
*/
class WorkspaceHelper implements ProtectedContextAwareInterface
{
Expand All @@ -41,9 +39,9 @@ class WorkspaceHelper implements ProtectedContextAwareInterface

/**
* @Flow\Inject
* @var WorkspacePublishingService
* @var UiWorkspaceService
*/
protected $workspacePublishingService;
protected $uiWorkspaceService;

/**
* @Flow\Inject
Expand All @@ -69,11 +67,11 @@ public function getPersonalWorkspace(ContentRepositoryId $contentRepositoryId):
$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);
$publishableNodes = $this->uiWorkspaceService->getPublishableNodeInfo($personalWorkspace->workspaceName, $contentRepository->id);
return [
'name' => $personalWorkspace->workspaceName->value,
'totalNumberOfChanges' => $pendingChanges->count(),
'publishableNodes' => $pendingChanges->toPublishableNodeInfo($contentRepository, $personalWorkspace->workspaceName),
'totalNumberOfChanges' => count($publishableNodes),
'publishableNodes' => $publishableNodes,
'baseWorkspace' => $personalWorkspace->baseWorkspaceName?->value,
'readOnly' => !($personalWorkspace->baseWorkspaceName !== null && $personalWorkspacePermissions->write),
'status' => $personalWorkspace->status->value,
Expand Down

0 comments on commit a398e65

Please sign in to comment.