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');
     }
 }
Exemple #2
0
 /**
  * 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("/");
     }
 }
Exemple #3
0
 public function setUp()
 {
     parent::setUp();
     $table = new USVN_Db_Table_Projects();
     $obj = $table->fetchNew();
     $obj->setFromArray(array('projects_name' => 'test', 'projects_start_date' => '1984-12-03 00:00:00'));
     $obj->save();
 }
Exemple #4
0
 /**
  * @param string Project name
  * @throw USVN_Exception if project is invalid
  */
 public function __construct($project)
 {
     $table = new USVN_Db_Table_Projects();
     if (!$table->isAProject($project)) {
         throw new USVN_Exception(T_("Invalid project name %s."), $project);
     }
     $this->_project = $project;
     $this->_repository = Zend_Registry::get('config')->subversion->path . '/svn/' . $this->_project;
 }
Exemple #5
0
 /**
  * Default action for every controller.
  *
  */
 public function indexAction()
 {
     $projects = new USVN_Db_Table_Projects();
     $this->view->projects = $projects->fetchAllAssignedTo($this->getRequest()->getParam('user'));
     $identity = Zend_Auth::getInstance()->getIdentity();
     $user_table = new USVN_Db_Table_Users();
     $user = $user_table->fetchRow(array('users_login = ?' => $identity['username']));
     $this->view->groups = $user->listGroups();
     $this->view->maxlen = 12;
 }
Exemple #6
0
 public static function generate()
 {
     $config = Zend_Registry::get('config');
     $oldUserConfig = self::loadExistingAuthzData($config->subversion->authz);
     $text = "# This is an auto generated file! Edit at your own risk!\n";
     $text .= "# You can edit this \"/\" section. Settings will be kept.\n#\n";
     $text .= "[/]\n";
     foreach ($oldUserConfig as $key => $value) {
         $text .= $key . " = " . $value . "\n";
     }
     $text .= "\n#\n# Don't edit anything below! All manual changes will be overwritten. \n#\n";
     $text .= "\n[groups]\n";
     $array = array();
     $groups = new USVN_Db_Table_Groups();
     foreach ($groups->fetchAllAndUsers() as $group) {
         $array[$group->name][] = $group->users_login;
     }
     foreach ($array as $group => $users) {
         $users = implode(", ", $users);
         $text .= "{$group} = {$users}\n";
     }
     $array = array();
     $projects = new USVN_Db_Table_Projects();
     foreach ($projects->fetchAllAndFilesRightsAndGroups() as $project) {
         /* @var $project USVN_Db_Table_Row_Project */
         if (!isset($array[$project->name])) {
             $array[$project->name] = array();
         }
         if ($project->files_rights_path) {
             if (!isset($array[$project->name][$project->files_rights_path])) {
                 $array[$project->name][$project->files_rights_path] = array();
             }
             if ($project->groups_name) {
                 $rights = $project->files_rights_is_readable ? "r" : "";
                 $rights .= $project->files_rights_is_writable ? "w" : "";
                 $array[$project->name][$project->files_rights_path][$project->groups_name] = $rights;
             }
         }
     }
     foreach ($array as $project => $files_paths) {
         $text .= "\n\n# Project {$project}\n";
         foreach ($files_paths as $files_path => $files_rights) {
             $text .= "[{$project}:{$files_path}]\n";
             foreach ($files_rights as $group => $rights) {
                 $text .= "@{$group} = {$rights}\n";
             }
             $text .= "\n";
         }
     }
     @file_put_contents($config->subversion->authz, $text);
 }
Exemple #7
0
 public function setUp()
 {
     parent::setUp();
     $table = new USVN_Db_Table_Projects();
     $project = $table->fetchNew();
     $project->setFromArray(array('projects_name' => 'project1', 'projects_start_date' => '1984-12-03 00:00:00'));
     $this->_projectid1 = $project->save();
     $table = new USVN_Db_Table_Projects();
     $project = $table->fetchNew();
     $project->setFromArray(array('projects_name' => 'project2', 'projects_start_date' => '1984-12-03 00:00:00'));
     $this->_projectid2 = $project->save();
     $table_files = new USVN_Db_Table_FilesRights();
     $id = $table_files->insert(array('projects_id' => $this->_projectid1, 'files_rights_path' => '/'));
 }
Exemple #8
0
 public function test_indexActionTwoProject()
 {
     $table_project = new USVN_Db_Table_Projects();
     $project = $table_project->fetchNew();
     $project->setFromArray(array('projects_name' => 'OpenBSD', 'projects_start_date' => '1984-12-03 00:00:00'));
     $project->save();
     $project->addUser($this->user);
     $project2 = $table_project->fetchNew();
     $project2->setFromArray(array('projects_name' => 'Hurd', 'projects_start_date' => '1984-12-03 00:00:00'));
     $project2->save();
     $project2->addUser($this->user);
     $this->runAction('index');
     $this->assertEquals(2, count($this->controller->view->projects));
     $this->assertContains('href="/project/OpenBSD">OpenBSD</a>', $this->getBody(), $this->getBody());
     $this->assertContains('href="/project/Hurd">Hurd</a>', $this->getBody());
 }
 public function setUp()
 {
     parent::setUp();
     $table = new USVN_Db_Table_Projects();
     $project = $table->fetchNew();
     $project->setFromArray(array('projects_name' => 'project1', 'projects_start_date' => '1984-12-03 00:00:00'));
     $this->_projectid1 = $project->save();
     $table = new USVN_Db_Table_Projects();
     $project = $table->fetchNew();
     $project->setFromArray(array('projects_name' => 'project2', 'projects_start_date' => '1984-12-03 00:00:00'));
     $this->_projectid2 = $project->save();
     $group_table = new USVN_Db_Table_Groups();
     $group = $group_table->fetchNew();
     $group->setFromArray(array("groups_name" => "toto"));
     $this->_groupid1 = $group->save();
     $group_table = new USVN_Db_Table_Groups();
     $group = $group_table->fetchNew();
     $group->setFromArray(array("groups_name" => "titi"));
     $this->_groupid2 = $group->save();
 }
Exemple #10
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");
     }
 }
Exemple #11
0
 public function testGetAllGroupsFor()
 {
     $this->user->addGroup($this->groups->find(42)->current());
     $this->user->addGroup($this->groups->find(43)->current());
     $table = new USVN_Db_Table_Projects();
     $proj = $table->createRow(array("projects_name" => "proj"));
     $proj->save();
     $proj->addGroup($this->groups->find(42)->current());
     $groups_name = $this->user->getAllGroupsFor("proj");
     $groups_object = $this->user->getAllGroupsFor($proj);
     $this->assertEquals($groups_name, $groups_object, "USVN_Db_Table_Row_User::getAllGroupsFor() must act the same way with a string or an object");
 }
