Beispiel #1
0
 public function executeJsonUpdate(sfWebRequest $request)
 {
     $isAjax = $request->isXmlHttpRequest();
     if (!$isAjax) {
         return $this->redirect('@homepage');
     }
     $id = $request->getParameter('id');
     $group = sfGuardGroupPeer::retrieveByPK($id);
     if (!$group) {
         $group_form = new sfGuardGroupForm();
     } else {
         $group_form = new sfGuardGroupForm($group);
     }
     $result = $this->processForm($request, $group_form);
     try {
         // remove existing permissions for the given group
         $c = new Criteria();
         $c->add(EtvaPermissionGroupPeer::GROUP_ID, $request->getParameter('id'), Criteria::EQUAL);
         $g_p = EtvaPermissionGroupPeer::doSelect($c);
         //filter group permissions
         foreach ($g_p as $p) {
             $p->delete();
         }
         // add new permission set
         $perm_list = $request->getParameter('sf_guard_group_permission_list');
         $perm_list_dec = json_decode($perm_list);
         foreach ($perm_list_dec as $object) {
             $g_p = new EtvaPermissionGroup();
             $g_p->setGroupId($request->getParameter('id'));
             $g_p->setEtvapermId($object);
             $g_p->save();
         }
     } catch (Exception $e) {
         $result = array('success' => false, 'error' => 'Could not perform operation', 'agent' => sfConfig::get('config_acronym'), 'info' => 'Could not perform operation');
     }
     if (!$result['success']) {
         $error = $this->setJsonError($result);
         return $this->renderText($error);
     }
     $msg_i18n = $this->getContext()->getI18N()->__('Group saved successfully');
     $response = array('success' => true, 'agent' => 'Central Management', 'response' => $msg_i18n, 'group_id' => $result['object']['Id']);
     $return = json_encode($response);
     $this->getResponse()->setHttpHeader('Content-type', 'application/json');
     return $this->renderText($return);
 }
Beispiel #2
0
 private function changeGroupsPermissions($id, $p_permtype, $level, $p_groups)
 {
     // remove groups from manually created permissions
     if ($level == 'cluster') {
         $groups = EtvaPermissionGroupQuery::create()->useEtvaPermissionQuery()->filterByPermType($p_permtype)->useEtvaPermissionClusterQuery()->filterByClusterId($id)->endUse()->endUse()->find();
         $groups->delete();
     } elseif ($level == 'server') {
         $groups = EtvaPermissionGroupQuery::create()->useEtvaPermissionQuery()->filterByPermType($p_permtype)->useEtvaPermissionServerQuery()->filterByServerId($id)->endUse()->endUse()->find();
         $groups->delete();
     }
     // get permission for the server/cluster and type
     if ($level == 'cluster') {
         $perm = EtvaPermissionQuery::create()->filterByDescription('auto_generated')->filterByPermType($p_permtype)->useEtvaPermissionClusterQuery()->filterByClusterId($id)->endUse()->findOne();
     } elseif ($level == 'server') {
         $perm = EtvaPermissionQuery::create()->filterByDescription('auto_generated')->filterByPermType($p_permtype)->useEtvaPermissionServerQuery()->filterByServerId($id)->endUse()->findOne();
     }
     // check if permission already exist
     if ($perm) {
         //remove old groups
         $groups = EtvaPermissionGroupQuery::create()->useEtvaPermissionQuery()->filterByPrimaryKey($perm->getId())->endUse()->find();
         $groups->delete();
     } else {
         //create a new permission
         $perm = new EtvaPermission();
         $perm->setDescription('auto_generated');
         $perm->setPermType($p_permtype);
         $perm->setName('auto_' . $level . '_' . $id);
         $perm->save();
         if ($level == 'cluster') {
             //associate new permission to datacenter
             $perm_dc = new EtvaPermissionCluster();
             $perm_dc->setClusterId($id);
             $perm_dc->setEtvaPermission($perm);
             $perm_dc->save();
         } elseif ($level == 'server') {
             //associate new permission to server
             $perm_srv = new EtvaPermissionServer();
             $perm_srv->setServerId($id);
             $perm_srv->setEtvaPermission($perm);
             $perm_srv->save();
         }
     }
     // add new group set
     foreach ($p_groups as $new_group_id) {
         $new_g = new EtvaPermissionGroup();
         $new_g->setGroupId($new_group_id);
         $new_g->setEtvaPermission($perm);
         $new_g->save();
     }
 }