Skip to content

Commit

Permalink
BUGFIX: new method to return label containing the workspace title/owner
Browse files Browse the repository at this point in the history
- UsageController.php: introduce new method to return `label` for workspace title based on privilege target and workspace type
- RelatedNodes.html: use new `label` for rendering

Issue: #5181
  • Loading branch information
habuchholz committed Jul 29, 2024
1 parent 35b3be1 commit 1d034a8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
24 changes: 17 additions & 7 deletions Neos.Media.Browser/Classes/Controller/UsageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,6 @@ class UsageController extends ActionController
public function relatedNodesAction(AssetInterface $asset)
{
$userWorkspace = $this->userService->getPersonalWorkspace();
$currentAccount = $this->securityContext->getAccount();

$isPrivilegedRole = false;
if ($currentAccount != null) {
$isPrivilegedRole = $this->privilegeManager->isPrivilegeTargetGranted('Neos.Media.Browser:WorkspaceName');
}

$usageReferences = $this->assetService->getUsageReferences($asset);
$relatedNodes = [];
Expand Down Expand Up @@ -136,6 +130,7 @@ public function relatedNodesAction(AssetInterface $asset)
$workspace = $this->workspaceRepository->findByIdentifier($usage->getWorkspaceName());
$accessible = $this->domainUserService->currentUserCanReadWorkspace($workspace);

$inaccessibleRelation['label'] = $this->getLabelForInaccessibleWorkspace($workspace);
$inaccessibleRelation['nodeIdentifier'] = $usage->getNodeIdentifier();
$inaccessibleRelation['workspaceName'] = $usage->getWorkspaceName();
$inaccessibleRelation['workspace'] = $workspace;
Expand Down Expand Up @@ -186,7 +181,6 @@ public function relatedNodesAction(AssetInterface $asset)
'relatedNodes' => $relatedNodes,
'contentDimensions' => $this->contentDimensionPresetSource->getAllPresets(),
'userWorkspace' => $userWorkspace,
'isPrivilegedRole' => $isPrivilegedRole,
]);
}

Expand All @@ -204,4 +198,20 @@ private function getNodeFrom(AssetUsageInNodeProperties $assetUsage)
]);
return $context->getNodeByIdentifier($assetUsage->getNodeIdentifier());
}

private function getLabelForInaccessibleWorkspace(Workspace $workspace): string
{
$currentAccount = $this->securityContext->getAccount();

if ($currentAccount != null && $this->privilegeManager->isPrivilegeTargetGranted('Neos.Media.Browser:WorkspaceName')) {
if ($workspace->isPrivateWorkspace()) {
$owner = $workspace->getOwner();
return '(' . $owner->getLabel() . ')';
} else {
return '(' . $workspace->getTitle() . ')';
}
}

return '';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,23 @@
title="{neos:backend.translate(id: 'workspaces.personalWorkspace', source: 'Modules', package: 'Neos.Neos')}"
data-neos-toggle="tooltip"></i>
{neos:backend.translate(id: 'workspaces.personalWorkspace', source: 'Modules', package: 'Neos.Neos')}
<f:if condition="{isPrivilegedRole}">({inaccessibleRelation.workspace.title})</f:if>
{inaccessibleRelation.label}
</f:case>
<f:case value="{inaccessibleRelation.workspace.privateWorkspace}">
<i class="fas fa-shield"
title="{neos:backend.translate(id: 'workspaces.privateWorkspace', source: 'Modules', package: 'Neos.Neos')}"
data-neos-toggle="tooltip"></i>
{neos:backend.translate(id: 'workspaces.privateWorkspace', source: 'Modules', package:
'Neos.Neos')}
<f:if condition="{isPrivilegedRole}">({inaccessibleRelation.workspace.owner.name.fullName})</f:if>
{inaccessibleRelation.label}
</f:case>
<f:case value="{inaccessibleRelation.workspace.internalWorkspace}">
<i class="fas fa-group"
title="{neos:backend.translate(id: 'workspaces.internalWorkspace', source: 'Modules', package: 'Neos.Neos')}"
data-neos-toggle="tooltip"></i>
{neos:backend.translate(id: 'workspaces.internalWorkspace', source: 'Modules', package:
'Neos.Neos')}
<f:if condition="{isPrivilegedRole}">({inaccessibleRelation.workspace.title})</f:if>
{inaccessibleRelation.label}
</f:case>
<f:defaultCase>
---
Expand Down

0 comments on commit 1d034a8

Please sign in to comment.