Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

Fix #45#48

Open
ezimuel wants to merge1 commit intozendframework:master
base:master
Choose a base branch
Loading
fromezimuel:fix/45
Open

Fix #45#48

ezimuel wants to merge1 commit intozendframework:masterfromezimuel:fix/45

Conversation

@ezimuel
Copy link
Contributor

This PRfixes#45 adding the children roles inRbac::addRole().

Copy link
Member

@michalbundyramichalbundyra left a comment

Choose a reason for hiding this comment

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

@ezimuel I think this is still not full solution. Please see my comment. I think we need iterator on roles as before. Also - documentation needs update.

}

if ($this->createMissingRoles) {
foreach ($role->getChildren()as$child) {
Copy link
Member

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:

  • when we add child role to the given role after it is attached to rbac:
$rbac =...$role1 =newRole('role1');$rbac->addRole($role1);$child =newRole('role2');$role1->addChild($child);self::assertFalse($rbac->hasRole('role2'));

but in v2 it will betrue.

  • 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).

Copy link
ContributorAuthor

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.

Copy link
Member

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.

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 thinkuser 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 detectingcircular references in the role hierarchy. What this patch doesn't do is include a check to see if the RBAC instancehas the child role before attempting to add it, which makes this a potentially destructive process.

My gut take is that we should:

  • Make$createMissingRoles betrue be default, so that the behavior matches user expectations, as well as the existing documentation.
  • Add tests to ensure that when we add a role, we do not overwrite existing roles.
  • Modify the patch to only add a child role when it does not already exist in the RBAC.

I'll work on those momentarily.

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, andtests continued to pass. Which indicates none of these scenarios were tested fully previously.

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 againsthasRole(). 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 differentRoleInterface implementations, and these would be considered equivalent in the RBAC.

But this also means we have a scenario where oneRoleInterface 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 asstrings, 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 inhasRole() 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 nameor aRoleInterface instance) — and even more so, as wemight 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.

}

if ($this->createMissingRoles) {
foreach ($role->getChildren()as$child) {

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 againsthasRole(). 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 differentRoleInterface implementations, and these would be considered equivalent in the RBAC.

But this also means we have a scenario where oneRoleInterface 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 asstrings, 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 inhasRole() 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 nameor aRoleInterface instance) — and even more so, as wemight 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.

@weierophinney
Copy link
Member

This repository has been closed and moved to laminas/laminas-permissions-rbac; a new issue has been opened atlaminas/laminas-permissions-rbac#2.

@weierophinney
Copy link
Member

This repository has been moved to laminas/laminas-permissions-rbac. If you feel that this patch is still relevant, please re-open against that repository, and reference this issue. To re-open, we suggest the following workflow:

  • Squash all commits in your branch (git rebase -i origin/{branch})
  • Make a note of all changed files (`git diff --name-only origin/{branch}...HEAD
  • Run the laminas/laminas-migration tool on the code.
  • Clone laminas/laminas-permissions-rbac to another directory.
  • Copy the files from the second bullet point to the clone of laminas/laminas-permissions-rbac.
  • In your clone of laminas/laminas-permissions-rbac, commit the files, push to your fork, and open the new PR.
    We will be providing tooling via laminas/laminas-migration soon to help automate the process.

Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.

Reviewers

2 more reviewers

@michalbundyramichalbundyramichalbundyra requested changes

@weierophinneyweierophinneyweierophinney requested changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Child roles not added

3 participants

@ezimuel@weierophinney@michalbundyra

[8]ページ先頭

©2009-2025 Movatter.jp