/** * Pre-dispatch routines * * Called before action method. If using class with * {@link Zend_Controller_Front}, it may modify the * {@link $_request Request object} and reset its dispatched flag in order * to skip processing the current action. * * @return void */ public function preDispatch() { parent::preDispatch(); $project = $this->getRequest()->getParam('project'); $table = new USVN_Db_Table_Projects(); $project = $table->fetchRow(array("projects_name = ?" => $project)); /* @var $project USVN_Db_Table_Row_Project */ if ($project === null) { $this->_redirect("/"); } $this->_project = $project; $table = new USVN_Db_Table_Users(); $user = $table->findBySecret($_GET['secret']); if ($user) { $groups = $user->findManyToManyRowset("USVN_Db_Table_Groups", "USVN_Db_Table_UsersToGroups"); $find = false; foreach ($groups as $group) { if ($project->groupIsMember($group)) { $find = true; break; } } if (!$find && !$this->isAdmin()) { $this->_redirect("/"); } } else { $this->_redirect("/"); } }
public function updateAction() { $data = $this->getProjectData($_POST); if (empty($data)) { $this->_redirect("/admin/project/new"); } $table = new USVN_Db_Table_Projects(); $project = $table->fetchRow(array("projects_name = ?" => str_replace(USVN_URL_SEP, '/', $this->getRequest()->getParam('name')))); if ($project === null) { $this->_redirect("/admin/project/"); } $identity = Zend_Auth::getInstance()->getIdentity(); $user_table = new USVN_Db_Table_Users(); $users = $user_table->fetchRow(array('users_login = ?' => $identity['username'])); if (isset($_POST['admin'])) { $table->AddUserToProject($users, $project); } else { $table->DeleteUserToProject($users, $project); } $project->setFromArray($data); try { $project->save(); $this->_redirect("/admin/project/"); } catch (Exception $e) { $this->view->project = $project; $this->view->message = nl2br($e->getMessage()); $this->render('edit'); } }
/** * Retrieve project history * * http://usvn.localhost/service/history * * <?xml version="1.0" encoding="UTF-8"?> * <usvn> * <auth> * <username>USERNAME</username> * <password>PASSWORD</password> * </auth> * <project>PROJECT_NAME</project> * </usvn> * * @todo Add translation for "You don't have permission to access project %s" */ public function historyAction() { // Parse XML request $this->_parseRequest(); // Authenticate if (!$this->_auth()) { throw new Zend_Exception("Authentication failure"); } // Get project information $project_name = (string) $this->_xml->project; $table = new USVN_Db_Table_Projects(); $project = $table->fetchRow(array("projects_name = ?" => (string) $project_name)); if (!$project) { $this->_outputErrorResponse(sprintf(T_("Invalid project name %s."), $project_name), 10); } // Verify user groups $hasGroup = FALSE; $groups = $this->_userRow->findManyToManyRowset("USVN_Db_Table_Groups", "USVN_Db_Table_UsersToGroups"); foreach ($groups as $group) { // Verify project groups if ($project->groupIsMember($group)) { $hasGroup = TRUE; break; } } // Verify user permission if ($this->_userRow['users_is_admin'] === 1 || $hasGroup === TRUE) { $SVN = new USVN_SVN($project_name); $logs = $SVN->log(100); // Start create XML return $dom = new DOMDocument("1.0", "UTF-8"); $xmlService = $dom->createElement("usvn"); $xmlService = $dom->appendChild($xmlService); // Loop into logs $xmlLogs = $xmlService->appendChild($dom->createElement("history")); foreach ($logs as $log) { $xmlNode = $xmlLogs->appendChild($dom->createElement("log")); $xmlNode->appendChild($dom->createElement("author", $log['author'])); $xmlNode->appendChild($dom->createElement("comment", $log['msg'])); $xmlNode->appendChild($dom->createElement("date", date("Y-m-d H:i:s", $log['date']))); } // Output $this->_outputResponse($dom); } else { $this->_outputErrorResponse(sprintf(T_("You don't have permission to access project %s"), $project_name), 10); } }
public function test_delete() { $projects = new USVN_Db_Table_Projects(); $this->assertNotNull($projects->fetchRow(array('projects_name = ?' => 'Indochine'))); $this->request->setParam('name', 'Indochine'); try { $this->runAction('delete'); } catch (USVN_Test_Exception_Redirect $e) { $this->assertEquals('/admin/project/', $e->url); } $this->assertNull($projects->fetchRow(array('projects_name = ?' => 'Indochine'))); }
public static function deleteProject($project_name) { $table = new USVN_Db_Table_Projects(); $project = $table->fetchRow(array('projects_name = ?' => $project_name)); if ($project === null) { throw new USVN_Exception(T_("Project %s doesn't exist."), $project_name); } $project->delete(); $groups = new USVN_Db_Table_Groups(); $where = $groups->getAdapter()->quoteInto("groups_name = ?", $project_name); $group = $groups->fetchRow($where); if ($group !== null) { $group->delete(); } USVN_DirectoryUtils::removeDirectory(Zend_Registry::get('config')->subversion->path . DIRECTORY_SEPARATOR . 'svn' . DIRECTORY_SEPARATOR . $project_name); }
public function lasthundredrequestAction() { $project = $this->getRequest()->getParam('project'); $table = new USVN_Db_Table_Projects(); $project = $table->fetchRow(array("projects_name = ?" => $project)); /* @var $project USVN_Db_Table_Row_Project */ if ($project === null) { $this->_redirect("/"); } $this->_project = $project; $this->view->project = $this->_project; $SVN = new USVN_SVN($this->_project->name); try { $number_start = $project = $this->getRequest()->getParam('number_start'); $number_end = $project = $this->getRequest()->getParam('number_end'); $this->view->number_start = $number_start; $this->view->number_end = $number_end; if (empty($number_end)) { $number_end = null; } else { $number_end = $this->convertDate($number_end); } $number_start = $this->convertDate($number_start); $this->view->log = $SVN->log(100, $number_start, $number_end); $this->render("timeline"); } catch (USVN_Exception $e) { $this->view->message = "No such revision found"; $this->view->log = $SVN->log(100); $this->render("timeline"); } }