public function execute() { // only allowed to global admin if (!wa()->getUser()->getRights('webasyst', 'backend')) { throw new waRightsException('Access denied.'); } $collection = new contactsCollection('users/all'); $group = null; $memberIds = array(); if ($id = waRequest::get('id')) { $group_model = new waGroupModel(); $group = $group_model->getById($id); } if ($group) { $user_groups_model = new waUserGroupsModel(); $memberIds = $user_groups_model->getContactIds($id); } $users = $collection->getContacts('id,name'); // array(id => array(id=>...,name=>...)) $members = array(); foreach ($memberIds as $mid) { if (isset($users[$mid])) { $members[$mid] = $users[$mid]; unset($users[$mid]); } } usort($members, array($this, '_cmp')); usort($users, array($this, '_cmp')); $this->view->assign('group', $group); $this->view->assign('notIncluded', $users); $this->view->assign('members', $members); }
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; } }
/** * Delete group * * @param int $id * @return bool */ public function delete($id) { // Delete all records from table of the links $user_groups_model = new waUserGroupsModel(); $user_groups_model->deleteByField('group_id', $id); // Delete group return $this->deleteById($id); }
public function execute() { // only allowed to global admin if (!wa()->getUser()->getRights('webasyst', 'backend')) { throw new waRightsException(_w('Access denied')); } $contact_id = waRequest::get('id'); $group_ids = null; if ($contact_id > 0) { $user_groups_model = new waUserGroupsModel(); $group_ids = $user_groups_model->getGroupIds($contact_id); $group_ids[] = 0; } $app_id = waRequest::get('app'); $right_model = new waContactRightsModel(); $rights = $right_model->get($contact_id, $app_id, null, false); $group_rights = null; if ($group_ids) { $group_rights = $right_model->get(array_map(wa_lambda('$a', 'return -$a;'), $group_ids), $app_id, null, false); } // Check custom rights items $app_config = SystemConfig::getAppConfig($app_id); $class_name = $app_config->getPrefix() . "RightConfig"; $file_path = $app_config->getAppPath('lib/config/' . $class_name . ".class.php"); if (file_exists($file_path)) { // Init app waSystem::getInstance($app_id, $app_config, true); include $file_path; /** * @var waRightConfig $right_config */ $right_config = new $class_name(); $rights += $right_config->getRights($contact_id); if ($group_ids) { $group_rights += $right_config->getRights(array_map(wa_lambda('$a', 'return -$a;'), $group_ids)); } $this->view->assign('html', $right_config->getHTML($rights, $group_rights)); waSystem::setActive('contacts'); } else { $this->view->assign('html', ''); } if ($contact_id > 0) { $this->view->assign('user', new waContact($contact_id)); } else { $gm = new waGroupModel(); $this->view->assign('group', $gm->getById(-$contact_id)); } $app = wa()->getAppInfo($app_id); $app['id'] = $app_id; $this->view->assign('app', $app); $this->view->assign('rights', $rights); $this->view->assign('group_rights', $group_rights); }
/** * Delete one or more contacts and fire event сontacts.delete * * @event contacts.delete * * @param int|array $id - contact id or array of contact ids * @return bool */ public function delete($id, $send_event = true) { if ($send_event) { // Fire @event contacts.delete allowing other applications to clean up their data if (!is_array($id)) { $id = array($id); } wa()->event(array('contacts', 'delete'), $id); } if (is_array($id)) { $nid = array(); foreach ($id as $i) { $nid[] = -(int) $i; } } else { $nid = -(int) $id; } // Delete rights $right_model = new waContactRightsModel(); $right_model->deleteByField('group_id', $nid); // Delete settings $setting_model = new waContactSettingsModel(); $setting_model->deleteByField('contact_id', $id); // Delete emails $contact_email_model = new waContactEmailsModel(); $contact_email_model->deleteByField('contact_id', $id); // Delete from groups $user_groups_model = new waUserGroupsModel(); $user_groups_model->deleteByField('contact_id', $id); // Delete from contact lists if (class_exists('contactsContactListsModel')) { // @todo: Use plugin for contacts $contact_lists_model = new contactsContactListsModel(); $contact_lists_model->deleteByField('contact_id', $id); } // Delete from contact rights $contact_rights_model = new contactsRightsModel(); $contact_rights_model->deleteByField('group_id', $nid); // Delete data $contact_data_model = new waContactDataModel(); $contact_data_model->deleteByField('contact_id', $id); $contact_data_text_model = new waContactDataTextModel(); $contact_data_text_model->deleteByField('contact_id', $id); // // Delete contact from logs // $login_log_model = new waLoginLogModel(); // $login_log_model->deleteByField('contact_id', $id); // Clear references $this->updateByField(array('company_contact_id' => $id), array('company_contact_id' => 0)); // Delete contact return $this->deleteById($id); }
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'; }
public function execute() { // only allowed to global admin if (!wa()->getUser()->getRights('webasyst', 'backend')) { throw new waRightsException(_w('Access denied')); } $group = null; $group_id = waRequest::get('id'); if ($group_id) { $group_model = new waGroupModel(); $group = $group_model->getById($group_id); } // only allowed to global admin $is_global_admin = wa()->getUser()->getRights('webasyst', 'backend'); $right_model = new waContactRightsModel(); $fullAccess = $right_model->get(-$group_id, 'webasyst', 'backend'); $apps = wa()->getApps(); if (!$fullAccess) { $appAccess = $right_model->getApps($group_id, 'backend'); } $noAccess = true; foreach ($apps as $app_id => &$app) { $app['id'] = $app_id; $app['customizable'] = isset($app['rights']) ? (bool) $app['rights'] : false; $app['access'] = $fullAccess ? 2 : 0; if (!$app['access'] && isset($appAccess[$app_id])) { $app['access'] = $appAccess[$app_id]; } $noAccess = $noAccess && !$app['access']; } unset($app); $user_groups = new waUserGroupsModel(); $users_count = $user_groups->countByField(array('group_id' => $group_id)); $this->view->assign('users_count', $users_count); $this->view->assign('apps', $apps); $this->view->assign('noAccess', $noAccess); $this->view->assign('fullAccess', $fullAccess); $this->view->assign('is_global_admin', $is_global_admin); $this->view->assign('group', $group); $this->view->assign('icons', waGroupModel::getIcons()); }
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); } } }
/** Using $this->id and $this->contact, if contact is a user, * collect and load vars into $this->view specific to waUser. */ protected function getUserInfo() { $system = waSystem::getInstance(); $rm = new waContactRightsModel(); $ugm = new waUserGroupsModel(); $gm = new waGroupModel(); // Personal and group access rights $groups = $ugm->getGroups($this->id); $ownAccess = $rm->getApps(-$this->id, 'backend', FALSE, FALSE); $groupAccess = $rm->getApps(array_keys($groups), 'backend', FALSE, FALSE); if (!isset($ownAccess['webasyst'])) { $ownAccess['webasyst'] = 0; } if (!isset($groupAccess['webasyst'])) { $groupAccess['webasyst'] = 0; } // Build application list with personal and group access rights for each app $apps = $system->getApps(); $noAccess = true; $gNoAccess = true; foreach ($apps as $app_id => &$app) { $app['id'] = $app_id; $app['customizable'] = isset($app['rights']) ? (bool) $app['rights'] : false; $app['access'] = $ownAccess['webasyst'] ? 2 : 0; if (!$app['access'] && isset($ownAccess[$app_id])) { $app['access'] = $ownAccess[$app_id]; } $app['gaccess'] = $groupAccess['webasyst'] ? 2 : 0; if (!$app['gaccess'] && isset($groupAccess[$app_id])) { $app['gaccess'] = $groupAccess[$app_id]; } $noAccess = $noAccess && !$app['gaccess'] && !$app['access']; $gNoAccess = $gNoAccess && !$app['gaccess']; } unset($app); $this->view->assign('apps', $apps); $this->view->assign('groups', $groups); $this->view->assign('noAccess', $noAccess ? 1 : 0); $this->view->assign('gNoAccess', $gNoAccess ? 1 : 0); $this->view->assign('all_groups', $gm->getNames()); $this->view->assign('fullAccess', $ownAccess['webasyst']); $this->view->assign('gFullAccess', $groupAccess['webasyst']); $this->view->assign('access_to_contacts', $this->getUser()->getRights('contacts', 'backend')); }
public function hasBackendAccess($contact_id) { $ugm = new waUserGroupsModel(); $rm = new waContactRightsModel(); $ownAccess = $rm->getApps(-$contact_id, 'backend', FALSE, FALSE); if (!isset($ownAccess['webasyst'])) { $ownAccess['webasyst'] = 0; } $groups = $ugm->getGroups($contact_id); $groupAccess = $rm->getApps(array_keys($groups), 'backend', FALSE, FALSE); if (!isset($groupAccess['webasyst'])) { $groupAccess['webasyst'] = 0; } $system = waSystem::getInstance(); $apps = $system->getApps(); $noAccess = true; $gNoAccess = true; foreach ($apps as $app_id => &$app) { $app['id'] = $app_id; $app['customizable'] = isset($app['rights']) ? (bool) $app['rights'] : false; $app['access'] = $ownAccess['webasyst'] ? 2 : 0; if (!$app['access'] && isset($ownAccess[$app_id])) { $app['access'] = $ownAccess[$app_id]; } $app['gaccess'] = $groupAccess['webasyst'] ? 2 : 0; if (!$app['gaccess'] && isset($groupAccess[$app_id])) { $app['gaccess'] = $groupAccess[$app_id]; } $noAccess = $noAccess && !$app['gaccess'] && !$app['access']; $gNoAccess = $gNoAccess && !$app['gaccess']; } unset($app); return $ownAccess['webasyst'] || !$noAccess; }
public static function getAccessTabTitle(waContact $contact) { $rm = new waContactRightsModel(); $ugm = new waUserGroupsModel(); $gm = new waGroupModel(); // Personal and group access rights $groups = $ugm->getGroups($contact['id']); $ownAccess = $rm->getApps(-$contact['id'], 'backend', false, false); $groupAccess = $rm->getApps(array_keys($groups), 'backend', false, false); if (!isset($ownAccess['webasyst'])) { $ownAccess['webasyst'] = 0; } if (!isset($groupAccess['webasyst'])) { $groupAccess['webasyst'] = 0; } // Build application list with personal and group access rights for each app $apps = wa()->getApps(); $noAccess = true; $gNoAccess = true; foreach ($apps as $app_id => &$app) { $app['id'] = $app_id; $app['customizable'] = isset($app['rights']) ? (bool) $app['rights'] : false; $app['access'] = $ownAccess['webasyst'] ? 2 : 0; if (!$app['access'] && isset($ownAccess[$app_id])) { $app['access'] = $ownAccess[$app_id]; } $app['gaccess'] = $groupAccess['webasyst'] ? 2 : 0; if (!$app['gaccess'] && isset($groupAccess[$app_id])) { $app['gaccess'] = $groupAccess[$app_id]; } $noAccess = $noAccess && !$app['gaccess'] && !$app['access']; $gNoAccess = $gNoAccess && !$app['gaccess']; } unset($app); $html = _w('Access'); $html .= ' <i class="icon16 c-access-icon '; if ($contact['is_user'] == -1) { $html .= 'delete'; } else { if (!$groupAccess['webasyst'] && !$ownAccess['webasyst'] && $noAccess) { $html .= 'key-bw'; } else { $html .= 'key'; } } $html .= '"></i>'; return $html; }
/** * Get access rights by group and key * @param int|array $id group ids (if positive) or contact ids (negative) * @param string $name key to check value for; default is 'backend' * @param boolean $check_groups (default is true) if set to false then only own access rights are considered, as if contact has no groups assigned * @param boolean $noWA * @return array (app_id => value) */ public function getApps($id, $name = 'backend', $check_groups = true, $noWA = true) { $cache = false; if ($check_groups && is_numeric($id) && $id < 0) { $user_groups_model = new waUserGroupsModel(); $cache = -$id; $id = array_merge(array($id, 0), $user_groups_model->getGroupIds(-$id)); } if (is_array($id) && !$id || !is_numeric($id) && !is_array($id)) { return array(); } $sql = "SELECT app_id, MAX(value) v\n FROM " . $this->table . "\n WHERE group_id IN (i:group_id)" . ($noWA ? " AND app_id != 'webasyst' " : '') . "AND name = s:name\n AND value > 0\n GROUP BY app_id"; $data = $this->query($sql, array('group_id' => $id, 'name' => $name)); $result = array(); foreach ($data as $row) { $result[$row['app_id']] = $row['v']; if ($cache) { self::$cache[$cache][$row['app_id']][$name] = $row['v']; } } return $result; }