-
Notifications
You must be signed in to change notification settings - Fork 23
AssertionInterface is inconvenient #24
Comments
What's most inconvenient with Can you introduce another method in For example, one would write something like this: class AssertionManager implements AssertionInterface
{
//...
public function checkAssertion(Rbac $rbac, $permission, $params)
{
switch ($permission) {
case 'profile.view.own' : return $params['user']==$this->authService->getIdentity();
}
return false;
}
} |
I can provide a pull request if you approve this. |
@olegkrivtsov I see your point and it makes sense to me. Since I'm planning to schedule a major version (3.0.0) of namespace Zend\Permissions\Rbac;
interface AssertionInterface
{
/**
* Assertion method - must return a boolean.
*
* @param Rbac $rbac
* @param string $permission
* @param RoleInterface $role
* @return bool
*/
public function assert(Rbac $rbac, $permission = null, $role = null);
} Regarding your proposal for a |
If you are already breaking things, please go all the way to have the best result possible, so make the new arguments mandatory. If they were optional that would suggest that we could assert something without any permission, which seems rather counter-intuitive. |
@PowerKiKi the parameters of namespace Zend\Permissions\Rbac;
interface AssertionInterface
{
/**
* Assertion method - must return a boolean.
*/
public function assert(Rbac $rbac, RoleInterface $role, string $permission) : bool;
} Notice: I also changed the parameter order of |
Hi,
I'm trying to use your
dev-develop
version ofzend-permissions-rbac
with the latest fixes. I'm testing how to use dynamic assertions and foundAssertionInterface
inconvenient.Currently, the
AssertionInterface
provides theassert(Rbac $rbac)
method. The$rbac
argument is not the primary data I need for assertion checking. Actually, I need the name of permission and some array of parameters. Permission name and additional parameters now have to be passed to assertion class via additional methods.My suggestion: why not to introduce the following assert method:
assert(Rbac $rbac, $permission, $params)
? That would make it easier to implement dynamic assertions in my code.P.S. Currently, assertion can be a class, a function, a closure, etc. The class is usable somehow, but the function/closure is absolutely not usable, because you pass only
$rbac
argument to it. How to pass the permission name and parameters to the function?The text was updated successfully, but these errors were encountered: