Last active
December 10, 2015 17:08
-
-
Save simkimsia/4465592 to your computer and use it in GitHub Desktop.
This is a Cake Shell class that helps to grant and deny access to users or groups based on controller actions. It calls the core AclShell by iterating through a list of permissions. I would love to write a Plugin for everyone to use, but I am not sure how to store the list of permissions in a way it is easy for everybody else to be able to use g…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class AclGrantDenyShell extends AppShell { | |
| /** | |
| * Contains instance of AclComponent | |
| * | |
| * @var permissions | |
| */ | |
| public $permissions = array( | |
| array('grant', 'Group.1', 'controllers'), | |
| array('deny', 'Group.2', 'controllers'), | |
| array('grant', 'Group.2', 'controllers/Products'), | |
| array('grant', 'Group.2', 'controllers/Clients', 'add'), | |
| array('grant', 'Group.2', 'controllers/Users', 'profile'), | |
| ); | |
| /** | |
| * Contains the acl shell command | |
| * | |
| * @var permissions | |
| */ | |
| public $acl = array('acl'); | |
| public function main() { | |
| $this->out('Update ACL Permissions:'); | |
| } | |
| public function update_permissions() { | |
| if (count($this->permissions) == 0) { | |
| $this->out('No permissions at all'); | |
| return; | |
| } | |
| foreach ($this->permissions as $singlePermission) { | |
| $newAclCommand = array_merge($this->acl, $singlePermission); | |
| $this->out($this->$newAclCommand[0]); | |
| $this->DispatchShell(implode(" ", $newAclCommand)); | |
| $action = $singlePermission[0]; | |
| $who = $singlePermission[1]; | |
| $controller = $singlePermission[2]; | |
| $controllerAction = (isset($singlePermission[3])) ? $singlePermission[3] : "*"; | |
| $controllerAction = $controller . "/" . $controllerAction; | |
| $this->out(sprintf("%s access to %s on %s", $action, $who, $controllerAction)); | |
| } | |
| $this->out("Update finish."); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment