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 1 commit
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: 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:
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: false
privilegedRoles: ['Neos.Neos:Administrator']
Copy link
Member

@Sebobo Sebobo Jul 23, 2024

Choose a reason for hiding this comment

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

Any reason why you didn't introduce an actual privilege instead of defining a privilege via the settings?

You could introduce a new privilege and integrators can add it to whichever role they want.
Could also be enabled by default for admins IMO.

This way you only need to check if the new privilege is granted and simplify the code a bit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, haven't thought about that one.

I've implemented the privilege but im stuck trying to check the role without looping over them.
Would be nice to have something like Account::hasRole() including parent roles.

Or should i just loop over the user (parent) roles and match them with the new privilege role.

Copy link
Member

Choose a reason for hiding this comment

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

You can either use $this->securityContext->hasRole($roleIdentifier) or $this->privilegeManager->isPrivilegeTargetGranted($privilegeTarget);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks worked like a charm!


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
Loading