Exemple #1
0
 /**
  * Delete a group from a project
  *
  * @param mixed Group
  */
 public function deleteGroup($group)
 {
     $group_id = 0;
     if (is_object($group)) {
         $group_id = $group->id;
     } elseif (is_numeric($group)) {
         $group_id = intval($group);
     }
     if ($group_id) {
         $table_groupstoproject = new USVN_Db_Table_GroupsToProjects();
         $p = $table_groupstoproject->getAdapter()->quoteInto("projects_id = ?", $this->id);
         $g = $table_groupstoproject->getAdapter()->quoteInto("groups_id = ?", $group_id);
         if ($table_groupstoproject->delete(array($p, $g)) == 0) {
             throw new USVN_Exception(T_("Invalid group %s for project %s."), $group_id, $this->id);
         }
         $table_groupstofilesrights = new USVN_Db_Table_GroupsToFilesRights();
         $rights = $table_groupstofilesrights->fetchAll($g);
         $file_rights = new USVN_Db_Table_FilesRights();
         foreach ($rights as $right) {
             $file_right = $file_rights->find($right->files_rights_id)->current();
             if ($file_right->projects_id == $this->id) {
                 $right->delete();
             }
         }
     } else {
         throw new USVN_Exception(T_("Invalid group %s for project %s."), $group, $this->id);
     }
 }
Exemple #2
0
 public function test_findByPath()
 {
     $file_rights = new USVN_Db_Table_FilesRights();
     $this->assertType('USVN_Db_Table_Row', $file_rights->findByPath($this->_projectid1, "/"));
     $this->assertNull($file_rights->findByPath($this->_projectid1, "/trunk"));
     $table_files = new USVN_Db_Table_FilesRights();
     $id = $table_files->insert(array('projects_id' => $this->_projectid1, 'files_rights_path' => '/trunk'));
     $this->assertType('USVN_Db_Table_Row', $file_rights->findByPath($this->_projectid1, "/trunk"));
     $this->assertType('USVN_Db_Table_Row', $file_rights->findByPath($this->_projectid1, "/trunk/"));
     $this->assertNull($file_rights->findByPath($this->_projectid2, "/trunk"));
 }
 public function test_findByIdRightsAndIdGroup()
 {
     $table_files = new USVN_Db_Table_FilesRights();
     $fileid = $table_files->insert(array('projects_id' => $this->_projectid1, 'files_rights_path' => '/trunk'));
     $table_groupstofiles = new USVN_Db_Table_GroupsToFilesRights();
     $res = $table_groupstofiles->findByIdRightsAndIdGroup($fileid, $this->_groupid1);
     $this->assertNull($res);
     $table_groupstofiles->insert(array('files_rights_id' => $fileid, 'files_rights_is_readable' => true, 'files_rights_is_writable' => false, 'groups_id' => $this->_groupid1));
     $res = $table_groupstofiles->findByIdRightsAndIdGroup($fileid, $this->_groupid1);
     $this->assertEquals(true, (bool) $res->files_rights_is_readable);
     $this->assertEquals(false, (bool) $res->files_rights_is_writable);
     $res = $table_groupstofiles->findByIdRightsAndIdGroup($fileid, $this->_groupid2);
     $this->assertNull($res);
 }
Exemple #4
0
 public function test_affectandremovegroup()
 {
     $table = new USVN_Db_Table_GroupsToProjects();
     $project = $this->createProject("project");
     $project2 = $this->createProject("project2");
     $this->assertEquals(0, count($table->findByProjectId($project->id)));
     $this->assertEquals(0, count($table->findByProjectId($project2->id)));
     $group1 = $this->createGroup("group1");
     $group2 = $this->createGroup("group2");
     $project->addGroup($group1);
     $project2->addGroup($group1);
     $project->addGroup($group2);
     $project2->addGroup($group2);
     $this->assertEquals(2, count($table->findByProjectId($project->id)));
     $this->assertEquals(2, count($table->findByProjectId($project2->id)));
     $table_files = new USVN_Db_Table_FilesRights();
     $fileid = $table_files->insert(array('projects_id' => $project->id, 'files_rights_path' => '/trunk'));
     $table_groupstofiles = new USVN_Db_Table_GroupsToFilesRights();
     $res = $table_groupstofiles->findByIdRightsAndIdGroup($fileid, $group1->id);
     $this->assertNull($res);
     $table_groupstofiles->insert(array('files_rights_id' => $fileid, 'files_rights_is_readable' => true, 'files_rights_is_writable' => false, 'groups_id' => $group1->id));
     $res = $table_groupstofiles->findByIdRightsAndIdGroup($fileid, $group1->id);
     $this->assertEquals(true, (bool) $res->files_rights_is_readable);
     $this->assertEquals(false, (bool) $res->files_rights_is_writable);
     $fileid2 = $table_files->insert(array('projects_id' => $project2->id, 'files_rights_path' => '/trunk'));
     $table_groupstofiles = new USVN_Db_Table_GroupsToFilesRights();
     $res = $table_groupstofiles->findByIdRightsAndIdGroup($fileid2, $group2->id);
     $this->assertNull($res);
     $table_groupstofiles->insert(array('files_rights_id' => $fileid2, 'files_rights_is_readable' => true, 'files_rights_is_writable' => false, 'groups_id' => $group1->id));
     $res = $table_groupstofiles->findByIdRightsAndIdGroup($fileid2, $group1->id);
     $this->assertEquals(true, (bool) $res->files_rights_is_readable);
     $this->assertEquals(false, (bool) $res->files_rights_is_writable);
     $project->deleteGroup($group1);
     $this->assertEquals(1, count($table->findByProjectId($project->id)));
     $this->assertEquals(2, count($table->findByProjectId($project2->id)));
     $res = $table_groupstofiles->findByIdRightsAndIdGroup($fileid2, $group1->id);
     $this->assertNotNull($res);
     $this->assertEquals(true, (bool) $res->files_rights_is_readable);
     $this->assertEquals(false, (bool) $res->files_rights_is_writable);
 }
 public function test_findByPathInherits()
 {
     $file_rights1 = new USVN_FilesAccessRights($this->_projectid1);
     $table_files = new USVN_Db_Table_FilesRights();
     $fileid = $table_files->findByPath($this->_projectid1, '/')->id;
     $table_groupstofiles = new USVN_Db_Table_GroupsToFilesRights();
     $table_groupstofiles->insert(array('files_rights_id' => $fileid, 'files_rights_is_readable' => true, 'files_rights_is_writable' => true, 'groups_id' => $this->_groupid1));
     $rights = $file_rights1->findByPath($this->_groupid1, '/trunk/test/tutu/titi');
     $this->assertTrue($rights['read']);
     $this->assertTrue($rights['write']);
     $file_rights1->setRightByPath($this->_groupid1, '/trunk', true, false);
     $rights = $file_rights1->findByPath($this->_groupid1, '/trunk/test/tutu/titi');
     $this->assertTrue($rights['read']);
     $this->assertFalse($rights['write']);
     $fileid = $table_files->insert(array('projects_id' => $this->_projectid1, 'files_rights_path' => '/trunk/test/tutu/'));
     $table_groupstofiles->insert(array('files_rights_id' => $fileid, 'files_rights_is_readable' => true, 'files_rights_is_writable' => true, 'groups_id' => $this->_groupid1));
     $rights = $file_rights1->findByPath($this->_groupid1, '/trunk/test/tutu/titi');
     $this->assertTrue($rights['read']);
     $this->assertTrue($rights['write']);
 }