Exemple #12
0
 public function completionAction()
 {
     echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
     $table = "<table width=100%>";
     $nb = 0;
     echo "<files>\n";
     if ($_GET['idx'] == 1) {
         if (isset($_GET['grp']) && $_GET['grp'] != "") {
             $table_groups = new USVN_Db_Table_Groups();
             $res_groups = $table_groups->findByGroupsName($_GET['grp']);
             $table_userstogroups = new USVN_Db_Table_UsersToGroups();
             $res_usersspe = $table_userstogroups->findByGroupId($res_groups->groups_id);
         } else {
             if (isset($_GET['prj']) && $_GET['prj'] != "") {
                 $table_project = new USVN_Db_Table_Projects();
                 $res_project = $table_project->findByName($_GET['prj']);
                 $table_userstoprojects = new USVN_Db_Table_UsersToProjects();
                 $res_usersspe = $table_userstoprojects->findByProjectId($res_project->projects_id);
             }
         }
         $table_users = new USVN_Db_Table_Users();
         $res_users = $table_users->allUsersLike($_GET['txt']);
         foreach ($res_users as $user) {
             $find = false;
             foreach ($res_usersspe as $tmpuser) {
                 if ($tmpuser->users_id == $user->users_id) {
                     $find = true;
                 }
             }
             if ($find == false) {
                 $table .= "<tr id='user" . $nb . "' class='comp'>";
                 $table .= "<td align=left onclick='javascript:dumpInput(" . "\"" . $user->users_login . "\"" . "," . "\"" . $_GET['input'] . "\"" . ", \"completion\")'>";
                 $table .= "<label id='luser" . $nb . "'>" . $user->users_login . "</label>";
                 $table .= "</td></tr>";
                 $nb++;
             }
         }
     }
     if ($_GET['idx'] == 2) {
         $table_project = new USVN_Db_Table_Projects();
         $res_project = $table_project->findByName($_GET['prj']);
         $table_groupstoprojects = new USVN_Db_Table_GroupsToProjects();
         $res_groupstoprojects = $table_groupstoprojects->findByProjectId($res_project->projects_id);
         $table_groups = new USVN_Db_Table_Groups();
         $res_groups = $table_groups->allGroupsLike($_GET['txt']);
         foreach ($res_groups as $group) {
             $find = false;
             foreach ($res_groupstoprojects as $tmpgrp) {
                 if ($tmpgrp->groups_id == $group->groups_id) {
                     $find = true;
                 }
             }
             if ($find == false) {
                 $table .= "<tr id='grp" . $nb . "' class='comp'>";
                 $table .= "<td align=left onclick='javascript:dumpInput(" . "\"" . $group->groups_name . "\"" . "," . "\"" . $_GET['input'] . "\"" . ", \"completion1\")'>";
                 $table .= "<label id='lgrp" . $nb . "'>" . $group->groups_name . "</label>";
                 $table .= "</td></tr>";
                 $nb++;
             }
         }
     }
     if ($_GET['idx'] == 3) {
         $table_users = new USVN_Db_Table_Users();
         $res_users = $table_users->allUsersLike($_GET['txt']);
         $table_groups = new USVN_Db_Table_Groups();
         $res_groups = $table_groups->findByGroupsName($_GET['grp']);
         $res_usersspe = $table_users->allLeader($res_groups->groups_id);
         foreach ($res_users as $user) {
             $find = false;
             foreach ($res_usersspe as $tmpuser) {
                 if ($tmpuser->users_id == $user->users_id) {
                     $find = true;
                 }
             }
             if ($find == false) {
                 $table .= "<tr id='user" . $nb . "' class='comp'>";
                 $table .= "<td align=left onclick='javascript:dumpInput(" . "\"" . $user->users_login . "\"" . "," . "\"" . $_GET['input'] . "\"" . ", \"completionleader\")'>";
                 $table .= "<label id='luser" . $nb . "'>" . $user->users_login . "</label>";
                 $table .= "</td></tr>";
                 $nb++;
             }
         }
     }
     if ($_GET['idx'] == 4) {
         $table_groups = new USVN_Db_Table_Groups();
         $res_groups = $table_groups->findByGroupsName($_GET['grp']);
         $table_userstogroups = new USVN_Db_Table_UsersToGroups();
         $res_usersspe = $table_userstogroups->noleaderFindByGroupId($res_groups->groups_id);
         $table_users = new USVN_Db_Table_Users();
         $res_users = $table_users->allUsersLike($_GET['txt']);
         foreach ($res_users as $user) {
             $find = false;
             foreach ($res_usersspe as $tmpuser) {
                 if ($tmpuser->users_id == $user->users_id) {
                     $find = true;
                 }
             }
             if ($find == false) {
                 $table .= "<tr id='user" . $nb . "' class='comp'>";
                 $table .= "<td align=left onclick='javascript:dumpInput(" . "\"" . $user->users_login . "\"" . "," . "\"" . $_GET['input'] . "\"" . ", \"completion\")'>";
                 $table .= "<label id='luser" . $nb . "'>" . $user->users_login . "</label>";
                 $table .= "</td></tr>";
                 $nb++;
             }
         }
     }
     $table .= "</table>";
     echo "<nbcomp>" . $nb . "</nbcomp>\n";
     echo "<tableau><![CDATA[" . $table . "]]></tableau>\n";
     echo "</files>\n";
 }
