Exemplo n.º 1
0
 /**
  * get waUser by login
  *
  * @param string $login
  * @return waUser or null if no user with this login exists
  */
 public static function getByLogin($login)
 {
     $user_model = new waUserModel();
     if (!($row = $user_model->getByField('login', $login))) {
         return null;
     }
     return new waUser($row['id']);
 }
 public function execute()
 {
     $ids = waRequest::post('id', array(), 'array_int');
     if (!$ids) {
         $ids = (int) waRequest::get('id');
         if (!$ids) {
             throw new Exception('No ids specified.');
         }
         $ids = array($ids);
     }
     // do not try to delete self
     if (in_array($this->getUser()->getId(), $ids)) {
         die('<p>' . _w('You can not delete yourself.') . '</p><p>' . _w('Please eliminate yourself from deletion list.') . '</p>');
     }
     // Only allow actions with contacts available for current user
     if (!$this->getRights('category.all')) {
         $crm = new contactsRightsModel();
         $ccm = new waContactCategoriesModel();
         $allowed = array_keys($crm->getAllowedCategories());
         foreach ($ccm->getContactsCategories($ids) as $id => $cats) {
             if (!array_intersect($allowed, $cats)) {
                 throw new waRightsException('Access denied');
             }
         }
     }
     $superadmin = wa()->getUser()->getRights('webasyst', 'backend');
     $result = wa()->event('links', $ids);
     $this->view->assign('apps', wa()->getApps());
     $links = array();
     foreach ($result as $app_id => $app_links) {
         foreach ($app_links as $contact_id => $contact_links) {
             if ($contact_links) {
                 $links[$contact_id][$app_id] = $contact_links;
             }
         }
     }
     // Do not allow non-superadmin to remove users
     if (!$superadmin) {
         $um = new waUserModel();
         $users = array_keys($um->getByField(array('id' => $ids, 'is_user' => 1), 'id'));
         foreach ($users as $user_id) {
             if (!isset($links[$user_id]['contacts'])) {
                 $links[$user_id]['contacts'] = array();
             }
             $links[$user_id]['contacts'][] = array('user', 1);
         }
     }
     $contact_model = new waContactModel();
     $this->view->assign('ids', $superadmin ? $ids : array_diff($ids, array_keys($links)));
     $this->view->assign('contacts', $contact_model->getName(array_keys($links)));
     $this->view->assign('superadmin', $superadmin);
     $this->view->assign('all', count($ids));
     $this->view->assign('links', $links);
 }
 public function execute()
 {
     $superadmin = $this->getUser()->getRights('webasyst', 'backend');
     $contacts = waRequest::post('id', array(), 'array_int');
     // do not try to delete self
     if (in_array($this->getUser()->getId(), $contacts)) {
         throw new waRightsException('Access denied: attempt to delete own account.');
     }
     $this->getRights();
     $crm = new contactsRightsModel();
     $contacts = $crm->getAllowedContactsIds($contacts);
     if (!$contacts) {
         throw new waRightsException('Access denied: no access to contacts ');
     }
     // Deletion of contacts with links to other applications is only allowed to superadmins
     if (!$superadmin && ($links = wa()->event('links', $contacts))) {
         foreach ($links as $app_id => $l) {
             foreach ($l as $contact_id => $contact_links) {
                 if ($contact_links) {
                     throw new waRightsException('Access denied: only superadmin is allowed to delete contacts with links to other applications.');
                 }
             }
         }
     }
     // Are there users among $contacts?
     $um = new waUserModel();
     $users = array_keys($um->getByField(array('id' => $contacts, 'is_user' => 1), 'id'));
     // deletion of users is only allowed to superadmins
     if (!$superadmin && $users) {
         throw new waRightsException('Access denied: only superadmin is allowed to delete users.');
     }
     // Revoke user access before deletion
     foreach ($users as $user_id) {
         waUser::revokeUser($user_id);
     }
     $contact_model = new waContactModel();
     $cnt = count($contacts);
     if ($cnt > 30) {
         $log_params = $cnt;
     } else {
         // contact names
         $log_params = $contact_model->getName($contacts);
     }
     $history_model = new contactsHistoryModel();
     foreach ($contacts as $contact_id) {
         $history_model->deleteByField(array('type' => 'add', 'hash' => '/contact/' . $contact_id));
     }
     // Bye bye...
     $contact_model->delete($contacts);
     // also throws a contacts.delete event
     $this->response['deleted'] = $cnt;
     $this->response['message'] = sprintf(_w("%d contact has been deleted", "%d contacts have been deleted", $this->response['deleted']), $this->response['deleted']);
     $this->logAction('contact_delete', $log_params);
 }
 public function execute()
 {
     $superadmin = $this->getUser()->getRights('webasyst', 'backend');
     $contacts = waRequest::post('id', array(), 'array_int');
     // do not try to delete self
     if (in_array($this->getUser()->getId(), $contacts)) {
         throw new waRightsException('Access denied: attempt to delete own account.');
     }
     // Only allow actions with contacts available for current user
     if (!$this->getRights('category.all')) {
         $crm = new contactsRightsModel();
         $ccm = new waContactCategoriesModel();
         $allowed = array_keys($crm->getAllowedCategories());
         foreach ($ccm->getContactsCategories($contacts) as $id => $cats) {
             if (!array_intersect($allowed, $cats)) {
                 throw new waRightsException('Access denied: no access to contact ' . $id);
             }
         }
     }
     // Deletion of contacts with links to other applications is only allowed to superadmins
     if (!$superadmin && ($links = wa()->event('links', $contacts))) {
         foreach ($links as $app_id => $l) {
             foreach ($l as $contact_id => $contact_links) {
                 if ($contact_links) {
                     throw new waRightsException('Access denied: only superadmin is allowed to delete contacts with links to other applications.');
                 }
             }
         }
     }
     // Are there users among $contacts?
     $um = new waUserModel();
     $users = array_keys($um->getByField(array('id' => $contacts, 'is_user' => 1), 'id'));
     // deletion of users is only allowed to superadmins
     if (!$superadmin && $users) {
         throw new waRightsException('Access denied: only superadmin is allowed to delete users.');
     }
     // Revoke user access before deletion
     foreach ($users as $user_id) {
         waUser::revokeUser($user_id);
     }
     // Bye bye...
     $contact_model = new waContactModel();
     $contact_model->delete($contacts);
     // also throws a contacts.delete event
     $this->response['deleted'] = count($contacts);
     $this->response['message'] = sprintf(_w("%d contact has been deleted", "%d contacts have been deleted", $this->response['deleted']), $this->response['deleted']);
     $this->log('contact_delete', count($contacts));
 }
 protected function loginExists($login, $id)
 {
     $user_model = new waUserModel();
     return $user_model->select('id,name')->where("login = s:0 AND id != i:1", array($login, $id))->limit(1)->fetch();
 }