
Originally Posted by
ClickHeRe
At the page controller level, I think there is still a need to have a kind of filter or way to change the action performed if the user doesn't have access to that action (index.php?/page/action/extra parms/...), the same way the page is rerouted in case the user doesn't have access at the page level in the FC.
I am assuming that by "page controller level" you mean a controller dispatched by a Front Controller and not an actual Page Controller (no FC). I agree at that level there is often a need to change things based on Access Controls. But that would usually just be part of the Action/Controller selecting a View or a View selecting a sub-View. That's why I think Rules would work best at all levels.
In this Skeleton code, the App Controller is Rule based, so you could add security rules as part of the state/transition logic very easily. For example, the first Rule could be an access check to see if the user is signed or in a certain group -- other presentation rules would follow.
In front of the Front Controller I was thinking of something like this:
PHP Code:
// the User class would probably be a gateway to session vars
$UserAccount =& new UserAccount();
// create filter with access to User info
$UserAccessFilter=& new UserAccessFilter($UserAccount );
// go to sign-in page if not signed-in
$UserAccessFilter->addRule(new RuleUserIsSignedIn('signin'));
// go to error page if not an editor
$UserAccessFilter->addRule(new RuleUserInGroup('editor', 'error'));
// you could execute this before the FC to rewrite the action param on errors
$UserAccessFilter->execute($Locator);
// FC gets passed, default, 'signin' or 'error' action params
$FrontController->execute($Locator);
// or add to a chain with the FC
$HandlerChain->addHandler($UserAccessFilter);
$HandlerChain->addHandler($FrontController);
$HandlerChain->execute($Locator);
In a Controller or View you could just use the rules
PHP Code:
$rule = new RuleUserInGroup('editor', '');
if ($rule->isValid()) {
// show editor options
} else {
// no editor options
}
I'm not sure this is the best way to deal with this, but it would reuse the simple parts (like the Rules and Validator) that the existing Skeleton uses. I think I would need to understand what the common use cases were. Let me know if this makes sense to you -- if so I could maybe create an Access Control example.
Bookmarks