[Pkg-owncloud-commits] [php-sabredav] 169/220: Principal-match implementation. Needs tests.
David Prévot
taffit at moszumanska.debian.org
Thu May 12 01:21:23 UTC 2016
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository php-sabredav.
commit 0ed5a56ffb36afaabdfb39a05f82125414e11900
Author: Evert Pot <me at evertpot.com>
Date: Mon Apr 18 17:57:31 2016 +0800
Principal-match implementation. Needs tests.
---
lib/DAVACL/Plugin.php | 74 ++++++++++++++++++++++++-
lib/DAVACL/Xml/Request/PrincipalMatchReport.php | 2 +-
2 files changed, 72 insertions(+), 4 deletions(-)
diff --git a/lib/DAVACL/Plugin.php b/lib/DAVACL/Plugin.php
index 065d02c..b7174a2 100644
--- a/lib/DAVACL/Plugin.php
+++ b/lib/DAVACL/Plugin.php
@@ -1254,10 +1254,78 @@ class Plugin extends DAV\ServerPlugin {
* @param Xml\Request\PrincipalMatchReport $report
* @return void
*/
- protected function principalMatchReport($report) {
+ protected function principalMatchReport(Xml\Request\PrincipalMatchReport $report) {
+
+ $depth = $this->server->getHTTPDepth(0);
+ if ($depth !== 0) {
+ throw new BadRequest('The principal-match report is only defined on Depth: 0');
+ }
+
+ $requestUri = $this->server->getRequestUri();
+ $currentPrincipals = $this->getCurrentUserPrincipals();
+
+ $result = [];
+
+ if ($report->type === Xml\Request\PrincipalMatchReport::SELF) {
+
+ // Finding all principals under the request uri that match the
+ // current principal.
+ foreach ($currentPrincipals as $currentPrincipal) {
+
+ if ($currentPrincipal === $requestUri || strpos($currentPrincipal, $requestUri . '/') === 0) {
+ $result[] = $currentPrincipal;
+ }
+
+ }
+
+ } else {
+
+ // We need to find all resources that have a property that matches
+ // one of the current principals.
+ $candidates = $this->server->getPropertiesForPath(
+ $requestUri,
+ [$report->principalProperty],
+ 1
+ );
+ foreach ($candidates as $candidate) {
+
+ if (!isset($candidate[200][$report->principalProperty])) {
+ continue;
+ }
+ $hrefs = $candidate[200][$report->principalProperty];
+
+ if (!$hrefs instanceof Href) {
+ continue;
+ }
+
+ foreach ($hrefs->getHref() as $href) {
+ if (in_array($href, $currentPrincipals)) {
+ $result[] = $candidate['href'];
+ continue 2;
+ }
+ }
+ }
+
+ }
+
+ $responses = [];
+
+ foreach ($result as $item) {
+
+ $properties = [];
+
+ if ($report->properties) {
+
+ $foo = $this->server->getPropertiesForPath($item, $report->properties);
+ unset($foo['href']);
+ $properties = $foo;
+
+ }
+
+ $responses[] = new Response($item, $properties, 'HTTP/1.1 200 OK');
+
+ }
- print_r($report);
- die();
}
diff --git a/lib/DAVACL/Xml/Request/PrincipalMatchReport.php b/lib/DAVACL/Xml/Request/PrincipalMatchReport.php
index 5c65077..d5710ca 100644
--- a/lib/DAVACL/Xml/Request/PrincipalMatchReport.php
+++ b/lib/DAVACL/Xml/Request/PrincipalMatchReport.php
@@ -79,7 +79,7 @@ class PrincipalMatchReport implements XmlDeserializable {
$principalMatch->properties = $elems['prop'];
}
- return $principalMatch;
+ return $principalMatch;
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-php/php-sabredav.git
More information about the Pkg-owncloud-commits
mailing list