/** * Before allowing someone to do stuff, check to see * whether they have access to the file they've requested * */ public function preDispatch() { if (za()->getUser()->getRole() == User::ROLE_EXTERNAL) { // make sure the id is valid $id = $this->_getParam('id'); $client = $this->clientService->getUserClient(za()->getUser()); $project = $this->byId($this->_getParam('projectid'), 'Project'); if ($client == null || $project == null) { $this->log->warn("User " . za()->getUser()->getUsername() . " tried viewing without valid client or project"); $this->requireLogin(); return; } if ($id) { // see whether the list of files for the current user's // company is valid /*$path = 'Clients/'.$client->title.'/Projects/'.$project->title; $okay = $this->fileService->isInDirectory($this->fileService->getFile($id), $path, true); if (!$okay) { $this->requireLogin(); }*/ } } }
/** * Load the contacts for a given client id */ public function contactlistAction() { $client = $this->clientService->getUserClient(za()->getUser()); if (!$client) { echo "Failed loading contacts"; return; } $this->view->client = $client; $this->view->contacts = $this->clientService->getContacts($client); $this->renderRawView('contact/ajax-list.php'); }
public function preDispatch() { $userClient = $this->clientService->getUserClient(za()->getUser()); if ($userClient != null) { $id = $this->_getParam('id'); // get the user's client if ($id != $userClient->id) { $this->_setParam('id', $userClient->id); } } else { $this->requireLogin(); } }
/** * Check that the user can access the requested project */ public function preDispatch() { $client = $this->clientService->getUserClient(za()->getUser()); if ($client != null) { // Set the client $this->_setParam('clientid', $client->id); } // make sure that the user is doing something they're allowed to do $id = $this->_getParam('id'); if ($id) { $obj = $this->byId(); if (!$obj || $client == null || $obj->clientid != $client->id) { $this->log->warn("Client is " . $client->title . " {$client->id} and {$obj->clientid}"); $this->requireLogin(); } } }
/** * Get the total number of clients for a given where clause * * @param array $where * @return int */ public function getIssueCount($where) { // if the current user is an external, filter by their clientid if (za()->getUser()->getRole() == User::ROLE_EXTERNAL) { // get their client $client = $this->clientService->getUserClient(za()->getUser()); $where['clientid='] = $client->id; } return $this->dbService->getObjectCount($where, 'Issue'); }
/** * Generates the appropriate query for returning a list of issues * * @param array $where * @return arrayobject */ protected function getList($type, $where = array()) { $query = $this->_getParam('query'); if (mb_strlen($query) >= 2) { $where[] = new Zend_Db_Expr("title like " . $this->dbService->quote('%' . $query . '%') . " OR description like " . $this->dbService->quote('%' . $query . '%')); } // Handle this up here otherwise a model object might take $sortDir = $this->_getParam('sortorder', $this->_getParam('dir', 'desc')); if ($sortDir == 'up' || $sortDir == 'asc') { $sortDir = 'asc'; } else { $sortDir = 'desc'; } // now just iterate parameters $params = $this->_getAllParams(); unset($params['title']); unset($params['sortorder']); $dummyObj = new $type(); // get all the type's parameters $fields = $dummyObj->unBind(); foreach ($fields as $name => $val) { // if we have a param with $name, add it to the filter $val = ifset($params, $name, null); if (!is_null($val)) { $where[$name . ' ='] = $val; } } // If not a User, can only see non-private issues if (za()->getUser()->getRole() == User::ROLE_EXTERNAL) { if (isset($fields['isprivate'])) { $where['isprivate='] = 0; } if (isset($fields['clientid'])) { $client = $this->clientService->getUserClient(za()->getUser()); $where['clientid='] = $client->id; } } $sort = $this->_getParam('sortname', $this->_getParam('sort', 'updated')); $sort .= ' ' . $sortDir; $this->view->totalCount = $this->dbService->getObjectCount($where, $type); $currentPage = ifset($params, 'page', 1); $this->view->listSize = $this->_getParam('rp', za()->getConfig('project_list_size', 10)); if ($this->_getParam("unlimited")) { $currentPage = null; } return $this->dbService->getObjects($type, $where, $sort, $currentPage, $this->view->listSize); }