Skip to content
This repository has been archived by the owner on Aug 18, 2024. It is now read-only.

Permission based access checks should return neutral if a permission is not granted #692

Merged
merged 7 commits into from
Oct 7, 2020

Conversation

pfrenssen
Copy link
Contributor

Fixes #691

Very happy with how this turned out.

It is remarkable how this small change cleans up our access code. By leveraging the core functionality we no longer need to handle the access checks and merging of cacheability metadata ourselves and the end result is very lean and readable code.

This is building on top of #684 so marking this as a draft until that PR is in.

@pfrenssen pfrenssen marked this pull request as draft August 12, 2020 09:17
@pfrenssen pfrenssen marked this pull request as ready for review August 12, 2020 15:17
@pfrenssen pfrenssen added this to the 8.x-1.0-alpha6 milestone Aug 12, 2020
Copy link
Collaborator

@claudiu-cristea claudiu-cristea left a comment

Choose a reason for hiding this comment

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

Opening the access check to 3rd party is a good decision. However, the proposal here aligns with the entity access check, where the a result of neutral reads as "allow access". I'm just curious why you chose entity over route access. Drupal core handles route access different than entity access. On routes, only an allowed result reads as "allow access", neutral means deny.

Relevant:

@pfrenssen
Copy link
Contributor Author

The reason for this is that we are indeed doing entity access checks. This code can also be called for route access but then the caller will need to translate a neutral result to forbidden. I haven't given much thought yet to route access. I see that indeed in AccessManager::checkRequest() the andIf() access merging strategy is used, while EntityAccessControlHandler uses orIf().

The code path that is being followed to reach these methods is: $entity->access($operation) -> EntityAccessControlHandler::check() -> og_entity_access() hook implementation -> OgAccess::userAccessEntityOperation()

So I am confident that this is using the right approach for this use case, but I need to research how route access checking relates to entity access checking. From a first glance they seem to be completely independent implementations. We might need to support this also in OG.

@pfrenssen
Copy link
Contributor Author

Assigning to me, I will update the documentation for the affected methods to make it clear which access result will be returned under which conditions.

@pfrenssen pfrenssen self-assigned this Aug 13, 2020
@MPParsley
Copy link
Collaborator

Glad to see this cleaned up some of the access code.

Just one question here: I know we're in alpha but changing the default from deny to neutral might break for some users, shouldn't we release this in a new major version (or document this)?

@amitaibu
Copy link
Member

IMO A new alpha would be the right move.

@pfrenssen
Copy link
Contributor Author

We are still in alpha and as such it is OK to make B/C breaking changes. We are also very clear about this, it is mentioned on the project page, and in the sticky post with the 8.0 roadmap.

@pfrenssen pfrenssen removed their assignment Aug 16, 2020
@pfrenssen pfrenssen mentioned this pull request Sep 24, 2020
Copy link
Collaborator

@claudiu-cristea claudiu-cristea left a comment

Choose a reason for hiding this comment

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

Nice work. I've anticipated somehow the reply to my question #692 (review), but I wanted to make sure we're doing right.

@pfrenssen
Copy link
Contributor Author

Thanks! Let's finish up this track so we can start preparing the next release.

@pfrenssen pfrenssen merged commit 9c9be3f into 8.x-1.x Oct 7, 2020
@pfrenssen pfrenssen deleted the neutral-access-result branch October 7, 2020 15:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OgAccess should return a neutral access result if a permission is not granted
4 participants