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

Conversation

habuchholz
Copy link
Contributor

Issue: #5181

Possibility to enable showing all workspace titles/owners to user with certain roles in the media usage tab.

Checklist

  • Code follows the PSR-2 coding style
  • Tests have been created, run and adjusted as needed
  • The PR is created against the lowest maintained branch
  • Reviewer - PR Title is brief but complete and starts with FEATURE|TASK|BUGFIX
  • Reviewer - The first section explains the change briefly for change-logs
  • Reviewer - Breaking Changes are marked with !!! and have upgrade-instructions

- configurable privilege roles

Issue: neos#5181
@habuchholz habuchholz force-pushed the bugfix/workspace-title_media-usage-tab branch from 621b27e to 0e15553 Compare July 12, 2024 17:14
# By default, disable showing the workspace owner/title in media browser usage tab
showWorkspaceOwnerOrName:
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!

- new role `Neos.Media.Browser:WorkspaceName`
- add new role to `Neos.Neos:Administrator` as parent role
- enable showing the workspace owner by default
- adjust UsageController.php to check if current user role matches the new role

Issue: neos#5181
@habuchholz habuchholz requested a review from Sebobo July 25, 2024 13:29
- remove unused variable `$policyService` and import in UsageController.php and fix formatting
- correct commentary in Settings.yaml

Issue: neos#5181
@@ -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

@@ -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.

@@ -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.

…ame` instead of the role

- introduce new privilege target `Neos.Media.Browser:WorkspaceName`, grant privilege to `Neos.Neos:Administrator` and remove obsolet abstract role `Neos.Media.Browser:WorkspaceName`
- remove unnecessary parent role from `Neos.Neos:Administrator`
- remove config in Settings.yaml
- adjust UsageController.php to work with new privilege target

Issue: neos#5181
Copy link
Member

@Sebobo Sebobo left a comment

Choose a reason for hiding this comment

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

We are getting there, thx for your work :)

I have an idea: you don't use the isPrivilegedRole variable but instead add a field label to the inaccessibleRelation entries.

There you use a new method getLabelForInaccessibleWorkspace which is checked by your WorkspaceName privilege.
If $isPrivilegedRole is not given, then you leave the label for the relation empty for now (maybe we can make this nicer in the future and also add the translated part in there.
This way you can just render the label in the template the same way in all 3 cases.

Wdyt? Hope I don't discourage you with my feedback, but things like this are sometimes a bit hard to get right, even though they look simple.

Neos.Media.Browser/Configuration/Policy.yaml Show resolved Hide resolved
- 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: neos#5181
@habuchholz habuchholz requested a review from Sebobo July 29, 2024 08:34
@dlubitz dlubitz self-requested a review August 13, 2024 09:18
@Jan3k3y
Copy link

Jan3k3y commented Sep 3, 2024

Any updates here?🤔

@Sebobo
Copy link
Member

Sebobo commented Sep 16, 2024

Everyone was on holidays 😉

Will take a look again and find some more reviews.

@markusguenther markusguenther self-assigned this Sep 23, 2024
Copy link
Member

@skurfuerst skurfuerst left a comment

Choose a reason for hiding this comment

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

thanks everybody :) (I reviewed it once again together with @Jan3k3y synchronously)

@skurfuerst skurfuerst merged commit 4da870e into neos:8.3 Oct 23, 2024
7 checks passed
@skurfuerst skurfuerst deleted the bugfix/workspace-title_media-usage-tab branch October 23, 2024 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants