Skip to content

Commit

Permalink
TASK: Use workspace classification to handle personal workspaces in t…
Browse files Browse the repository at this point in the history
…he ui
  • Loading branch information
Sebobo committed Dec 20, 2024
1 parent d552690 commit 1e06fbe
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 59 deletions.
46 changes: 3 additions & 43 deletions Neos.Workspace.Ui/Classes/Controller/WorkspaceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,13 @@ public function indexAction(string $sortBy = 'title', bool $sortAscending = true
$this->view->assign('displayContentRepositorySelector', $numberOfContentRepositories > 1);

$contentRepository = $this->contentRepositoryRegistry->get($contentRepositoryId);
$workspaceListItems = $this->getWorkspaceListItems($contentRepository, $currentUser);
$workspaceListItems = $this->getWorkspaceListItems($contentRepository);

if ($sortBy === 'title') {
$workspaceListItems = $workspaceListItems->sortByTitle($sortAscending);
}

$this->view->assignMultiple([
// todo remove userWorkspaceName field and add distinction to $workspaceListItems as $workspaceListItems->userWorkspace and $workspaceListItems->otherWorkspaces or something.
'userWorkspaceName' => $this->workspaceService->getPersonalWorkspaceForUser($contentRepositoryId, $currentUser->getId())->workspaceName->value,
'workspaceListItems' => $workspaceListItems,
'flashMessages' => $this->controllerContext->getFlashMessageContainer()->getMessagesAndFlush(),
'sortAscending' => $sortAscending,
Expand Down Expand Up @@ -422,20 +420,16 @@ public function updateAction(
)
);

$workspaceListItems = $this->getWorkspaceListItems($contentRepository, $currentUser);
$workspaceListItems = $this->getWorkspaceListItems($contentRepository);

$this->view->assignMultiple([
'userWorkspaceName' => $this->workspaceService->getPersonalWorkspaceForUser($contentRepositoryId, $currentUser->getId())->workspaceName->value,
'workspaceListItems' => $workspaceListItems,
]);
}

/**
* Delete a workspace
*
* TODO: Add force delete option to ignore unpublished nodes or dependent workspaces, the later should be rebased instead
*
* @param WorkspaceName $workspaceName A workspace to delete
* @throws StopActionException
*/
public function deleteAction(WorkspaceName $workspaceName): void
Expand Down Expand Up @@ -499,7 +493,7 @@ public function deleteAction(WorkspaceName $workspaceName): void
);
$this->addFlashMessage($message, '', Message::SEVERITY_WARNING);
$this->throwStatus(403, 'Workspace has unpublished nodes');
// delete workspace on POST -> todo make this more FLOW-ig by possibly having a DeleteController with post() and get() _or_ by having deleteAction_post and deleteAction_get?? Or a separate action?
// delete workspace on POST -> TODO: Split this into 2 actions like the create or edit workflows
} elseif ($this->request->getHttpRequest()->getMethod() === 'POST') {
$this->workspaceService->deleteWorkspace($contentRepositoryId, $workspaceName);

Expand Down Expand Up @@ -967,15 +961,11 @@ protected function renderContentChanges(
$originalPropertyValue = ($originalNode?->getProperty($propertyName));

if ($changedPropertyValue === $originalPropertyValue) {
// TODO && !$changedNode->isRemoved()
continue;
}

if (!is_object($originalPropertyValue) && !is_object($changedPropertyValue)) {
$originalSlimmedDownContent = $this->renderSlimmedDownContent($originalPropertyValue);
// TODO $changedSlimmedDownContent = $changedNode->isRemoved()
// ? ''
// : $this->renderSlimmedDownContent($changedPropertyValue);
$changedSlimmedDownContent = $this->renderSlimmedDownContent($changedPropertyValue);

$diff = new Diff(
Expand Down Expand Up @@ -1223,38 +1213,9 @@ public function getModuleLabel(string $id, array $arguments = [], mixed $quantit

protected function getWorkspaceListItems(
ContentRepository $contentRepository,
User $userWorkspaceOwner,
): WorkspaceListItems {
$workspaceListItems = [];
$allWorkspaces = $contentRepository->findWorkspaces();
// todo this throws "No workspace is assigned to the user with id" for the case user logs first into workspace module before workspace exists!!!
$userWorkspace = $this->workspaceService->getPersonalWorkspaceForUser($contentRepository->id, $userWorkspaceOwner->getId());
$userWorkspaceMetadata = $this->workspaceService->getWorkspaceMetadata($contentRepository->id, $userWorkspace->workspaceName);
$workspaceRoleAssignments = $this->workspaceService->getWorkspaceRoleAssignments(
$contentRepository->id,
$userWorkspace->workspaceName
);
$userWorkspacesPermissions = $this->authorizationService->getWorkspacePermissions(
$contentRepository->id,
$userWorkspace->workspaceName,
$this->securityContext->getRoles(),
$userWorkspaceOwner->getId()
);

// add user workspace first
$workspaceListItems[$userWorkspace->workspaceName->value] = new WorkspaceListItem(
$userWorkspace->workspaceName->value,
$userWorkspaceMetadata->classification->value,
$userWorkspace->status->value,
$userWorkspaceMetadata->title->value,
$userWorkspaceMetadata->description->value,
$userWorkspace->baseWorkspaceName?->value,
$this->computePendingChanges($userWorkspace, $contentRepository),
!$allWorkspaces->getDependantWorkspaces($userWorkspace->workspaceName)->isEmpty(),
$userWorkspaceOwner->getLabel(),
$userWorkspacesPermissions,
$workspaceRoleAssignments,
);

// add other, accessible workspaces
foreach ($allWorkspaces as $workspace) {
Expand All @@ -1272,7 +1233,6 @@ protected function getWorkspaceListItems(
continue;
}

// TODO use owner/WorkspaceRoleAssignment?
// TODO: If user is allowed to edit child workspace, we need to at least show the parent workspaces in the list
if ($workspacesPermissions->read === false) {
continue;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
Neos.Workspace.Ui.WorkspaceController.index = Neos.Fusion:Component {
/// string
userWorkspaceName = ${userWorkspaceName}
/// Neos\Workspace\Ui\ViewModel\WorkspaceListItems
workspaceListItems = ${workspaceListItems}
/// array
Expand All @@ -26,7 +24,6 @@ Neos.Workspace.Ui.WorkspaceController.index = Neos.Fusion:Component {
<main class="neos-content neos-container-fluid">
<div class="neos-row-fluid">
<Neos.Workspace.Ui:Component.WorkspaceTable
userWorkspaceName={props.userWorkspaceName}
workspaceListItems={props.workspaceListItems}
sortBy={props.sortBy}
sortAscending={props.sortAscending}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
# Update response after a workspace has been edited via the edit modal
#
Neos.Workspace.Ui.WorkspaceController.update = Neos.Fusion:Component {
/// string
userWorkspaceName = ${userWorkspaceName}
/// Neos\Workspace\Ui\ViewModel\WorkspaceListItems
workspaceListItems = ${workspaceListItems}

renderer = afx`
<Neos.Workspace.Ui:Component.WorkspaceTable
userWorkspaceName={props.userWorkspaceName}
workspaceListItems={props.workspaceListItems}
/>
`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# Renders a list of workspaces
#
prototype(Neos.Workspace.Ui:Component.WorkspaceTable) < prototype(Neos.Fusion:Component) {
/// string
userWorkspaceName = null
/// \Neos\Workspace\Ui\ViewModel\WorkspaceListItems
workspaceListItems = ${{}}
/// string
Expand Down Expand Up @@ -48,7 +46,6 @@ prototype(Neos.Workspace.Ui:Component.WorkspaceTable) < prototype(Neos.Fusion:Co
</thead>
<tbody>
<Neos.Workspace.Ui:Component.WorkspaceTreeNode
userWorkspaceName={props.userWorkspaceName}
workspaceName="live"
workspaceListItems={props.workspaceListItems}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# Renders a single workspace list item
#
prototype(Neos.Workspace.Ui:Component.WorkspaceTableRow) < prototype(Neos.Fusion:Component) {
/// string
userWorkspaceName = null
/// Neos\Workspace\Ui\ViewModel\WorkspaceListItem
workspaceListItem = ${[]}
/// integer
Expand Down Expand Up @@ -76,7 +74,7 @@ prototype(Neos.Workspace.Ui:Component.WorkspaceTableRow) < prototype(Neos.Fusion
<td class="workspace-label-column" style={'--indent-level:' + props.level }>
<Neos.Workspace.Ui:Component.Icon icon="level-up-alt" @if={props.level > 1}/>
{props.workspaceListItem.title}
<span class="workspace__info-text" @if={props.workspaceListItem.name == props.userWorkspaceName}>
<span class="workspace__info-text" @if={props.workspaceListItem.personal}>
({private.i18n.id('workspaces.workspace.userWorkspace')})
</span>
</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# Renders a single workspace list item and its subworkspaces
#
prototype(Neos.Workspace.Ui:Component.WorkspaceTreeNode) < prototype(Neos.Fusion:Component) {
/// string
userWorkspaceName = null
/// Neos\Workspace\Ui\ViewModel\WorkspaceListItem
workspaceListItem = null
/// Neos\Workspace\Ui\ViewModel\WorkspaceListItems
Expand All @@ -18,14 +16,12 @@ prototype(Neos.Workspace.Ui:Component.WorkspaceTreeNode) < prototype(Neos.Fusion

renderer = afx`
<Neos.Workspace.Ui:Component.WorkspaceTableRow
userWorkspaceName={props.userWorkspaceName}
workspaceListItem={props.workspaceListItem}
level={props.level}
@if={props.workspaceName != 'live'}
/>
<Neos.Fusion:Loop items={private.baseWorkspaceListItems} itemName="workspaceListItem">
<Neos.Workspace.Ui:Component.WorkspaceTreeNode
userWorkspaceName={props.userWorkspaceName}
workspaceListItem={workspaceListItem}
workspaceListItems={props.workspaceListItems}
level={props.level + 1}
Expand Down

0 comments on commit 1e06fbe

Please sign in to comment.