-
Notifications
You must be signed in to change notification settings - Fork 4
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
Split RouteAccessControl from AccessBehaviorTrait #7
base: master
Are you sure you want to change the base?
Conversation
…orTrait rule; use the new filter in the trait
And while we're at it, I would recommend moving the new The advantage would be: since the filter itself has no dependencies, it would be an easier to use component in other yii2 projects. |
src/filters/RouteAccessControl.php
Outdated
|
||
public function beforeAction($action) | ||
{ | ||
$this->rules[] = $this->getRouteAcessControlRule(); |
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.
Let‘s add a index here e.g. routeAccess. Even if we don‘t need it (yet), it is better to have it.
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.
done in 9e8213d
…ndex in the rules array, fix routeCheckParams usage
…s to _ as before)
I have to correct myself here: Since the separator for the route checks is now configurable in the new RouteAccessControl filter, I have also patched \User::checkAccessRoute() so that the separator can also be configured there via the optional routePartSeparator parameter. see: 7fc3775 The default is the underscore in both places as before, but if the separator can be changed, it must be possible in both places. |
@handcode merge & release at will |
This PR create a new
RouteAccessControl
filter which (re)implements the logic from the prev.AccessBehaviorTrait
rule.The new filter can be used as "normal" behavior without the trait drawbacks.
For BC the
AccessBehaviorTrait
still exists and use the newRouteAccessControl
filter now.Besides the separation itself, a few small changes were made to the AccessCheck logic during refactoring:
yii\web\Controller
. In all other cases,\Yii::$app->controller
is used.user->can()
checks for the various "levels" of the route-permission are made inside the access rule now. This means that the check can be used with anyyii\web\User
instance now, previously only withdmstr\web\User
instances, as the actual route checks were executed there.user
instance for the checks is taken from theyii\filters\AccessControl::user
property, so it is configurable now.If this PR, or rather the idea behind it, is accepted, we should be able to remove the
dmstr\web\User::checkAccessRoute()
method, as it is no longer necessary for the RouteAccess check and as it is private it cannot be used outside of class.