Exemplo n.º 1
0
 public function executeJsonUpdate(sfWebRequest $request)
 {
     $isAjax = $request->isXmlHttpRequest();
     if (!$isAjax) {
         return $this->redirect('@homepage');
     }
     $id = $request->getParameter('id');
     $user = sfGuardUserPeer::retrieveByPK($id);
     if (!$user) {
         $user_form = new sfGuardUserAdminForm();
     } else {
         $user_form = new sfGuardUserAdminForm($user);
     }
     $result = $this->processForm($request, $user_form);
     try {
         if ($perm_list = $request->getParameter('sf_guard_user_permission_list')) {
             // remove existing permissions for the given user
             $c = new Criteria();
             $c->add(EtvaPermissionUserPeer::USER_ID, $request->getParameter('id'), Criteria::EQUAL);
             $g_p = EtvaPermissionUserPeer::doSelect($c);
             //filter user permissions
             foreach ($g_p as $p) {
                 $p->delete();
             }
             // add new permission set
             $perm_list_dec = json_decode($perm_list);
             foreach ($perm_list_dec as $object) {
                 $g_p = new EtvaPermissionUser();
                 $g_p->setUserId($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()->__('User saved successfully');
     $response = array('success' => true, 'agent' => 'Central Management', 'response' => $msg_i18n, 'user_id' => $result['object']['Id']);
     $return = json_encode($response);
     $this->getResponse()->setHttpHeader('Content-type', 'application/json');
     return $this->renderText($return);
 }
Exemplo n.º 2
0
 private function addUserPermission($user_id, $p_permtype, $level, $id)
 {
     // get permission for the server/cluster and type
     if ($level == 'cluster') {
         $perm = EtvaPermissionQuery::create()->filterByPermType($p_permtype)->useEtvaPermissionClusterQuery()->filterByClusterId($id)->endUse()->findOne();
     } elseif ($level == 'server') {
         $perm = EtvaPermissionQuery::create()->filterByPermType($p_permtype)->useEtvaPermissionServerQuery()->filterByServerId($id)->endUse()->findOne();
     }
     // check if permission already exist
     if (!$perm) {
         //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 user set
     $new_g = new EtvaPermissionUser();
     $new_g->setUserId($user_id);
     $new_g->setEtvaPermission($perm);
     $new_g->save();
 }