Exemple #13
0
 public function testfetchAllAssignedToAll()
 {
     $users = array('stem', 'noplay', 'crivis_s', 'duponc_j', 'dolean_j', 'billar_m', 'attal_m', 'joanic_g', 'guyoll_o');
     foreach ($users as $user) {
         ${$user} = $this->createUser($user, "password");
     }
     /* @var $stem USVN_Db_Table_Row_User */
     /* @var $noplay USVN_Db_Table_Row_User */
     /* @var $crivis_s USVN_Db_Table_Row_User */
     /* @var $duponc_j USVN_Db_Table_Row_User */
     /* @var $dolean_j USVN_Db_Table_Row_User */
     /* @var $billar_m USVN_Db_Table_Row_User */
     /* @var $attal_m USVN_Db_Table_Row_User */
     /* @var $joanic_g USVN_Db_Table_Row_User */
     /* @var $guyoll_o USVN_Db_Table_Row_User */
     $projects = array('usvn', 'private', 'website', 'proj4', 'proj5', 'proj6', 'proj7', 'proj8', 'proj9', 'proj10', 'proj11');
     foreach ($projects as $project) {
         ${$project} = $this->createProject($project);
         ${$project}->addUser($stem);
         if ($project != 'private' && $project != 'website') {
             $group = "group_{$project}";
             ${$group} = $this->createGroup($group);
             ${$project}->addGroup(${$group});
             if ($project == 'usvn') {
                 $crivis_s->addGroup(${$group});
                 $dolean_j->addGroup(${$group});
                 $guyoll_o->addGroup(${$group});
                 $billar_m->addGroup(${$group});
                 $attal_m->addGroup(${$group});
                 $joanic_g->addGroup(${$group});
                 $duponc_j->addGroup(${$group});
             } else {
                 $stem->addGroup(${$group});
             }
         } else {
             ${$project}->addGroup(${"group_usvn"});
         }
     }
     /* @var $usvn USVN_Db_Table_Row_Project */
     /* @var $private USVN_Db_Table_Row_Project */
     /* @var $website USVN_Db_Table_Row_Project */
     /* @var $ETNA USVN_Db_Table_Row_Project */
     /* @var $toeic USVN_Db_Table_Row_Project */
     /* @var $conf USVN_Db_Table_Row_Project */
     /* @var $dotNET USVN_Db_Table_Row_Project */
     /* @var $generic USVN_Db_Table_Row_Project */
     $table = new USVN_Db_Table_Projects();
     $this->assertEquals(3, count($table->fetchAllAssignedTo($crivis_s)));
     $this->assertEquals(count($projects), count($table->fetchAllAssignedTo($stem)));
 }
Exemple #14
0
 public function testDeleteProject()
 {
     USVN_Project::createProject(array('projects_name' => 'InsertProjectOK', 'projects_start_date' => '1984-12-03 00:00:00'), "test", true, true, true, false);
     USVN_Project::deleteProject('InsertProjectOK');
     $table = new USVN_Db_Table_Projects();
     $this->assertFalse($table->isAProject('InsertProjectOk'), "Le projet n'est pas supprime");
     $table_groups = new USVN_Db_Table_Groups();
     $this->assertFalse($table_groups->isAGroup('InsertProjectOk'), "Le groupe n'est pas supprime");
 }
