Exemplo n.º 1
0
 /**
  * Save the permission
  * @param $id
  */
 public static function SaveAll($data, $id = null)
 {
     if (!empty($data) && is_array($data)) {
         if (is_numeric($id)) {
             $role = Doctrine::getTable('AdminRoles')->find($id);
         } else {
             $role = new AdminRoles();
         }
         // Save the role label
         if (!empty($data['name'])) {
             $role['name'] = Shineisp_Commons_UrlRewrites::format($data['name']);
             $role->save();
         }
         // Set the new Role ID to the users selected
         if (!empty($data['users'])) {
             foreach ($data['users'] as $user) {
                 AdminUser::setUserRoleID($user, $id);
             }
         }
         // Clear old permissions
         AdminPermissions::clearPermissionByRoleID($id);
         if (!empty($data['resources'])) {
             // Explode the string into an array
             $resources = explode("/", $data['resources']);
             // Add the new permissions
             foreach ($resources as $resource) {
                 list($module, $controller) = explode(':', $resource);
                 AdminPermissions::addPermission($id, $module, $controller);
             }
         }
         return $role;
     }
     return false;
 }
Exemplo n.º 2
0
 /**
  * Add a new permission in the database for a specific resource
  * @param integer $roleID
  * @param integer $resourceID
  */
 public static function addPermission($roleID, $module, $controller, $permission = "allow")
 {
     $resource = AdminResources::createResource($module, $controller);
     if (!empty($resource)) {
         $adminpermission = new AdminPermissions();
         $adminpermission['role_id'] = $roleID;
         $adminpermission['resource_id'] = (string) $resource->resource_id;
         $adminpermission['permission'] = $permission;
         if ($adminpermission->trySave()) {
             return $adminpermission;
         }
     }
     return false;
 }
Exemplo n.º 3
0
 /**
  * editAction
  * Get a record and populate the application form 
  * @return unknown_type
  */
 public function editAction()
 {
     $auth = Zend_Auth::getInstance();
     // Get the common resources of ShineISP from the ACL file
     $aclConfig = new Zend_Config_Xml(APPLICATION_PATH . '/configs/acl.xml', 'acl');
     $form = $this->getForm('/admin/roles/process');
     $id = $this->getRequest()->getParam('id');
     // Create the buttons in the edit form
     $this->view->buttons = array(array("url" => "#", "label" => $this->translator->translate('Save'), "params" => array('css' => null, 'id' => 'submit')), array("url" => "/admin/roles/list", "label" => $this->translator->translate('List'), "params" => array('css' => null)), array("url" => "/admin/roles/new/", "label" => $this->translator->translate('New'), "params" => array('css' => null)));
     if (!empty($id) && is_numeric($id)) {
         $rs = AdminRoles::find($id, null, true);
         if (!empty($rs[0])) {
             // Load the users connected to this role
             $users = AdminUser::getUserbyRoleID($id);
             // Load the roles of each resource
             $roles = AdminPermissions::getPermissionByRoleID($id);
             // Load the resources
             $this->view->resources = json_encode(AdminResources::createResourcesTree($aclConfig->modules, $roles));
             // Join the roles and the users
             $rs[0]['users'] = $users;
             $form->populate($rs[0]);
             $this->view->buttons[] = array("url" => "/admin/roles/confirm/id/{$id}", "label" => $this->translator->translate('Delete'), "params" => array('css' => null));
         }
     }
     $this->view->mex = $this->getRequest()->getParam('mex');
     $this->view->mexstatus = $this->getRequest()->getParam('status');
     $this->view->title = $this->translator->translate("Role edit");
     $this->view->description = $this->translator->translate("Here you can edit the role permissions.");
     $this->view->form = $form;
     $this->render('applicantform');
 }