Beispiel #1
0
 public function indexAction()
 {
     $this->view->project = $this->_project;
     $SVN = new USVN_SVN($this->_project->name);
     $this->view->log = $SVN->log(5);
     $this->render("index");
 }
Beispiel #2
0
 /**
  * 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);
     }
 }
Beispiel #3
0
 public function test_listFile()
 {
     USVN_SVNUtils::createSVN('tests/tmp/svn/test');
     USVN_SVNUtils::createStandardDirectories('tests/tmp/svn/test');
     USVN_SVNUtils::checkoutSvn('tests/tmp/svn/test', 'tests/tmp/out');
     $path = getcwd();
     chdir('tests/tmp/out');
     mkdir('trunk/testdir');
     `svn add trunk/testdir`;
     touch('trunk/testfile');
     `svn add trunk/testfile`;
     `svn commit --non-interactive -m Test`;
     chdir($path);
     $svn = new USVN_SVN('test');
     $res = $svn->listFile('/');
     $this->assertEquals(3, count($res));
     $this->assertContains(array("name" => "trunk", "isDirectory" => true, "path" => "/trunk/"), $res);
     $this->assertContains(array("name" => "branches", "isDirectory" => true, "path" => "/branches/"), $res);
     $this->assertContains(array("name" => "tags", "isDirectory" => true, "path" => "/tags/"), $res);
     $res = $svn->listFile('/trunk');
     $this->assertEquals(2, count($res));
     $this->assertContains(array("name" => "testdir", "isDirectory" => true, "path" => "/trunk/testdir/"), $res);
     $this->assertContains(array("name" => "testfile", "isDirectory" => false, "path" => "/trunk/testfile"), $res);
 }
Beispiel #4
0
 /**
  * Get list files of subversion directory.
  */
 public function getListFileAction()
 {
     $path = str_replace('//', '/', $_GET['name']);
     $project_name = str_replace(USVN_URL_SEP, '/', $this->_request->getParam('project'));
     $SVN = new USVN_SVN($project_name);
     $tab = $SVN->listFile($path);
     ob_start();
     echo $this->getTopLink($project_name, $path);
     $user = $this->getRequest()->getParam('user');
     /* @var $user USVN_Db_Table_Row_User */
     $table = new USVN_Db_Table_Projects();
     $project = $table->findByName($this->getRequest()->getParam('project'));
     $read = false;
     $acces_rights = new USVN_FilesAccessRights($project->id);
     $groups = $user->getAllGroupsFor($project);
     foreach ($groups as $group) {
         $access = $acces_rights->findByPath($group->id, $path);
         if ($access['read']) {
             $read = true;
             break;
         }
     }
     if (!$read && ($user->is_admin || $project->userIsAdmin($user))) {
         $read = true;
     }
     if ($read) {
         echo '<table class="usvn_table">';
         echo '<thead>';
         echo '<tr><th>', T_('Name'), '</th><th>', T_('File revision'), '</th><th width="50px">', T_('Action'), '</th></tr>';
         echo '</thead>';
         echo '<tbody>';
         $i = 0;
         if ($path != "/" && $path != "//") {
             if (dirname($path) == "\\") {
                 $pathbefore = "/";
             } else {
                 $pathbefore = dirname($path) . "/";
             }
             echo "<tr class=\"" . (++$i % 2 ? 'even' : 'odd') . "\"><td>";
             echo "<a href='javascript:getListFile(" . "\"" . $pathbefore . "\"" . ");'>" . $this->view->img('folder.png', T_('Folder')) . " ..</a></td><td></td><td></td></tr>";
         }
         foreach ($tab as &$tabl) {
             $tabl['path_raw'] = $tabl['path'];
             $tabl['path'] = rawurlencode($tabl['path']);
             echo "<tr class=\"" . (++$i % 2 ? 'even' : 'odd') . "\">";
             $dir = false;
             if ($tabl['isDirectory'] == 1) {
                 $dir = true;
                 $tabl['isDirectory'] = $this->view->img('folder.png', T_('Folder'));
             } else {
                 $tabl['isDirectory'] = $this->view->img('file.png', T_('File'));
             }
             echo "<td>";
             if ($dir) {
                 echo "<a href='javascript:getListFile(\"{$tabl['path']}\");'>{$tabl['isDirectory']} {$tabl['name']}</a></td>";
             } else {
                 $tabl['size'] = round($tabl['size'] / 1000.0, 2) . ' Ko';
                 echo "<a href=\"" . $this->view->url(array('project' => $project->name, 'file' => substr($tabl['path_raw'], 1)), 'show', false, false) . "\">{$tabl['isDirectory']} {$tabl['name']}</a> <span style=\"font-size: 8px; text-align: right;\">({$tabl['size']})</span></td>";
             }
             if (isset($tabl['revision'])) {
                 echo "<td><a href=\"" . $this->view->url(array('project' => $project->name, 'action' => 'commit', 'commit' => $tabl['revision']), 'commit') . "\">{$tabl['revision']}</a> by {$tabl['author']}</td>";
             } else {
                 echo "<td></td>";
             }
             echo "<td class=\"align-center\"><a href='javascript:dumpRights(\"{$tabl['path']}\");'>" . $this->view->img('lock.png', T_('Rights')) . "</a></td></tr>";
         }
         echo "</tbody></table>";
     } else {
         echo T_("You don't have read access to this folder");
     }
     $txthtml = ob_get_clean();
     echo "<txthtml><![CDATA[";
     echo $txthtml;
     echo "]]></txthtml>\n";
     $this->view->browser = $tab;
 }
Beispiel #5
0
 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");
     }
 }