Exemple #6
0
 public function testCreateProjectWithGroupWithoutAdmin()
 {
     $project = USVN_Project::createProject(array('projects_name' => 'InsertProjectOk', 'projects_start_date' => '1984-12-03 00:00:00'), "test", true, true, false, true);
     $table = new USVN_Db_Table_Projects();
     $this->assertTrue($table->isAProject('InsertProjectOk'), "Le projet n'est pas cree");
     $this->assertTrue(USVN_SVNUtils::isSVNRepository('tests/tmp/svn/InsertProjectOk'), "Le repository n'est pas cree");
     $table = new USVN_Db_Table_Groups();
     $this->assertTrue($table->isAGroup('InsertProjectOk'), "Le groupe n'est pas cree");
     $group = $table->fetchRow(array("groups_name = ?" => 'InsertProjectOk'));
     $table = new USVN_Db_Table_FilesRights();
     $right = $table->fetchRow(array("files_rights_path = ?" => "/", "projects_id = ?" => $project->id));
     $this->assertNotNull($right, "La ligne pour les droits sur / n'a pas ete trouvee");
     $table = new USVN_Db_Table_GroupsToFilesRights();
     $rights = $table->fetchRow(array("files_rights_id = ?" => $right->id, "groups_id = ?" => $group->id));
     $this->assertNotNull($rights, "La ligne pour les droits du groupe n'a pas ete trouvee");
     $this->assertEquals(1, $rights->files_rights_is_readable, "Le groupe n'a pas la lecture");
     $this->assertEquals(1, $rights->files_rights_is_readable, "Le groupe n'a pas l'ecriture");
     $this->assertTrue($group->hasUser($this->_user));
     $this->assertFalse($project->userIsAdmin($this->_user));
 }
Exemple #7
0
 public function testThreeUsersInTwoGroupsAndOneProjectWithPermissionAndGroupPermissions()
 {
     list($group1, $group2, $group3) = $this->_generateGroups(3);
     /* @var $group1 USVN_Db_Table_Row_Group */
     /* @var $group2 USVN_Db_Table_Row_Group */
     list($user1, $user2, $user3) = $this->_generateUsers(3);
     /* @var $user1 USVN_Db_Table_Row_User */
     /* @var $user2 USVN_Db_Table_Row_User */
     /* @var $user3 USVN_Db_Table_Row_User */
     $group1->addUser($user1);
     $group1->addUser($user2);
     $group1->addUser($user3);
     $group2->addUser($user1);
     $group2->addUser($user2);
     $group3->addUser($user1);
     $group3->addUser($user3);
     list($project1, $project2, $project3) = $this->_generateProjects(3);
     /* @var $project1 USVN_Db_Table_Row_Project */
     /* @var $project2 USVN_Db_Table_Row_Project */
     /* @var $project3 USVN_Db_Table_Row_Project */
     $table = new USVN_Db_Table_FilesRights();
     for ($i = 1; $i <= 5; $i++) {
         for ($j = 1; $j <= 3; $j++) {
             ${"files_rights" . $i . $j} = $table->fetchNew();
             ${"files_rights" . $i . $j}->projects_id = ${"project" . $j}->id;
             ${"files_rights" . $i . $j}->path = "/directory{$i}";
             ${"files_rights" . $i . $j}->save();
             for ($k = 1; $k <= 3; $k++) {
                 if ($k == $j) {
                     $tmp = new USVN_Db_Table_GroupsToFilesRights();
                     $array = array();
                     $array["groups_id"] = ${"group" . $k}->id;
                     $array["files_rights_is_readable"] = true;
                     $array["files_rights_is_writable"] = true;
                     $array["files_rights_id"] = ${"files_rights" . $i . $j}->id;
                     $tmp = $tmp->createRow($array);
                     $tmp->save();
                 } else {
                     if ($k & 1 && $i & 1) {
                         $tmp = new USVN_Db_Table_GroupsToFilesRights();
                         $array = array();
                         $array["groups_id"] = ${"group" . $k}->id;
                         $array["files_rights_is_readable"] = true;
                         $array["files_rights_is_writable"] = false;
                         $array["files_rights_id"] = ${"files_rights" . $i . $j}->id;
                         $tmp = $tmp->createRow($array);
                         $tmp->save();
                     } else {
                         $tmp = new USVN_Db_Table_GroupsToFilesRights();
                         $array = array();
                         $array["groups_id"] = ${"group" . $k}->id;
                         $array["files_rights_is_readable"] = false;
                         $array["files_rights_is_writable"] = false;
                         $array["files_rights_id"] = ${"files_rights" . $i . $j}->id;
                         $tmp = $tmp->createRow($array);
                         $tmp->save();
                     }
                 }
             }
         }
     }
     $file = file_get_contents(Zend_Registry::get('config')->subversion->authz);
     $this->assertEquals($this->_start . "group1 = user1, user2, user3\ngroup2 = user1, user2\ngroup3 = user1, user3\nproject1 = \nproject2 = \nproject3 = \n\n\n# Project project1\n[project1:/]\n@project1 = rw\n\n[project1:/directory1]\n@group1 = rw\n@group2 = \n@group3 = r\n\n[project1:/directory2]\n@group1 = rw\n@group2 = \n@group3 = \n\n[project1:/directory3]\n@group1 = rw\n@group2 = \n@group3 = r\n\n[project1:/directory4]\n@group1 = rw\n@group2 = \n@group3 = \n\n[project1:/directory5]\n@group1 = rw\n@group2 = \n@group3 = r\n\n\n\n# Project project2\n[project2:/]\n@project2 = rw\n\n[project2:/directory1]\n@group1 = r\n@group2 = rw\n@group3 = r\n\n[project2:/directory2]\n@group1 = \n@group2 = rw\n@group3 = \n\n[project2:/directory3]\n@group1 = r\n@group2 = rw\n@group3 = r\n\n[project2:/directory4]\n@group1 = \n@group2 = rw\n@group3 = \n\n[project2:/directory5]\n@group1 = r\n@group2 = rw\n@group3 = r\n\n\n\n# Project project3\n[project3:/]\n@project3 = rw\n\n[project3:/directory1]\n@group1 = r\n@group2 = \n@group3 = rw\n\n[project3:/directory2]\n@group1 = \n@group2 = \n@group3 = rw\n\n[project3:/directory3]\n@group1 = r\n@group2 = \n@group3 = rw\n\n[project3:/directory4]\n@group1 = \n@group2 = \n@group3 = rw\n\n[project3:/directory5]\n@group1 = r\n@group2 = \n@group3 = rw\n\n", $file);
 }
