Skip to content

Commit

Permalink
BUGFIX: Show correct workspace visibility state in the workspace list
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebobo committed Dec 19, 2024
1 parent 22b8c69 commit 89b7cae
Show file tree
Hide file tree
Showing 35 changed files with 245 additions and 191 deletions.
13 changes: 12 additions & 1 deletion Neos.Workspace.Ui/Classes/Controller/WorkspaceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public function createAction(
/**
* Edit a workspace
*
* Renders /Resource/Private/Fusion/Views/Edit.fusion
* @param WorkspaceName $workspaceName The name of the workspace that is being edited
*/
public function editAction(WorkspaceName $workspaceName): void
{
Expand Down Expand Up @@ -318,8 +318,10 @@ public function editAction(WorkspaceName $workspaceName): void
* Update a workspace
*
* @Flow\Validate(argumentName="title", type="\Neos\Flow\Validation\Validator\NotEmptyValidator")
* @param WorkspaceName $workspaceName The name of the workspace that is being updated
* @param WorkspaceTitle $title Human friendly title of the workspace, for example "Christmas Campaign"
* @param WorkspaceDescription $description A description explaining the purpose of the new workspace
* @param WorkspaceName $baseWorkspace A description explaining the purpose of the new workspace
*/
public function updateAction(
WorkspaceName $workspaceName,
Expand Down Expand Up @@ -651,6 +653,7 @@ public function confirmPublishAllChangesAction(WorkspaceName $workspaceName): vo
'workspaceTitle' => $workspaceMetadata->title->value,
]);
}

public function confirmDiscardAllChangesAction(WorkspaceName $workspaceName): void
{
$contentRepositoryId = SiteDetectionResult::fromRequest($this->request->getHttpRequest())->contentRepositoryId;
Expand Down Expand Up @@ -693,6 +696,7 @@ public function confirmPublishSelectedChangesAction(WorkspaceName $workspaceName
'baseWorkspaceTitle' => $baseWorkspaceMetadata->title->value,
]);
}

