Example #1
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));
 }
Example #2
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}/_%");
     }
 }