Пример #1
0
 protected function setUp()
 {
     parent::setUp();
     $users = new USVN_Db_Table_Users();
     $users->insert(array("users_id" => 42, "users_login" => "Telephone", "users_password" => "secret"));
     $users->insert(array("users_id" => 43, "users_login" => "Indochine", "users_password" => "secret"));
     $groups = new USVN_Db_Table_Groups();
     $groups->insert(array("groups_id" => 42, "groups_name" => "Telephone", "groups_description" => "test"));
 }
Пример #2
0
 public function test_indexActionTwoGroup()
 {
     $groups = new USVN_Db_Table_Groups();
     $g1 = $groups->insert(array("groups_id" => 42, "groups_name" => "Telephone", "groups_description" => "test"));
     $g2 = $groups->insert(array("groups_id" => 43, "groups_name" => "Indochine", "groups_description" => "Bob morane"));
     $this->user->addGroup($g1);
     $this->user->addGroup($g2);
     $this->runAction('index');
     $this->assertEquals(2, count($this->controller->view->groups));
     $this->assertContains('href="/group/Indochine">Indochine</a>', $this->getBody(), $this->getBody());
     $this->assertContains('href="/group/Telephone">Telephone</a>', $this->getBody());
 }
Пример #3
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);
 }
Пример #4
0
 public function setUp()
 {
     parent::setUp();
     $table = new USVN_Db_Table_Users();
     $this->_user = $table->fetchNew();
     $this->_user->setFromArray(array('users_login' => 'test', 'users_password' => 'password', 'users_firstname' => 'firstname', 'users_lastname' => 'lastname', 'users_email' => '*****@*****.**'));
     $this->_user->save();
     $this->_projectid1 = USVN_Project::createProject(array('projects_name' => "project1"), "test", true, false, false, true)->id;
     $this->_projectid2 = USVN_Project::createProject(array('projects_name' => "project2"), "test", true, false, false, true)->id;
     $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();
 }
Пример #5
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();
     $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();
 }
Пример #6
0
 public function testfetchAllAssignedTwoUserInGroup()
 {
     $table_user = new USVN_Db_Table_Users();
     $user = $table_user->fetchNew();
     $user->setFromArray(array('users_login' => 'test', 'users_password' => 'password', 'users_firstname' => 'firstname', 'users_lastname' => 'lastname', 'users_email' => '*****@*****.**'));
     $user->save();
     $user2 = $table_user->fetchNew();
     $user2->setFromArray(array('users_login' => 'test2', 'users_password' => 'password', 'users_firstname' => 'firstname', 'users_lastname' => 'lastname', 'users_email' => '*****@*****.**'));
     $user2->save();
     $table_project = new USVN_Db_Table_Projects();
     $project = $table_project->fetchNew();
     $project->setFromArray(array('projects_name' => 'InsertProjectOk', 'projects_start_date' => '1984-12-03 00:00:00'));
     $project->save();
     $project2 = $table_project->fetchNew();
     $project2->setFromArray(array('projects_name' => 'Project2', 'projects_start_date' => '1984-12-03 00:00:00'));
     $project2->save();
     $group_table = new USVN_Db_Table_Groups();
     $group_table->insert(array("groups_id" => 2, "groups_name" => "toto"));
     $group = $group_table->find(2)->current();
     $group_table = new USVN_Db_Table_Groups();
     $group_table->insert(array("groups_id" => 3, "groups_name" => "titi"));
     $group = $group_table->find(3)->current();
     $project->addGroup($group);
     $this->assertEquals(count($table_project->fetchAllAssignedTo($user)), 0);
     $group->addUser($user);
     $group->addUser($user2);
     $this->assertEquals(count($table_project->fetchAllAssignedTo($user)), 1);
 }
Пример #7
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";
 }
Пример #8
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";
 }
Пример #9
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);
 }
Пример #10
0
 public function test_edit()
 {
     $groups = new USVN_Db_Table_Groups();
     $group = $groups->find(43)->current();
     $group->addUser($this->user);
     $this->request->setParam('name', 'Indochine');
     $this->runAction('edit');
     $this->assertEquals(2, count($this->controller->view->users));
     $this->assertContains('Indochine', $this->getBody(), $this->getBody());
 }
