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

The role instance is in charge of checking the permission type. #11

Merged
merged 4 commits into from
Feb 6, 2014
Merged

The role instance is in charge of checking the permission type. #11

merged 4 commits into from
Feb 6, 2014

Conversation

jmleroux
Copy link
Contributor

Another try to resove #9 and #10.

I keep PermissionInterface but it should be removed...

@@ -38,13 +36,11 @@ public function __construct(TraversalStrategyInterface $strategy)
* Determines if access is granted by checking the roles for permission.
*
* @param RoleInterface|RoleInterface[]|Traversable $roles
* @param PermissionInterface|string $permission
* @param PermissionInterface $permission
Copy link
Contributor

Choose a reason for hiding this comment

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

You must allow strings here, it'll receive string most of time, since currently ZfcRbac casts it to string before call Rbac::isGranted()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I allow string in implementation. I just didn't know what to do with PermissionInterface in phpDoc.
I'll rewrite mixed

@danizord
Copy link
Contributor

Your PR breaks BC a lot and makes things more strict. Some cases developer need to work with Permission entity rathen than a string. So, I'm 👎

Instead of it, I'd suggest is to accept mixed everywhere and let the RoleInterface implementation check the needed type.

@jmleroux
Copy link
Contributor Author

Instead of it, I'd suggest is to accept mixed everywhere and let the RoleInterface implementation check the needed type.

Yes, that's what i wanted to do, but i did not dare remove the PermissionInterface. This led to this bad state.

I'll rewrite with mixed

@@ -4,3 +4,4 @@ data/
vendor/
composer.lock
composer.phar
.idea
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For PhpStorm

@danizord
Copy link
Contributor

@jmleroux Since you're breaking backwards compatibility, your PR can't be merged until we start the next release (ZF3). So, if you're breaking BC anyway, why don't you remove PermissionInterface completely? I'm not sure if @bakura10 wants this change, but it's ok to me.

@jmleroux
Copy link
Contributor Author

@jmleroux Since you're breaking backwards compatibility, your PR can't be merged until we start the next release (ZF3)

It was on purpose. I thought this project was for ZF3.

So, if you're breaking BC anyway, why don't you remove PermissionInterface completely?

Keeping it just for the "string system". And because @bakura10 seems to want it. ;)

I'm not sure if @bakura10 wants this change, but it's ok to me.

I'm not sure either, and frankly the "string system" is all i need.

@bakura10
Copy link
Member

bakura10 commented Feb 2, 2014

Hi,

So. I'd say you guys are "right" regarding the removal of PermissionInterface, however I have one concern: the PermissionInterface job was mostly to enforce the __toString and avoid a lot of

if ($permission instanceof PermissionInterface) {
    $name = $permission->getName();
} else {
   $name = (string) $permission;
}

and to have better performance (__toString is much faster than a lot of conditionals).

However, I agree that this should actually be left to the Role implementation to decide what to expect and what to do. BUT there are several places where this thing is actually useful:

  • ZendDeveloperTools: thanks to this interface we can simply show permissions. Without this interface, how could we know how to extract the permission name?
  • Assertion plugin manager: since ZfcRbac 2.0 we introduced the assertion plugin manager. To work, we need to index the assertion map with the permission name. How could you write the "addAssertion" method without this interface?

It was on purpose. I thought this project was for ZF3.

Yes, this project is likely to be the Rbac component for ZF3. However it's used for ZfcRbac 2 so I need to keep BC. However no problem for opening an issue with various changes we could add for ZF3 when I'll make the PR.

@danizord
Copy link
Contributor

danizord commented Feb 3, 2014

@bakura10 I agree, but fortunately that places are under ZfcRbac namespace. So... 😃

@@ -12,7 +12,8 @@
use Rbac\Permission\PermissionInterface;

/**
* Simple implementation for a role
* Simple implementation for a role without hierarchy
Copy link
Member

Choose a reason for hiding this comment

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

It can fit in one line.

@bakura10
Copy link
Member

bakura10 commented Feb 5, 2014

It's okay for everyone to merge this? ping @danizord and @arekkas. In turn I'll be able to merge this one: ZF-Commons/zfc-rbac#183

I think the potential of BC is really small on this one. What do you think?

@aeneasr
Copy link
Contributor

aeneasr commented Feb 6, 2014

Well what doesn't really makes sense to me is that the Role implementation is dependent on an interface but the Interface, the role implements, is not. So imho: either remove it completely or keep it in the RoleInterface as well.

Regarding ZfcRbac: If a PermissionInterface with __toString is required, why not provide it via the ZfcRbac namespace? I think it doesn't make much sense to keep the Interface here only because it is needed in ZfcRbac

@bakura10
Copy link
Member

bakura10 commented Feb 6, 2014

Completely agree that the permission interface should be moved to ZfcRbac. Actually this can be done without any BC by deprecating it on rbac side, and creating it on ZfcRbac where the ZfcRbac permission interface extends the Rbac one.

Envoyé de mon iPhone

Le 6 févr. 2014 à 11:19, arekkas [email protected] a écrit :

Well what doesn't really makes sense to me is that the Role implementation is dependent on an interface but the Interface, the role implements, is not. So imho: either remove it completely or keep it in the RoleInterface as well.

Regarding ZfcRbac: If a PermissionInterface with __toString is required, why not provide it via the ZfcRbac namespace? I think it doesn't make much sense to keep the Interface here only because it is needed in ZfcRbac


Reply to this email directly or view it on GitHub.

@danizord
Copy link
Contributor

danizord commented Feb 6, 2014

Yeah, 👍 let's move it to ZfcRbac.

bakura10 added a commit that referenced this pull request Feb 6, 2014
The role instance is in charge of checking the permission type.
@bakura10 bakura10 merged commit 6727c41 into zf-fr:master Feb 6, 2014
@jmleroux jmleroux deleted the permission-type branch February 6, 2014 11:09
@bakura10
Copy link
Member

bakura10 commented Feb 6, 2014

I just realized @jmleroux that Role has not been updated and still references PermissionInterface: http://github.com/zf-fr/rbac/blob/master/src/Rbac/Role/Role.php

How do you deal with this?

@jmleroux
Copy link
Contributor Author

jmleroux commented Feb 6, 2014

Indeed, this is a problem.
How can we retrieve the permission in hasPermission for example if we don't rely on a string conversion ?
Do we have to iterate on the $permissions to compare the permissions without relying on a string key ?
And what will be the criteria for comparison ?
...

@danizord
Copy link
Contributor

danizord commented Feb 6, 2014

Just silently remove the interface from docblocks and keep the (string) casting ;)

@bakura10
Copy link
Member

bakura10 commented Feb 6, 2014

But what's the point of casting if we do not enforce a PermissionInterface. If we have "mixed" then we cannot cast to string because it may be na object that do not have any __toString defined.

You see, the interface was actually useful :/.

@danizord
Copy link
Contributor

danizord commented Feb 6, 2014

@bakura10 The Rbac\Role\Role implementation would always expect string. So since we don't have string typehint in PHP, we can at least cast it to string. But anyway, the docblock will tell that it expects a string.

@danizord
Copy link
Contributor

danizord commented Feb 6, 2014

Most of time developers will write their own implementation of RoleInterface if they need to accept the permission as object (ZfcRbac does that).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants