Passed
Push — master ( 4908d8...fbbdc6 )
by Joas
16:12 queued 12s
created
apps/files/lib/Settings/PersonalSettings.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -31,15 +31,15 @@
 block discarded – undo
31 31
 use OCP\Settings\ISettings;
32 32
 
33 33
 class PersonalSettings implements ISettings {
34
-	public function getForm(): TemplateResponse {
35
-		return new TemplateResponse(Application::APP_ID, 'settings-personal');
36
-	}
34
+    public function getForm(): TemplateResponse {
35
+        return new TemplateResponse(Application::APP_ID, 'settings-personal');
36
+    }
37 37
 
38
-	public function getSection(): string {
39
-		return 'sharing';
40
-	}
38
+    public function getSection(): string {
39
+        return 'sharing';
40
+    }
41 41
 
42
-	public function getPriority(): int {
43
-		return 90;
44
-	}
42
+    public function getPriority(): int {
43
+        return 90;
44
+    }
45 45
 }
Please login to merge, or discard this patch.
apps/files/lib/Collaboration/Resources/ResourceProvider.php 1 patch
Indentation   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -37,100 +37,100 @@
 block discarded – undo
37 37
 use OCP\IUser;
38 38
 
39 39
 class ResourceProvider implements IProvider {
40
-	public const RESOURCE_TYPE = 'file';
41
-
42
-	/** @var IRootFolder */
43
-	protected $rootFolder;
44
-	/** @var IPreview */
45
-	private $preview;
46
-	/** @var IURLGenerator */
47
-	private $urlGenerator;
48
-
49
-	/** @var array */
50
-	protected $nodes = [];
51
-
52
-	public function __construct(IRootFolder $rootFolder,
53
-								IPreview $preview,
54
-								IURLGenerator $urlGenerator) {
55
-		$this->rootFolder = $rootFolder;
56
-		$this->preview = $preview;
57
-		$this->urlGenerator = $urlGenerator;
58
-	}
59
-
60
-	private function getNode(IResource $resource): ?Node {
61
-		if (isset($this->nodes[(int) $resource->getId()])) {
62
-			return $this->nodes[(int) $resource->getId()];
63
-		}
64
-		$nodes = $this->rootFolder->getById((int) $resource->getId());
65
-		if (!empty($nodes)) {
66
-			$this->nodes[(int) $resource->getId()] = array_shift($nodes);
67
-			return $this->nodes[(int) $resource->getId()];
68
-		}
69
-		return null;
70
-	}
71
-
72
-	/**
73
-	 * @param IResource $resource
74
-	 * @return array
75
-	 * @since 16.0.0
76
-	 */
77
-	public function getResourceRichObject(IResource $resource): array {
78
-		if (isset($this->nodes[(int) $resource->getId()])) {
79
-			$node = $this->nodes[(int) $resource->getId()]->getPath();
80
-		} else {
81
-			$node = $this->getNode($resource);
82
-		}
83
-
84
-		if ($node instanceof Node) {
85
-			$link = $this->urlGenerator->linkToRouteAbsolute(
86
-				'files.viewcontroller.showFile',
87
-				['fileid' => $resource->getId()]
88
-			);
89
-			return [
90
-				'type' => 'file',
91
-				'id' => $resource->getId(),
92
-				'name' => $node->getName(),
93
-				'path' => $node->getInternalPath(),
94
-				'link' => $link,
95
-				'mimetype' => $node->getMimetype(),
96
-				'preview-available' => $this->preview->isAvailable($node),
97
-			];
98
-		}
99
-
100
-		throw new ResourceException('File not found');
101
-	}
102
-
103
-	/**
104
-	 * Can a user/guest access the collection
105
-	 *
106
-	 * @param IResource $resource
107
-	 * @param IUser $user
108
-	 * @return bool
109
-	 * @since 16.0.0
110
-	 */
111
-	public function canAccessResource(IResource $resource, IUser $user = null): bool {
112
-		if (!$user instanceof IUser) {
113
-			return false;
114
-		}
115
-
116
-		$userFolder = $this->rootFolder->getUserFolder($user->getUID());
117
-		$nodes = $userFolder->getById((int) $resource->getId());
118
-
119
-		if (!empty($nodes)) {
120
-			$this->nodes[(int) $resource->getId()] = array_shift($nodes);
121
-			return true;
122
-		}
123
-
124
-		return false;
125
-	}
126
-
127
-	/**
128
-	 * Get the resource type of the provider
129
-	 *
130
-	 * @return string
131
-	 * @since 16.0.0
132
-	 */
133
-	public function getType(): string {
134
-		return self::RESOURCE_TYPE;
135
-	}
40
+    public const RESOURCE_TYPE = 'file';
41
+
42
+    /** @var IRootFolder */
43
+    protected $rootFolder;
44
+    /** @var IPreview */
45
+    private $preview;
46
+    /** @var IURLGenerator */
47
+    private $urlGenerator;
48
+
49
+    /** @var array */
50
+    protected $nodes = [];
51
+
52
+    public function __construct(IRootFolder $rootFolder,
53
+                                IPreview $preview,
54
+                                IURLGenerator $urlGenerator) {
55
+        $this->rootFolder = $rootFolder;
56
+        $this->preview = $preview;
57
+        $this->urlGenerator = $urlGenerator;
58
+    }
59
+
60
+    private function getNode(IResource $resource): ?Node {
61
+        if (isset($this->nodes[(int) $resource->getId()])) {
62
+            return $this->nodes[(int) $resource->getId()];
63
+        }
64
+        $nodes = $this->rootFolder->getById((int) $resource->getId());
65
+        if (!empty($nodes)) {
66
+            $this->nodes[(int) $resource->getId()] = array_shift($nodes);
67
+            return $this->nodes[(int) $resource->getId()];
68
+        }
69
+        return null;
70
+    }
71
+
72
+    /**
73
+     * @param IResource $resource
74
+     * @return array
75
+     * @since 16.0.0
76
+     */
77
+    public function getResourceRichObject(IResource $resource): array {
78
+        if (isset($this->nodes[(int) $resource->getId()])) {
79
+            $node = $this->nodes[(int) $resource->getId()]->getPath();
80
+        } else {
81
+            $node = $this->getNode($resource);
82
+        }
83
+
84
+        if ($node instanceof Node) {
85
+            $link = $this->urlGenerator->linkToRouteAbsolute(
86
+                'files.viewcontroller.showFile',
87
+                ['fileid' => $resource->getId()]
88
+            );
89
+            return [
90
+                'type' => 'file',
91
+                'id' => $resource->getId(),
92
+                'name' => $node->getName(),
93
+                'path' => $node->getInternalPath(),
94
+                'link' => $link,
95
+                'mimetype' => $node->getMimetype(),
96
+                'preview-available' => $this->preview->isAvailable($node),
97
+            ];
98
+        }
99
+
100
+        throw new ResourceException('File not found');
101
+    }
102
+
103
+    /**
104
+     * Can a user/guest access the collection
105
+     *
106
+     * @param IResource $resource
107
+     * @param IUser $user
108
+     * @return bool
109
+     * @since 16.0.0
110
+     */
111
+    public function canAccessResource(IResource $resource, IUser $user = null): bool {
112
+        if (!$user instanceof IUser) {
113
+            return false;
114
+        }
115
+
116
+        $userFolder = $this->rootFolder->getUserFolder($user->getUID());
117
+        $nodes = $userFolder->getById((int) $resource->getId());
118
+
119
+        if (!empty($nodes)) {
120
+            $this->nodes[(int) $resource->getId()] = array_shift($nodes);
121
+            return true;
122
+        }
123
+
124
+        return false;
125
+    }
126
+
127
+    /**
128
+     * Get the resource type of the provider
129
+     *
130
+     * @return string
131
+     * @since 16.0.0
132
+     */
133
+    public function getType(): string {
134
+        return self::RESOURCE_TYPE;
135
+    }
136 136
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/Exception/InvalidPath.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -49,17 +49,17 @@
 block discarded – undo
49 49
 	 * @param \DOMElement $errorNode
50 50
 	 * @return void
51 51
 	 */
52
-	public function serialize(\Sabre\DAV\Server $server,\DOMElement $errorNode) {
52
+	public function serialize(\Sabre\DAV\Server $server, \DOMElement $errorNode) {
53 53
 
54 54
 		// set ownCloud namespace
55 55
 		$errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD);
56 56
 
57 57
 		// adding the retry node
58
-		$error = $errorNode->ownerDocument->createElementNS('o:','o:retry', var_export($this->retry, true));
58
+		$error = $errorNode->ownerDocument->createElementNS('o:', 'o:retry', var_export($this->retry, true));
59 59
 		$errorNode->appendChild($error);
60 60
 
61 61
 		// adding the message node
62
-		$error = $errorNode->ownerDocument->createElementNS('o:','o:reason', $this->getMessage());
62
+		$error = $errorNode->ownerDocument->createElementNS('o:', 'o:reason', $this->getMessage());
63 63
 		$errorNode->appendChild($error);
64 64
 	}
65 65
 }
Please login to merge, or discard this patch.
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -26,51 +26,51 @@
 block discarded – undo
26 26
 use Sabre\DAV\Exception;
27 27
 
28 28
 class InvalidPath extends Exception {
29
-	public const NS_OWNCLOUD = 'http://owncloud.org/ns';
29
+    public const NS_OWNCLOUD = 'http://owncloud.org/ns';
30 30
 
31
-	/**
32
-	 * @var bool
33
-	 */
34
-	private $retry;
31
+    /**
32
+     * @var bool
33
+     */
34
+    private $retry;
35 35
 
36
-	/**
37
-	 * @param string $message
38
-	 * @param bool $retry
39
-	 * @param \Exception|null $previous
40
-	 */
41
-	public function __construct($message, $retry = false, \Exception $previous = null) {
42
-		parent::__construct($message, 0, $previous);
43
-		$this->retry = $retry;
44
-	}
36
+    /**
37
+     * @param string $message
38
+     * @param bool $retry
39
+     * @param \Exception|null $previous
40
+     */
41
+    public function __construct($message, $retry = false, \Exception $previous = null) {
42
+        parent::__construct($message, 0, $previous);
43
+        $this->retry = $retry;
44
+    }
45 45
 
46
-	/**
47
-	 * Returns the HTTP status code for this exception
48
-	 *
49
-	 * @return int
50
-	 */
51
-	public function getHTTPCode() {
52
-		return 400;
53
-	}
46
+    /**
47
+     * Returns the HTTP status code for this exception
48
+     *
49
+     * @return int
50
+     */
51
+    public function getHTTPCode() {
52
+        return 400;
53
+    }
54 54
 
55
-	/**
56
-	 * This method allows the exception to include additional information
57
-	 * into the WebDAV error response
58
-	 *
59
-	 * @param \Sabre\DAV\Server $server
60
-	 * @param \DOMElement $errorNode
61
-	 * @return void
62
-	 */
63
-	public function serialize(\Sabre\DAV\Server $server,\DOMElement $errorNode) {
55
+    /**
56
+     * This method allows the exception to include additional information
57
+     * into the WebDAV error response
58
+     *
59
+     * @param \Sabre\DAV\Server $server
60
+     * @param \DOMElement $errorNode
61
+     * @return void
62
+     */
63
+    public function serialize(\Sabre\DAV\Server $server,\DOMElement $errorNode) {
64 64
 
65
-		// set ownCloud namespace
66
-		$errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD);
65
+        // set ownCloud namespace
66
+        $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD);
67 67
 
68
-		// adding the retry node
69
-		$error = $errorNode->ownerDocument->createElementNS('o:','o:retry', var_export($this->retry, true));
70
-		$errorNode->appendChild($error);
68
+        // adding the retry node
69
+        $error = $errorNode->ownerDocument->createElementNS('o:','o:retry', var_export($this->retry, true));
70
+        $errorNode->appendChild($error);
71 71
 
72
-		// adding the message node
73
-		$error = $errorNode->ownerDocument->createElementNS('o:','o:reason', $this->getMessage());
74
-		$errorNode->appendChild($error);
75
-	}
72
+        // adding the message node
73
+        $error = $errorNode->ownerDocument->createElementNS('o:','o:reason', $this->getMessage());
74
+        $errorNode->appendChild($error);
75
+    }
76 76
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/QuotaPlugin.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 			return;
93 93
 		}
94 94
 
95
-		return $this->checkQuota($parent->getPath() . '/' . basename($uri));
95
+		return $this->checkQuota($parent->getPath().'/'.basename($uri));
96 96
 	}
97 97
 
98 98
 	/**
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
 				// there is still enough space for the remaining chunks
164 164
 				$length -= $chunkHandler->getCurrentSize();
165 165
 				// use target file name for free space check in case of shared files
166
-				$path = rtrim($parentPath, '/') . '/' . $info['name'];
166
+				$path = rtrim($parentPath, '/').'/'.$info['name'];
167 167
 			}
168 168
 			$freeSpace = $this->getFreeSpace($path);
169 169
 			if ($freeSpace >= 0 && $length > $freeSpace) {
Please login to merge, or discard this patch.
Indentation   +203 added lines, -203 removed lines patch added patch discarded remove patch
@@ -44,207 +44,207 @@
 block discarded – undo
44 44
  * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
45 45
  */
46 46
 class QuotaPlugin extends \Sabre\DAV\ServerPlugin {
47
-	/** @var \OC\Files\View */
48
-	private $view;
49
-
50
-	/**
51
-	 * Reference to main server object
52
-	 *
53
-	 * @var \Sabre\DAV\Server
54
-	 */
55
-	private $server;
56
-
57
-	/**
58
-	 * @param \OC\Files\View $view
59
-	 */
60
-	public function __construct($view) {
61
-		$this->view = $view;
62
-	}
63
-
64
-	/**
65
-	 * This initializes the plugin.
66
-	 *
67
-	 * This function is called by \Sabre\DAV\Server, after
68
-	 * addPlugin is called.
69
-	 *
70
-	 * This method should set up the requires event subscriptions.
71
-	 *
72
-	 * @param \Sabre\DAV\Server $server
73
-	 * @return void
74
-	 */
75
-	public function initialize(\Sabre\DAV\Server $server) {
76
-		$this->server = $server;
77
-
78
-		$server->on('beforeWriteContent', [$this, 'beforeWriteContent'], 10);
79
-		$server->on('beforeCreateFile', [$this, 'beforeCreateFile'], 10);
80
-		$server->on('beforeMove', [$this, 'beforeMove'], 10);
81
-		$server->on('beforeCopy', [$this, 'beforeCopy'], 10);
82
-	}
83
-
84
-	/**
85
-	 * Check quota before creating file
86
-	 *
87
-	 * @param string $uri target file URI
88
-	 * @param resource $data data
89
-	 * @param INode $parent Sabre Node
90
-	 * @param bool $modified modified
91
-	 */
92
-	public function beforeCreateFile($uri, $data, INode $parent, $modified) {
93
-		if (!$parent instanceof Node) {
94
-			return;
95
-		}
96
-
97
-		return $this->checkQuota($parent->getPath() . '/' . basename($uri));
98
-	}
99
-
100
-	/**
101
-	 * Check quota before writing content
102
-	 *
103
-	 * @param string $uri target file URI
104
-	 * @param INode $node Sabre Node
105
-	 * @param resource $data data
106
-	 * @param bool $modified modified
107
-	 */
108
-	public function beforeWriteContent($uri, INode $node, $data, $modified) {
109
-		if (!$node instanceof Node) {
110
-			return;
111
-		}
112
-
113
-		return $this->checkQuota($node->getPath());
114
-	}
115
-
116
-	/**
117
-	 * Check if we're moving a Futurefile in which case we need to check
118
-	 * the quota on the target destination.
119
-	 *
120
-	 * @param string $source source path
121
-	 * @param string $destination destination path
122
-	 */
123
-	public function beforeMove($source, $destination) {
124
-		$sourceNode = $this->server->tree->getNodeForPath($source);
125
-		if (!$sourceNode instanceof FutureFile) {
126
-			return;
127
-		}
128
-
129
-		// get target node for proper path conversion
130
-		if ($this->server->tree->nodeExists($destination)) {
131
-			$destinationNode = $this->server->tree->getNodeForPath($destination);
132
-			$path = $destinationNode->getPath();
133
-		} else {
134
-			$parent = dirname($destination);
135
-			if ($parent === '.') {
136
-				$parent = '';
137
-			}
138
-			$parentNode = $this->server->tree->getNodeForPath($parent);
139
-			$path = $parentNode->getPath();
140
-		}
141
-
142
-		return $this->checkQuota($path, $sourceNode->getSize());
143
-	}
144
-
145
-	/**
146
-	 * Check quota on the target destination before a copy.
147
-	 */
148
-	public function beforeCopy(string $sourcePath, string $destinationPath): bool {
149
-		$sourceNode = $this->server->tree->getNodeForPath($sourcePath);
150
-		if (!$sourceNode instanceof Node) {
151
-			return true;
152
-		}
153
-
154
-		// get target node for proper path conversion
155
-		if ($this->server->tree->nodeExists($destinationPath)) {
156
-			$destinationNode = $this->server->tree->getNodeForPath($destinationPath);
157
-			if (!$destinationNode instanceof Node) {
158
-				return true;
159
-			}
160
-			$path = $destinationNode->getPath();
161
-		} else {
162
-			$parent = dirname($destinationPath);
163
-			if ($parent === '.') {
164
-				$parent = '';
165
-			}
166
-			$parentNode = $this->server->tree->getNodeForPath($parent);
167
-			if (!$parentNode instanceof Node) {
168
-				return true;
169
-			}
170
-			$path = $parentNode->getPath();
171
-		}
172
-
173
-		return $this->checkQuota($path, $sourceNode->getSize());
174
-	}
175
-
176
-
177
-	/**
178
-	 * This method is called before any HTTP method and validates there is enough free space to store the file
179
-	 *
180
-	 * @param string $path relative to the users home
181
-	 * @param int|float|null $length
182
-	 * @throws InsufficientStorage
183
-	 * @return bool
184
-	 */
185
-	public function checkQuota($path, $length = null) {
186
-		if ($length === null) {
187
-			$length = $this->getLength();
188
-		}
189
-
190
-		if ($length) {
191
-			[$parentPath, $newName] = \Sabre\Uri\split($path);
192
-			if (is_null($parentPath)) {
193
-				$parentPath = '';
194
-			}
195
-			$req = $this->server->httpRequest;
196
-			if ($req->getHeader('OC-Chunked')) {
197
-				$info = \OC_FileChunking::decodeName($newName);
198
-				$chunkHandler = $this->getFileChunking($info);
199
-				// subtract the already uploaded size to see whether
200
-				// there is still enough space for the remaining chunks
201
-				$length -= $chunkHandler->getCurrentSize();
202
-				// use target file name for free space check in case of shared files
203
-				$path = rtrim($parentPath, '/') . '/' . $info['name'];
204
-			}
205
-			$freeSpace = $this->getFreeSpace($path);
206
-			if ($freeSpace >= 0 && $length > $freeSpace) {
207
-				if (isset($chunkHandler)) {
208
-					$chunkHandler->cleanup();
209
-				}
210
-				throw new InsufficientStorage("Insufficient space in $path, $length required, $freeSpace available");
211
-			}
212
-		}
213
-		return true;
214
-	}
215
-
216
-	public function getFileChunking($info) {
217
-		// FIXME: need a factory for better mocking support
218
-		return new \OC_FileChunking($info);
219
-	}
220
-
221
-	public function getLength() {
222
-		$req = $this->server->httpRequest;
223
-		$length = $req->getHeader('X-Expected-Entity-Length');
224
-		if (!is_numeric($length)) {
225
-			$length = $req->getHeader('Content-Length');
226
-			$length = is_numeric($length) ? $length : null;
227
-		}
228
-
229
-		$ocLength = $req->getHeader('OC-Total-Length');
230
-		if (is_numeric($length) && is_numeric($ocLength)) {
231
-			return max($length, $ocLength);
232
-		}
233
-
234
-		return $length;
235
-	}
236
-
237
-	/**
238
-	 * @param string $uri
239
-	 * @return mixed
240
-	 * @throws ServiceUnavailable
241
-	 */
242
-	public function getFreeSpace($uri) {
243
-		try {
244
-			$freeSpace = $this->view->free_space(ltrim($uri, '/'));
245
-			return $freeSpace;
246
-		} catch (StorageNotAvailableException $e) {
247
-			throw new ServiceUnavailable($e->getMessage());
248
-		}
249
-	}
47
+    /** @var \OC\Files\View */
48
+    private $view;
49
+
50
+    /**
51
+     * Reference to main server object
52
+     *
53
+     * @var \Sabre\DAV\Server
54
+     */
55
+    private $server;
56
+
57
+    /**
58
+     * @param \OC\Files\View $view
59
+     */
60
+    public function __construct($view) {
61
+        $this->view = $view;
62
+    }
63
+
64
+    /**
65
+     * This initializes the plugin.
66
+     *
67
+     * This function is called by \Sabre\DAV\Server, after
68
+     * addPlugin is called.
69
+     *
70
+     * This method should set up the requires event subscriptions.
71
+     *
72
+     * @param \Sabre\DAV\Server $server
73
+     * @return void
74
+     */
75
+    public function initialize(\Sabre\DAV\Server $server) {
76
+        $this->server = $server;
77
+
78
+        $server->on('beforeWriteContent', [$this, 'beforeWriteContent'], 10);
79
+        $server->on('beforeCreateFile', [$this, 'beforeCreateFile'], 10);
80
+        $server->on('beforeMove', [$this, 'beforeMove'], 10);
81
+        $server->on('beforeCopy', [$this, 'beforeCopy'], 10);
82
+    }
83
+
84
+    /**
85
+     * Check quota before creating file
86
+     *
87
+     * @param string $uri target file URI
88
+     * @param resource $data data
89
+     * @param INode $parent Sabre Node
90
+     * @param bool $modified modified
91
+     */
92
+    public function beforeCreateFile($uri, $data, INode $parent, $modified) {
93
+        if (!$parent instanceof Node) {
94
+            return;
95
+        }
96
+
97
+        return $this->checkQuota($parent->getPath() . '/' . basename($uri));
98
+    }
99
+
100
+    /**
101
+     * Check quota before writing content
102
+     *
103
+     * @param string $uri target file URI
104
+     * @param INode $node Sabre Node
105
+     * @param resource $data data
106
+     * @param bool $modified modified
107
+     */
108
+    public function beforeWriteContent($uri, INode $node, $data, $modified) {
109
+        if (!$node instanceof Node) {
110
+            return;
111
+        }
112
+
113
+        return $this->checkQuota($node->getPath());
114
+    }
115
+
116
+    /**
117
+     * Check if we're moving a Futurefile in which case we need to check
118
+     * the quota on the target destination.
119
+     *
120
+     * @param string $source source path
121
+     * @param string $destination destination path
122
+     */
123
+    public function beforeMove($source, $destination) {
124
+        $sourceNode = $this->server->tree->getNodeForPath($source);
125
+        if (!$sourceNode instanceof FutureFile) {
126
+            return;
127
+        }
128
+
129
+        // get target node for proper path conversion
130
+        if ($this->server->tree->nodeExists($destination)) {
131
+            $destinationNode = $this->server->tree->getNodeForPath($destination);
132
+            $path = $destinationNode->getPath();
133
+        } else {
134
+            $parent = dirname($destination);
135
+            if ($parent === '.') {
136
+                $parent = '';
137
+            }
138
+            $parentNode = $this->server->tree->getNodeForPath($parent);
139
+            $path = $parentNode->getPath();
140
+        }
141
+
142
+        return $this->checkQuota($path, $sourceNode->getSize());
143
+    }
144
+
145
+    /**
146
+     * Check quota on the target destination before a copy.
147
+     */
148
+    public function beforeCopy(string $sourcePath, string $destinationPath): bool {
149
+        $sourceNode = $this->server->tree->getNodeForPath($sourcePath);
150
+        if (!$sourceNode instanceof Node) {
151
+            return true;
152
+        }
153
+
154
+        // get target node for proper path conversion
155
+        if ($this->server->tree->nodeExists($destinationPath)) {
156
+            $destinationNode = $this->server->tree->getNodeForPath($destinationPath);
157
+            if (!$destinationNode instanceof Node) {
158
+                return true;
159
+            }
160
+            $path = $destinationNode->getPath();
161
+        } else {
162
+            $parent = dirname($destinationPath);
163
+            if ($parent === '.') {
164
+                $parent = '';
165
+            }
166
+            $parentNode = $this->server->tree->getNodeForPath($parent);
167
+            if (!$parentNode instanceof Node) {
168
+                return true;
169
+            }
170
+            $path = $parentNode->getPath();
171
+        }
172
+
173
+        return $this->checkQuota($path, $sourceNode->getSize());
174
+    }
175
+
176
+
177
+    /**
178
+     * This method is called before any HTTP method and validates there is enough free space to store the file
179
+     *
180
+     * @param string $path relative to the users home
181
+     * @param int|float|null $length
182
+     * @throws InsufficientStorage
183
+     * @return bool
184
+     */
185
+    public function checkQuota($path, $length = null) {
186
+        if ($length === null) {
187
+            $length = $this->getLength();
188
+        }
189
+
190
+        if ($length) {
191
+            [$parentPath, $newName] = \Sabre\Uri\split($path);
192
+            if (is_null($parentPath)) {
193
+                $parentPath = '';
194
+            }
195
+            $req = $this->server->httpRequest;
196
+            if ($req->getHeader('OC-Chunked')) {
197
+                $info = \OC_FileChunking::decodeName($newName);
198
+                $chunkHandler = $this->getFileChunking($info);
199
+                // subtract the already uploaded size to see whether
200
+                // there is still enough space for the remaining chunks
201
+                $length -= $chunkHandler->getCurrentSize();
202
+                // use target file name for free space check in case of shared files
203
+                $path = rtrim($parentPath, '/') . '/' . $info['name'];
204
+            }
205
+            $freeSpace = $this->getFreeSpace($path);
206
+            if ($freeSpace >= 0 && $length > $freeSpace) {
207
+                if (isset($chunkHandler)) {
208
+                    $chunkHandler->cleanup();
209
+                }
210
+                throw new InsufficientStorage("Insufficient space in $path, $length required, $freeSpace available");
211
+            }
212
+        }
213
+        return true;
214
+    }
215
+
216
+    public function getFileChunking($info) {
217
+        // FIXME: need a factory for better mocking support
218
+        return new \OC_FileChunking($info);
219
+    }
220
+
221
+    public function getLength() {
222
+        $req = $this->server->httpRequest;
223
+        $length = $req->getHeader('X-Expected-Entity-Length');
224
+        if (!is_numeric($length)) {
225
+            $length = $req->getHeader('Content-Length');
226
+            $length = is_numeric($length) ? $length : null;
227
+        }
228
+
229
+        $ocLength = $req->getHeader('OC-Total-Length');
230
+        if (is_numeric($length) && is_numeric($ocLength)) {
231
+            return max($length, $ocLength);
232
+        }
233
+
234
+        return $length;
235
+    }
236
+
237
+    /**
238
+     * @param string $uri
239
+     * @return mixed
240
+     * @throws ServiceUnavailable
241
+     */
242
+    public function getFreeSpace($uri) {
243
+        try {
244
+            $freeSpace = $this->view->free_space(ltrim($uri, '/'));
245
+            return $freeSpace;
246
+        } catch (StorageNotAvailableException $e) {
247
+            throw new ServiceUnavailable($e->getMessage());
248
+        }
249
+    }
250 250
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/FilesReportPlugin.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -186,14 +186,14 @@  discard block
 block discarded – undo
186 186
 			return;
187 187
 		}
