This repository has been archived by the owner on Jan 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Fix #45 #48
Open
ezimuel
wants to merge
1
commit into
zendframework:master
Choose a base branch
from
ezimuel:fix/45
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Fix #45 #48
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about this solution as well, but it is gonna work different way that it was in v2:
but in v2 it will be
true
.createMissingRoles
is default false, so it's not gonna add the child roles by default (it was also not the case in v2, as iterator worked there on all roles and all children).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know that there's a difference between v2 but this is ok, we are on v3 and the scope of my refactoring was about consistence (see #34).
Regarding your example,
role2
is not added automatically to$rbac
and I think is correct. If you want to have alsorole2
you need to add it as child to$role1
and finally assign it to$rbac
usingaddRole
. I don't see any issue here.createMissingRoles
was alsofalse
in v2. Maybe, we need to be more explicit in the documentation about that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ezimuel If you think the case I've provided above is desired then it should be also included in tests and described in the docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since
$createMissingRoles
is currentlyfalse
by default, changing its value totrue
would be a BC break.That said, I think user expectations are that if you add a child role to a role, but not directly to the RBAC, it would still be considered a role in the RBAC. This was the behavior in v2, and the problem reported in #45. In looking through the 3.0.0 CHANGELOG, there is no reference to this change in behavior, which means it is unexpected.
What the CHANGELOG does note is that there is now support for detecting circular references in the role hierarchy. What this patch doesn't do is include a check to see if the RBAC instance has the child role before attempting to add it, which makes this a potentially destructive process.
My gut take is that we should:
$createMissingRoles
betrue
be default, so that the behavior matches user expectations, as well as the existing documentation.I'll work on those momentarily.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interestingly, I just switched the default value of
$createMissingRoles
, and tests continued to pass. Which indicates none of these scenarios were tested fully previously.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started by adding tests that would not add a role if it already exists in the RBAC, by testing against
hasRole()
. Unfortunately, this failed, becausehasRole()
has logic that checks if the$role
implementsRoleInterface
, and, if so, it does a strict equality check against the internal instance and the instance passed.I considered removing that strict equality check, but that leaves us in a situation where we could have two different
RoleInterface
implementations, and these would be considered equivalent in the RBAC.But this also means we have a scenario where one
RoleInterface
implementation could be registered with its own set of parents and/or children, and then another entirely differentRoleInterface
instance using the same role added later. In this scenario, the latter would overwrite the original, and we would potentially have completely different inheritance trees within the RBAC using the same role name, but with different instances.What's really crazy is that if
$parents
are specified as strings, these end up being newRole
instances, and overwriting any previous versions of those roles in the RBAC.This feels really confusing to me, and I'm not sure it's something we want to support.
So, my question here is: what should the behavior be? Silently overwriting feels like it has huge potential for misuse and WTF moments. Doing strict checks in
hasRole()
seems like it has potential for problems, as it can return a false negative when a role of the same name exists, but it is a different instance than that provided to the method (as the method takes either the string name or aRoleInterface
instance) — and even more so, as we might want to toggle that strictness off when building the RBAC, but on again later, or even vary based on the role we're adding.Basically, we need a list of scenarios and how they should behave before we can continue with any of this.