Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUGFIX: show workspace owner/title in media usage tab #5182

Merged
merged 6 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions 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,12 @@ 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']) {
$isPrivilegedRole = $this->securityContext->hasRole('Neos.Media.Browser:WorkspaceName');
}

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

Expand All @@ -175,13 +195,12 @@ public function relatedNodesAction(AssetInterface $asset)
*/
private function getNodeFrom(AssetUsageInNodeProperties $assetUsage)
{
$context = $this->_contextFactory->create(
[
$context = $this->_contextFactory->create([
'workspaceName' => $assetUsage->getWorkspaceName(),
'dimensions' => $assetUsage->getDimensionValues(),
'invisibleContentShown' => true,
'removedContentShown' => true]
);
'removedContentShown' => true
]);
return $context->getNodeByIdentifier($assetUsage->getNodeIdentifier());
}
}
3 changes: 3 additions & 0 deletions Neos.Media.Browser/Configuration/Policy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ privilegeTargets:
matcher: 'method(Neos\Media\Browser\Controller\(Asset|Image)Controller->(replaceAssetResource|updateAssetResource)Action())'

roles:
'Neos.Media.Browser:WorkspaceName':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we just assign the privilege to the admin, we don't need this role IMO. If someone needs it, they can create their own.

abstract: true

'Neos.Neos:AbstractEditor':
privileges:
-
Expand Down
3 changes: 3 additions & 0 deletions Neos.Media.Browser/Configuration/Settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ Neos:
# By default, enable the option to create redirects for replaced asset resources
createAssetRedirectsOption:
enable: true
# By default, enable showing the workspace owner/title in media browser usage tab
showWorkspaceOwnerOrName:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO we don't need this switch. If someone doesn't want the feature they can disable or remove the privilege.

enable: true

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
3 changes: 1 addition & 2 deletions Neos.Neos/Configuration/Policy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,7 @@ roles:
'Neos.Neos:Administrator':
label: Neos Administrator
description: Grants access to all modules and functionalities of the Neos backend.

parentRoles: ['Neos.Neos:Editor']
parentRoles: ['Neos.Neos:Editor', 'Neos.Media.Browser:WorkspaceName']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to assign the privilege in the Media.Browser package to not add a dependency here.
This is already done there for several other privileges like this example:

  'Neos.Neos:Administrator':
    privileges:
      -
        privilegeTarget: 'Neos.Media.Browser:ManageAssetCollections'
        permission: GRANT

privileges:
-
privilegeTarget: 'Neos.Neos:Backend.Module.Administration'
Expand Down
Loading