Exemple #8
0
 public function testDeleteGroupWithFileRights()
 {
     $table_files = new USVN_Db_Table_FilesRights();
     $fileid = $table_files->insert(array('projects_id' => $this->project->id, 'files_rights_path' => '/trunk'));
     $fileid2 = $table_files->insert(array('projects_id' => $this->project2->id, 'files_rights_path' => '/trunk'));
     $table_groupstofiles = new USVN_Db_Table_GroupsToFilesRights();
     $this->project->addGroup($this->groups->find(42)->current());
     $this->project2->addGroup($this->groups->find(42)->current());
     $table_groupstofiles->insert(array('files_rights_id' => $fileid, 'files_rights_is_readable' => true, 'files_rights_is_writable' => false, 'groups_id' => 42));
     $table_groupstofiles->insert(array('files_rights_id' => $fileid2, 'files_rights_is_readable' => true, 'files_rights_is_writable' => false, 'groups_id' => 42));
     $this->assertNotNull($table_groupstofiles->findByIdRightsAndIdGroup($fileid, 42));
     $this->assertNotNull($table_groupstofiles->findByIdRightsAndIdGroup($fileid2, 42));
     $this->project->deleteGroup($this->groups->find(42)->current());
     $this->assertNull($table_groupstofiles->findByIdRightsAndIdGroup($fileid, 42));
     $this->assertNotNull($table_groupstofiles->findByIdRightsAndIdGroup($fileid2, 42));
 }
Exemple #9
0
 private function unsetRightByPath($group_id, $path)
 {
     $filesRightsId = array();
     $tableFilesRights = new USVN_Db_Table_FilesRights();
     $whereFilesRights = $tableFilesRights->getAdapter()->quoteInto("files_rights_path LIKE ? ", $path);
     $whereFilesRights .= $tableFilesRights->getAdapter()->quoteInto(" AND projects_id = ? ", $this->_project);
     foreach ($tableFilesRights->fetchAll($whereFilesRights) as $filesRights) {
         $filesRightsId[] = $filesRights->id;
     }
     if (count($filesRightsId) > 0) {
         $table = new USVN_Db_Table_GroupsToFilesRights();
         $where = $table->getAdapter()->quoteInto("files_rights_id IN (?) ", $filesRightsId);
         $where .= $table->getAdapter()->quoteInto("and groups_id = ? ", $group_id);
         $table->delete($where);
         $where = $table->getAdapter()->quoteInto("files_rights_id IN (?) ", $filesRightsId);
         if (count($table->fetchAll($where)) == 0) {
             $tableFilesRights->delete($whereFilesRights);
         }
     }
 }