Skip to content

Commit

Permalink
TASK: simplify workspace tree node fusion integration
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Jan 8, 2025
1 parent c2a4e0e commit a7d6cc1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
34 changes: 18 additions & 16 deletions Neos.Workspace.Ui/Classes/Controller/WorkspaceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public function newAction(): void
$contentRepositoryId = SiteDetectionResult::fromRequest($this->request->getHttpRequest())->contentRepositoryId;
$contentRepository = $this->contentRepositoryRegistry->get($contentRepositoryId);

$this->view->assign('baseWorkspaceOptions', $this->prepareBaseWorkspaceOptions($contentRepository));
$this->view->assign('baseWorkspaceOptions', $this->prepareBaseWorkspaceOptions($contentRepository, null));
}

public function createAction(
Expand Down Expand Up @@ -1104,39 +1104,41 @@ protected function postProcessDiffArray(array &$diffArray): void
}

/**
* Creates an array of workspace names and their respective titles which are possible base workspaces for other
* workspaces.
* If $excludedWorkspace is set, this workspace and all its base workspaces will be excluded from the list of returned workspaces
* Creates an array of workspace names and their respective titles which are possible base workspaces
*
* If $editedWorkspace is set, this workspace and all its nested workspaces will be excluded from the list of returned workspaces
*
* @return array<string,string>
*/
protected function prepareBaseWorkspaceOptions(
ContentRepository $contentRepository,
WorkspaceName $excludedWorkspace = null,
WorkspaceName|null $editedWorkspaceName
): array {
$user = $this->userService->getCurrentUser();
$baseWorkspaceOptions = [];
$workspaces = $contentRepository->findWorkspaces();
foreach ($workspaces as $workspace) {
if (
$excludedWorkspace !== null) {
if ($workspace->workspaceName->equals($excludedWorkspace)) {
if ($editedWorkspaceName !== null) {
if ($workspace->workspaceName->equals($editedWorkspaceName)) {
continue;
}
if ( $workspaces->getBaseWorkspaces($workspace->workspaceName)->get(
$excludedWorkspace
) !== null) {
if ($workspaces->getBaseWorkspaces($workspace->workspaceName)->get($editedWorkspaceName) !== null) {
continue;
}
}
$workspaceMetadata = $this->workspaceService->getWorkspaceMetadata($contentRepository->id, $workspace->workspaceName);
$workspaceMetadata = $this->workspaceService->getWorkspaceMetadata(
$contentRepository->id,
$workspace->workspaceName
);
if (!in_array($workspaceMetadata->classification, [WorkspaceClassification::SHARED, WorkspaceClassification::ROOT], true)) {
continue;
}
if ($user === null) {
continue;
}
$permissions = $this->authorizationService->getWorkspacePermissions($contentRepository->id, $workspace->workspaceName, $this->securityContext->getRoles(), $user->getId());
$permissions = $this->authorizationService->getWorkspacePermissions(
$contentRepository->id,
$workspace->workspaceName,
$this->securityContext->getRoles(),
$user?->getId()
);
if (!$permissions->read) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ prototype(Neos.Workspace.Ui:Component.WorkspaceTable) < prototype(Neos.Fusion:Co
<tbody>
<Neos.Workspace.Ui:Component.WorkspaceTreeNode
workspaceListItems={props.workspaceListItems}
baseWorkspaceListItems={Array.filter(props.workspaceListItems, (entryWorkspace) => entryWorkspace.baseWorkspaceName == 'live')}
/>
</tbody>
</table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,22 @@ prototype(Neos.Workspace.Ui:Component.WorkspaceTreeNode) < prototype(Neos.Fusion
workspaceListItem = null
/// Neos\Workspace\Ui\ViewModel\WorkspaceListItems
workspaceListItems = null
// array<Neos\Workspace\Ui\ViewModel\WorkspaceListItem>
baseWorkspaceListItems = null
/// int
level = 0

@private {
baseWorkspaceListItems = ${Array.filter(props.workspaceListItems, (workspaceListItem) => workspaceListItem.baseWorkspaceName == (props.workspaceListItem.name || 'live'))}
}

renderer = afx`
<Neos.Workspace.Ui:Component.WorkspaceTableRow
workspaceListItem={props.workspaceListItem}
level={props.level}
@if={props.workspaceListItem != null}
/>
<Neos.Fusion:Loop items={private.baseWorkspaceListItems} itemName="workspaceListItem">
<Neos.Fusion:Loop items={props.baseWorkspaceListItems} itemName="workspaceListItem">
<Neos.Workspace.Ui:Component.WorkspaceTreeNode
workspaceListItem={workspaceListItem}
workspaceListItems={props.workspaceListItems}
baseWorkspaceListItems={Array.filter(props.workspaceListItems, (workspace) => workspace.baseWorkspaceName == workspaceListItem.name)}
level={props.level + 1}
/>
</Neos.Fusion:Loop>
Expand Down

0 comments on commit a7d6cc1

Please sign in to comment.