Skip to content

Commit

Permalink
FIX: show workspace owner/title in media usage tab
Browse files Browse the repository at this point in the history
- configurable privilege roles

Issue: neos#5181
  • Loading branch information
habuchholz committed Jul 12, 2024
1 parent 3ca0811 commit 621b27e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
29 changes: 28 additions & 1 deletion Neos.Media.Browser/Classes/Controller/UsageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Neos\Eel\FlowQuery\FlowQuery;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Mvc\Controller\ActionController;
use Neos\Flow\Security\Context;
use Neos\Media\Domain\Model\AssetInterface;
use Neos\Media\Domain\Service\AssetService;
use Neos\Neos\Controller\CreateContentContextTrait;
Expand Down Expand Up @@ -80,6 +81,18 @@ class UsageController extends ActionController
*/
protected $domainUserService;

/**
* @Flow\Inject
* @var Context
*/
protected $securityContext;

/**
* @Flow\InjectConfiguration(package="Neos.Media.Browser", path="features.showWorkspaceOwnerOrName")
* @var array
*/
protected $showWorkspaceOwnerOrNameConfiguration;

/**
* Get Related Nodes for an asset
*
Expand All @@ -89,6 +102,19 @@ class UsageController extends ActionController
public function relatedNodesAction(AssetInterface $asset)
{
$userWorkspace = $this->userService->getPersonalWorkspace();
$currentAccount = $this->securityContext->getAccount();

$isPrivilegedRole = false;
if ($currentAccount != null && $this->showWorkspaceOwnerOrNameConfiguration['enable']) {
$roles = array_keys($currentAccount->getRoles());

foreach ($this->showWorkspaceOwnerOrNameConfiguration['privilegedRoles'] as $role) {
if (in_array($role, $roles)) {
$isPrivilegedRole = true;
break;
}
}
}

$usageReferences = $this->assetService->getUsageReferences($asset);
$relatedNodes = [];
Expand Down Expand Up @@ -165,7 +191,8 @@ public function relatedNodesAction(AssetInterface $asset)
'inaccessibleRelations' => $inaccessibleRelations,
'relatedNodes' => $relatedNodes,
'contentDimensions' => $this->contentDimensionPresetSource->getAllPresets(),
'userWorkspace' => $userWorkspace
'userWorkspace' => $userWorkspace,
'isPrivilegedRole' => $isPrivilegedRole,
]);
}

Expand Down
4 changes: 4 additions & 0 deletions Neos.Media.Browser/Configuration/Settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ Neos:
# By default, enable the option to create redirects for replaced asset resources
createAssetRedirectsOption:
enable: true
# By default, disable showing the workspace owner/title in media browser usage tab
showWorkspaceOwnerOrName:
enable: false
privilegedRoles: ['Neos.Neos:Administrator']

Flow:
security:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +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>
</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>
</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>
</f:case>
<f:defaultCase>
---
Expand Down

0 comments on commit 621b27e

Please sign in to comment.