commit e02def60a343ce1345781282bea48b008930b5af
parent c51df8498230a5fbc2417c908afa136d0f582335
Author: Jan Dankert <develop@jandankert.de>
Date: Wed, 6 Nov 2019 23:21:38 +0100
Fix: Enable creation of projects and folders.
Diffstat:
5 files changed, 91 insertions(+), 25 deletions(-)
diff --git a/cms/CMS.class.php b/cms/CMS.class.php
@@ -50,7 +50,14 @@ class CMS
return $result;
}
-
+
+ function projectAdd($name)
+ {
+ $result = $this->call(CMS_WRITE,'projectlist','add',array('name'=>$name) );
+
+ return $result;
+ }
+
function folder($id)
{
$content = $this->call(CMS_READ,'folder','edit',array('id'=>$id) );
@@ -58,7 +65,14 @@ class CMS
return( array( 'content'=>$content, 'properties'=>$prop ) );
}
-
+
+ function folderAdd($parentid,$name)
+ {
+ $result = $this->call(CMS_WRITE,'folder','createfolder',array('id'=>$parentid,'name'=>$name) );
+
+ return $result;
+ }
+
function page($id)
{
$result = $this->call(CMS_READ,'page','edit',array('id'=>$id) );
diff --git a/dav.ini b/dav.ini
@@ -4,7 +4,7 @@
dav.enable=true
dav.create=true
-dav.readonly = true
+dav.readonly = false
dav.anonymous = false
log.file=log/dav.log
diff --git a/dav/DAV.class.php b/dav/DAV.class.php
@@ -254,6 +254,22 @@ abstract class DAV
header('X-DAV-Status: '.$status,true);
}
+
+ /**
+ * Setzt einen HTTP-Status.<br>
+ * <br>
+ * Es wird ein HTTP-Status gesetzt, zus�tzlich wird der Status in den Header "X-DAV-Status" geschrieben.<br>
+ * Ist der Status nicht 200 oder 207 (hier folgt ein BODY), wird das Skript beendet.
+ */
+ public static function httpForbidden()
+ {
+ $status = 403;
+ header('HTTP/1.1 '.$status);
+ header('X-WebDAV-Status: '.$status,true);
+ Logger::debug('WEBDAV: HTTP-Status: '.$status);
+ }
+
+
/**
* Setzt einen HTTP-Status.<br>
* <br>
diff --git a/dav/URIParser.class.php b/dav/URIParser.class.php
@@ -3,13 +3,21 @@
use dav\exception\NotFoundException;
+/**
+ * Class URIParser.
+ * Parsing a DAV url in the format "/<projectname>/<folder>/<folder>/<object>".
+ */
class URIParser
{
- const ROOT = 'root';
+ const ROOT = 'root';
+ const PROJECT = 'project';
+ const FOLDER = 'folder';
public $type;
public $projectid;
public $objectid;
+ public $folderid;
+ public $basename;
private $uri;
/**
@@ -47,6 +55,7 @@ class URIParser
return;
}
+ $this->type = '';
try {
$result = $this->client->projectlist();
@@ -55,7 +64,7 @@ class URIParser
Logger::error("Failed to read projects: \n".$this->client->__toString()."\n".$e->getMessage() );
throw $e;
}
- //Logger::trace( print_r( $result,true) );
+
$projects = $result['projects'];
@@ -64,7 +73,9 @@ class URIParser
$this->projectid = $id;
if ( ! $this->projectid ) {
- throw new RuntimeException( 'Project \''.$projectName.'\' not found.' );
+ $this->basename = $projectName;
+ $this->type = self::PROJECT;
+ return;
}
$project = $this->client->project($this->projectid);
@@ -72,7 +83,9 @@ class URIParser
$objectid = $project['rootobjectid'];
- $type = 'folder';
+ $folderid = $objectid;
+ $type = 'folder';
+ $name = $projectName;
while (sizeof($uriParts) > 0) {
$name = array_shift($uriParts);
@@ -81,6 +94,7 @@ class URIParser
continue; // empty path segments
$folder = $this->client->folder($objectid);
+ $folderid = $objectid;
$found = false;
foreach ($folder['content']['object'] as $oid => $object) {
@@ -96,17 +110,36 @@ class URIParser
}
if (!$found) {
- throw new NotFoundException('Not found path segment: '.$name );
+ $objectid = null;
+ break;
}
}
$this->type = $type;
+ $this->folderid = $folderid;
$this->objectid = $objectid;
+ $this->basename = $name;
}
+ public function isRoot() {
+
+ return $this->type == self::ROOT;
+ }
+
+ public function exists() {
+ return boolval($this->objectid);
+ }
+
+
+
+ /**
+ * Representation of this URI.
+ *
+ * @return string
+ */
public function __toString()
{
- return "DAV-Object: $this->uri ==> [$this->type] projectid: $this->projectid / objectid: $this->objectid";
+ return "DAV-URI: $this->uri ==> [$this->type] projectid: $this->projectid / objectid: $this->objectid folderid: $this->folderid name: $this->basename";
}
}
\ No newline at end of file
diff --git a/dav/method/MKCOL.class.php b/dav/method/MKCOL.class.php
@@ -8,35 +8,38 @@ class DAV_MKCOL extends DAV
*/
public function execute()
{
-
- if ( !empty($this->data) )
+
+ if ( $this->data )
{
$this->httpStatus('415 Unsupported Media Type' ); // Kein Body erlaubt
}
elseif ( $this->readonly )
{
- $this->httpStatus('403 Forbidden' ); // Kein Schreibzugriff erlaubt
- }
- elseif ( !$this->folder->hasRight( ACL_CREATE_FOLDER ) )
- {
- $this->httpStatus('403 Forbidden' ); // Benutzer darf das nicht
+ Logger::trace('hi');
+ $this->httpForbidden(); // Kein Schreibzugriff erlaubt
}
- elseif ( $this->obj == null )
+ elseif ( $this->request->type == URIParser::PROJECT && ! $this->request->exists() )
{
- // Die URI ist noch nicht vorhanden
- $f = new Folder();
- $f->filename = basename($this->sitePath);
- $f->parentid = $this->folder->objectid;
- $f->projectid = $this->project->projectid;
- $f->add();
- $this->httpStatus('201 Created');
+ // Create a new empty project.
+ $this->client->projectAdd( $this->request->basename);
}
- else
+ elseif ( $this->request->type == URIParser::FOLDER && ! $this->request->exists() )
+ {
+ // Create a new folder
+ $this->client->folderAdd( $this->request->folderid, $this->request->basename );
+ $this->httpStatus('201 Created');
+ }
+ elseif ( $this->request->exists() )
{
// MKCOL ist nicht moeglich, wenn die URI schon existiert.
Logger::warn('MKCOL-Request to an existing resource');
$this->httpMethodNotAllowed();
}
+ else
+ {
+ Logger::warn('');
+ throw new InvalidArgumentException();
+ }
}
}