Exemplo n.º 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);
     }
 }
Exemplo n.º 2
0
 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);
 }
Exemplo n.º 3
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);
 }
Exemplo n.º 4
0
 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']);
 }
Exemplo n.º 5
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));
 }
Exemplo n.º 6
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));
 }
Exemplo n.º 7
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);
         }
     }
 }