Esempio n. 1
0
 public function delete($role_name)
 {
     // validate role name
     if ($role = Roles::findFirst($role_name)) {
         $role->delete();
     }
     return array('status' => false, 'message' => 'role not found');
 }
Esempio n. 2
0
 /**
  * Rebuilds the access list into a file
  *
  * @return \Phalcon\Acl\Adapter\Memory
  */
 public function rebuild()
 {
     $acl = new AclMemory();
     $acl->setDefaultAction(\Phalcon\Acl::DENY);
     // Register roles
     $roles = Roles::find();
     foreach ($roles as $role) {
         $acl->addRole(new AclRole($role->name));
     }
     foreach ($this->privateResources as $resource => $actions) {
         $acl->addResource(new AclResource($resource), $actions);
     }
     // Grant acess to private area to role Users
     foreach ($roles as $role) {
         // Grant permissions in "permissions" model
         foreach ($role->getPermissions() as $permission) {
             $acl->allow($role->name, $permission->controller, $permission->action);
         }
         // Always grant these permissions
         foreach ($this->privateResources as $controller => $actions) {
             foreach ($actions as $action) {
                 $acl->allow('admins', $controller, $action);
             }
         }
     }
     if (touch(APP_DIR . $this->filePath) && is_writable(APP_DIR . $this->filePath)) {
         file_put_contents(APP_DIR . $this->filePath, serialize($acl));
         chmod(APP_DIR . $this->filePath, 0777);
         // Store the ACL in APC
         if (function_exists('apc_store')) {
             apc_store('phalconseed-acl', $acl);
         }
     } else {
         $this->flash->error('The user does not have write permissions to create the ACL list at ' . APP_DIR . $this->filePath);
     }
     return $acl;
 }