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