public function execute()
 {
     $ids = waRequest::request('id', array(), 'array_int');
     if (!$ids) {
         throw new waException('Contact id not specified.');
     }
     // only allowed to global admin
     if (!wa()->getUser()->getRights('webasyst', 'backend')) {
         throw new waRightsException(_w('Access denied'));
     }
     $groups = waRequest::post('groups', array(), 'array_int');
     $counters = array();
     $ugm = new waUserGroupsModel();
     if ($this->getRequest()->request('set')) {
         foreach ($ids as $id) {
             $ugm->delete($id, array());
         }
     }
     foreach ($ids as $id) {
         if ($groups) {
             $ugm->add(array_map(wa_lambda('$gid', 'return array(' . $id . ', $gid);'), $groups));
         }
     }
     $gm = new waGroupModel();
     foreach ($groups as $gid) {
         $cnt = $ugm->countByField(array('group_id' => $gid));
         $gm->updateCount($gid, $cnt);
         $counters[$gid] = $cnt;
     }
     $this->response['counters'] = $counters;
     $this->response['message'] = _w("%d user has been added", "%d users have been added", count($ids));
     $this->response['message'] .= ' ';
     $this->response['message'] .= _w("to %d group", "to %d groups", count($groups));
 }
 public function execute()
 {
     // only allowed to global admin
     if (!wa()->getUser()->getRights('webasyst', 'backend')) {
         throw new waRightsException(_w('Access denied'));
     }
     $contacts = $this->getRequest()->post('contacts', array(), 'array_int');
     $groups = $this->getRequest()->post('groups', array(), 'array_int');
     if (!$contacts || !$groups) {
         return;
     }
     $ugm = new waUserGroupsModel();
     $gm = new waGroupModel();
     foreach ($contacts as $id) {
         if ($groups) {
             $ugm->delete($id, $groups);
         }
     }
     $counters = array();
     foreach ($groups as $gid) {
         $cnt = $ugm->countByField(array('group_id' => $gid));
         $gm->updateCount($gid, $cnt);
         $counters[$gid] = $cnt;
     }
     $contacts_count = count($contacts);
     $groups_count = count($groups);
     $this->response['message'] = sprintf(_w("%d user excluded", "%d users excluded", $contacts_count), $contacts_count);
     $this->response['message'] .= ' ';
     $this->response['message'] .= sprintf(_w("from %d group", "from %d groups", $groups_count), $groups_count);
     $this->response['counters'] = $counters;
 }
 public function execute()
 {
     // only allowed to global admin
     if (!wa()->getUser()->getRights('webasyst', 'backend')) {
         throw new waRightsException('Access denied.');
     }
     $group_model = new waGroupModel();
     // Create a group or retreive by id
     $id = waRequest::post('id');
     $name = waRequest::post('name');
     if (!$id) {
         if (!$name && $name !== '0') {
             throw new waException('No group id and no name given.');
         }
         $id = $group_model->add($name);
         $this->log('group_add', 1);
     } else {
         if ($name || $name === '0') {
             $group_model->updateById($id, array('name' => $name));
         }
     }
     if (!$id) {
         throw new waException('Still no id here...');
         // should not happen
     }
     $group = $group_model->getById($id);
     if (!$group) {
         throw new waException('No group with such id: ' . $id);
     }
     $this->response['id'] = $id;
     $users = waRequest::post('users', array(), 'array_int');
     $type = waRequest::post('user_operation');
     $user_groups_model = new waUserGroupsModel();
     switch ($type) {
         case 'del':
             if ($users) {
                 $user_groups_model->delete($users, $id);
             }
             break;
         case 'set':
             $user_groups_model->emptyGroup($id);
             // breakthrough
         // breakthrough
         case 'add':
         default:
             if (!$users) {
                 break;
             }
             $data = array();
             foreach ($users as $contact_id) {
                 $data[] = array($contact_id, $id);
             }
             $user_groups_model->add($data);
             if ($type == 'set') {
                 $group_model->updateCount($id, count($users));
             }
             break;
     }
 }
 public function execute()
 {
     if (!($id = (int) waRequest::get('id'))) {
         throw new waException('Contact id not specified.');
     }
     // only allowed to global admin
     if (!wa()->getUser()->getRights('webasyst', 'backend')) {
         throw new waRightsException('Access denied.');
     }
     $groups = waRequest::post('groups', array(), 'array_int');
     $ugm = new waUserGroupsModel();
     $ugm->delete($id, array());
     if ($groups) {
         $ugm->add(array_map(wa_lambda('$gid', 'return array(' . $id . ', $gid);'), $groups));
     }
     $this->response = 'ok';
 }
Exemplo n.º 5
0
 public static function revokeUser($id)
 {
     // wa_contact
     $user = new waContact($id);
     $user['is_user'] = 0;
     $user['login'] = null;
     $user['password'] = '';
     $user->save();
     // user groups
     $ugm = new waUserGroupsModel();
     $ugm->delete($id);
     // Access rigths
     $right_model = new waContactRightsModel();
     $right_model->deleteByField('group_id', -$id);
     // Custom application access rigths
     foreach (wa()->getApps() as $aid => $app) {
         if (isset($app['rights']) && $app['rights']) {
             $app_config = SystemConfig::getAppConfig($aid);
             $class_name = $app_config->getPrefix() . "RightConfig";
             $file_path = $app_config->getAppPath('lib/config/' . $class_name . ".class.php");
             $right_config = null;
             if (!file_exists($file_path)) {
                 continue;
             }
             waSystem::getInstance($aid, $app_config);
             include_once $file_path;
             /**
              * @var waRightConfig $right_config
              */
             $right_config = new $class_name();
             $right_config->clearRights($id);
         }
     }
 }