188 188
 
189
-		$ns = '{' . $this::NS_OWNCLOUD . '}';
189
+		$ns = '{'.$this::NS_OWNCLOUD.'}';
190 190
 		$requestedProps = [];
191 191
 		$filterRules = [];
192 192
 
193 193
 		// parse report properties and gather filter info
194 194
 		foreach ($report as $reportProps) {
195 195
 			$name = $reportProps['name'];
196
-			if ($name === $ns . 'filter-rules') {
196
+			if ($name === $ns.'filter-rules') {
197 197
 				$filterRules = $reportProps['value'];
198 198
 			} elseif ($name === '{DAV:}prop') {
199 199
 				// propfind properties
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
 		if (empty($filesUri)) {
255 255
 			return '';
256 256
 		}
257
-		return '/' . $filesUri;
257
+		return '/'.$filesUri;
258 258
 	}
259 259
 
260 260
 	/**
@@ -266,19 +266,19 @@  discard block
 block discarded – undo
266 266
 	 * @throws TagNotFoundException whenever a tag was not found
267 267
 	 */
268 268
 	protected function processFilterRules($filterRules) {
269
-		$ns = '{' . $this::NS_OWNCLOUD . '}';
269
+		$ns = '{'.$this::NS_OWNCLOUD.'}';
270 270
 		$resultFileIds = null;
271 271
 		$systemTagIds = [];
272 272
 		$circlesIds = [];
273 273
 		$favoriteFilter = null;
274 274
 		foreach ($filterRules as $filterRule) {
275
-			if ($filterRule['name'] === $ns . 'systemtag') {
275
+			if ($filterRule['name'] === $ns.'systemtag') {
276 276
 				$systemTagIds[] = $filterRule['value'];
277 277
 			}
278 278
 			if ($filterRule['name'] === self::CIRCLE_PROPERTYNAME) {
279 279
 				$circlesIds[] = $filterRule['value'];
280 280
 			}
281
-			if ($filterRule['name'] === $ns . 'favorite') {
281
+			if ($filterRule['name'] === $ns.'favorite') {
282 282
 				$favoriteFilter = true;
283 283
 			}
284 284
 		}
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
 			}
327 327
 
328 328
 			if (!empty($unknownTagIds)) {
329
-				throw new TagNotFoundException('Tag with ids ' . implode(', ', $unknownTagIds) . ' not found');
329
+				throw new TagNotFoundException('Tag with ids '.implode(', ', $unknownTagIds).' not found');
330 330
 			}
331 331
 		}
332 332
 
@@ -379,7 +379,7 @@  discard block
 block discarded – undo
379 379
 	public function prepareResponses($filesUri, $requestedProps, $nodes) {
380 380
 		$responses = [];
381 381
 		foreach ($nodes as $node) {
382
-			$propFind = new PropFind($filesUri . $node->getPath(), $requestedProps);
382
+			$propFind = new PropFind($filesUri.$node->getPath(), $requestedProps);
383 383
 
384 384
 			$this->server->getPropertiesByNode($propFind, $node);
385 385
 			// copied from Sabre Server's getPropertiesForPath
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
 			}
393 393
 
394 394
 			$responses[] = new Response(
395
-				rtrim($this->server->getBaseUri(), '/') . $filesUri . $node->getPath(),
395
+				rtrim($this->server->getBaseUri(), '/').$filesUri.$node->getPath(),
396 396
 				$result,
397 397
 				200
398 398
 			);
Please login to merge, or discard this patch.
Indentation   +392 added lines, -392 removed lines patch added patch discarded remove patch
@@ -46,396 +46,396 @@
 block discarded – undo
46 46
 
47 47
 class FilesReportPlugin extends ServerPlugin {
48 48
 
49
-	// namespace
50
-	public const NS_OWNCLOUD = 'http://owncloud.org/ns';
51
-	public const REPORT_NAME = '{http://owncloud.org/ns}filter-files';
52
-	public const SYSTEMTAG_PROPERTYNAME = '{http://owncloud.org/ns}systemtag';
53
-	public const CIRCLE_PROPERTYNAME = '{http://owncloud.org/ns}circle';
54
-
55
-	/**
56
-	 * Reference to main server object
57
-	 *
58
-	 * @var \Sabre\DAV\Server
59
-	 */
60
-	private $server;
61
-
62
-	/**
63
-	 * @var Tree
64
-	 */
65
-	private $tree;
66
-
67
-	/**
68
-	 * @var View
69
-	 */
70
-	private $fileView;
71
-
72
-	/**
73
-	 * @var ISystemTagManager
74
-	 */
75
-	private $tagManager;
76
-
77
-	/**
78
-	 * @var ISystemTagObjectMapper
79
-	 */
80
-	private $tagMapper;
81
-
82
-	/**
83
-	 * Manager for private tags
84
-	 *
85
-	 * @var ITagManager
86
-	 */
87
-	private $fileTagger;
88
-
89
-	/**
90
-	 * @var IUserSession
91
-	 */
92
-	private $userSession;
93
-
94
-	/**
95
-	 * @var IGroupManager
96
-	 */
97
-	private $groupManager;
98
-
99
-	/**
100
-	 * @var Folder
101
-	 */
102
-	private $userFolder;
103
-
104
-	/**
105
-	 * @var IAppManager
106
-	 */
107
-	private $appManager;
108
-
109
-	/**
110
-	 * @param Tree $tree
111
-	 * @param View $view
112
-	 * @param ISystemTagManager $tagManager
113
-	 * @param ISystemTagObjectMapper $tagMapper
114
-	 * @param ITagManager $fileTagger manager for private tags
115
-	 * @param IUserSession $userSession
116
-	 * @param IGroupManager $groupManager
117
-	 * @param Folder $userFolder
118
-	 * @param IAppManager $appManager
119
-	 */
120
-	public function __construct(Tree $tree,
121
-								View $view,
122
-								ISystemTagManager $tagManager,
123
-								ISystemTagObjectMapper $tagMapper,
124
-								ITagManager $fileTagger,
125
-								IUserSession $userSession,
126
-								IGroupManager $groupManager,
127
-								Folder $userFolder,
128
-								IAppManager $appManager
129
-	) {
130
-		$this->tree = $tree;
131
-		$this->fileView = $view;
132
-		$this->tagManager = $tagManager;
133
-		$this->tagMapper = $tagMapper;
134
-		$this->fileTagger = $fileTagger;
135
-		$this->userSession = $userSession;
136
-		$this->groupManager = $groupManager;
137
-		$this->userFolder = $userFolder;
138
-		$this->appManager = $appManager;
139
-	}
140
-
141
-	/**
142
-	 * This initializes the plugin.
143
-	 *
144
-	 * This function is called by \Sabre\DAV\Server, after
145
-	 * addPlugin is called.
146
-	 *
147
-	 * This method should set up the required event subscriptions.
148
-	 *
149
-	 * @param \Sabre\DAV\Server $server
150
-	 * @return void
151
-	 */
152
-	public function initialize(\Sabre\DAV\Server $server) {
153
-		$server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc';
154
-
155
-		$this->server = $server;
156
-		$this->server->on('report', [$this, 'onReport']);
157
-	}
158
-
159
-	/**
160
-	 * Returns a list of reports this plugin supports.
161
-	 *
162
-	 * This will be used in the {DAV:}supported-report-set property.
163
-	 *
164
-	 * @param string $uri
165
-	 * @return array
166
-	 */
167
-	public function getSupportedReportSet($uri) {
168
-		return [self::REPORT_NAME];
169
-	}
170
-
171
-	/**
172
-	 * REPORT operations to look for files
173
-	 *
174
-	 * @param string $reportName
175
-	 * @param $report
176
-	 * @param string $uri
177
-	 * @return bool
178
-	 * @throws BadRequest
179
-	 * @throws PreconditionFailed
180
-	 * @internal param $ [] $report
181
-	 */
182
-	public function onReport($reportName, $report, $uri) {
183
-		$reportTargetNode = $this->server->tree->getNodeForPath($uri);
184
-		if (!$reportTargetNode instanceof Directory || $reportName !== self::REPORT_NAME) {
185
-			return;
186
-		}
187
-
188
-		$ns = '{' . $this::NS_OWNCLOUD . '}';
189
-		$requestedProps = [];
190
-		$filterRules = [];
191
-
192
-		// parse report properties and gather filter info
193
-		foreach ($report as $reportProps) {
194
-			$name = $reportProps['name'];
195
-			if ($name === $ns . 'filter-rules') {
196
-				$filterRules = $reportProps['value'];
197
-			} elseif ($name === '{DAV:}prop') {
198
-				// propfind properties
199
-				foreach ($reportProps['value'] as $propVal) {
200
-					$requestedProps[] = $propVal['name'];
201
-				}
202
-			}
203
-		}
204
-
205
-		if (empty($filterRules)) {
206
-			// an empty filter would return all existing files which would be slow
207
-			throw new BadRequest('Missing filter-rule block in request');
208
-		}
209
-
210
-		// gather all file ids matching filter
211
-		try {
212
-			$resultFileIds = $this->processFilterRules($filterRules);
213
-		} catch (TagNotFoundException $e) {
214
-			throw new PreconditionFailed('Cannot filter by non-existing tag', 0, $e);
215
-		}
216
-
217
-		// find sabre nodes by file id, restricted to the root node path
218
-		$results = $this->findNodesByFileIds($reportTargetNode, $resultFileIds);
219
-
220
-		$filesUri = $this->getFilesBaseUri($uri, $reportTargetNode->getPath());
221
-		$responses = $this->prepareResponses($filesUri, $requestedProps, $results);
222
-
223
-		$xml = $this->server->xml->write(
224
-			'{DAV:}multistatus',
225
-			new MultiStatus($responses)
226
-		);
227
-
228
-		$this->server->httpResponse->setStatus(207);
229
-		$this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8');
230
-		$this->server->httpResponse->setBody($xml);
231
-
232
-		return false;
233
-	}
234
-
235
-	/**
236
-	 * Returns the base uri of the files root by removing
237
-	 * the subpath from the URI
238
-	 *
239
-	 * @param string $uri URI from this request
240
-	 * @param string $subPath subpath to remove from the URI
241
-	 *
242
-	 * @return string files base uri
243
-	 */
244
-	private function getFilesBaseUri(string $uri, string $subPath): string {
245
-		$uri = trim($uri, '/');
246
-		$subPath = trim($subPath, '/');
247
-		if (empty($subPath)) {
248
-			$filesUri = $uri;
249
-		} else {
250
-			$filesUri = substr($uri, 0, strlen($uri) - strlen($subPath));
251
-		}
252
-		$filesUri = trim($filesUri, '/');
253
-		if (empty($filesUri)) {
254
-			return '';
255
-		}
256
-		return '/' . $filesUri;
257
-	}
258
-
259
-	/**
260
-	 * Find file ids matching the given filter rules
261
-	 *
262
-	 * @param array $filterRules
263
-	 * @return array array of unique file id results
264
-	 *
265
-	 * @throws TagNotFoundException whenever a tag was not found
266
-	 */
267
-	protected function processFilterRules($filterRules) {
268
-		$ns = '{' . $this::NS_OWNCLOUD . '}';
269
-		$resultFileIds = null;
270
-		$systemTagIds = [];
271
-		$circlesIds = [];
272
-		$favoriteFilter = null;
273
-		foreach ($filterRules as $filterRule) {
274
-			if ($filterRule['name'] === $ns . 'systemtag') {
275
-				$systemTagIds[] = $filterRule['value'];
276
-			}
277
-			if ($filterRule['name'] === self::CIRCLE_PROPERTYNAME) {
278
-				$circlesIds[] = $filterRule['value'];
279
-			}
280
-			if ($filterRule['name'] === $ns . 'favorite') {
281
-				$favoriteFilter = true;
282
-			}
283
-		}
284
-
285
-		if ($favoriteFilter !== null) {
286
-			$resultFileIds = $this->fileTagger->load('files')->getFavorites();
287
-			if (empty($resultFileIds)) {
288
-				return [];
289
-			}
290
-		}
291
-
292
-		if (!empty($systemTagIds)) {
293
-			$fileIds = $this->getSystemTagFileIds($systemTagIds);
294
-			if (empty($resultFileIds)) {
295
-				$resultFileIds = $fileIds;
296
-			} else {
297
-				$resultFileIds = array_intersect($fileIds, $resultFileIds);
298
-			}
299
-		}
300
-
301
-		if (!empty($circlesIds)) {
302
-			$fileIds = $this->getCirclesFileIds($circlesIds);
303
-			if (empty($resultFileIds)) {
304
-				$resultFileIds = $fileIds;
305
-			} else {
306
-				$resultFileIds = array_intersect($fileIds, $resultFileIds);
307
-			}
308
-		}
309
-
310
-		return $resultFileIds;
311
-	}
312
-
313
-	private function getSystemTagFileIds($systemTagIds) {
314
-		$resultFileIds = null;
315
-
316
-		// check user permissions, if applicable
317
-		if (!$this->isAdmin()) {
318
-			// check visibility/permission
319
-			$tags = $this->tagManager->getTagsByIds($systemTagIds);
320
-			$unknownTagIds = [];
321
-			foreach ($tags as $tag) {
322
-				if (!$tag->isUserVisible()) {
323
-					$unknownTagIds[] = $tag->getId();
324
-				}
325
-			}
326
-
327
-			if (!empty($unknownTagIds)) {
328
-				throw new TagNotFoundException('Tag with ids ' . implode(', ', $unknownTagIds) . ' not found');
329
-			}
330
-		}
331
-
332
-		// fetch all file ids and intersect them
333
-		foreach ($systemTagIds as $systemTagId) {
334
-			$fileIds = $this->tagMapper->getObjectIdsForTags($systemTagId, 'files');
335
-
336
-			if (empty($fileIds)) {
337
-				// This tag has no files, nothing can ever show up
338
-				return [];
339
-			}
340
-
341
-			// first run ?
342
-			if ($resultFileIds === null) {
343
-				$resultFileIds = $fileIds;
344
-			} else {
345
-				$resultFileIds = array_intersect($resultFileIds, $fileIds);
346
-			}
347
-
348
-			if (empty($resultFileIds)) {
349
-				// Empty intersection, nothing can show up anymore
350
-				return [];
351
-			}
352
-		}
353
-		return $resultFileIds;
354
-	}
355
-
356
-	/**
357
-	 * @suppress PhanUndeclaredClassMethod
358
-	 * @param array $circlesIds
359
-	 * @return array
360
-	 */
361
-	private function getCirclesFileIds(array $circlesIds) {
362
-		if (!$this->appManager->isEnabledForUser('circles') || !class_exists('\OCA\Circles\Api\v1\Circles')) {
363
-			return [];
364
-		}
365
-		return \OCA\Circles\Api\v1\Circles::getFilesForCircles($circlesIds);
366
-	}
367
-
368
-
369
-	/**
370
-	 * Prepare propfind response for the given nodes
371
-	 *
372
-	 * @param string $filesUri $filesUri URI leading to root of the files URI,
373
-	 * with a leading slash but no trailing slash
374
-	 * @param string[] $requestedProps requested properties
375
-	 * @param Node[] nodes nodes for which to fetch and prepare responses
376
-	 * @return Response[]
377
-	 */
378
-	public function prepareResponses($filesUri, $requestedProps, $nodes) {
379
-		$responses = [];
380
-		foreach ($nodes as $node) {
381
-			$propFind = new PropFind($filesUri . $node->getPath(), $requestedProps);
382
-
383
-			$this->server->getPropertiesByNode($propFind, $node);
384
-			// copied from Sabre Server's getPropertiesForPath
385
-			$result = $propFind->getResultForMultiStatus();
386
-			$result['href'] = $propFind->getPath();
387
-
388
-			$resourceType = $this->server->getResourceTypeForNode($node);
389
-			if (in_array('{DAV:}collection', $resourceType) || in_array('{DAV:}principal', $resourceType)) {
390
-				$result['href'] .= '/';
391
-			}
392
-
393
-			$responses[] = new Response(
394
-				rtrim($this->server->getBaseUri(), '/') . $filesUri . $node->getPath(),
395
-				$result,
396
-				200
397
-			);
398
-		}
399
-		return $responses;
400
-	}
401
-
402
-	/**
403
-	 * Find Sabre nodes by file ids
404
-	 *
405
-	 * @param Node $rootNode root node for search
406
-	 * @param array $fileIds file ids
407
-	 * @return Node[] array of Sabre nodes
408
-	 */
409
-	public function findNodesByFileIds($rootNode, $fileIds) {
410
-		$folder = $this->userFolder;
411
-		if (trim($rootNode->getPath(), '/') !== '') {
412
-			$folder = $folder->get($rootNode->getPath());
413
-		}
414
-
415
-		$results = [];
416
-		foreach ($fileIds as $fileId) {
417
-			$entry = $folder->getById($fileId);
418
-			if ($entry) {
419
-				$entry = current($entry);
420
-				if ($entry instanceof \OCP\Files\File) {
421
-					$results[] = new File($this->fileView, $entry);
422
-				} elseif ($entry instanceof \OCP\Files\Folder) {
423
-					$results[] = new Directory($this->fileView, $entry);
424
-				}
425
-			}
426
-		}
427
-
428
-		return $results;
429
-	}
430
-
431
-	/**
432
-	 * Returns whether the currently logged in user is an administrator
433
-	 */
434
-	private function isAdmin() {
435
-		$user = $this->userSession->getUser();
436
-		if ($user !== null) {
437
-			return $this->groupManager->isAdmin($user->getUID());
438
-		}
439
-		return false;
440
-	}
49
+    // namespace
50
+    public const NS_OWNCLOUD = 'http://owncloud.org/ns';
51
+    public const REPORT_NAME = '{http://owncloud.org/ns}filter-files';
52
+    public const SYSTEMTAG_PROPERTYNAME = '{http://owncloud.org/ns}systemtag';
53
+    public const CIRCLE_PROPERTYNAME = '{http://owncloud.org/ns}circle';
54
+
55
+    /**
56
+     * Reference to main server object
57
+     *
58
+     * @var \Sabre\DAV\Server
59
+     */
60
+    private $server;
61
+
62
+    /**
63
+     * @var Tree
64
+     */
65
+    private $tree;
66
+
67
+    /**
68
+     * @var View
69
+     */
70
+    private $fileView;
71
+
72
+    /**
73
+     * @var ISystemTagManager
74
+     */
75
+    private $tagManager;
76
+
77
+    /**
78
+     * @var ISystemTagObjectMapper
79
+     */
80
+    private $tagMapper;
81
+
82
+    /**
83
+     * Manager for private tags
84
+     *
85
+     * @var ITagManager
86
+     */
87
+    private $fileTagger;
88
+
89
+    /**
90
+     * @var IUserSession
91
+     */
92
+    private $userSession;
93
+
94
+    /**
95
+     * @var IGroupManager
96
+     */
97
+    private $groupManager;
98
+
99
+    /**
100
+     * @var Folder
101
+     */
102
+    private $userFolder;
103
+
104
+    /**
105
+     * @var IAppManager
106
+     */
107
+    private $appManager;
108
+
109
+    /**
110
+     * @param Tree $tree
111
+     * @param View $view
112
+     * @param ISystemTagManager $tagManager
113
+     * @param ISystemTagObjectMapper $tagMapper
114
+     * @param ITagManager $fileTagger manager for private tags
115
+     * @param IUserSession $userSession
116
+     * @param IGroupManager $groupManager
117
+     * @param Folder $userFolder
118
+     * @param IAppManager $appManager
119
+     */
120
+    public function __construct(Tree $tree,
121
+                                View $view,
122
+                                ISystemTagManager $tagManager,
123
+                                ISystemTagObjectMapper $tagMapper,
124
+                                ITagManager $fileTagger,
125
+                                IUserSession $userSession,
126
+                                IGroupManager $groupManager,
127
+                                Folder $userFolder,
128
+                                IAppManager $appManager
129
+    ) {
130
+        $this->tree = $tree;
131
+        $this->fileView = $view;
132
+        $this->tagManager = $tagManager;
133
+        $this->tagMapper = $tagMapper;
134
+        $this->fileTagger = $fileTagger;
135
+        $this->userSession = $userSession;
136
+        $this->groupManager = $groupManager;
137
+        $this->userFolder = $userFolder;
138
+        $this->appManager = $appManager;
139
+    }
140
+
141
+    /**
142
+     * This initializes the plugin.
143
+     *
144
+     * This function is called by \Sabre\DAV\Server, after
145
+     * addPlugin is called.
146
+     *
147
+     * This method should set up the required event subscriptions.
148
+     *
149
+     * @param \Sabre\DAV\Server $server
150
+     * @return void
151
+     */
152
+    public function initialize(\Sabre\DAV\Server $server) {
153
+        $server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc';
154
+
155
+        $this->server = $server;
156
+        $this->server->on('report', [$this, 'onReport']);
157
+    }
158
+
159
+    /**
160
+     * Returns a list of reports this plugin supports.
161
+     *
162
+     * This will be used in the {DAV:}supported-report-set property.
163
+     *
164
+     * @param string $uri
165
+     * @return array
166
+     */
167
+    public function getSupportedReportSet($uri) {
168
+        return [self::REPORT_NAME];
169
+    }
170
+
171
+    /**
172
+     * REPORT operations to look for files
173
+     *
174
+     * @param string $reportName
175
+     * @param $report
176
+     * @param string $uri
177
+     * @return bool
178
+     * @throws BadRequest
179
+     * @throws PreconditionFailed
180
+     * @internal param $ [] $report
181
+     */
182
+    public function onReport($reportName, $report, $uri) {
183
+        $reportTargetNode = $this->server->tree->getNodeForPath($uri);
184
+        if (!$reportTargetNode instanceof Directory || $reportName !== self::REPORT_NAME) {
185
+            return;
186
+        }
187
+
188
+        $ns = '{' . $this::NS_OWNCLOUD . '}';
189
+        $requestedProps = [];
190
+        $filterRules = [];
191
+
192
+        // parse report properties and gather filter info
193
+        foreach ($report as $reportProps) {
194
+            $name = $reportProps['name'];
195
+            if ($name === $ns . 'filter-rules') {
196
+                $filterRules = $reportProps['value'];
197
+            } elseif ($name === '{DAV:}prop') {
198
+                // propfind properties
199
+                foreach ($reportProps['value'] as $propVal) {
200
+                    $requestedProps[] = $propVal['name'];
201
+                }
202
+            }
203
+        }
204
+
205
+        if (empty($filterRules)) {
206
+            // an empty filter would return all existing files which would be slow
207
+            throw new BadRequest('Missing filter-rule block in request');
208
+        }
209
+
210
+        // gather all file ids matching filter
211
+        try {
212
+            $resultFileIds = $this->processFilterRules($filterRules);
213
+        } catch (TagNotFoundException $e) {
214
+            throw new PreconditionFailed('Cannot filter by non-existing tag', 0, $e);
215
+        }
216
+
217
+        // find sabre nodes by file id, restricted to the root node path
218
+        $results = $this->findNodesByFileIds($reportTargetNode, $resultFileIds);
219
+
220
+        $filesUri = $this->getFilesBaseUri($uri, $reportTargetNode->getPath());
221
+        $responses = $this->prepareResponses($filesUri, $requestedProps, $results);
222
+
223
+        $xml = $this->server->xml->write(
224
+            '{DAV:}multistatus',
225
+            new MultiStatus($responses)
226
+        );
227
+
228
+        $this->server->httpResponse->setStatus(207);
229
+        $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8');
230
+        $this->server->httpResponse->setBody($xml);
231
+
232
+        return false;
233
+    }
234
+
235
+    /**
236
+     * Returns the base uri of the files root by removing
237
+     * the subpath from the URI
238
+     *
239
+     * @param string $uri URI from this request
240
+     * @param string $subPath subpath to remove from the URI
241
+     *
242
+     * @return string files base uri
243
+     */
244
+    private function getFilesBaseUri(string $uri, string $subPath): string {
245
+        $uri = trim($uri, '/');
246
+        $subPath = trim($subPath, '/');
247
+        if (empty($subPath)) {
248
+            $filesUri = $uri;
249
+        } else {
250
+            $filesUri = substr($uri, 0, strlen($uri) - strlen($subPath));
251
+        }
252
+        $filesUri = trim($filesUri, '/');
253
+        if (empty($filesUri)) {
254
+            return '';
255
+        }
256
+        return '/' . $filesUri;
257
+    }
258
+
259
+    /**
260
+     * Find file ids matching the given filter rules
261
+     *
262
+     * @param array $filterRules
263
+     * @return array array of unique file id results
264
+     *
265
+     * @throws TagNotFoundException whenever a tag was not found
266
+     */
267
+    protected function processFilterRules($filterRules) {
268
+        $ns = '{' . $this::NS_OWNCLOUD . '}';
269
+        $resultFileIds = null;
270
+        $systemTagIds = [];
271
+        $circlesIds = [];
272
+        $favoriteFilter = null;
273
+        foreach ($filterRules as $filterRule) {
274
+            if ($filterRule['name'] === $ns . 'systemtag') {
275
+                $systemTagIds[] = $filterRule['value'];
276
+            }
277
+            if ($filterRule['name'] === self::CIRCLE_PROPERTYNAME) {
278
+                $circlesIds[] = $filterRule['value'];
279
+            }
280
+            if ($filterRule['name'] === $ns . 'favorite') {
281
+                $favoriteFilter = true;
282
+            }
283
+        }
284
+
285
+        if ($favoriteFilter !== null) {
286
+            $resultFileIds = $this->fileTagger->load('files')->getFavorites();
287
+            if (empty($resultFileIds)) {
288
+                return [];
289
+            }
290
+        }
291
+
292
+        if (!empty($systemTagIds)) {
293
+            $fileIds = $this->getSystemTagFileIds($systemTagIds);
294
+            if (empty($resultFileIds)) {
295
+                $resultFileIds = $fileIds;
296
+            } else {
297
+                $resultFileIds = array_intersect($fileIds, $resultFileIds);
298
+            }
299
+        }
300
+
301
+        if (!empty($circlesIds)) {
302
+            $fileIds = $this->getCirclesFileIds($circlesIds);
303
+            if (empty($resultFileIds)) {
304
+                $resultFileIds = $fileIds;
305
+            } else {
306
+                $resultFileIds = array_intersect($fileIds, $resultFileIds);
307
+            }
308
+        }
309
+
310
+        return $resultFileIds;
311
+    }
312
+
313
+    private function getSystemTagFileIds($systemTagIds) {
314
+        $resultFileIds = null;
315
+
316
+        // check user permissions, if applicable
317
+        if (!$this->isAdmin()) {
318
+            // check visibility/permission
319
+            $tags = $this->tagManager->getTagsByIds($systemTagIds);
320
+            $unknownTagIds = [];
321
+            foreach ($tags as $tag) {
322
+                if (!$tag->isUserVisible()) {
323
+                    $unknownTagIds[] = $tag->getId();
324
+                }
325
+            }
326
+
327
+            if (!empty($unknownTagIds)) {
328
+                throw new TagNotFoundException('Tag with ids ' . implode(', ', $unknownTagIds) . ' not found');
329
+            }
330
+        }
331
+
332
+        // fetch all file ids and intersect them
333
+        foreach ($systemTagIds as $systemTagId) {
334
+            $fileIds = $this->tagMapper->getObjectIdsForTags($systemTagId, 'files');
335
+
336
+            if (empty($fileIds)) {
337
+                // This tag has no files, nothing can ever show up
338
+                return [];
339
+            }
340
+
341
+            // first run ?
342
+            if ($resultFileIds === null) {
343
+                $resultFileIds = $fileIds;
344
+            } else {
345
+                $resultFileIds = array_intersect($resultFileIds, $fileIds);
346
+            }
347
+
348
+            if (empty($resultFileIds)) {
349
+                // Empty intersection, nothing can show up anymore
350
+                return [];
351
+            }
352
+        }
353
+        return $resultFileIds;
354
+    }
355
+
356
+    /**
357
+     * @suppress PhanUndeclaredClassMethod
358
+     * @param array $circlesIds
359
+     * @return array
360
+     */
361
+    private function getCirclesFileIds(array $circlesIds) {
362
+        if (!$this->appManager->isEnabledForUser('circles') || !class_exists('\OCA\Circles\Api\v1\Circles')) {
363
+            return [];
364
+        }
365
+        return \OCA\Circles\Api\v1\Circles::getFilesForCircles($circlesIds);
366
+    }
367
+
368
+
369
+    /**
370
+     * Prepare propfind response for the given nodes
371
+     *
372
+     * @param string $filesUri $filesUri URI leading to root of the files URI,
373
+     * with a leading slash but no trailing slash
374
+     * @param string[] $requestedProps requested properties
375
+     * @param Node[] nodes nodes for which to fetch and prepare responses
376
+     * @return Response[]
377
+     */
378
+    public function prepareResponses($filesUri, $requestedProps, $nodes) {
379
+        $responses = [];
380
+        foreach ($nodes as $node) {
381
+            $propFind = new PropFind($filesUri . $node->getPath(), $requestedProps);
382
+
383
+            $this->server->getPropertiesByNode($propFind, $node);
384
+            // copied from Sabre Server's getPropertiesForPath
385
+            $result = $propFind->getResultForMultiStatus();
386
+            $result['href'] = $propFind->getPath();
387
+
388
+            $resourceType = $this->server->getResourceTypeForNode($node);
389
+            if (in_array('{DAV:}collection', $resourceType) || in_array('{DAV:}principal', $resourceType)) {
390
+                $result['href'] .= '/';
391
+            }
392
+
393
+            $responses[] = new Response(
394
+                rtrim($this->server->getBaseUri(), '/') . $filesUri . $node->getPath(),
395
+                $result,
396
+                200
397
+            );
398
+        }
399
+        return $responses;
400
+    }
401
+
402
+    /**
403
+     * Find Sabre nodes by file ids
404
+     *
405
+     * @param Node $rootNode root node for search
406
+     * @param array $fileIds file ids
407
+     * @return Node[] array of Sabre nodes
408
+     */
409
+    public function findNodesByFileIds($rootNode, $fileIds) {
410
+        $folder = $this->userFolder;
411
+        if (trim($rootNode->getPath(), '/') !== '') {
412
+            $folder = $folder->get($rootNode->getPath());
413
+        }
414
+
415
+        $results = [];
416
+        foreach ($fileIds as $fileId) {
417
+            $entry = $folder->getById($fileId);
418
+            if ($entry) {
419
+                $entry = current($entry);
420
+                if ($entry instanceof \OCP\Files\File) {
421
+                    $results[] = new File($this->fileView, $entry);
422
+                } elseif ($entry instanceof \OCP\Files\Folder) {
423
+                    $results[] = new Directory($this->fileView, $entry);
424
+                }
425
+            }
426
+        }
427
+
428
+        return $results;
429
+    }
430
+
431
+    /**
432
+     * Returns whether the currently logged in user is an administrator
433
+     */
434
+    private function isAdmin() {
435
+        $user = $this->userSession->getUser();
436
+        if ($user !== null) {
437
+            return $this->groupManager->isAdmin($user->getUID());
438
+        }
439
+        return false;
440
+    }
441 441
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/ServerFactory.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -141,7 +141,7 @@
 block discarded – undo
141 141
 		}
142 142
 
143 143
 		// wait with registering these until auth is handled and the filesystem is setup
144
-		$server->on('beforeMethod:*', function () use ($server, $objectTree, $viewCallBack) {
144
+		$server->on('beforeMethod:*', function() use ($server, $objectTree, $viewCallBack) {
145 145
 			// ensure the skeleton is copied
146 146
 			$userFolder = \OC::$server->getUserFolder();
147 147
 
Please login to merge, or discard this patch.
Indentation   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -49,165 +49,165 @@
 block discarded – undo
49 49
 use Symfony\Component\EventDispatcher\EventDispatcherInterface;
50 50
 
51 51
 class ServerFactory {
52
-	private IConfig $config;
53
-	private LoggerInterface $logger;
54
-	private IDBConnection $databaseConnection;
55
-	private IUserSession $userSession;
56
-	private IMountManager $mountManager;
57
-	private ITagManager $tagManager;
58
-	private IRequest $request;
59
-	private IPreview $previewManager;
60
-	private EventDispatcherInterface $eventDispatcher;
61
-	private IL10N $l10n;
52
+    private IConfig $config;
53
+    private LoggerInterface $logger;
54
+    private IDBConnection $databaseConnection;
55
+    private IUserSession $userSession;
56
+    private IMountManager $mountManager;
57
+    private ITagManager $tagManager;
58
+    private IRequest $request;
59
+    private IPreview $previewManager;
60
+    private EventDispatcherInterface $eventDispatcher;
61
+    private IL10N $l10n;
62 62
 
63
-	public function __construct(
64
-		IConfig $config,
65
-		LoggerInterface $logger,
66
-		IDBConnection $databaseConnection,
67
-		IUserSession $userSession,
68
-		IMountManager $mountManager,
69
-		ITagManager $tagManager,
70
-		IRequest $request,
71
-		IPreview $previewManager,
72
-		EventDispatcherInterface $eventDispatcher,
73
-		IL10N $l10n
74
-	) {
75
-		$this->config = $config;
76
-		$this->logger = $logger;
77
-		$this->databaseConnection = $databaseConnection;
78
-		$this->userSession = $userSession;
79
-		$this->mountManager = $mountManager;
80
-		$this->tagManager = $tagManager;
81
-		$this->request = $request;
82
-		$this->previewManager = $previewManager;
83
-		$this->eventDispatcher = $eventDispatcher;
84
-		$this->l10n = $l10n;
85
-	}
63
+    public function __construct(
64
+        IConfig $config,
65
+        LoggerInterface $logger,
66
+        IDBConnection $databaseConnection,
67
+        IUserSession $userSession,
68
+        IMountManager $mountManager,
69
+        ITagManager $tagManager,
70
+        IRequest $request,
71
+        IPreview $previewManager,
72
+        EventDispatcherInterface $eventDispatcher,
73
+        IL10N $l10n
74
+    ) {
75
+        $this->config = $config;
76
+        $this->logger = $logger;
77
+        $this->databaseConnection = $databaseConnection;
78
+        $this->userSession = $userSession;
79
+        $this->mountManager = $mountManager;
80
+        $this->tagManager = $tagManager;
81
+        $this->request = $request;
82
+        $this->previewManager = $previewManager;
83
+        $this->eventDispatcher = $eventDispatcher;
84
+        $this->l10n = $l10n;
85
+    }
86 86
 
87
-	/**
88
-	 * @param callable $viewCallBack callback that should return the view for the dav endpoint
89
-	 */
90
-	public function createServer(string $baseUri,
91
-								 string $requestUri,
92
-								 Plugin $authPlugin,
93
-								 callable $viewCallBack): Server {
94
-		// Fire up server
95
-		$objectTree = new \OCA\DAV\Connector\Sabre\ObjectTree();
96
-		$server = new \OCA\DAV\Connector\Sabre\Server($objectTree);
97
-		// Set URL explicitly due to reverse-proxy situations
98
-		$server->httpRequest->setUrl($requestUri);
99
-		$server->setBaseUri($baseUri);
87
+    /**
88
+     * @param callable $viewCallBack callback that should return the view for the dav endpoint
89
+     */
90
+    public function createServer(string $baseUri,
91
+                                    string $requestUri,
92
+                                    Plugin $authPlugin,
93
+                                    callable $viewCallBack): Server {
94
+        // Fire up server
95
+        $objectTree = new \OCA\DAV\Connector\Sabre\ObjectTree();
96
+        $server = new \OCA\DAV\Connector\Sabre\Server($objectTree);
97
+        // Set URL explicitly due to reverse-proxy situations
98
+        $server->httpRequest->setUrl($requestUri);
99
+        $server->setBaseUri($baseUri);
100 100
 
101
-		// Load plugins
102
-		$server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin($this->config, $this->l10n));
103
-		$server->addPlugin(new \OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin($this->config));
104
-		$server->addPlugin(new \OCA\DAV\Connector\Sabre\AnonymousOptionsPlugin());
105
-		$server->addPlugin($authPlugin);
106
-		// FIXME: The following line is a workaround for legacy components relying on being able to send a GET to /
107
-		$server->addPlugin(new \OCA\DAV\Connector\Sabre\DummyGetResponsePlugin());
108
-		$server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $this->logger));
109
-		$server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin());
101
+        // Load plugins
102
+        $server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin($this->config, $this->l10n));
103
+        $server->addPlugin(new \OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin($this->config));
104
+        $server->addPlugin(new \OCA\DAV\Connector\Sabre\AnonymousOptionsPlugin());
105
+        $server->addPlugin($authPlugin);
106
+        // FIXME: The following line is a workaround for legacy components relying on being able to send a GET to /
107
+        $server->addPlugin(new \OCA\DAV\Connector\Sabre\DummyGetResponsePlugin());
108
+        $server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $this->logger));
109
+        $server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin());
110 110
 
111
-		$server->addPlugin(new RequestIdHeaderPlugin(\OC::$server->get(IRequest::class)));
111
+        $server->addPlugin(new RequestIdHeaderPlugin(\OC::$server->get(IRequest::class)));
112 112
 
113
-		// Some WebDAV clients do require Class 2 WebDAV support (locking), since
114
-		// we do not provide locking we emulate it using a fake locking plugin.
115
-		if ($this->request->isUserAgent([
116
-			'/WebDAVFS/',
117
-			'/OneNote/',
118
-			'/Microsoft-WebDAV-MiniRedir/',
119
-		])) {
120
-			$server->addPlugin(new \OCA\DAV\Connector\Sabre\FakeLockerPlugin());
121
-		}
113
+        // Some WebDAV clients do require Class 2 WebDAV support (locking), since
114
+        // we do not provide locking we emulate it using a fake locking plugin.
115
+        if ($this->request->isUserAgent([
116
+            '/WebDAVFS/',
117
+            '/OneNote/',
118
+            '/Microsoft-WebDAV-MiniRedir/',
119
+        ])) {
120
+            $server->addPlugin(new \OCA\DAV\Connector\Sabre\FakeLockerPlugin());
121
+        }
122 122
 
123
-		if (BrowserErrorPagePlugin::isBrowserRequest($this->request)) {
124
-			$server->addPlugin(new BrowserErrorPagePlugin());
125
-		}
123
+        if (BrowserErrorPagePlugin::isBrowserRequest($this->request)) {
124
+            $server->addPlugin(new BrowserErrorPagePlugin());
125
+        }
126 126
 
127
-		// wait with registering these until auth is handled and the filesystem is setup
128
-		$server->on('beforeMethod:*', function () use ($server, $objectTree, $viewCallBack) {
129
-			// ensure the skeleton is copied
130
-			$userFolder = \OC::$server->getUserFolder();
127
+        // wait with registering these until auth is handled and the filesystem is setup
128
+        $server->on('beforeMethod:*', function () use ($server, $objectTree, $viewCallBack) {
129
+            // ensure the skeleton is copied
130
+            $userFolder = \OC::$server->getUserFolder();
131 131
 
132
-			/** @var \OC\Files\View $view */
133
-			$view = $viewCallBack($server);
134
-			if ($userFolder instanceof Folder && $userFolder->getPath() === $view->getRoot()) {
135
-				$rootInfo = $userFolder;
136
-			} else {
137
-				$rootInfo = $view->getFileInfo('');
138
-			}
132
+            /** @var \OC\Files\View $view */
133
+            $view = $viewCallBack($server);
134
+            if ($userFolder instanceof Folder && $userFolder->getPath() === $view->getRoot()) {
135
+                $rootInfo = $userFolder;
136
+            } else {
137
+                $rootInfo = $view->getFileInfo('');
138
+            }
139 139
 
140
-			// Create Nextcloud Dir
141
-			if ($rootInfo->getType() === 'dir') {
142
-				$root = new \OCA\DAV\Connector\Sabre\Directory($view, $rootInfo, $objectTree);
143
-			} else {
144
-				$root = new \OCA\DAV\Connector\Sabre\File($view, $rootInfo);
145
-			}
146
-			$objectTree->init($root, $view, $this->mountManager);
140
+            // Create Nextcloud Dir
141
+            if ($rootInfo->getType() === 'dir') {
142
+                $root = new \OCA\DAV\Connector\Sabre\Directory($view, $rootInfo, $objectTree);
143
+            } else {
144
+                $root = new \OCA\DAV\Connector\Sabre\File($view, $rootInfo);
145
+            }
146
+            $objectTree->init($root, $view, $this->mountManager);
147 147
 
148
-			$server->addPlugin(
149
-				new \OCA\DAV\Connector\Sabre\FilesPlugin(
150
-					$objectTree,
151
-					$this->config,
152
-					$this->request,
153
-					$this->previewManager,
154
-					$this->userSession,
155
-					false,
156
-					!$this->config->getSystemValue('debug', false)
157
-				)
158
-			);
159
-			$server->addPlugin(new \OCA\DAV\Connector\Sabre\QuotaPlugin($view, true));
160
-			$server->addPlugin(new \OCA\DAV\Connector\Sabre\ChecksumUpdatePlugin());
148
+            $server->addPlugin(
149
+                new \OCA\DAV\Connector\Sabre\FilesPlugin(
150
+                    $objectTree,
151
+                    $this->config,
152
+                    $this->request,
153
+                    $this->previewManager,
154
+                    $this->userSession,
155
+                    false,
156
+                    !$this->config->getSystemValue('debug', false)
157
+                )
158
+            );
159
+            $server->addPlugin(new \OCA\DAV\Connector\Sabre\QuotaPlugin($view, true));
160
+            $server->addPlugin(new \OCA\DAV\Connector\Sabre\ChecksumUpdatePlugin());
161 161
 
162
-			// Allow view-only plugin for webdav requests
163
-			$server->addPlugin(new ViewOnlyPlugin(
164
-				$this->logger
165
-			));
162
+            // Allow view-only plugin for webdav requests
163
+            $server->addPlugin(new ViewOnlyPlugin(
164
+                $this->logger
165
+            ));
166 166
 
167
-			if ($this->userSession->isLoggedIn()) {
168
-				$server->addPlugin(new \OCA\DAV\Connector\Sabre\TagsPlugin($objectTree, $this->tagManager));
169
-				$server->addPlugin(new \OCA\DAV\Connector\Sabre\SharesPlugin(
170
-					$objectTree,
171
-					$this->userSession,
172
-					$userFolder,
173
-					\OC::$server->getShareManager()
174
-				));
175
-				$server->addPlugin(new \OCA\DAV\Connector\Sabre\CommentPropertiesPlugin(\OC::$server->getCommentsManager(), $this->userSession));
176
-				$server->addPlugin(new \OCA\DAV\Connector\Sabre\FilesReportPlugin(
177
-					$objectTree,
178
-					$view,
179
-					\OC::$server->getSystemTagManager(),
180
-					\OC::$server->getSystemTagObjectMapper(),
181
-					\OC::$server->getTagManager(),
182
-					$this->userSession,
183
-					\OC::$server->getGroupManager(),
184
-					$userFolder,
185
-					\OC::$server->getAppManager()
186
-				));
187
-				// custom properties plugin must be the last one
188
-				$server->addPlugin(
189
-					new \Sabre\DAV\PropertyStorage\Plugin(
190
-						new \OCA\DAV\DAV\CustomPropertiesBackend(
191
-							$objectTree,
192
-							$this->databaseConnection,
193
-							$this->userSession->getUser()
194
-						)
195
-					)
196
-				);
197
-			}
198
-			$server->addPlugin(new \OCA\DAV\Connector\Sabre\CopyEtagHeaderPlugin());
167
+            if ($this->userSession->isLoggedIn()) {
168
+                $server->addPlugin(new \OCA\DAV\Connector\Sabre\TagsPlugin($objectTree, $this->tagManager));
169
+                $server->addPlugin(new \OCA\DAV\Connector\Sabre\SharesPlugin(
170
+                    $objectTree,
171
+                    $this->userSession,
172
+                    $userFolder,
173
+                    \OC::$server->getShareManager()
174
+                ));
175
+                $server->addPlugin(new \OCA\DAV\Connector\Sabre\CommentPropertiesPlugin(\OC::$server->getCommentsManager(), $this->userSession));
176
+                $server->addPlugin(new \OCA\DAV\Connector\Sabre\FilesReportPlugin(
177
+                    $objectTree,
178
+                    $view,
179
+                    \OC::$server->getSystemTagManager(),
180
+                    \OC::$server->getSystemTagObjectMapper(),
181
+                    \OC::$server->getTagManager(),
182
+                    $this->userSession,
183
+                    \OC::$server->getGroupManager(),
184
+                    $userFolder,
185
+                    \OC::$server->getAppManager()
186
+                ));
187
+                // custom properties plugin must be the last one
188
+                $server->addPlugin(
189
+                    new \Sabre\DAV\PropertyStorage\Plugin(
190
+                        new \OCA\DAV\DAV\CustomPropertiesBackend(
191
+                            $objectTree,
192
+                            $this->databaseConnection,
193
+                            $this->userSession->getUser()
194
+                        )
195
+                    )
196
+                );
197
+            }
198
+            $server->addPlugin(new \OCA\DAV\Connector\Sabre\CopyEtagHeaderPlugin());
199 199
 
200
-			// Load dav plugins from apps
201
-			$event = new SabrePluginEvent($server);
202
-			$this->eventDispatcher->dispatch($event);
203
-			$pluginManager = new PluginManager(
204
-				\OC::$server,
205
-				\OC::$server->getAppManager()
206
-			);
207
-			foreach ($pluginManager->getAppPlugins() as $appPlugin) {
208
-				$server->addPlugin($appPlugin);
209
-			}
210
-		}, 30); // priority 30: after auth (10) and acl(20), before lock(50) and handling the request
211
-		return $server;
212
-	}
200
+            // Load dav plugins from apps
201
+            $event = new SabrePluginEvent($server);
202
+            $this->eventDispatcher->dispatch($event);
203
+            $pluginManager = new PluginManager(
204
+                \OC::$server,
205
+                \OC::$server->getAppManager()
206
+            );
207
+            foreach ($pluginManager->getAppPlugins() as $appPlugin) {
208
+                $server->addPlugin($appPlugin);
209
+            }
210
+        }, 30); // priority 30: after auth (10) and acl(20), before lock(50) and handling the request
211
+        return $server;
212
+    }
213 213
 }
