[Pkg-owncloud-commits] [php-sabredav] 45/148: ACL reports wip.
David Prévot
taffit at moszumanska.debian.org
Wed Apr 15 01:37:11 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository php-sabredav.
commit a02dca0bd814bb3bbf1507b3c35a1eb45986514f
Author: Evert Pot <me at evertpot.com>
Date: Fri Feb 13 18:00:55 2015 -0500
ACL reports wip.
---
lib/DAVACL/Plugin.php | 78 ++++---------
lib/DAVACL/Xml/Request/ExpandPropertyReport.php | 103 +++++++++++++++++
.../Xml/Request/PrincipalPropertySearchReport.php | 127 +++++++++++++++++++++
.../Request/PrincipalSearchPropertySetReport.php | 82 +++++++++++++
tests/Sabre/DAVACL/PrincipalPropertySearchTest.php | 4 +-
5 files changed, 336 insertions(+), 58 deletions(-)
diff --git a/lib/DAVACL/Plugin.php b/lib/DAVACL/Plugin.php
index 2693d86..4cf137c 100644
--- a/lib/DAVACL/Plugin.php
+++ b/lib/DAVACL/Plugin.php
@@ -4,6 +4,7 @@ namespace Sabre\DAVACL;
use Sabre\DAV;
use Sabre\DAV\INode;
+use Sabre\DAV\Exception\BadRequest;
use Sabre\HTTP\RequestInterface;
use Sabre\HTTP\ResponseInterface;
use Sabre\Uri;
@@ -710,6 +711,7 @@ class Plugin extends DAV\ServerPlugin {
$server->xml->elementMap['{DAV:}group-member-set'] = 'Sabre\\DAV\\Xml\\Property\\Href';
$server->xml->elementMap['{DAV:}acl'] = 'Sabre\\DAVACL\\Xml\\Property\\Acl';
$server->xml->elementMap['{DAV:}expand-property'] = 'Sabre\\DAVACL\\Xml\\Request\\ExpandPropertyReport';
+ $server->xml->elementMap['{DAV:}principal-property-search'] = 'Sabre\\DAVACL\\Xml\\Request\\PrincipalPropertySearchReport';
}
@@ -980,24 +982,24 @@ class Plugin extends DAV\ServerPlugin {
* This method handles HTTP REPORT requests
*
* @param string $reportName
- * @param \DOMNode $dom
+ * @param mixed $report
* @return bool
*/
- function report($reportName, $dom) {
+ function report($reportName, $report) {
switch($reportName) {
case '{DAV:}principal-property-search' :
$this->server->transactionType = 'report-principal-property-search';
- $this->principalPropertySearchReport($dom);
+ $this->principalPropertySearchReport($report);
return false;
case '{DAV:}principal-search-property-set' :
$this->server->transactionType = 'report-principal-search-property-set';
- $this->principalSearchPropertySetReport($dom);
+ $this->principalSearchPropertySetReport($report);
return false;
case '{DAV:}expand-property' :
$this->server->transactionType = 'report-expand-property';
- $this->expandPropertyReport($dom);
+ $this->expandPropertyReport($report);
return false;
}
@@ -1104,16 +1106,15 @@ class Plugin extends DAV\ServerPlugin {
* Other rfc's, such as ACL rely on this report, so it made sense to put
* it in this plugin.
*
- * @param \DOMElement $dom
+ * @param Xml\Request\ExpandPropertyReport $report
* @return void
*/
- protected function expandPropertyReport($dom) {
+ protected function expandPropertyReport($report) {
- $requestedProperties = $this->parseExpandPropertyReportRequest($dom->firstChild->firstChild);
$depth = $this->server->getHTTPDepth(0);
$requestUri = $this->server->getRequestUri();
- $result = $this->expandProperties($requestUri,$requestedProperties,$depth);
+ $result = $this->expandProperties($requestUri, $report->properties, $depth);
$xml = $this->server->xml->write([
'{DAV:}multistatus' => new DAV\Xml\Response\MultiStatus(
@@ -1127,42 +1128,6 @@ class Plugin extends DAV\ServerPlugin {
}
/**
- * This method is used by expandPropertyReport to parse
- * out the entire HTTP request.
- *
- * @param \DOMElement $node
- * @return array
- */
- protected function parseExpandPropertyReportRequest($node) {
-
- $requestedProperties = [];
- do {
-
- if (DAV\XMLUtil::toClarkNotation($node)!=='{DAV:}property') continue;
-
- if ($node->firstChild) {
-
- $children = $this->parseExpandPropertyReportRequest($node->firstChild);
-
- } else {
-
- $children = [];
-
- }
-
- $namespace = $node->getAttribute('namespace');
- if (!$namespace) $namespace = 'DAV:';
-
- $propName = '{'.$namespace.'}' . $node->getAttribute('name');
- $requestedProperties[$propName] = $children;
-
- } while ($node = $node->nextSibling);
-
- return $requestedProperties;
-
- }
-
- /**
* This method expands all the properties and returns
* a list with property values
*
@@ -1285,23 +1250,24 @@ class Plugin extends DAV\ServerPlugin {
* clients to search for groups of principals, based on the value of one
* or more properties.
*
- * @param \DOMDocument $dom
+ * @param Xml\Request\PrincipalPropertySearchReport $report
* @return void
*/
- protected function principalPropertySearchReport(\DOMDocument $dom) {
-
- list(
- $searchProperties,
- $requestedProperties,
- $applyToPrincipalCollectionSet,
- $test
- ) = $this->parsePrincipalPropertySearchReportRequest($dom);
+ protected function principalPropertySearchReport($report) {
$uri = null;
- if (!$applyToPrincipalCollectionSet) {
+ if (!$report->applyToPrincipalCollectionSet) {
$uri = $this->server->getRequestUri();
}
- $result = $this->principalSearch($searchProperties, $requestedProperties, $uri, $test);
+ if ($this->server->getHttpDepth('0')!==0) {
+ throw new BadRequest('Depth must be 0');
+ }
+ $result = $this->principalSearch(
+ $report->searchProperties,
+ $report->properties,
+ $uri,
+ $report->test
+ );
$prefer = $this->server->getHTTPPRefer();
diff --git a/lib/DAVACL/Xml/Request/ExpandPropertyReport.php b/lib/DAVACL/Xml/Request/ExpandPropertyReport.php
new file mode 100644
index 0000000..0702d26
--- /dev/null
+++ b/lib/DAVACL/Xml/Request/ExpandPropertyReport.php
@@ -0,0 +1,103 @@
+<?php
+
+namespace Sabre\DAVACL\Xml\Request;
+
+use Sabre\Xml\Reader;
+use Sabre\Xml\XmlDeserializable;
+
+/**
+ * ExpandProperty request parser.
+ *
+ * This class parses the {DAV:}expand-property REPORT, as defined in:
+ *
+ * http://tools.ietf.org/html/rfc3253#section-3.8
+ *
+ * @copyright Copyright (C) 2007-2013 Rooftop Solutions. All rights reserved.
+ * @author Evert Pot (http://www.rooftopsolutions.nl/)
+ * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
+ */
+class ExpandPropertyReport implements XmlDeserializable {
+
+ /**
+ * An array with requested properties.
+ *
+ * The requested properties will be used as keys in this array. The value
+ * is normally null.
+ *
+ * If the value is an array though, it means the property must be expanded.
+ * Within the array, the sub-properties, which themselves may be null or
+ * arrays.
+ *
+ * @var array
+ */
+ public $properties;
+
+ /**
+ * The deserialize method is called during xml parsing.
+ *
+ * This method is called statictly, this is because in theory this method
+ * may be used as a type of constructor, or factory method.
+ *
+ * Often you want to return an instance of the current class, but you are
+ * free to return other data as well.
+ *
+ * You are responsible for advancing the reader to the next element. Not
+ * doing anything will result in a never-ending loop.
+ *
+ * If you just want to skip parsing for this element altogether, you can
+ * just call $reader->next();
+ *
+ * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
+ * the next element.
+ *
+ * @param Reader $reader
+ * @return mixed
+ */
+ static function xmlDeserialize(Reader $reader) {
+
+ $elems = $reader->parseInnerTree();
+
+ $obj = new self();
+ $obj->properties = self::traverse($elems);
+
+ return $obj;
+
+ }
+
+ /**
+ * This method is used by deserializeXml, to recursively parse the
+ * {DAV:}property elements.
+ *
+ * @param array $elems
+ * @return void
+ */
+ static private function traverse($elems) {
+
+ $result = [];
+
+ foreach($elems as $elem) {
+
+ if ($elem['name'] !== '{DAV:}property') {
+ continue;
+ }
+
+ $namespace = isset($elem['attributes']['namespace']) ?
+ $elem['attributes']['namespace'] :
+ 'DAV:';
+
+ $propName = '{' . $namespace . '}' . $elem['attributes']['name'];
+
+ $value = null;
+ if (is_array($elem['value'])) {
+ $value = self::traverse($elem['value']);
+ }
+
+ $result[$propName] = $value;
+
+ }
+
+ return $result;
+
+ }
+
+}
diff --git a/lib/DAVACL/Xml/Request/PrincipalPropertySearchReport.php b/lib/DAVACL/Xml/Request/PrincipalPropertySearchReport.php
new file mode 100644
index 0000000..d28f78e
--- /dev/null
+++ b/lib/DAVACL/Xml/Request/PrincipalPropertySearchReport.php
@@ -0,0 +1,127 @@
+<?php
+
+namespace Sabre\DAVACL\XML\Request;
+
+use Sabre\XML\Reader;
+use Sabre\XML\XmlDeserializable;
+use Sabre\DAV\Exception\BadRequest;
+
+/**
+ * PrincipalSearchPropertySetReport request parser.
+ *
+ * This class parses the {DAV:}principal-property-search REPORT, as defined
+ * in:
+ *
+ * https://tools.ietf.org/html/rfc3744#section-9.4
+ *
+ * @copyright Copyright (C) 2007-2013 Rooftop Solutions. All rights reserved.
+ * @author Evert Pot (http://www.rooftopsolutions.nl/)
+ * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
+ */
+class PrincipalPropertySearchReport implements XmlDeserializable {
+
+ /**
+ * The requested properties.
+ *
+ * @var array|null
+ */
+ public $properties;
+
+ /**
+ * searchProperties
+ *
+ * @var array
+ */
+ public $searchProperties = [];
+
+ /**
+ * By default the property search will be conducted on the url of the http
+ * request. If this is set to true, it will be applied to the principal
+ * collection set instead.
+ *
+ * @var bool
+ */
+ public $applyToPrincipalCollectionSet = false;
+
+ /**
+ * Search for principals matching ANY of the properties (OR) or a ALL of
+ * the properties (AND).
+ *
+ * This property is either "anyof" or "allof".
+ *
+ * @var string
+ */
+ public $test;
+
+ /**
+ * The deserialize method is called during xml parsing.
+ *
+ * This method is called statictly, this is because in theory this method
+ * may be used as a type of constructor, or factory method.
+ *
+ * Often you want to return an instance of the current class, but you are
+ * free to return other data as well.
+ *
+ * You are responsible for advancing the reader to the next element. Not
+ * doing anything will result in a never-ending loop.
+ *
+ * If you just want to skip parsing for this element altogether, you can
+ * just call $reader->next();
+ *
+ * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
+ * the next element.
+ *
+ * @param Reader $reader
+ * @return mixed
+ */
+ static function xmlDeserialize(Reader $reader) {
+
+ $self = new self();
+
+ $foundSearchProp = false;
+ $self->test = 'allof';
+ if ($reader->getAttribute('test')==='anyof') {
+ $self->test = 'anyof';
+ }
+
+ $elemMap = [
+ '{DAV:}property-search' => 'Sabre\\Xml\\Element\\KeyValue',
+ '{DAV:}prop' => 'Sabre\\Xml\\Element\\KeyValue',
+ ];
+
+ foreach($reader->parseInnerTree($elemMap) as $elem) {
+
+ switch($elem['name']) {
+
+ case '{DAV:}prop' :
+ $self->properties = array_keys($elem['value']);
+ break;
+ case '{DAV:}property-search' :
+ $foundSearchProp = true;
+ // This property has two sub-elements:
+ // {DAV:}prop - The property to be searched on. This may
+ // also be more than one
+ // {DAV:}match - The value to match with
+ if (!isset($elem['value']['{DAV:}prop']) || !isset($elem['value']['{DAV:}match'])) {
+ throw new BadRequest('The {DAV:}property-search element must contain one {DAV:}match and one {DAV:}prop element');
+ }
+ foreach($elem['value']['{DAV:}prop'] as $propName=>$discard) {
+ $self->searchProperties[$propName] = $elem['value']['{DAV:}match'];
+ }
+ break;
+ case '{DAV:}apply-to-principal-collection-set' :
+ $self->applyToPrincipalCollectionSet = true;
+ break;
+
+ }
+
+ }
+ if (!$foundSearchProp) {
+ throw new BadRequest('The {DAV:}principal-property-search report must contain at least 1 {DAV:}property-search element');
+ }
+
+ return $self;
+
+ }
+
+}
diff --git a/lib/DAVACL/Xml/Request/PrincipalSearchPropertySetReport.php b/lib/DAVACL/Xml/Request/PrincipalSearchPropertySetReport.php
new file mode 100644
index 0000000..3a5d234
--- /dev/null
+++ b/lib/DAVACL/Xml/Request/PrincipalSearchPropertySetReport.php
@@ -0,0 +1,82 @@
+<?php
+
+namespace Sabre\DAVACL\XML\Request;
+
+use
+ Sabre\XML\Element,
+ Sabre\XML\Reader,
+ Sabre\XML\Writer,
+ Sabre\DAV\Exception\CannotSerialize,
+ Sabre\DAV\Exception\BadRequest;
+
+/**
+ * PrincipalSearchPropertySetReport request parser.
+ *
+ * This class parses the {DAV:}principal-search-property-set REPORT, as defined
+ * in:
+ *
+ * https://tools.ietf.org/html/rfc3744#section-9.5
+ *
+ * @copyright Copyright (C) 2007-2013 Rooftop Solutions. All rights reserved.
+ * @author Evert Pot (http://www.rooftopsolutions.nl/)
+ * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
+ */
+class PrincipalSearchPropertySetReport implements Element {
+
+ /**
+ * The serialize method is called during xml writing.
+ *
+ * It should use the $writer argument to encode this object into XML.
+ *
+ * Important note: it is not needed to create the parent element. The
+ * parent element is already created, and we only have to worry about
+ * attributes, child elements and text (if any).
+ *
+ * Important note 2: If you are writing any new elements, you are also
+ * responsible for closing them.
+ *
+ * @param Writer $writer
+ * @return void
+ */
+ public function serializeXml(Writer $writer) {
+
+ throw new CannotSerialize('This element cannot be serialized.');
+
+ }
+
+ /**
+ * The deserialize method is called during xml parsing.
+ *
+ * This method is called statictly, this is because in theory this method
+ * may be used as a type of constructor, or factory method.
+ *
+ * Often you want to return an instance of the current class, but you are
+ * free to return other data as well.
+ *
+ * Important note 2: You are responsible for advancing the reader to the
+ * next element. Not doing anything will result in a never-ending loop.
+ *
+ * If you just want to skip parsing for this element altogether, you can
+ * just call $reader->next();
+ *
+ * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
+ * the next element.
+ *
+ * @param Reader $reader
+ * @return mixed
+ */
+ static public function deserializeXml(Reader $reader) {
+
+ if (!$reader->isEmptyElement) {
+ throw new BadRequest('The {DAV:}principal-search-property-set element must be empty');
+ }
+
+ // The element is actually empty, so there's not much to do.
+ $reader->next();
+
+ $self = new self();
+ return $self;
+
+ }
+
+}
diff --git a/tests/Sabre/DAVACL/PrincipalPropertySearchTest.php b/tests/Sabre/DAVACL/PrincipalPropertySearchTest.php
index 5897051..3227a4f 100644
--- a/tests/Sabre/DAVACL/PrincipalPropertySearchTest.php
+++ b/tests/Sabre/DAVACL/PrincipalPropertySearchTest.php
@@ -62,7 +62,7 @@ class PrincipalPropertySearchTest extends \PHPUnit_Framework_TestCase {
$server->exec();
- $this->assertEquals(400, $server->httpResponse->status);
+ $this->assertEquals(400, $server->httpResponse->getStatus(), $server->httpResponse->getBodyAsString());
$this->assertEquals(array(
'X-Sabre-Version' => [DAV\Version::VERSION],
'Content-Type' => ['application/xml; charset=utf-8'],
@@ -101,7 +101,7 @@ class PrincipalPropertySearchTest extends \PHPUnit_Framework_TestCase {
$server->exec();
- $this->assertEquals(207, $server->httpResponse->status);
+ $this->assertEquals(207, $server->httpResponse->getStatus(), "Full body: " . $server->httpResponse->getBodyAsString());
$this->assertEquals(array(
'X-Sabre-Version' => [DAV\Version::VERSION],
'Content-Type' => ['application/xml; charset=utf-8'],
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/php-sabredav.git
More information about the Pkg-owncloud-commits
mailing list