public function confirmDiscardSelectedChangesAction(WorkspaceName $workspaceName): void
{
$contentRepositoryId = SiteDetectionResult::fromRequest($this->request->getHttpRequest())->contentRepositoryId;
Expand Down Expand Up @@ -1246,6 +1250,10 @@ protected function getWorkspaceListItems(
// 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,
Expand All @@ -1265,11 +1273,13 @@ protected function getWorkspaceListItems(
!$allWorkspaces->getDependantWorkspaces($userWorkspace->workspaceName)->isEmpty(),
$userWorkspaceOwner->getLabel(),
$userWorkspacesPermissions,
$workspaceRoleAssignments,
);

// add other, accessible workspaces
foreach ($allWorkspaces as $workspace) {
$workspaceMetadata = $this->workspaceService->getWorkspaceMetadata($contentRepository->id, $workspace->workspaceName);
$workspaceRoleAssignments = $this->workspaceService->getWorkspaceRoleAssignments($contentRepository->id, $workspace->workspaceName);
$workspacesPermissions = $this->authorizationService->getWorkspacePermissions(
$contentRepository->id,
$workspace->workspaceName,
Expand Down Expand Up @@ -1303,6 +1313,7 @@ protected function getWorkspaceListItems(
!$allWorkspaces->getDependantWorkspaces($workspace->workspaceName)->isEmpty(),
$workspaceOwner?->getLabel(),
$workspacesPermissions,
$workspaceRoleAssignments,
);
}
return WorkspaceListItems::fromArray($workspaceListItems);
Expand Down
36 changes: 36 additions & 0 deletions Neos.Workspace.Ui/Classes/ViewModel/WorkspaceListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
namespace Neos\Workspace\Ui\ViewModel;

use Neos\Flow\Annotations as Flow;
use Neos\Neos\Domain\Model\WorkspaceClassification;
use Neos\Neos\Domain\Model\WorkspacePermissions;
use Neos\Neos\Domain\Model\WorkspaceRole;
use Neos\Neos\Domain\Model\WorkspaceRoleAssignments;

#[Flow\Proxy(false)]
final readonly class WorkspaceListItem
Expand All @@ -33,6 +36,39 @@ public function __construct(
// todo check if necessary, only for personal workspaces that others have permissions to
public ?string $owner,
public WorkspacePermissions $permissions,
public WorkspaceRoleAssignments $roleAssignments,
) {
}

public function isPersonal(): bool
{
return $this->classification === WorkspaceClassification::PERSONAL->value;
}

public function isPrivate(): bool
{
if ($this->classification !== WorkspaceClassification::SHARED->value ||
$this->roleAssignments->count() > 1) {
return false;
}
foreach ($this->roleAssignments as $roleAssignment) {
if ($roleAssignment->role === WorkspaceRole::COLLABORATOR) {
return false;
}
}
return true;
}

public function isShared(): bool
{
if ($this->roleAssignments->count() > 1) {
return true;
}
foreach ($this->roleAssignments as $roleAssignment) {
if ($roleAssignment->role === WorkspaceRole::COLLABORATOR) {
return true;
}
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ prototype(Neos.Workspace.Ui:Component.Icon) < prototype(Neos.Fusion:Component) {
secondaryIcon = ''
spin = false
rotate = false
// TODO: Support colors
style = ''

renderer = afx`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,13 @@ prototype(Neos.Workspace.Ui:Component.WorkspaceTableRow) < prototype(Neos.Fusion
i18n = ${I18n.id('').source('Main').package('Neos.Workspace.Ui')}
workspace = ${props.workspaceListItem.workspace}
workspaceTableRowId = ${'workspace-row-' + props.workspaceListItem.name}
// todo move state calculation to php
workspaceStatus = Neos.Fusion:Case {
personal-workspace {
condition = ${props.workspaceListItem.name == props.userWorkspaceName}
renderer = 'personal-workspace'
}
stale {
// TODO: Calculate stale status based on last change data
condition = false
renderer = 'stale'
}
withAcl {
// TODO: Calculate acl status on whether the workspace is shared with selected users
condition = false
renderer = 'with-acl'
personal {
condition = ${props.workspaceListItem.personal}
renderer = 'personal'
}
private {
condition = ${props.workspaceListItem.owner}
condition = ${props.workspaceListItem.private}
renderer = 'private'
}
default {
Expand All @@ -39,18 +28,16 @@ prototype(Neos.Workspace.Ui:Component.WorkspaceTableRow) < prototype(Neos.Fusion
}
}
workspaceStatusLabel = Neos.Fusion:Match {
// todo status private doesnt exist anymore
@subject = ${private.workspaceStatus}
@default = ${private.i18n.id('table.column.access.internal').value('Internal workspace')}
personal-workspace = ${private.i18n.id('badge.isPersonalWorkspace').value('This is your personal workspace')}
stale = ${private.i18n.id('badge.isStale').value('This workspace has not been used for a long time')}
with-acl = ${private.i18n.id('table.column.access.acl').value('This workspace is owned by ' + props.workspaceListItem.owner + ' but allows access to additional users')}
private = ${private.i18n.id('table.column.access.private').value('This workspace is owned by ' + props.workspaceListItem.owner)}
@default = ${private.i18n.id('table.column.access.shared')}
personal = ${private.i18n.id('table.column.access.personal').arguments([props.workspaceListItem.owner])}
private = ${private.i18n.id('table.column.access.private')}
}
workspaceStatusIcon = Neos.Fusion:Match {
@subject = ${private.workspaceStatus}
@default = 'user'
shared = 'users'
private = 'user-shield'
with-acl = 'user-plus'
}
reviewWorkspaceUri = Neos.Fusion:ActionUri {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ prototype(Neos.Workspace.Ui:Component.Modal.Create) < prototype(Neos.Fusion:Comp
field.name="visibility"
field.value="shared"
>
{private.i18n.id('workspaces.workspace.visibility.internal')}
{private.i18n.id('workspaces.workspace.visibility.shared')}
</Neos.Fusion.Form:Radio>
<p>
{private.i18n.id('workspaces.workspace.visibility.internal.help')}
{private.i18n.id('workspaces.workspace.visibility.shared.help')}
</p>
<br/>
<Neos.Fusion.Form:Radio
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,17 @@ prototype(Neos.Workspace.Ui:Component.Modal.Edit) < prototype(Neos.Fusion:Compon
<Neos.Fusion.Form:Form
form.target.action="update"
form.target.format="htmx"
form.target.arguments.workspaceName={props.workspaceName}
attributes.class="neos-inline"
attributes.hx-post={form.getTarget()}
attributes.hx-disabled-elt="find button"
attributes.hx-on--after-request={'document.getElementById("' + private.popoverId + '").hidePopover()'}
>
<section>
<fieldset>
<Neos.Fusion.Form:Hidden
field.name="workspaceName"
field.value={props.workspaceName}
/>
<Neos.Fusion.Form:Neos.BackendModule.FieldContainer
field.name="title"
field.value={props.workspaceTitle}
Expand Down Expand Up @@ -101,15 +104,10 @@ prototype(Neos.Workspace.Ui:Component.Modal.Edit) < prototype(Neos.Fusion:Compon
</Neos.Fusion.Form:Select.Option>
</Neos.Fusion:Loop>
</Neos.Fusion.Form:Select>
<!-- TODO: use component and styling -->
<p
style={{ marginTop: '.5em' }}
@if.workspaceHasChanges={props.workspaceHasChanges}
>
<i
class="fas fa-exclamation-triangle"
style={{ color: 'var(--warningText)', marginRight: '.5em' }}
></i>{' '}
<br/>
<p @if.workspaceHasChanges={props.workspaceHasChanges}>
<Neos.Workspace.Ui:Component.Icon icon="exclamation-triangle" style={{ color: 'var(--warningText)' }}/>
{' '}
{private.i18n.id('workspaces.cantChangeBaseWorkspaceBecauseWorkspaceContainsChanges')}
</p>
</Neos.Fusion.Form:Neos.BackendModule.FieldContainer>
Expand All @@ -123,10 +121,10 @@ prototype(Neos.Workspace.Ui:Component.Modal.Edit) < prototype(Neos.Fusion:Compon
field.name="visibility"
field.value="shared"
>
{private.i18n.id('workspaces.workspace.visibility.internal')}
{private.i18n.id('workspaces.workspace.visibility.shared')}
</Neos.Fusion.Form:Radio>
<p>
{private.i18n.id('workspaces.workspace.visibility.internal.help')}
{private.i18n.id('workspaces.workspace.visibility.shared.help')}
</p>
<br/>
<Neos.Fusion.Form:Radio
Expand Down
10 changes: 5 additions & 5 deletions Neos.Workspace.Ui/Resources/Private/Translations/ar/Main.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
<source>Private workspace</source>
<target state="translated">مجال العمل الخاص</target>
</trans-unit>
<trans-unit id="workspaces.internalWorkspace" xml:space="preserve">
<source>Internal workspace</source>
<trans-unit id="workspaces.sharedWorkspace" xml:space="preserve">
<source>Shared workspace</source>
<target state="translated">فضاء العمل الداخلي</target>
</trans-unit>
<trans-unit id="workspaces.readonlyWorkspace" xml:space="preserve">
Expand Down Expand Up @@ -95,11 +95,11 @@
<source>Only reviewers and administrators can access and modify this workspace</source>
<target state="translated">فضاء العمل هذا لا يمكن الوصول إليه وتعديله إلا من طرف المراجعين والمسؤولين فقط</target>
</trans-unit>
<trans-unit id="workspaces.workspace.visibility.internal" xml:space="preserve">
<source>Internal</source>
<trans-unit id="workspaces.workspace.visibility.shared" xml:space="preserve">
<source>Shared</source>
<target state="translated">داخلي</target>
</trans-unit>
<trans-unit id="workspaces.workspace.visibility.internal.help" xml:space="preserve">
<trans-unit id="workspaces.workspace.visibility.shared.help" xml:space="preserve">
<source>Any logged in editor can see and modify this workspace.</source>
<target state="translated">يمكن لأي محرر تسجيل الدخول رؤية وتعديل فضاء العمل هذا.</target>
</trans-unit>
Expand Down
14 changes: 7 additions & 7 deletions Neos.Workspace.Ui/Resources/Private/Translations/cs/Main.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@
<source>Private workspace</source>
<target state="needs-translation">Private workspace</target>
</trans-unit>
<trans-unit id="workspaces.internalWorkspace" xml:space="preserve">
<source>Internal workspace</source>
<target state="needs-translation">Internal workspace</target>
<trans-unit id="workspaces.sharedWorkspace" xml:space="preserve">
<source>Shared workspace</source>
<target state="needs-translation">Shared workspace</target>
</trans-unit>
<trans-unit id="workspaces.readonlyWorkspace" xml:space="preserve">
<source>Read-only workspace</source>
Expand Down Expand Up @@ -95,11 +95,11 @@
<source>Only reviewers and administrators can access and modify this workspace</source>
<target state="needs-translation">Only reviewers and administrators can access and modify this workspace</target>
</trans-unit>
<trans-unit id="workspaces.workspace.visibility.internal" xml:space="preserve">
<source>Internal</source>
<target state="needs-translation">Internal</target>
<trans-unit id="workspaces.workspace.visibility.shared" xml:space="preserve">
<source>Shared</source>
<target state="needs-translation">Shared</target>
</trans-unit>
<trans-unit id="workspaces.workspace.visibility.internal.help" xml:space="preserve">
<trans-unit id="workspaces.workspace.visibility.shared.help" xml:space="preserve">
<source>Any logged in editor can see and modify this workspace.</source>
<target state="needs-translation">Any logged in editor can see and modify this workspace.</target>
</trans-unit>
Expand Down
10 changes: 5 additions & 5 deletions Neos.Workspace.Ui/Resources/Private/Translations/da/Main.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
<source>Private workspace</source>
<target state="final">Privat arbejdsrum</target>
</trans-unit>
<trans-unit id="workspaces.internalWorkspace" xml:space="preserve" approved="yes">
<source>Internal workspace</source>
<trans-unit id="workspaces.sharedWorkspace" xml:space="preserve" approved="yes">
<source>Shared workspace</source>
<target state="final">Internt arbejdsrum</target>
</trans-unit>
<trans-unit id="workspaces.readonlyWorkspace" xml:space="preserve" approved="yes">
Expand Down Expand Up @@ -95,11 +95,11 @@
<source>Only reviewers and administrators can access and modify this workspace</source>
<target state="final">Kun korrekturlæsere og administratorer kan få adgang til og ændre dette arbejdsrum</target>
</trans-unit>
<trans-unit id="workspaces.workspace.visibility.internal" xml:space="preserve" approved="yes">
<source>Internal</source>
<trans-unit id="workspaces.workspace.visibility.shared" xml:space="preserve" approved="yes">
<source>Shared</source>
<target state="final">Internt</target>
</trans-unit>
<trans-unit id="workspaces.workspace.visibility.internal.help" xml:space="preserve" approved="yes">
<trans-unit id="workspaces.workspace.visibility.shared.help" xml:space="preserve" approved="yes">
<source>Any logged in editor can see and modify this workspace.</source>
<target state="final">Enhver redaktør som er logget ind kan se og ændre dette arbejdsrum.</target>
</trans-unit>
Expand Down
22 changes: 17 additions & 5 deletions Neos.Workspace.Ui/Resources/Private/Translations/de/Main.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
<source>Private workspace</source>
<target state="final">Privater Arbeitsbereich</target>
</trans-unit>
<trans-unit id="workspaces.internalWorkspace" xml:space="preserve" approved="yes">
<source>Internal workspace</source>
<trans-unit id="workspaces.sharedWorkspace" xml:space="preserve" approved="yes">
<source>Shared workspace</source>
<target state="final">Interner Arbeitsbereich</target>
</trans-unit>
<trans-unit id="workspaces.readonlyWorkspace" xml:space="preserve" approved="yes">
Expand Down Expand Up @@ -95,11 +95,11 @@
<source>Only reviewers and administrators can access and modify this workspace</source>
<target state="final">Nur Reviewer und Administratoren können auf diesen Arbeitsbereich zugreifen und ihn bearbeiten</target>
</trans-unit>
<trans-unit id="workspaces.workspace.visibility.internal" xml:space="preserve" approved="yes">
<source>Internal</source>
<trans-unit id="workspaces.workspace.visibility.shared" xml:space="preserve" approved="yes">
<source>Shared</source>
<target state="final">Intern</target>
</trans-unit>
<trans-unit id="workspaces.workspace.visibility.internal.help" xml:space="preserve" approved="yes">
<trans-unit id="workspaces.workspace.visibility.shared.help" xml:space="preserve" approved="yes">
<source>Any logged in editor can see and modify this workspace.</source>
<target state="final">Jeder angemeldete Redakteur kann diesen Arbeitsbereich sehen und bearbeiten.</target>
</trans-unit>
Expand Down Expand Up @@ -269,6 +269,18 @@
<source>Select all current changes</source>
<target state="final">Alle aktuellen Änderungen auswählen</target>
</trans-unit>
<trans-unit id="table.column.access.shared" approved="yes">
<source>This is a shared workspace</source>
<target>Dies ist ein gemeinsamer Arbeitsbereich</target>
</trans-unit>
<trans-unit id="table.column.access.private" approved="yes">
<source>This is a private workspace</source>
<target>Dies ist ein privater Arbeitsbereich</target>
</trans-unit>
<trans-unit id="table.column.access.personal" approved="yes">
<source>This is the personal workspace of "{0}"</source>
<target>Dies ist der persönliche Arbeitsbereich von "{0}"</target>
</trans-unit>
</body>
</file>
</xliff>
Loading

0 comments on commit 89b7cae

Please sign in to comment.