Please login to merge, or discard this patch.
apps/dav/lib/Provisioning/Apple/AppleProvisioningPlugin.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 	 * @return boolean
107 107
 	 */
108 108
 	public function httpGet(RequestInterface $request, ResponseInterface $response):bool {
109
-		if ($request->getPath() !== 'provisioning/' . AppleProvisioningNode::FILENAME) {
109
+		if ($request->getPath() !== 'provisioning/'.AppleProvisioningNode::FILENAME) {
110 110
 			return true;
111 111
 		}
112 112
 
@@ -144,19 +144,19 @@  discard block
 block discarded – undo
144 144
 		$carddavUUID = call_user_func($this->uuidClosure);
145 145
 		$profileUUID = call_user_func($this->uuidClosure);
146 146
 
147
-		$caldavIdentifier = $reverseDomain . '.' . $caldavUUID;
148
-		$carddavIdentifier = $reverseDomain . '.' . $carddavUUID;
149
-		$profileIdentifier = $reverseDomain . '.' . $profileUUID;
147
+		$caldavIdentifier = $reverseDomain.'.'.$caldavUUID;
148
+		$carddavIdentifier = $reverseDomain.'.'.$carddavUUID;
149
+		$profileIdentifier = $reverseDomain.'.'.$profileUUID;
150 150
 
151 151
 		$caldavDescription = $this->l10n->t('Configures a CalDAV account');
152
-		$caldavDisplayname = $description . ' CalDAV';
152
+		$caldavDisplayname = $description.' CalDAV';
153 153
 		$carddavDescription = $this->l10n->t('Configures a CardDAV account');
154
-		$carddavDisplayname = $description . ' CardDAV';
154
+		$carddavDisplayname = $description.' CardDAV';
155 155
 
156
-		$filename = $userId . '-' . AppleProvisioningNode::FILENAME;
156
+		$filename = $userId.'-'.AppleProvisioningNode::FILENAME;
157 157
 
158 158
 		$xmlSkeleton = $this->getTemplate();
159
-		$body = vsprintf($xmlSkeleton, array_map(function ($v) {
159
+		$body = vsprintf($xmlSkeleton, array_map(function($v) {
160 160
 			return \htmlspecialchars($v, ENT_XML1, 'UTF-8');
161 161
 		}, [
162 162
 			$description,
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 		));
183 183
 
184 184
 		$response->setStatus(200);
185
-		$response->setHeader('Content-Disposition', 'attachment; filename="' . $filename . '"');
185
+		$response->setHeader('Content-Disposition', 'attachment; filename="'.$filename.'"');
186 186
 		$response->setHeader('Content-Type', 'application/xml; charset=utf-8');
187 187
 		$response->setBody($body);
188 188
 
Please login to merge, or discard this patch.
Indentation   +133 added lines, -133 removed lines patch added patch discarded remove patch
@@ -36,162 +36,162 @@  discard block
 block discarded – undo
36 36
 use Sabre\HTTP\ResponseInterface;
37 37
 
38 38
 class AppleProvisioningPlugin extends ServerPlugin {
39
-	/**
40
-	 * @var Server
41
-	 */
42
-	protected $server;
39
+    /**
40
+     * @var Server
41
+     */
42
+    protected $server;
43 43
 
44
-	/**
45
-	 * @var IURLGenerator
46
-	 */
47
-	protected $urlGenerator;
44
+    /**
45
+     * @var IURLGenerator
46
+     */
47
+    protected $urlGenerator;
48 48
 
49
-	/**
50
-	 * @var IUserSession
51
-	 */
52
-	protected $userSession;
49
+    /**
50
+     * @var IUserSession
51
+     */
52
+    protected $userSession;
53 53
 
54
-	/**
55
-	 * @var \OC_Defaults
56
-	 */
57
-	protected $themingDefaults;
54
+    /**
55
+     * @var \OC_Defaults
56
+     */
57
+    protected $themingDefaults;
58 58
 
59
-	/**
60
-	 * @var IRequest
61
-	 */
62
-	protected $request;
59
+    /**
60
+     * @var IRequest
61
+     */
62
+    protected $request;
63 63
 
64
-	/**
65
-	 * @var IL10N
66
-	 */
67
-	protected $l10n;
64
+    /**
65
+     * @var IL10N
66
+     */
67
+    protected $l10n;
68 68
 
69
-	/**
70
-	 * @var \Closure
71
-	 */
72
-	protected $uuidClosure;
69
+    /**
70
+     * @var \Closure
71
+     */
72
+    protected $uuidClosure;
73 73
 
74
-	/**
75
-	 * AppleProvisioningPlugin constructor.
76
-	 */
77
-	public function __construct(
78
-		IUserSession $userSession,
79
-		IURLGenerator $urlGenerator,
80
-		\OC_Defaults $themingDefaults,
81
-		IRequest $request,
82
-		IL10N $l10n,
83
-		\Closure $uuidClosure
84
-	) {
85
-		$this->userSession = $userSession;
86
-		$this->urlGenerator = $urlGenerator;
87
-		$this->themingDefaults = $themingDefaults;
88
-		$this->request = $request;
89
-		$this->l10n = $l10n;
90
-		$this->uuidClosure = $uuidClosure;
91
-	}
74
+    /**
75
+     * AppleProvisioningPlugin constructor.
76
+     */
77
+    public function __construct(
78
+        IUserSession $userSession,
79
+        IURLGenerator $urlGenerator,
80
+        \OC_Defaults $themingDefaults,
81
+        IRequest $request,
82
+        IL10N $l10n,
83
+        \Closure $uuidClosure
84
+    ) {
85
+        $this->userSession = $userSession;
86
+        $this->urlGenerator = $urlGenerator;
87
+        $this->themingDefaults = $themingDefaults;
88
+        $this->request = $request;
89
+        $this->l10n = $l10n;
90
+        $this->uuidClosure = $uuidClosure;
91
+    }
92 92
 
93
-	/**
94
-	 * @param Server $server
95
-	 */
96
-	public function initialize(Server $server) {
97
-		$this->server = $server;
98
-		$this->server->on('method:GET', [$this, 'httpGet'], 90);
99
-	}
93
+    /**
94
+     * @param Server $server
95
+     */
96
+    public function initialize(Server $server) {
97
+        $this->server = $server;
98
+        $this->server->on('method:GET', [$this, 'httpGet'], 90);
99
+    }
100 100
 
101
-	/**
102
-	 * @param RequestInterface $request
103
-	 * @param ResponseInterface $response
104
-	 * @return boolean
105
-	 */
106
-	public function httpGet(RequestInterface $request, ResponseInterface $response):bool {
107
-		if ($request->getPath() !== 'provisioning/' . AppleProvisioningNode::FILENAME) {
108
-			return true;
109
-		}
101
+    /**
102
+     * @param RequestInterface $request
103
+     * @param ResponseInterface $response
104
+     * @return boolean
105
+     */
106
+    public function httpGet(RequestInterface $request, ResponseInterface $response):bool {
107
+        if ($request->getPath() !== 'provisioning/' . AppleProvisioningNode::FILENAME) {
108
+            return true;
109
+        }
110 110
 
111
-		$user = $this->userSession->getUser();
112
-		if (!$user) {
113
-			return true;
114
-		}
111
+        $user = $this->userSession->getUser();
112
+        if (!$user) {
113
+            return true;
114
+        }
115 115
 
116
-		$serverProtocol = $this->request->getServerProtocol();
117
-		$useSSL = ($serverProtocol === 'https');
116
+        $serverProtocol = $this->request->getServerProtocol();
117
+        $useSSL = ($serverProtocol === 'https');
118 118
 
119
-		if (!$useSSL) {
120
-			$response->setStatus(200);
121
-			$response->setHeader('Content-Type', 'text/plain; charset=utf-8');
122
-			$response->setBody($this->l10n->t('Your %s needs to be configured to use HTTPS in order to use CalDAV and CardDAV with iOS/macOS.', [$this->themingDefaults->getName()]));
119
+        if (!$useSSL) {
120
+            $response->setStatus(200);
121
+            $response->setHeader('Content-Type', 'text/plain; charset=utf-8');
122
+            $response->setBody($this->l10n->t('Your %s needs to be configured to use HTTPS in order to use CalDAV and CardDAV with iOS/macOS.', [$this->themingDefaults->getName()]));
123 123
 
124
-			return false;
125
-		}
124
+            return false;
125
+        }
126 126
 
127
-		$absoluteURL = $this->urlGenerator->getBaseUrl();
128
-		$parsedUrl = parse_url($absoluteURL);
129
-		if (isset($parsedUrl['port'])) {
130
-			$serverPort = $parsedUrl['port'];
131
-		} else {
132
-			$serverPort = 443;
133
-		}
134
-		$server_url = $parsedUrl['host'];
127
+        $absoluteURL = $this->urlGenerator->getBaseUrl();
128
+        $parsedUrl = parse_url($absoluteURL);
129
+        if (isset($parsedUrl['port'])) {
130
+            $serverPort = $parsedUrl['port'];
131
+        } else {
132
+            $serverPort = 443;
133
+        }
134
+        $server_url = $parsedUrl['host'];
135 135
 
136
-		$description = $this->themingDefaults->getName();
137
-		$userId = $user->getUID();
136
+        $description = $this->themingDefaults->getName();
137
+        $userId = $user->getUID();
138 138
 
139
-		$reverseDomain = implode('.', array_reverse(explode('.', $parsedUrl['host'])));
139
+        $reverseDomain = implode('.', array_reverse(explode('.', $parsedUrl['host'])));
140 140
 
141
-		$caldavUUID = call_user_func($this->uuidClosure);
142
-		$carddavUUID = call_user_func($this->uuidClosure);
143
-		$profileUUID = call_user_func($this->uuidClosure);
141
+        $caldavUUID = call_user_func($this->uuidClosure);
142
+        $carddavUUID = call_user_func($this->uuidClosure);
143
+        $profileUUID = call_user_func($this->uuidClosure);
144 144
 
145
-		$caldavIdentifier = $reverseDomain . '.' . $caldavUUID;
146
-		$carddavIdentifier = $reverseDomain . '.' . $carddavUUID;
147
-		$profileIdentifier = $reverseDomain . '.' . $profileUUID;
145
+        $caldavIdentifier = $reverseDomain . '.' . $caldavUUID;
146
+        $carddavIdentifier = $reverseDomain . '.' . $carddavUUID;
147
+        $profileIdentifier = $reverseDomain . '.' . $profileUUID;
148 148
 
149
-		$caldavDescription = $this->l10n->t('Configures a CalDAV account');
150
-		$caldavDisplayname = $description . ' CalDAV';
151
-		$carddavDescription = $this->l10n->t('Configures a CardDAV account');
152
-		$carddavDisplayname = $description . ' CardDAV';
149
+        $caldavDescription = $this->l10n->t('Configures a CalDAV account');
150
+        $caldavDisplayname = $description . ' CalDAV';
151
+        $carddavDescription = $this->l10n->t('Configures a CardDAV account');
152
+        $carddavDisplayname = $description . ' CardDAV';
153 153
 
154
-		$filename = $userId . '-' . AppleProvisioningNode::FILENAME;
154
+        $filename = $userId . '-' . AppleProvisioningNode::FILENAME;
155 155
 
156
-		$xmlSkeleton = $this->getTemplate();
157
-		$body = vsprintf($xmlSkeleton, array_map(function ($v) {
158
-			return \htmlspecialchars($v, ENT_XML1, 'UTF-8');
159
-		}, [
160
-			$description,
161
-			$server_url,
162
-			$userId,
163
-			$serverPort,
164
-			$caldavDescription,
165
-			$caldavDisplayname,
166
-			$caldavIdentifier,
167
-			$caldavUUID,
168
-			$description,
169
-			$server_url,
170
-			$userId,
171
-			$serverPort,
172
-			$carddavDescription,
173
-			$carddavDisplayname,
174
-			$carddavIdentifier,
175
-			$carddavUUID,
176
-			$description,
177
-			$profileIdentifier,
178
-			$profileUUID
179
-		]
180
-		));
156
+        $xmlSkeleton = $this->getTemplate();
157
+        $body = vsprintf($xmlSkeleton, array_map(function ($v) {
158
+            return \htmlspecialchars($v, ENT_XML1, 'UTF-8');
159
+        }, [
160
+            $description,
161
+            $server_url,
162
+            $userId,
163
+            $serverPort,
164
+            $caldavDescription,
165
+            $caldavDisplayname,
166
+            $caldavIdentifier,
167
+            $caldavUUID,
168
+            $description,
169
+            $server_url,
170
+            $userId,
171
+            $serverPort,
172
+            $carddavDescription,
173
+            $carddavDisplayname,
174
+            $carddavIdentifier,
175
+            $carddavUUID,
176
+            $description,
177
+            $profileIdentifier,
178
+            $profileUUID
179
+        ]
180
+        ));
181 181
 
182
-		$response->setStatus(200);
183
-		$response->setHeader('Content-Disposition', 'attachment; filename="' . $filename . '"');
184
-		$response->setHeader('Content-Type', 'application/xml; charset=utf-8');
185
-		$response->setBody($body);
182
+        $response->setStatus(200);
183
+        $response->setHeader('Content-Disposition', 'attachment; filename="' . $filename . '"');
184
+        $response->setHeader('Content-Type', 'application/xml; charset=utf-8');
185
+        $response->setBody($body);
186 186
 
187
-		return false;
188
-	}
187
+        return false;
188
+    }
189 189
 
190
-	/**
191
-	 * @return string
192
-	 */
193
-	private function getTemplate():string {
194
-		return <<<EOF
190
+    /**
191
+     * @return string
192
+     */
193
+    private function getTemplate():string {
194
+        return <<<EOF
195 195
 <?xml version="1.0" encoding="UTF-8"?>
196 196
 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
197 197
 <plist version="1.0">
@@ -263,5 +263,5 @@  discard block
 block discarded – undo
263 263
 </plist>
264 264
 
265 265
 EOF;
266
-	}
266
+    }
267 267
 }
Please login to merge, or discard this patch.
apps/dav/lib/CalDAV/Integration/ExternalCalendar.php 1 patch
Indentation   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -33,99 +33,99 @@
 block discarded – undo
33 33
  */
34 34
 abstract class ExternalCalendar implements CalDAV\ICalendar, DAV\IProperties {
35 35
 
36
-	/** @var string */
37
-	private const PREFIX = 'app-generated';
36
+    /** @var string */
37
+    private const PREFIX = 'app-generated';
38 38
 
39
-	/**
40
-	 * @var string
41
-	 *
42
-	 * Double dash is a valid delimiter,
43
-	 * because it will always split the calendarURIs correctly:
44
-	 * - our prefix contains only one dash and won't be split
45
-	 * - appIds are not allowed to contain dashes as per spec:
46
-	 * > must contain only lowercase ASCII characters and underscore
47
-	 * - explode has a limit of three, so even if the app-generated
48
-	 *   calendar uri has double dashes, it won't be split
49
-	 */
50
-	private const DELIMITER = '--';
39
+    /**
40
+     * @var string
41
+     *
42
+     * Double dash is a valid delimiter,
43
+     * because it will always split the calendarURIs correctly:
44
+     * - our prefix contains only one dash and won't be split
45
+     * - appIds are not allowed to contain dashes as per spec:
46
+     * > must contain only lowercase ASCII characters and underscore
47
+     * - explode has a limit of three, so even if the app-generated
48
+     *   calendar uri has double dashes, it won't be split
49
+     */
50
+    private const DELIMITER = '--';
51 51
 
52
-	/** @var string */
53
-	private $appId;
52
+    /** @var string */
53
+    private $appId;
54 54
 
55
-	/** @var string */
56
-	private $calendarUri;
55
+    /** @var string */
56
+    private $calendarUri;
57 57
 
58
-	/**
59
-	 * ExternalCalendar constructor.
60
-	 *
61
-	 * @param string $appId
62
-	 * @param string $calendarUri
63
-	 */
64
-	public function __construct(string $appId, string $calendarUri) {
65
-		$this->appId = $appId;
66
-		$this->calendarUri = $calendarUri;
67
-	}
58
+    /**
59
+     * ExternalCalendar constructor.
60
+     *
61
+     * @param string $appId
62
+     * @param string $calendarUri
63
+     */
64
+    public function __construct(string $appId, string $calendarUri) {
65
+        $this->appId = $appId;
66
+        $this->calendarUri = $calendarUri;
67
+    }
68 68
 
69
-	/**
70
-	 * @inheritDoc
71
-	 */
72
-	final public function getName() {
73
-		return implode(self::DELIMITER, [
74
-			self::PREFIX,
75
-			$this->appId,
76
-			$this->calendarUri,
77
-		]);
78
-	}
69
+    /**
70
+     * @inheritDoc
71
+     */
72
+    final public function getName() {
73
+        return implode(self::DELIMITER, [
74
+            self::PREFIX,
75
+            $this->appId,
76
+            $this->calendarUri,
77
+        ]);
78
+    }
79 79
 
80
-	/**
81
-	 * @inheritDoc
82
-	 */
83
-	final public function setName($name) {
84
-		throw new DAV\Exception\MethodNotAllowed('Renaming calendars is not yet supported');
85
-	}
80
+    /**
81
+     * @inheritDoc
82
+     */
83
+    final public function setName($name) {
84
+        throw new DAV\Exception\MethodNotAllowed('Renaming calendars is not yet supported');
85
+    }
86 86
 
87
-	/**
88
-	 * @inheritDoc
89
-	 */
90
-	final public function createDirectory($name) {
91
-		throw new DAV\Exception\MethodNotAllowed('Creating collections in calendar objects is not allowed');
92
-	}
87
+    /**
88
+     * @inheritDoc
89
+     */
90
+    final public function createDirectory($name) {
91
+        throw new DAV\Exception\MethodNotAllowed('Creating collections in calendar objects is not allowed');
92
+    }
93 93
 
94
-	/**
95
-	 * Checks whether the calendar uri is app-generated
96
-	 *
97
-	 * @param string $calendarUri
98
-	 * @return bool
99
-	 */
100
-	public static function isAppGeneratedCalendar(string $calendarUri):bool {
101
-		return strpos($calendarUri, self::PREFIX) === 0 && substr_count($calendarUri, self::DELIMITER) >= 2;
102
-	}
94
+    /**
95
+     * Checks whether the calendar uri is app-generated
96
+     *
97
+     * @param string $calendarUri
98
+     * @return bool
99
+     */
100
+    public static function isAppGeneratedCalendar(string $calendarUri):bool {
101
+        return strpos($calendarUri, self::PREFIX) === 0 && substr_count($calendarUri, self::DELIMITER) >= 2;
102
+    }
103 103
 
104
-	/**
105
-	 * Splits an app-generated calendar-uri into appId and calendarUri
106
-	 *
107
-	 * @param string $calendarUri
108
-	 * @return array
109
-	 */
110
-	public static function splitAppGeneratedCalendarUri(string $calendarUri):array {
111
-		$array = array_slice(explode(self::DELIMITER, $calendarUri, 3), 1);
112
-		// Check the array has expected amount of elements
113
-		// and none of them is an empty string
114
-		if (\count($array) !== 2 || \in_array('', $array, true)) {
115
-			throw new \InvalidArgumentException('Provided calendar uri was not app-generated');
116
-		}
104
+    /**
105
+     * Splits an app-generated calendar-uri into appId and calendarUri
106
+     *
107
+     * @param string $calendarUri
108
+     * @return array
109
+     */
110
+    public static function splitAppGeneratedCalendarUri(string $calendarUri):array {
111
+        $array = array_slice(explode(self::DELIMITER, $calendarUri, 3), 1);
112
+        // Check the array has expected amount of elements
113
+        // and none of them is an empty string
114
+        if (\count($array) !== 2 || \in_array('', $array, true)) {
115
+            throw new \InvalidArgumentException('Provided calendar uri was not app-generated');
116
+        }
117 117
 
118
-		return $array;
119
-	}
118
+        return $array;
119
+    }
120 120
 
121
-	/**
122
-	 * Checks whether a calendar-name, the user wants to create, violates
123
-	 * the reserved name for calendar uris
124
-	 *
125
-	 * @param string $calendarUri
126
-	 * @return bool
127
-	 */
128
-	public static function doesViolateReservedName(string $calendarUri):bool {
129
-		return strpos($calendarUri, self::PREFIX) === 0;
130
-	}
121
+    /**
122
+     * Checks whether a calendar-name, the user wants to create, violates
123
+     * the reserved name for calendar uris
124
+     *
125
+     * @param string $calendarUri
126
+     * @return bool
127
+     */
128
+    public static function doesViolateReservedName(string $calendarUri):bool {
129
+        return strpos($calendarUri, self::PREFIX) === 0;
130
+    }
131 131
 }
Please login to merge, or discard this patch.
apps/dav/lib/CalDAV/CachedSubscription.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -60,16 +60,16 @@  discard block
 block discarded – undo
60 60
 			],
61 61
 			[
62 62
 				'privilege' => '{DAV:}read',
63
-				'principal' => $this->getOwner() . '/calendar-proxy-write',
63
+				'principal' => $this->getOwner().'/calendar-proxy-write',
64 64
 				'protected' => true,
65 65
 			],
66 66
 			[
67 67
 				'privilege' => '{DAV:}read',
68
-				'principal' => $this->getOwner() . '/calendar-proxy-read',
68
+				'principal' => $this->getOwner().'/calendar-proxy-read',
69 69
 				'protected' => true,
70 70
 			],
71 71
 			[
72
-				'privilege' => '{' . Plugin::NS_CALDAV . '}read-free-busy',
72
+				'privilege' => '{'.Plugin::NS_CALDAV.'}read-free-busy',
73 73
 				'principal' => '{DAV:}authenticated',
74 74
 				'protected' => true,
75 75
 			],
@@ -89,12 +89,12 @@  discard block
 block discarded – undo
89 89
 
90 90
 			[
91 91
 				'privilege' => '{DAV:}read',
92
-				'principal' => $this->getOwner() . '/calendar-proxy-write',
92
+				'principal' => $this->getOwner().'/calendar-proxy-write',
93 93
 				'protected' => true,
94 94
 			],
95 95
 			[
96 96
 				'privilege' => '{DAV:}read',
97
-				'principal' => $this->getOwner() . '/calendar-proxy-read',
97
+				'principal' => $this->getOwner().'/calendar-proxy-read',
98 98
 				'protected' => true,
99 99
 			],
100 100
 
Please login to merge, or discard this patch.
Indentation   +165 added lines, -165 removed lines patch added patch discarded remove patch
@@ -42,171 +42,171 @@
 block discarded – undo
42 42
  */
43 43
 class CachedSubscription extends \Sabre\CalDAV\Calendar {
44 44
 
45
-	/**
46
-	 * @return string
47
-	 */
48
-	public function getPrincipalURI():string {
49
-		return $this->calendarInfo['principaluri'];
50
-	}
51
-
52
-	/**
53
-	 * @return array
54
-	 */
55
-	public function getACL() {
56
-		return [
57
-			[
58
-				'privilege' => '{DAV:}read',
59
-				'principal' => $this->getOwner(),
60
-				'protected' => true,
61
-			],
62
-			[
63
-				'privilege' => '{DAV:}read',
64
-				'principal' => $this->getOwner() . '/calendar-proxy-write',
65
-				'protected' => true,
66
-			],
67
-			[
68
-				'privilege' => '{DAV:}read',
69
-				'principal' => $this->getOwner() . '/calendar-proxy-read',
70
-				'protected' => true,
71
-			],
72
-			[
73
-				'privilege' => '{' . Plugin::NS_CALDAV . '}read-free-busy',
74
-				'principal' => '{DAV:}authenticated',
75
-				'protected' => true,
76
-			],
77
-		];
78
-	}
79
-
80
-	/**
81
-	 * @return array
82
-	 */
83
-	public function getChildACL() {
84
-		return [
85
-			[
86
-				'privilege' => '{DAV:}read',
87
-				'principal' => $this->getOwner(),
88
-				'protected' => true,
89
-			],
90
-
91
-			[
92
-				'privilege' => '{DAV:}read',
93
-				'principal' => $this->getOwner() . '/calendar-proxy-write',
94
-				'protected' => true,
95
-			],
96
-			[
97
-				'privilege' => '{DAV:}read',
98
-				'principal' => $this->getOwner() . '/calendar-proxy-read',
99
-				'protected' => true,
100
-			],
101
-
102
-		];
103
-	}
104
-
105
-	/**
106
-	 * @return null|string
107
-	 */
108
-	public function getOwner() {
109
-		if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
110
-			return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'];
111
-		}
112
-		return parent::getOwner();
113
-	}
45
+    /**
46
+     * @return string
47
+     */
48
+    public function getPrincipalURI():string {
49
+        return $this->calendarInfo['principaluri'];
50
+    }
51
+
52
+    /**
53
+     * @return array
54
+     */
55
+    public function getACL() {
56
+        return [
57
+            [
58
+                'privilege' => '{DAV:}read',
59
+                'principal' => $this->getOwner(),
60
+                'protected' => true,
61
+            ],
62
+            [
63
+                'privilege' => '{DAV:}read',
64
+                'principal' => $this->getOwner() . '/calendar-proxy-write',
65
+                'protected' => true,
66
+            ],
67
+            [
68
+                'privilege' => '{DAV:}read',
69
+                'principal' => $this->getOwner() . '/calendar-proxy-read',
70
+                'protected' => true,
71
+            ],
72
+            [
73
+                'privilege' => '{' . Plugin::NS_CALDAV . '}read-free-busy',
74
+                'principal' => '{DAV:}authenticated',
75
+                'protected' => true,
76
+            ],
77
+        ];
78
+    }
79
+
80
+    /**
81
+     * @return array
82
+     */
83
+    public function getChildACL() {
84
+        return [
85
+            [
86
+                'privilege' => '{DAV:}read',
87
+                'principal' => $this->getOwner(),
88
+                'protected' => true,
89
+            ],
90
+
91
+            [
92
+                'privilege' => '{DAV:}read',
93
+                'principal' => $this->getOwner() . '/calendar-proxy-write',
94
+                'protected' => true,
95
+            ],
96
+            [
97
+                'privilege' => '{DAV:}read',
98
+                'principal' => $this->getOwner() . '/calendar-proxy-read',
99
+                'protected' => true,
100
+            ],
101
+
102
+        ];
103
+    }
104
+
105
+    /**
106
+     * @return null|string
107
+     */
108
+    public function getOwner() {
109
+        if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
110
+            return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'];
111
+        }
112
+        return parent::getOwner();
113
+    }
114 114
 
115 115
 	
116
-	public function delete() {
117
-		$this->caldavBackend->deleteSubscription($this->calendarInfo['id']);
118
-	}
119
-
120
-	/**
121
-	 * @param PropPatch $propPatch
122
-	 */
123
-	public function propPatch(PropPatch $propPatch) {
124
-		$this->caldavBackend->updateSubscription($this->calendarInfo['id'], $propPatch);
125
-	}
126
-
127
-	/**
128
-	 * @param string $name
129
-	 * @return CalendarObject|\Sabre\CalDAV\ICalendarObject
130
-	 * @throws NotFound
131
-	 */
132
-	public function getChild($name) {
133
-		$obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);
134
-		if (!$obj) {
135
-			throw new NotFound('Calendar object not found');
136
-		}
137
-
138
-		$obj['acl'] = $this->getChildACL();
139
-		return new CachedSubscriptionObject($this->caldavBackend, $this->calendarInfo, $obj);
140
-	}
141
-
142
-	/**
143
-	 * @return INode[]
144
-	 */
145
-	public function getChildren(): array {
146
-		$objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id'], CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);
147
-
148
-		$children = [];
149
-		foreach ($objs as $obj) {
150
-			$children[] = new CachedSubscriptionObject($this->caldavBackend, $this->calendarInfo, $obj);
151
-		}
152
-
153
-		return $children;
154
-	}
155
-
156
-	/**
157
-	 * @param array $paths
158
-	 * @return array
159
-	 */
160
-	public function getMultipleChildren(array $paths):array {
161
-		$objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);
162
-
163
-		$children = [];
164
-		foreach ($objs as $obj) {
165
-			$children[] = new CachedSubscriptionObject($this->caldavBackend, $this->calendarInfo, $obj);
166
-		}
167
-
168
-		return $children;
169
-	}
170
-
171
-	/**
172
-	 * @param string $name
173
-	 * @param null|resource|string $calendarData
174
-	 * @return null|string
175
-	 * @throws MethodNotAllowed
176
-	 */
177
-	public function createFile($name, $calendarData = null) {
178
-		throw new MethodNotAllowed('Creating objects in cached subscription is not allowed');
179
-	}
180
-
181
-	/**
182
-	 * @param string $name
183
-	 * @return bool
184
-	 */
185
-	public function childExists($name):bool {
186
-		$obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);
187
-		if (!$obj) {
188
-			return false;
189
-		}
190
-
191
-		return true;
192
-	}
193
-
194
-	/**
195
-	 * @param array $filters
196
-	 * @return array
197
-	 */
198
-	public function calendarQuery(array $filters):array {
199
-		return $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);
200
-	}
201
-
202
-	/**
203
-	 * @inheritDoc
204
-	 */
205
-	public function getChanges($syncToken, $syncLevel, $limit = null) {
206
-		if (!$syncToken && $limit) {
207
-			throw new UnsupportedLimitOnInitialSyncException();
208
-		}
209
-
210
-		return parent::getChanges($syncToken, $syncLevel, $limit);
211
-	}
116
+    public function delete() {
117
+        $this->caldavBackend->deleteSubscription($this->calendarInfo['id']);
118
+    }
119
+
120
+    /**
121
+     * @param PropPatch $propPatch
122
+     */
123
+    public function propPatch(PropPatch $propPatch) {
124
+        $this->caldavBackend->updateSubscription($this->calendarInfo['id'], $propPatch);
125
+    }
126
+
127
+    /**
128
+     * @param string $name
129
+     * @return CalendarObject|\Sabre\CalDAV\ICalendarObject
130
+     * @throws NotFound
131
+     */
132
+    public function getChild($name) {
133
+        $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);
134
+        if (!$obj) {
135
+            throw new NotFound('Calendar object not found');
136
+        }
137
+
138
+        $obj['acl'] = $this->getChildACL();
139
+        return new CachedSubscriptionObject($this->caldavBackend, $this->calendarInfo, $obj);
140
+    }
141
+
142
+    /**
143
+     * @return INode[]
144
+     */
145
+    public function getChildren(): array {
146
+        $objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id'], CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);
147
+
148
+        $children = [];
149
+        foreach ($objs as $obj) {
150
+            $children[] = new CachedSubscriptionObject($this->caldavBackend, $this->calendarInfo, $obj);
151
+        }
152
+
153
+        return $children;
154
+    }
155
+
156
+    /**
157
+     * @param array $paths
158
+     * @return array
159
+     */
160
+    public function getMultipleChildren(array $paths):array {
161
+        $objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);
162
+
163
+        $children = [];
164
+        foreach ($objs as $obj) {
165
+            $children[] = new CachedSubscriptionObject($this->caldavBackend, $this->calendarInfo, $obj);
166
+        }
167
+
168
+        return $children;
169
+    }
170
+
171
+    /**
172
+     * @param string $name
173
+     * @param null|resource|string $calendarData
174
+     * @return null|string
175
+     * @throws MethodNotAllowed
176
+     */
177
+    public function createFile($name, $calendarData = null) {
178
+        throw new MethodNotAllowed('Creating objects in cached subscription is not allowed');
179
+    }
180
+
181
+    /**
182
+     * @param string $name
183
+     * @return bool
184
+     */
185
+    public function childExists($name):bool {
186
+        $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);
187
+        if (!$obj) {
188
+            return false;
189
+        }
190
+
191
+        return true;
192
+    }
193
+
194
+    /**
195
+     * @param array $filters
196
+     * @return array
197
+     */
198
+    public function calendarQuery(array $filters):array {
199
+        return $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);
200
+    }
201
+
202
+    /**
203
+     * @inheritDoc
204
+     */
205
+    public function getChanges($syncToken, $syncLevel, $limit = null) {
206
+        if (!$syncToken && $limit) {
207
+            throw new UnsupportedLimitOnInitialSyncException();
208
+        }
209
+
210
+        return parent::getChanges($syncToken, $syncLevel, $limit);
211
+    }
212 212
 }
Please login to merge, or discard this patch.