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
 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 #3
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']);
 }
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));
 }
Example #5
0
 /**
  * Set right for a group
  *
  * @param integer Group id
  * @param string Path
  * @param bool read
  * @param bool write
  */
 public function setRightByPath($group_id, $path, $read, $write, $recursive = false)
 {
     $path = preg_replace('#[/]{2,}#', '/', $path);
     if (strlen($path) == 0 || $path[0] !== '/') {
         throw new USVN_Exception(T_("Invalid path %s."), $path);
     }
     $table_files = new USVN_Db_Table_FilesRights();
     $res_files = $table_files->findByPath($this->_project, $path);
     $table_groupstofiles = new USVN_Db_Table_GroupsToFilesRights();
     if ($res_files === null) {
         $file_id = $table_files->insert(array('projects_id' => $this->_project, 'files_rights_path' => $path));
         $table_groupstofiles->insert(array('files_rights_id' => $file_id, 'files_rights_is_readable' => $read === true ? 1 : 0, 'files_rights_is_writable' => $write === true ? 1 : 0, 'groups_id' => $group_id));
     } else {
         $file_id = $res_files->files_rights_id;
         $where = $table_groupstofiles->getAdapter()->quoteInto('files_rights_id = ?', $file_id);
         $where .= $table_groupstofiles->getAdapter()->quoteInto(' and groups_id = ?', $group_id);
         $groupstofiles = $table_groupstofiles->fetchRow($where);
         if ($groupstofiles === null) {
             $table_groupstofiles->insert(array('files_rights_id' => $file_id, 'files_rights_is_readable' => $read === true ? 1 : 0, 'files_rights_is_writable' => $write === true ? 1 : 0, 'groups_id' => $group_id));
         } else {
             $groupstofiles->files_rights_is_readable = $read === true ? 1 : 0;
             $groupstofiles->files_rights_is_writable = $write === true ? 1 : 0;
             $groupstofiles->save();
         }
     }
     if ($recursive === true) {
         $path = rtrim($path, "/");
         $this->unsetRightByPath($group_id, "{$path}/_%");
     }
 }