Пример #11
0
 function testFetchAllForUserAndProject()
 {
     $group1 = $this->createGroup("group1");
     $group2 = $this->createGroup("group2");
     $group3 = $this->createGroup("group3");
     $group4 = $this->createGroup("group4");
     $user1 = $this->createUser("user1");
     $user1->addGroup($group1);
     $user1->addGroup($group2);
     $user1->addGroup($group4);
     $user2 = $this->createUser("user2");
     $user2->addGroup($group1);
     $user2->addGroup($group3);
     $user2->addGroup($group4);
     $proj1 = $this->createProject("proj1");
     $proj1->addGroup($group1);
     $proj1->addGroup($group3);
     $proj2 = $this->createProject("proj2");
     $proj2->addGroup($group2);
     $proj2->addGroup($group4);
     $table = new USVN_Db_Table_Groups();
     $groups = $table->fetchAllForUserAndProject($user1, $proj1);
     $res = array();
     foreach ($groups as $group) {
         array_push($res, $group->name);
     }
     $this->assertContains("group1", $res);
     $this->assertNotContains("group2", $res);
     $this->assertNotContains("group3", $res);
     $this->assertNotContains("group4", $res);
     $groups = $table->fetchAllForUserAndProject($user1, $proj2);
     $res = array();
     foreach ($groups as $group) {
         array_push($res, $group->name);
     }
     $this->assertContains("group2", $res);
     $this->assertContains("group4", $res);
     $this->assertNotContains("group1", $res);
     $this->assertNotContains("group3", $res);
     $groups = $table->fetchAllForUserAndProject($user2, $proj1);
     $res = array();
     foreach ($groups as $group) {
         array_push($res, $group->name);
     }
     $this->assertContains("group1", $res);
     $this->assertContains("group3", $res);
     $this->assertNotContains("group2", $res);
     $this->assertNotContains("group4", $res);
     $groups = $table->fetchAllForUserAndProject($user2, $proj2);
     $res = array();
     foreach ($groups as $group) {
         array_push($res, $group->name);
     }
     $this->assertContains("group4", $res);
     $this->assertNotContains("group1", $res);
     $this->assertNotContains("group2", $res);
     $this->assertNotContains("group3", $res);
 }
Пример #12
0
 public function updateAction()
 {
     $data = $this->getUserData($_POST);
     if (empty($data)) {
         $this->_redirect("/admin/user/new");
     }
     $user = null;
     /* some ugly hack of variable scope... */
     try {
         $table = new USVN_Db_Table_Users();
         $login = $this->getRequest()->getParam('login');
         $user = $table->fetchRow(array("users_login = ?" => $login));
         if ($user === null) {
             throw new USVN_Exception(sprintf(T_("User %s does not exist."), $login));
         }
         $user->setFromArray($data);
         $u = USVN_User::update($user, $data, isset($_POST['groups']) ? $_POST['groups'] : null);
         $u->save();
         $this->_redirect("/admin/user/");
     } catch (USVN_Exception $e) {
         $this->view->user = $user;
         $this->view->message = $e->getMessage();
         $table = new USVN_Db_Table_Groups();
         $this->view->groups = $table->fetchAll(null, 'groups_name');
         $this->render('edit');
     }
 }
Пример #13
0
Файл: DB.php Проект: phpscr/usvn
 /**
  * Create and save a group
  *
  * @return USVN_Db_Table_Row_Group
  */
 public function createGroup($name)
 {
     $table = new USVN_Db_Table_Groups();
     try {
         $group = $table->createRow(array("groups_name" => "{$name}", "groups_description" => "{$name}'s description"));
         $group->save();
         return $group;
     } catch (Exception $e) {
         $this->fail($name . " : " . $e->getMessage());
     }
 }
