Example #1
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);
 }
Example #2
0
 /**
  * Return the rights of a groups for the given path
  *
  * @param integer Group id
  * @param string Path
  * @return array ex: ("read" => true, "write" => false)
  */
 public function findByPath($group_id, $path)
 {
     $path = str_replace('//', '/', $path);
     if (strlen($path) == 0 || $path[0] !== '/') {
         throw new USVN_Exception(T_("Invalid path %s."), $path);
     }
     $response = array('read' => false, 'write' => false);
     $table_files = new USVN_Db_Table_FilesRights();
     $res_file_rights = $table_files->findByPath($this->_project, $path);
     if ($res_file_rights !== null) {
         $table_groupsfiles = new USVN_Db_Table_GroupsToFilesRights();
         $res_groupstofiles = $table_groupsfiles->findByIdRightsAndIdGroup($res_file_rights->files_rights_id, $group_id);
         if ($res_groupstofiles != null) {
             if ($res_groupstofiles->files_rights_is_readable) {
                 $response['read'] = true;
             }
             if ($res_groupstofiles->files_rights_is_writable) {
                 $response['write'] = true;
             }
         } else {
             if ($path != '/') {
                 return $this->findByPath($group_id, str_replace(basename($path), '', $path));
                 // Ugly hack do not use dirname because problems with \
             }
         }
     } else {
         if ($path != '/') {
             return $this->findByPath($group_id, str_replace(basename($path), '', $path));
             // Ugly hack do not use dirname because problems with \
         }
     }
     return $response;
 }
Example #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);
 }
Example #4
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));
 }