Exemple #15
0
 /**
  * Get all groups associated with $project for this user
  *
  * Project can be the project name as a string or a project row.
  *
  * @param string|USVN_Db_Table_Row_Project $project
  * @return Zend_Db_Table_Rowset
  */
 public function getAllGroupsFor($project)
 {
     if (!is_object($project)) {
         $projects = new USVN_Db_Table_Projects();
         $project = $projects->findByName($project);
     }
     $groups = new USVN_Db_Table_Groups();
     return $groups->fetchAllForUserAndProject($this, $project);
 }
Exemple #16
0
 /**
  * Generate and save a project
  *
  * @param string $name
  * @return USVN_Db_Table_Row_Project
  */
 protected function createProject($name)
 {
     $table = new USVN_Db_Table_Projects();
     try {
         $obj = $table->fetchNew();
         $obj->setFromArray(array('projects_name' => $name));
         $obj->save();
         return $obj;
     } catch (Exception $e) {
         $this->fail($name . " : " . $e->getMessage());
     }
 }
Exemple #17
0
 /**
  * Return list of projects
  * 
  * 	http://usvn.localhost/service/list
  * 
  * 	<?xml version="1.0" encoding="UTF-8"?>
  * 	<usvn>
  * 		<auth>
  * 			<username>USERNAME</username>
  * 			<password>PASSWORD</password>
  * 		</auth>
  * </usvn>
  */
 public function listAction()
 {
     // Parse XML request
     $this->_parseRequest();
     // Authenticate
     if (!$this->_auth()) {
         throw new Zend_Exception("Authentication failure");
     }
     // Retrieve projects from the authenticated user
     $projects = new USVN_Db_Table_Projects();
     $list = $projects->fetchAllAssignedTo($this->_userRow);
     // Start create XML return
     $dom = new DOMDocument("1.0", "UTF-8");
     $xmlService = $dom->createElement("usvn");
     $xmlService = $dom->appendChild($xmlService);
     // Create project rows
     $xmlProjects = $xmlService->appendChild($dom->createElement("projects"));
     foreach ($list as $row) {
         $xmlNode = $xmlProjects->appendChild($dom->createElement("project"));
         $xmlNode->appendChild($dom->createElement("id", $row->projects_id));
         $xmlNode->appendChild($dom->createElement("name", $row->projects_name));
         $xmlNode->appendChild($dom->createElement("start_date", $row->projects_start_date));
         $xmlNode->appendChild($dom->createElement("description", $row->projects_description));
     }
     // Output xml
     $this->_outputResponse($dom);
 }
Exemple #18
0
 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 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')));
 }
Exemple #20
0
 /**
  * If files exist update rights if not insert rights
  */
 public function updateOrInsertRightsAction()
 {
     try {
         $table_project = new USVN_Db_Table_Projects();
         $res_project = $table_project->findByName(str_replace(USVN_URL_SEP, '/', $this->_request->getParam('project')));
         $acces_rights = new USVN_FilesAccessRights($res_project->projects_id);
         $user = $this->getRequest()->getParam('user');
         if (!$res_project->userIsAdmin($user) && !$user->is_admin) {
             $this->_redirect("/");
         }
         $msg = "Ok";
         $tabgroup = split(",", $_GET['group']);
         $tabrights = split(",", $_GET['rights']);
         $j = 0;
         foreach ($tabgroup as $group) {
             $table_group = new USVN_Db_Table_Groups();
             $res_groups = $table_group->findByGroupsName($group);
             $acces_rights->setRightByPath($res_groups->groups_id, $_GET['name'], $tabrights[$j] == 'true' ? true : false, $tabrights[$j + 1] == 'true' ? true : false, $tabrights[$j + 2] == 'true' ? true : false);
             $j += 3;
         }
     } catch (Exception $e) {
         $msg = nl2br($e->getMessage());
     }
     echo "<msg>" . $msg . "</msg>\n";
 }