Пример #14
0
 public function addleadergroupAction()
 {
     if ($this->_group->isLeaderOrAdmin($this->view->user) == 1) {
         $request = $this->getRequest();
         /* @var $request USVN_Controller_Request_Http */
         $table = new USVN_Db_Table_Groups();
         $group = $table->fetchRow(array("groups_name = ?" => str_replace(USVN_URL_SEP, '/', $request->getParam('group'))));
         /* @var $group USVN_Db_Table_Row_Group */
         try {
             $table = new USVN_Db_Table_Users();
             if ($request->getParam('ap', "") != "") {
                 $user = $table->fetchRow(array("users_login = ?" => $request->getParam('ap')));
                 if ($user === null) {
                     throw new USVN_Exception(sprintf(T_("Unknown user %s"), $request->getParam('ap')));
                 }
                 if (!$group->hasUser($user)) {
                     $group->addUser($user, true);
                 } else {
                     $group->updateLeaderUser($user, 1);
                 }
             }
             if ($request->getParam('deleteid', 0) != 0) {
                 $user = $table->fetchRow(array("users_id = ?" => $request->getParam('deleteid')));
                 if ($user === null) {
                     throw new USVN_Exception(sprintf(T_("Unknown user %s"), $request->getParam('deleteid')));
                 }
                 if ($group->hasUser($user)) {
                     $group->deleteUser($user);
                 }
             }
         } catch (Exception $e) {
             $this->view->message = $e->getMessage();
         }
         $this->view->group = $group;
     } else {
         throw new USVN_Exception(sprintf(T_("Access denied.")));
     }
 }
Пример #15
0
 public function testHasUserNewGroup()
 {
     $groups = new USVN_Db_Table_Groups();
     $group = $groups->createRow();
     $group->name = 'test';
     $group->save();
     $user2 = $this->users["test"];
     $this->assertFalse($group->hasUser($user2));
 }
Пример #16
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");
 }
Пример #17
0
 public function addgroupAction()
 {
     $this->requireAdmin();
     $table = new USVN_Db_Table_Groups();
     $group = $table->fetchRow(array("groups_name = ?" => $this->getRequest()->getParam('groups_name')));
     if ($group !== null) {
         try {
             $this->_project->addGroup($group);
         } catch (Exception $e) {
         }
     }
     $this->_redirect("/project/" . str_replace('/', USVN_URL_SEP, $this->_project->name) . "/");
 }
Пример #18
0
 /**
  * Genere un tableau de groupe
  *
  * @param int $n
  */
 function _generateGroups($n)
 {
     $table = new USVN_Db_Table_Groups();
     $ret = array();
     for ($i = 1; $i <= $n; $i++) {
         $ret[$i - 1] = $table->fetchNew();
         $ret[$i - 1]->name = "group{$i}";
         $ret[$i - 1]->save();
     }
     return $ret;
 }
Пример #19
0
 public function deleteAction()
 {
     $table = new USVN_Db_Table_Groups();
     $group_name = str_replace(USVN_URL_SEP, '/', $this->getRequest()->getParam('name'));
     $group = $table->fetchRow(array('groups_name = ?' => $group_name));
     if ($group === null) {
         throw new USVN_Exception(T_("Invalid group %s."), $group_name);
     }
     $group->delete();
     $this->_redirect("/admin/group/");
 }
Пример #20
0
 /**
  * Save all information
  *
  */
 public function save()
 {
     $this->user->save();
     if ($this->createGroup) {
         $table = new USVN_Db_Table_Groups();
         $group = $table->createRow(array("groups_name" => $this->user->login));
         try {
             $group->save();
             $this->groups[] = $group->id;
         } catch (Exception $e) {
             $table = new USVN_Db_Table_Groups();
             $where = $table->getAdapter()->quoteInto('groups_name = ?', $this->user->login);
             $row = $table->fetchRow($where);
             if ($row != null) {
                 $this->user->delete();
                 throw new USVN_Exception(T_("This user can't be created. A group has the same name."));
             } else {
                 throw $e;
             }
         }
     }
     if ($this->groups !== null) {
         $this->user->deleteAllGroups();
         foreach ($this->groups as $group) {
             $this->user->addGroup($group);
         }
     }
 }
Пример #21
0
 private function get_created_group()
 {
     $groups = new USVN_Db_Table_Groups();
     return $groups->fetchRow(array('groups_name = ?' => 'Test'));
 }
Пример #22
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);
 }