Passed
Push — master ( a9798a...74f31b )
by John
14:36 queued 12s
created
lib/public/SystemTag/ISystemTagManager.php 1 patch
Indentation   +120 added lines, -120 removed lines patch added patch discarded remove patch
@@ -34,133 +34,133 @@
 block discarded – undo
34 34
  * @since 9.0.0
35 35
  */
36 36
 interface ISystemTagManager {
37
-	/**
38
-	 * Returns the tag objects matching the given tag ids.
39
-	 *
40
-	 * @param array|string $tagIds id or array of unique ids of the tag to retrieve
41
-	 *
42
-	 * @return ISystemTag[] array of system tags with tag id as key
43
-	 *
44
-	 * @throws \InvalidArgumentException if at least one given tag ids is invalid (string instead of integer, etc.)
45
-	 * @throws TagNotFoundException if at least one given tag ids did no exist
46
-	 * 			The message contains a json_encoded array of the ids that could not be found
47
-	 *
48
-	 * @since 9.0.0
49
-	 */
50
-	public function getTagsByIds($tagIds): array;
37
+    /**
38
+     * Returns the tag objects matching the given tag ids.
39
+     *
40
+     * @param array|string $tagIds id or array of unique ids of the tag to retrieve
41
+     *
42
+     * @return ISystemTag[] array of system tags with tag id as key
43
+     *
44
+     * @throws \InvalidArgumentException if at least one given tag ids is invalid (string instead of integer, etc.)
45
+     * @throws TagNotFoundException if at least one given tag ids did no exist
46
+     * 			The message contains a json_encoded array of the ids that could not be found
47
+     *
48
+     * @since 9.0.0
49
+     */
50
+    public function getTagsByIds($tagIds): array;
51 51
 
52
-	/**
53
-	 * Returns the tag object matching the given attributes.
54
-	 *
55
-	 * @param string $tagName tag name
56
-	 * @param bool $userVisible whether the tag is visible by users
57
-	 * @param bool $userAssignable whether the tag is assignable by users
58
-	 *
59
-	 * @return ISystemTag system tag
60
-	 *
61
-	 * @throws TagNotFoundException if tag does not exist
62
-	 *
63
-	 * @since 9.0.0
64
-	 */
65
-	public function getTag(string $tagName, bool $userVisible, bool $userAssignable): ISystemTag;
52
+    /**
53
+     * Returns the tag object matching the given attributes.
54
+     *
55
+     * @param string $tagName tag name
56
+     * @param bool $userVisible whether the tag is visible by users
57
+     * @param bool $userAssignable whether the tag is assignable by users
58
+     *
59
+     * @return ISystemTag system tag
60
+     *
61
+     * @throws TagNotFoundException if tag does not exist
62
+     *
63
+     * @since 9.0.0
64
+     */
65
+    public function getTag(string $tagName, bool $userVisible, bool $userAssignable): ISystemTag;
66 66
 
67
-	/**
68
-	 * Creates the tag object using the given attributes.
69
-	 *
70
-	 * @param string $tagName tag name
71
-	 * @param bool $userVisible whether the tag is visible by users
72
-	 * @param bool $userAssignable whether the tag is assignable by users
73
-	 *
74
-	 * @return ISystemTag system tag
75
-	 *
76
-	 * @throws TagAlreadyExistsException if tag already exists
77
-	 *
78
-	 * @since 9.0.0
79
-	 */
80
-	public function createTag(string $tagName, bool $userVisible, bool $userAssignable): ISystemTag;
67
+    /**
68
+     * Creates the tag object using the given attributes.
69
+     *
70
+     * @param string $tagName tag name
71
+     * @param bool $userVisible whether the tag is visible by users
72
+     * @param bool $userAssignable whether the tag is assignable by users
73
+     *
74
+     * @return ISystemTag system tag
75
+     *
76
+     * @throws TagAlreadyExistsException if tag already exists
77
+     *
78
+     * @since 9.0.0
79
+     */
80
+    public function createTag(string $tagName, bool $userVisible, bool $userAssignable): ISystemTag;
81 81
 
82
-	/**
83
-	 * Returns all known tags, optionally filtered by visibility.
84
-	 *
85
-	 * @param bool|null $visibilityFilter filter by visibility if non-null
86
-	 * @param string $nameSearchPattern optional search pattern for the tag name
87
-	 *
88
-	 * @return ISystemTag[] array of system tags or empty array if none found
89
-	 *
90
-	 * @since 9.0.0
91
-	 */
92
-	public function getAllTags($visibilityFilter = null, $nameSearchPattern = null): array;
82
+    /**
83
+     * Returns all known tags, optionally filtered by visibility.
84
+     *
85
+     * @param bool|null $visibilityFilter filter by visibility if non-null
86
+     * @param string $nameSearchPattern optional search pattern for the tag name
87
+     *
88
+     * @return ISystemTag[] array of system tags or empty array if none found
89
+     *
90
+     * @since 9.0.0
91
+     */
92
+    public function getAllTags($visibilityFilter = null, $nameSearchPattern = null): array;
93 93
 
94
-	/**
95
-	 * Updates the given tag
96
-	 *
97
-	 * @param string $tagId tag id
98
-	 * @param string $newName the new tag name
99
-	 * @param bool $userVisible whether the tag is visible by users
100
-	 * @param bool $userAssignable whether the tag is assignable by users
101
-	 *
102
-	 * @throws TagNotFoundException if tag with the given id does not exist
103
-	 * @throws TagAlreadyExistsException if there is already another tag
104
-	 * with the same attributes
105
-	 *
106
-	 * @since 9.0.0
107
-	 */
108
-	public function updateTag(string $tagId, string $newName, bool $userVisible, bool $userAssignable);
94
+    /**
95
+     * Updates the given tag
96
+     *
97
+     * @param string $tagId tag id
98
+     * @param string $newName the new tag name
99
+     * @param bool $userVisible whether the tag is visible by users
100
+     * @param bool $userAssignable whether the tag is assignable by users
101
+     *
102
+     * @throws TagNotFoundException if tag with the given id does not exist
103
+     * @throws TagAlreadyExistsException if there is already another tag
104
+     * with the same attributes
105
+     *
106
+     * @since 9.0.0
107
+     */
108
+    public function updateTag(string $tagId, string $newName, bool $userVisible, bool $userAssignable);
109 109
 
110
-	/**
111
-	 * Delete the given tags from the database and all their relationships.
112
-	 *
113
-	 * @param string|array $tagIds array of tag ids
114
-	 *
115
-	 * @throws TagNotFoundException if at least one tag did not exist
116
-	 *
117
-	 * @since 9.0.0
118
-	 */
119
-	public function deleteTags($tagIds);
110
+    /**
111
+     * Delete the given tags from the database and all their relationships.
112
+     *
113
+     * @param string|array $tagIds array of tag ids
114
+     *
115
+     * @throws TagNotFoundException if at least one tag did not exist
116
+     *
117
+     * @since 9.0.0
118
+     */
119
+    public function deleteTags($tagIds);
120 120
 
121
-	/**
122
-	 * Checks whether the given user is allowed to assign/unassign the tag with the
123
-	 * given id.
124
-	 *
125
-	 * @param ISystemTag $tag tag to check permission for
126
-	 * @param IUser $user user to check permission for
127
-	 *
128
-	 * @return bool true if the user is allowed to assign/unassign the tag, false otherwise
129
-	 *
130
-	 * @since 9.1.0
131
-	 */
132
-	public function canUserAssignTag(ISystemTag $tag, IUser $user): bool;
121
+    /**
122
+     * Checks whether the given user is allowed to assign/unassign the tag with the
123
+     * given id.
124
+     *
125
+     * @param ISystemTag $tag tag to check permission for
126
+     * @param IUser $user user to check permission for
127
+     *
128
+     * @return bool true if the user is allowed to assign/unassign the tag, false otherwise
129
+     *
130
+     * @since 9.1.0
131
+     */
132
+    public function canUserAssignTag(ISystemTag $tag, IUser $user): bool;
133 133
 
134
-	/**
135
-	 * Checks whether the given user is allowed to see the tag with the given id.
136
-	 *
137
-	 * @param ISystemTag $tag tag to check permission for
138
-	 * @param IUser $user user to check permission for
139
-	 *
140
-	 * @return bool true if the user can see the tag, false otherwise
141
-	 *
142
-	 * @since 9.1.0
143
-	 */
144
-	public function canUserSeeTag(ISystemTag $tag, IUser $user): bool;
134
+    /**
135
+     * Checks whether the given user is allowed to see the tag with the given id.
136
+     *
137
+     * @param ISystemTag $tag tag to check permission for
138
+     * @param IUser $user user to check permission for
139
+     *
140
+     * @return bool true if the user can see the tag, false otherwise
141
+     *
142
+     * @since 9.1.0
143
+     */
144
+    public function canUserSeeTag(ISystemTag $tag, IUser $user): bool;
145 145
 
146
-	/**
147
-	 * Set groups that can assign a given tag.
148
-	 *
149
-	 * @param ISystemTag $tag tag for group assignment
150
-	 * @param string[] $groupIds group ids of groups that can assign/unassign the tag
151
-	 *
152
-	 * @since 9.1.0
153
-	 */
154
-	public function setTagGroups(ISystemTag $tag, array $groupIds);
146
+    /**
147
+     * Set groups that can assign a given tag.
148
+     *
149
+     * @param ISystemTag $tag tag for group assignment
150
+     * @param string[] $groupIds group ids of groups that can assign/unassign the tag
151
+     *
152
+     * @since 9.1.0
153
+     */
154
+    public function setTagGroups(ISystemTag $tag, array $groupIds);
155 155
 
156
-	/**
157
-	 * Get groups that can assign a given tag.
158
-	 *
159
-	 * @param ISystemTag $tag tag for group assignment
160
-	 *
161
-	 * @return string[] group ids of groups that can assign/unassign the tag
162
-	 *
163
-	 * @since 9.1.0
164
-	 */
165
-	public function getTagGroups(ISystemTag $tag): array;
156
+    /**
157
+     * Get groups that can assign a given tag.
158
+     *
159
+     * @param ISystemTag $tag tag for group assignment
160
+     *
161
+     * @return string[] group ids of groups that can assign/unassign the tag
162
+     *
163
+     * @since 9.1.0
164
+     */
165
+    public function getTagGroups(ISystemTag $tag): array;
166 166
 }
Please login to merge, or discard this patch.
apps/dav/lib/Server.php 1 patch
Indentation   +293 added lines, -293 removed lines patch added patch discarded remove patch
@@ -86,297 +86,297 @@
 block discarded – undo
86 86
 use SearchDAV\DAV\SearchPlugin;
87 87
 
88 88
 class Server {
89
-	private IRequest $request;
90
-	private string $baseUri;
91
-	public Connector\Sabre\Server $server;
92
-	private IProfiler $profiler;
93
-
94
-	public function __construct(IRequest $request, string $baseUri) {
95
-		$this->profiler = \OC::$server->get(IProfiler::class);
96
-		if ($this->profiler->isEnabled()) {
97
-			/** @var IEventLogger $eventLogger */
98
-			$eventLogger = \OC::$server->get(IEventLogger::class);
99
-			$eventLogger->start('runtime', 'DAV Runtime');
100
-		}
101
-
102
-		$this->request = $request;
103
-		$this->baseUri = $baseUri;
104
-		$logger = \OC::$server->get(LoggerInterface::class);
105
-		$dispatcher = \OC::$server->getEventDispatcher();
106
-		/** @var IEventDispatcher $newDispatcher */
107
-		$newDispatcher = \OC::$server->query(IEventDispatcher::class);
108
-
109
-		$root = new RootCollection();
110
-		$this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root));
111
-
112
-		// Add maintenance plugin
113
-		$this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig(), \OC::$server->getL10N('dav')));
114
-
115
-		$this->server->addPlugin(new \OCA\DAV\Connector\Sabre\AppleQuirksPlugin());
116
-
117
-		// Backends
118
-		$authBackend = new Auth(
119
-			\OC::$server->getSession(),
120
-			\OC::$server->getUserSession(),
121
-			\OC::$server->getRequest(),
122
-			\OC::$server->getTwoFactorAuthManager(),
123
-			\OC::$server->getBruteForceThrottler()
124
-		);
125
-
126
-		// Set URL explicitly due to reverse-proxy situations
127
-		$this->server->httpRequest->setUrl($this->request->getRequestUri());
128
-		$this->server->setBaseUri($this->baseUri);
129
-
130
-		$this->server->addPlugin(new ProfilerPlugin($this->request));
131
-		$this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig()));
132
-		$this->server->addPlugin(new AnonymousOptionsPlugin());
133
-		$authPlugin = new Plugin();
134
-		$authPlugin->addBackend(new PublicAuth());
135
-		$this->server->addPlugin($authPlugin);
136
-
137
-		// allow setup of additional auth backends
138
-		$event = new SabrePluginEvent($this->server);
139
-		$dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event);
140
-
141
-		$newAuthEvent = new SabrePluginAuthInitEvent($this->server);
142
-		$newDispatcher->dispatchTyped($newAuthEvent);
143
-
144
-		$bearerAuthBackend = new BearerAuth(
145
-			\OC::$server->getUserSession(),
146
-			\OC::$server->getSession(),
147
-			\OC::$server->getRequest()
148
-		);
149
-		$authPlugin->addBackend($bearerAuthBackend);
150
-		// because we are throwing exceptions this plugin has to be the last one
151
-		$authPlugin->addBackend($authBackend);
152
-
153
-		// debugging
154
-		if (\OC::$server->getConfig()->getSystemValue('debug', false)) {
155
-			$this->server->addPlugin(new \Sabre\DAV\Browser\Plugin());
156
-		} else {
157
-			$this->server->addPlugin(new DummyGetResponsePlugin());
158
-		}
159
-
160
-		$this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger));
161
-		$this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin());
162
-		$this->server->addPlugin(new \Sabre\DAV\Sync\Plugin());
163
-
164
-		// acl
165
-		$acl = new DavAclPlugin();
166
-		$acl->principalCollectionSet = [
167
-			'principals/users',
168
-			'principals/groups',
169
-			'principals/calendar-resources',
170
-			'principals/calendar-rooms',
171
-		];
172
-		$this->server->addPlugin($acl);
173
-
174
-		// calendar plugins
175
-		if ($this->requestIsForSubtree(['calendars', 'public-calendars', 'system-calendars', 'principals'])) {
176
-			$this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin());
177
-			$this->server->addPlugin(new \OCA\DAV\CalDAV\ICSExportPlugin\ICSExportPlugin(\OC::$server->getConfig(), $logger));
178
-			$this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(\OC::$server->getConfig(), \OC::$server->get(LoggerInterface::class)));
179
-			if (\OC::$server->getConfig()->getAppValue('dav', 'sendInvitations', 'yes') === 'yes') {
180
-				$this->server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class));
181
-			}
182
-
183
-			$this->server->addPlugin(\OC::$server->get(\OCA\DAV\CalDAV\Trashbin\Plugin::class));
184
-			$this->server->addPlugin(new \OCA\DAV\CalDAV\WebcalCaching\Plugin($request));
185
-			if (\OC::$server->getConfig()->getAppValue('dav', 'allow_calendar_link_subscriptions', 'yes') === 'yes') {
186
-				$this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin());
187
-			}
188
-
189
-			$this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin());
190
-			$this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest(), \OC::$server->getConfig()));
191
-			$this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin(
192
-				\OC::$server->getConfig(),
193
-				\OC::$server->getURLGenerator()
194
-			));
195
-		}
196
-
197
-		// addressbook plugins
198
-		if ($this->requestIsForSubtree(['addressbooks', 'principals'])) {
199
-			$this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest(), \OC::$server->getConfig()));
200
-			$this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin());
201
-			$this->server->addPlugin(new VCFExportPlugin());
202
-			$this->server->addPlugin(new MultiGetExportPlugin());
203
-			$this->server->addPlugin(new HasPhotoPlugin());
204
-			$this->server->addPlugin(new ImageExportPlugin(new PhotoCache(
205
-				\OC::$server->getAppDataDir('dav-photocache'),
206
-				$logger)
207
-			));
208
-		}
209
-
210
-		// system tags plugins
211
-		$this->server->addPlugin(\OC::$server->get(SystemTagPlugin::class));
212
-
213
-		// comments plugin
214
-		$this->server->addPlugin(new CommentsPlugin(
215
-			\OC::$server->getCommentsManager(),
216
-			\OC::$server->getUserSession()
217
-		));
218
-
219
-		$this->server->addPlugin(new CopyEtagHeaderPlugin());
220
-		$this->server->addPlugin(new RequestIdHeaderPlugin(\OC::$server->get(IRequest::class)));
221
-		$this->server->addPlugin(new ChunkingV2Plugin(\OCP\Server::get(ICacheFactory::class)));
222
-		$this->server->addPlugin(new ChunkingPlugin());
223
-
224
-		// allow setup of additional plugins
225
-		$dispatcher->dispatch('OCA\DAV\Connector\Sabre::addPlugin', $event);
226
-
227
-		// Some WebDAV clients do require Class 2 WebDAV support (locking), since
228
-		// we do not provide locking we emulate it using a fake locking plugin.
229
-		if ($request->isUserAgent([
230
-			'/WebDAVFS/',
231
-			'/OneNote/',
232
-			'/^Microsoft-WebDAV/',// Microsoft-WebDAV-MiniRedir/6.1.7601
233
-		])) {
234
-			$this->server->addPlugin(new FakeLockerPlugin());
235
-		}
236
-
237
-		// Allow view-only plugin for webdav requests
238
-		$this->server->addPlugin(new ViewOnlyPlugin(
239
-			$logger
240
-		));
241
-
242
-		if (BrowserErrorPagePlugin::isBrowserRequest($request)) {
243
-			$this->server->addPlugin(new BrowserErrorPagePlugin());
244
-		}
245
-
246
-		$lazySearchBackend = new LazySearchBackend();
247
-		$this->server->addPlugin(new SearchPlugin($lazySearchBackend));
248
-
249
-		// wait with registering these until auth is handled and the filesystem is setup
250
-		$this->server->on('beforeMethod:*', function () use ($root, $lazySearchBackend, $logger) {
251
-			// custom properties plugin must be the last one
252
-			$userSession = \OC::$server->getUserSession();
253
-			$user = $userSession->getUser();
254
-			if ($user !== null) {
255
-				$view = \OC\Files\Filesystem::getView();
256
-				$this->server->addPlugin(
257
-					new FilesPlugin(
258
-						$this->server->tree,
259
-						\OC::$server->getConfig(),
260
-						$this->request,
261
-						\OC::$server->getPreviewManager(),
262
-						\OC::$server->getUserSession(),
263
-						false,
264
-						!\OC::$server->getConfig()->getSystemValue('debug', false)
265
-					)
266
-				);
267
-				$this->server->addPlugin(new ChecksumUpdatePlugin());
268
-
269
-				$this->server->addPlugin(
270
-					new \Sabre\DAV\PropertyStorage\Plugin(
271
-						new CustomPropertiesBackend(
272
-							$this->server->tree,
273
-							\OC::$server->getDatabaseConnection(),
274
-							\OC::$server->getUserSession()->getUser()
275
-						)
276
-					)
277
-				);
278
-				if ($view !== null) {
279
-					$this->server->addPlugin(
280
-						new QuotaPlugin($view));
281
-				}
282
-				$this->server->addPlugin(
283
-					new TagsPlugin(
284
-						$this->server->tree, \OC::$server->getTagManager()
285
-					)
286
-				);
287
-				// TODO: switch to LazyUserFolder
288
-				$userFolder = \OC::$server->getUserFolder();
289
-				$this->server->addPlugin(new SharesPlugin(
290
-					$this->server->tree,
291
-					$userSession,
292
-					$userFolder,
293
-					\OC::$server->getShareManager()
294
-				));
295
-				$this->server->addPlugin(new CommentPropertiesPlugin(
296
-					\OC::$server->getCommentsManager(),
297
-					$userSession
298
-				));
299
-				$this->server->addPlugin(new \OCA\DAV\CalDAV\Search\SearchPlugin());
300
-				if ($view !== null) {
301
-					$this->server->addPlugin(new FilesReportPlugin(
302
-						$this->server->tree,
303
-						$view,
304
-						\OC::$server->getSystemTagManager(),
305
-						\OC::$server->getSystemTagObjectMapper(),
306
-						\OC::$server->getTagManager(),
307
-						$userSession,
308
-						\OC::$server->getGroupManager(),
309
-						$userFolder,
310
-						\OC::$server->getAppManager()
311
-					));
312
-					$lazySearchBackend->setBackend(new \OCA\DAV\Files\FileSearchBackend(
313
-						$this->server->tree,
314
-						$user,
315
-						\OC::$server->getRootFolder(),
316
-						\OC::$server->getShareManager(),
317
-						$view
318
-					));
319
-					$this->server->addPlugin(
320
-						new BulkUploadPlugin(
321
-							$userFolder,
322
-							$logger
323
-						)
324
-					);
325
-				}
326
-				$this->server->addPlugin(new \OCA\DAV\CalDAV\BirthdayCalendar\EnablePlugin(
327
-					\OC::$server->getConfig(),
328
-					\OC::$server->query(BirthdayService::class)
329
-				));
330
-				$this->server->addPlugin(new AppleProvisioningPlugin(
331
-					\OC::$server->getUserSession(),
332
-					\OC::$server->getURLGenerator(),
333
-					\OC::$server->getThemingDefaults(),
334
-					\OC::$server->getRequest(),
335
-					\OC::$server->getL10N('dav'),
336
-					function () {
337
-						return UUIDUtil::getUUID();
338
-					}
339
-				));
340
-			}
341
-
342
-			// register plugins from apps
343
-			$pluginManager = new PluginManager(
344
-				\OC::$server,
345
-				\OC::$server->getAppManager()
346
-			);
347
-			foreach ($pluginManager->getAppPlugins() as $appPlugin) {
348
-				$this->server->addPlugin($appPlugin);
349
-			}
350
-			foreach ($pluginManager->getAppCollections() as $appCollection) {
351
-				$root->addChild($appCollection);
352
-			}
353
-		});
354
-
355
-		$this->server->addPlugin(
356
-			new PropfindCompressionPlugin()
357
-		);
358
-	}
359
-
360
-	public function exec() {
361
-		/** @var IEventLogger $eventLogger */
362
-		$eventLogger = \OC::$server->get(IEventLogger::class);
363
-		$eventLogger->start('dav_server_exec', '');
364
-		$this->server->exec();
365
-		$eventLogger->end('dav_server_exec');
366
-		if ($this->profiler->isEnabled()) {
367
-			$eventLogger->end('runtime');
368
-			$profile = $this->profiler->collect(\OC::$server->get(IRequest::class), new Response());
369
-			$this->profiler->saveProfile($profile);
370
-		}
371
-	}
372
-
373
-	private function requestIsForSubtree(array $subTrees): bool {
374
-		foreach ($subTrees as $subTree) {
375
-			$subTree = trim($subTree, ' /');
376
-			if (strpos($this->server->getRequestUri(), $subTree.'/') === 0) {
377
-				return true;
378
-			}
379
-		}
380
-		return false;
381
-	}
89
+    private IRequest $request;
90
+    private string $baseUri;
91
+    public Connector\Sabre\Server $server;
92
+    private IProfiler $profiler;
93
+
94
+    public function __construct(IRequest $request, string $baseUri) {
95
+        $this->profiler = \OC::$server->get(IProfiler::class);
96
+        if ($this->profiler->isEnabled()) {
97
+            /** @var IEventLogger $eventLogger */
98
+            $eventLogger = \OC::$server->get(IEventLogger::class);
99
+            $eventLogger->start('runtime', 'DAV Runtime');
100
+        }
101
+
102
+        $this->request = $request;
103
+        $this->baseUri = $baseUri;
104
+        $logger = \OC::$server->get(LoggerInterface::class);
105
+        $dispatcher = \OC::$server->getEventDispatcher();
106
+        /** @var IEventDispatcher $newDispatcher */
107
+        $newDispatcher = \OC::$server->query(IEventDispatcher::class);
108
+
109
+        $root = new RootCollection();
110
+        $this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root));
111
+
112
+        // Add maintenance plugin
113
+        $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig(), \OC::$server->getL10N('dav')));
114
+
115
+        $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\AppleQuirksPlugin());
116
+
117
+        // Backends
118
+        $authBackend = new Auth(
119
+            \OC::$server->getSession(),
120
+            \OC::$server->getUserSession(),
121
+            \OC::$server->getRequest(),
122
+            \OC::$server->getTwoFactorAuthManager(),
123
+            \OC::$server->getBruteForceThrottler()
124
+        );
125
+
126
+        // Set URL explicitly due to reverse-proxy situations
127
+        $this->server->httpRequest->setUrl($this->request->getRequestUri());
128
+        $this->server->setBaseUri($this->baseUri);
129
+
130
+        $this->server->addPlugin(new ProfilerPlugin($this->request));
131
+        $this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig()));
132
+        $this->server->addPlugin(new AnonymousOptionsPlugin());
133
+        $authPlugin = new Plugin();
134
+        $authPlugin->addBackend(new PublicAuth());
135
+        $this->server->addPlugin($authPlugin);
136
+
137
+        // allow setup of additional auth backends
138
+        $event = new SabrePluginEvent($this->server);
139
+        $dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event);
140
+
141
+        $newAuthEvent = new SabrePluginAuthInitEvent($this->server);
142
+        $newDispatcher->dispatchTyped($newAuthEvent);
143
+
144
+        $bearerAuthBackend = new BearerAuth(
145
+            \OC::$server->getUserSession(),
146
+            \OC::$server->getSession(),
147
+            \OC::$server->getRequest()
148
+        );
149
+        $authPlugin->addBackend($bearerAuthBackend);
150
+        // because we are throwing exceptions this plugin has to be the last one
151
+        $authPlugin->addBackend($authBackend);
152
+
153
+        // debugging
154
+        if (\OC::$server->getConfig()->getSystemValue('debug', false)) {
155
+            $this->server->addPlugin(new \Sabre\DAV\Browser\Plugin());
156
+        } else {
157
+            $this->server->addPlugin(new DummyGetResponsePlugin());
158
+        }
159
+
160
+        $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger));
161
+        $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin());
162
+        $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin());
163
+
164
+        // acl
165
+        $acl = new DavAclPlugin();
166
+        $acl->principalCollectionSet = [
167
+            'principals/users',
168
+            'principals/groups',
169
+            'principals/calendar-resources',
170
+            'principals/calendar-rooms',
171
+        ];
172
+        $this->server->addPlugin($acl);
173
+
174
+        // calendar plugins
175
+        if ($this->requestIsForSubtree(['calendars', 'public-calendars', 'system-calendars', 'principals'])) {
176
+            $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin());
177
+            $this->server->addPlugin(new \OCA\DAV\CalDAV\ICSExportPlugin\ICSExportPlugin(\OC::$server->getConfig(), $logger));
178
+            $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(\OC::$server->getConfig(), \OC::$server->get(LoggerInterface::class)));
179
+            if (\OC::$server->getConfig()->getAppValue('dav', 'sendInvitations', 'yes') === 'yes') {
180
+                $this->server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class));
181
+            }
182
+
183
+            $this->server->addPlugin(\OC::$server->get(\OCA\DAV\CalDAV\Trashbin\Plugin::class));
184
+            $this->server->addPlugin(new \OCA\DAV\CalDAV\WebcalCaching\Plugin($request));
185
+            if (\OC::$server->getConfig()->getAppValue('dav', 'allow_calendar_link_subscriptions', 'yes') === 'yes') {
186
+                $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin());
187
+            }
188
+
189
+            $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin());
190
+            $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest(), \OC::$server->getConfig()));
191
+            $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin(
192
+                \OC::$server->getConfig(),
193
+                \OC::$server->getURLGenerator()
194
+            ));
195
+        }
196
+
197
+        // addressbook plugins
198
+        if ($this->requestIsForSubtree(['addressbooks', 'principals'])) {
199
+            $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest(), \OC::$server->getConfig()));
200
+            $this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin());
201
+            $this->server->addPlugin(new VCFExportPlugin());
202
+            $this->server->addPlugin(new MultiGetExportPlugin());
203
+            $this->server->addPlugin(new HasPhotoPlugin());
204
+            $this->server->addPlugin(new ImageExportPlugin(new PhotoCache(
205
+                \OC::$server->getAppDataDir('dav-photocache'),
206
+                $logger)
207
+            ));
208
+        }
209
+
210
+        // system tags plugins
211
+        $this->server->addPlugin(\OC::$server->get(SystemTagPlugin::class));
212
+
213
+        // comments plugin
214
+        $this->server->addPlugin(new CommentsPlugin(
215
+            \OC::$server->getCommentsManager(),
216
+            \OC::$server->getUserSession()
217
+        ));
218
+
219
+        $this->server->addPlugin(new CopyEtagHeaderPlugin());
220
+        $this->server->addPlugin(new RequestIdHeaderPlugin(\OC::$server->get(IRequest::class)));
221
+        $this->server->addPlugin(new ChunkingV2Plugin(\OCP\Server::get(ICacheFactory::class)));
222
+        $this->server->addPlugin(new ChunkingPlugin());
223
+
224
+        // allow setup of additional plugins
225
+        $dispatcher->dispatch('OCA\DAV\Connector\Sabre::addPlugin', $event);
226
+
227
+        // Some WebDAV clients do require Class 2 WebDAV support (locking), since
228
+        // we do not provide locking we emulate it using a fake locking plugin.
229
+        if ($request->isUserAgent([
230
+            '/WebDAVFS/',
231
+            '/OneNote/',
232
+            '/^Microsoft-WebDAV/',// Microsoft-WebDAV-MiniRedir/6.1.7601
233
+        ])) {
234
+            $this->server->addPlugin(new FakeLockerPlugin());
235
+        }
236
+
237
+        // Allow view-only plugin for webdav requests
238
+        $this->server->addPlugin(new ViewOnlyPlugin(
239
+            $logger
240
+        ));
241
+
242
+        if (BrowserErrorPagePlugin::isBrowserRequest($request)) {
243
+            $this->server->addPlugin(new BrowserErrorPagePlugin());
244
+        }
245
+
246
+        $lazySearchBackend = new LazySearchBackend();
247
+        $this->server->addPlugin(new SearchPlugin($lazySearchBackend));
248
+
249
+        // wait with registering these until auth is handled and the filesystem is setup
250
+        $this->server->on('beforeMethod:*', function () use ($root, $lazySearchBackend, $logger) {
251
+            // custom properties plugin must be the last one
252
+            $userSession = \OC::$server->getUserSession();
253
+            $user = $userSession->getUser();
254
+            if ($user !== null) {
255
+                $view = \OC\Files\Filesystem::getView();
256
+                $this->server->addPlugin(
257
+                    new FilesPlugin(
258
+                        $this->server->tree,
259
+                        \OC::$server->getConfig(),
260
+                        $this->request,
261
+                        \OC::$server->getPreviewManager(),
262
+                        \OC::$server->getUserSession(),
263
+                        false,
264
+                        !\OC::$server->getConfig()->getSystemValue('debug', false)
265
+                    )
266
+                );
267
+                $this->server->addPlugin(new ChecksumUpdatePlugin());
268
+
269
+                $this->server->addPlugin(
270
+                    new \Sabre\DAV\PropertyStorage\Plugin(
271
+                        new CustomPropertiesBackend(
272
+                            $this->server->tree,
273
+                            \OC::$server->getDatabaseConnection(),
274
+                            \OC::$server->getUserSession()->getUser()
275
+                        )
276
+                    )
277
+                );
278
+                if ($view !== null) {
279
+                    $this->server->addPlugin(
280
+                        new QuotaPlugin($view));
281
+                }
282
+                $this->server->addPlugin(
283
+                    new TagsPlugin(
284
+                        $this->server->tree, \OC::$server->getTagManager()
285
+                    )
286
+                );
287
+                // TODO: switch to LazyUserFolder
288
+                $userFolder = \OC::$server->getUserFolder();
289
+                $this->server->addPlugin(new SharesPlugin(
290
+                    $this->server->tree,
291
+                    $userSession,
292
+                    $userFolder,
293
+                    \OC::$server->getShareManager()
294
+                ));
295
+                $this->server->addPlugin(new CommentPropertiesPlugin(
296
+                    \OC::$server->getCommentsManager(),
297
+                    $userSession
298
+                ));
299
+                $this->server->addPlugin(new \OCA\DAV\CalDAV\Search\SearchPlugin());
300
+                if ($view !== null) {
301
+                    $this->server->addPlugin(new FilesReportPlugin(
302
+                        $this->server->tree,
303
+                        $view,
304
+                        \OC::$server->getSystemTagManager(),
305
+                        \OC::$server->getSystemTagObjectMapper(),
306
+                        \OC::$server->getTagManager(),
307
+                        $userSession,
308
+                        \OC::$server->getGroupManager(),
309
+                        $userFolder,
310
+                        \OC::$server->getAppManager()
311
+                    ));
312
+                    $lazySearchBackend->setBackend(new \OCA\DAV\Files\FileSearchBackend(
313
+                        $this->server->tree,
314
+                        $user,
315
+                        \OC::$server->getRootFolder(),
316
+                        \OC::$server->getShareManager(),
317
+                        $view
318
+                    ));
319
+                    $this->server->addPlugin(
320
+                        new BulkUploadPlugin(
321
+                            $userFolder,
322
+                            $logger
323
+                        )
324
+                    );
325
+                }
326
+                $this->server->addPlugin(new \OCA\DAV\CalDAV\BirthdayCalendar\EnablePlugin(
327
+                    \OC::$server->getConfig(),
328
+                    \OC::$server->query(BirthdayService::class)
329
+                ));
330
+                $this->server->addPlugin(new AppleProvisioningPlugin(
331
+                    \OC::$server->getUserSession(),
332
+                    \OC::$server->getURLGenerator(),
333
+                    \OC::$server->getThemingDefaults(),
334
+                    \OC::$server->getRequest(),
335
+                    \OC::$server->getL10N('dav'),
336
+                    function () {
337
+                        return UUIDUtil::getUUID();
338
+                    }
339
+                ));
340
+            }
341
+
342
+            // register plugins from apps
343
+            $pluginManager = new PluginManager(
344
+                \OC::$server,
345
+                \OC::$server->getAppManager()
346
+            );
347
+            foreach ($pluginManager->getAppPlugins() as $appPlugin) {
348
+                $this->server->addPlugin($appPlugin);
349
+            }
350
+            foreach ($pluginManager->getAppCollections() as $appCollection) {
351
+                $root->addChild($appCollection);
352
+            }
353
+        });
354
+
355
+        $this->server->addPlugin(
356
+            new PropfindCompressionPlugin()
357
+        );
358
+    }
359
+
360
+    public function exec() {
361
+        /** @var IEventLogger $eventLogger */
362
+        $eventLogger = \OC::$server->get(IEventLogger::class);
363
+        $eventLogger->start('dav_server_exec', '');
364
+        $this->server->exec();
365
+        $eventLogger->end('dav_server_exec');
366
+        if ($this->profiler->isEnabled()) {
367
+            $eventLogger->end('runtime');
368
+            $profile = $this->profiler->collect(\OC::$server->get(IRequest::class), new Response());
369
+            $this->profiler->saveProfile($profile);
370
+        }
371
+    }
372
+
373
+    private function requestIsForSubtree(array $subTrees): bool {
374
+        foreach ($subTrees as $subTree) {
375
+            $subTree = trim($subTree, ' /');
376
+            if (strpos($this->server->getRequestUri(), $subTree.'/') === 0) {
377
+                return true;
378
+            }
379
+        }
380
+        return false;
381
+    }
382 382
 }
Please login to merge, or discard this patch.
apps/dav/lib/SystemTag/SystemTagMappingNode.php 1 patch
Indentation   +135 added lines, -135 removed lines patch added patch discarded remove patch
@@ -37,139 +37,139 @@
 block discarded – undo
37 37
  * Mapping node for system tag to object id
38 38
  */
39 39
 class SystemTagMappingNode implements \Sabre\DAV\INode {
40
-	/**
41
-	 * @var ISystemTag
42
-	 */
43
-	protected $tag;
44
-
45
-	/**
46
-	 * @var string
47
-	 */
48
-	private $objectId;
49
-
50
-	/**
51
-	 * @var string
52
-	 */
53
-	private $objectType;
54
-
55
-	/**
56
-	 * User
57
-	 *
58
-	 * @var IUser
59
-	 */
60
-	protected $user;
61
-
62
-	/**
63
-	 * @var ISystemTagManager
64
-	 */
65
-	protected $tagManager;
66
-
67
-	/**
68
-	 * @var ISystemTagObjectMapper
69
-	 */
70
-	private $tagMapper;
71
-
72
-	/**
73
-	 * Sets up the node, expects a full path name
74
-	 *
75
-	 * @param ISystemTag $tag system tag
76
-	 * @param string $objectId
77
-	 * @param string $objectType
78
-	 * @param IUser $user user
79
-	 * @param ISystemTagManager $tagManager
80
-	 * @param ISystemTagObjectMapper $tagMapper
81
-	 */
82
-	public function __construct(
83
-		ISystemTag $tag,
84
-		$objectId,
85
-		$objectType,
86
-		IUser $user,
87
-		ISystemTagManager $tagManager,
88
-		ISystemTagObjectMapper $tagMapper
89
-	) {
90
-		$this->tag = $tag;
91
-		$this->objectId = $objectId;
92
-		$this->objectType = $objectType;
93
-		$this->user = $user;
94
-		$this->tagManager = $tagManager;
95
-		$this->tagMapper = $tagMapper;
96
-	}
97
-
98
-	/**
99
-	 * Returns the object id of the relationship
100
-	 *
101
-	 * @return string object id
102
-	 */
103
-	public function getObjectId() {
104
-		return $this->objectId;
105
-	}
106
-
107
-	/**
108
-	 * Returns the object type of the relationship
109
-	 *
110
-	 * @return string object type
111
-	 */
112
-	public function getObjectType() {
113
-		return $this->objectType;
114
-	}
115
-
116
-	/**
117
-	 * Returns the system tag represented by this node
118
-	 *
119
-	 * @return ISystemTag system tag
120
-	 */
121
-	public function getSystemTag() {
122
-		return $this->tag;
123
-	}
124
-
125
-	/**
126
-	 *  Returns the id of the tag
127
-	 *
128
-	 * @return string
129
-	 */
130
-	public function getName() {
131
-		return $this->tag->getId();
132
-	}
133
-
134
-	/**
135
-	 * Renames the node
136
-	 *
137
-	 * @param string $name The new name
138
-	 *
139
-	 * @throws MethodNotAllowed not allowed to rename node
140
-	 *
141
-	 * @return never
142
-	 */
143
-	public function setName($name) {
144
-		throw new MethodNotAllowed();
145
-	}
146
-
147
-	/**
148
-	 * Returns null, not supported
149
-	 *
150
-	 * @return null
151
-	 */
152
-	public function getLastModified() {
153
-		return null;
154
-	}
155
-
156
-	/**
157
-	 * Delete tag to object association
158
-	 *
159
-	 * @return void
160
-	 */
161
-	public function delete() {
162
-		try {
163
-			if (!$this->tagManager->canUserSeeTag($this->tag, $this->user)) {
164
-				throw new NotFound('Tag with id ' . $this->tag->getId() . ' not found');
165
-			}
166
-			if (!$this->tagManager->canUserAssignTag($this->tag, $this->user)) {
167
-				throw new Forbidden('No permission to unassign tag ' . $this->tag->getId());
168
-			}
169
-			$this->tagMapper->unassignTags($this->objectId, $this->objectType, $this->tag->getId());
170
-		} catch (TagNotFoundException $e) {
171
-			// can happen if concurrent deletion occurred
172
-			throw new NotFound('Tag with id ' . $this->tag->getId() . ' not found', 0, $e);
173
-		}
174
-	}
40
+    /**
41
+     * @var ISystemTag
42
+     */
43
+    protected $tag;
44
+
45
+    /**
46
+     * @var string
47
+     */
48
+    private $objectId;
49
+
50
+    /**
51
+     * @var string
52
+     */
53
+    private $objectType;
54
+
55
+    /**
56
+     * User
57
+     *
58
+     * @var IUser
59
+     */
60
+    protected $user;
61
+
62
+    /**
63
+     * @var ISystemTagManager
64
+     */
65
+    protected $tagManager;
66
+
67
+    /**
68
+     * @var ISystemTagObjectMapper
69
+     */
70
+    private $tagMapper;
71
+
72
+    /**
73
+     * Sets up the node, expects a full path name
74
+     *
75
+     * @param ISystemTag $tag system tag
76
+     * @param string $objectId
77
+     * @param string $objectType
78
+     * @param IUser $user user
79
+     * @param ISystemTagManager $tagManager
80
+     * @param ISystemTagObjectMapper $tagMapper
81
+     */
82
+    public function __construct(
83
+        ISystemTag $tag,
84
+        $objectId,
85
+        $objectType,
86
+        IUser $user,
87
+        ISystemTagManager $tagManager,
88
+        ISystemTagObjectMapper $tagMapper
89
+    ) {
90
+        $this->tag = $tag;
91
+        $this->objectId = $objectId;
92
+        $this->objectType = $objectType;
93
+        $this->user = $user;
94
+        $this->tagManager = $tagManager;
95
+        $this->tagMapper = $tagMapper;
96
+    }
97
+
98
+    /**
99
+     * Returns the object id of the relationship
100
+     *
101
+     * @return string object id
102
+     */
103
+    public function getObjectId() {
104
+        return $this->objectId;
105
+    }
106
+
107
+    /**
108
+     * Returns the object type of the relationship
109
+     *
110
+     * @return string object type
111
+     */
112
+    public function getObjectType() {
113
+        return $this->objectType;
114
+    }
115
+
116
+    /**
117
+     * Returns the system tag represented by this node
118
+     *
119
+     * @return ISystemTag system tag
120
+     */
121
+    public function getSystemTag() {
122
+        return $this->tag;
123
+    }
124
+
125
+    /**
126
+     *  Returns the id of the tag
127
+     *
128
+     * @return string
129
+     */
130
+    public function getName() {
131
+        return $this->tag->getId();
132
+    }
133
+
134
+    /**
135
+     * Renames the node
136
+     *
137
+     * @param string $name The new name
138
+     *
139
+     * @throws MethodNotAllowed not allowed to rename node
140
+     *
141
+     * @return never
142
+     */
143
+    public function setName($name) {
144
+        throw new MethodNotAllowed();
145
+    }
146
+
147
+    /**
148
+     * Returns null, not supported
149
+     *
150
+     * @return null
151
+     */
152
+    public function getLastModified() {
153
+        return null;
154
+    }
155
+
156
+    /**
157
+     * Delete tag to object association
158
+     *
159
+     * @return void
160
+     */
161
+    public function delete() {
162
+        try {
163
+            if (!$this->tagManager->canUserSeeTag($this->tag, $this->user)) {
164
+                throw new NotFound('Tag with id ' . $this->tag->getId() . ' not found');
165
+            }
166
+            if (!$this->tagManager->canUserAssignTag($this->tag, $this->user)) {
167
+                throw new Forbidden('No permission to unassign tag ' . $this->tag->getId());
168
+            }
169
+            $this->tagMapper->unassignTags($this->objectId, $this->objectType, $this->tag->getId());
170
+        } catch (TagNotFoundException $e) {
171
+            // can happen if concurrent deletion occurred
172
+            throw new NotFound('Tag with id ' . $this->tag->getId() . ' not found', 0, $e);
173
+        }
174
+    }
175 175
 }
Please login to merge, or discard this patch.
apps/dav/lib/SystemTag/SystemTagList.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -33,41 +33,41 @@
 block discarded – undo
33 33
  * This property contains multiple "tag" elements, each containing a tag name.
34 34
  */
35 35
 class SystemTagList implements Element {
36
-	public const NS_NEXTCLOUD = 'http://nextcloud.org/ns';
36
+    public const NS_NEXTCLOUD = 'http://nextcloud.org/ns';
37 37
 
38
-	/** @var ISystemTag[] */
39
-	private array $tags;
40
-	private ISystemTagManager $tagManager;
41
-	private IUser $user;
38
+    /** @var ISystemTag[] */
39
+    private array $tags;
40
+    private ISystemTagManager $tagManager;
41
+    private IUser $user;
42 42
 
43
-	public function __construct(array $tags, ISystemTagManager $tagManager, IUser $user) {
44
-		$this->tags = $tags;
45
-		$this->tagManager = $tagManager;
46
-		$this->user = $user;
47
-	}
43
+    public function __construct(array $tags, ISystemTagManager $tagManager, IUser $user) {
44
+        $this->tags = $tags;
45
+        $this->tagManager = $tagManager;
46
+        $this->user = $user;
47
+    }
48 48
 
49
-	/**
50
-	 * @return ISystemTag[]
51
-	 */
52
-	public function getTags(): array {
53
-		return $this->tags;
54
-	}
49
+    /**
50
+     * @return ISystemTag[]
51
+     */
52
+    public function getTags(): array {
53
+        return $this->tags;
54
+    }
55 55
 
56
-	public static function xmlDeserialize(Reader $reader): void {
57
-		// unsupported/unused
58
-	}
56
+    public static function xmlDeserialize(Reader $reader): void {
57
+        // unsupported/unused
58
+    }
59 59
 
60
-	public function xmlSerialize(Writer $writer): void {
61
-		foreach ($this->tags as $tag) {
62
-			$writer->startElement('{' . self::NS_NEXTCLOUD . '}system-tag');
63
-			$writer->writeAttributes([
64
-				SystemTagPlugin::CANASSIGN_PROPERTYNAME => $this->tagManager->canUserAssignTag($tag, $this->user) ? 'true' : 'false',
65
-				SystemTagPlugin::ID_PROPERTYNAME => $tag->getId(),
66
-				SystemTagPlugin::USERASSIGNABLE_PROPERTYNAME => $tag->isUserAssignable() ? 'true' : 'false',
67
-				SystemTagPlugin::USERVISIBLE_PROPERTYNAME => $tag->isUserVisible() ? 'true' : 'false',
68
-			]);
69
-			$writer->write($tag->getName());
70
-			$writer->endElement();
71
-		}
72
-	}
60
+    public function xmlSerialize(Writer $writer): void {
61
+        foreach ($this->tags as $tag) {
62
+            $writer->startElement('{' . self::NS_NEXTCLOUD . '}system-tag');
63
+            $writer->writeAttributes([
64
+                SystemTagPlugin::CANASSIGN_PROPERTYNAME => $this->tagManager->canUserAssignTag($tag, $this->user) ? 'true' : 'false',
65
+                SystemTagPlugin::ID_PROPERTYNAME => $tag->getId(),
66
+                SystemTagPlugin::USERASSIGNABLE_PROPERTYNAME => $tag->isUserAssignable() ? 'true' : 'false',
67
+                SystemTagPlugin::USERVISIBLE_PROPERTYNAME => $tag->isUserVisible() ? 'true' : 'false',
68
+            ]);
69
+            $writer->write($tag->getName());
70
+            $writer->endElement();
71
+        }
72
+    }
73 73
 }
Please login to merge, or discard this patch.
apps/dav/lib/SystemTag/SystemTagsByIdCollection.php 1 patch
Indentation   +163 added lines, -163 removed lines patch added patch discarded remove patch
@@ -36,167 +36,167 @@
 block discarded – undo
36 36
 
37 37
 class SystemTagsByIdCollection implements ICollection {
38 38
 
39
-	/**
40
-	 * @var ISystemTagManager
41
-	 */
42
-	private $tagManager;
43
-
44
-	/**
45
-	 * @var IGroupManager
46
-	 */
47
-	private $groupManager;
48
-
49
-	/**
50
-	 * @var IUserSession
51
-	 */
52
-	private $userSession;
53
-
54
-	/**
55
-	 * SystemTagsByIdCollection constructor.
56
-	 *
57
-	 * @param ISystemTagManager $tagManager
58
-	 * @param IUserSession $userSession
59
-	 * @param IGroupManager $groupManager
60
-	 */
61
-	public function __construct(
62
-		ISystemTagManager $tagManager,
63
-		IUserSession $userSession,
64
-		IGroupManager $groupManager
65
-	) {
66
-		$this->tagManager = $tagManager;
67
-		$this->userSession = $userSession;
68
-		$this->groupManager = $groupManager;
69
-	}
70
-
71
-	/**
72
-	 * Returns whether the currently logged in user is an administrator
73
-	 *
74
-	 * @return bool true if the user is an admin
75
-	 */
76
-	private function isAdmin() {
77
-		$user = $this->userSession->getUser();
78
-		if ($user !== null) {
79
-			return $this->groupManager->isAdmin($user->getUID());
80
-		}
81
-		return false;
82
-	}
83
-
84
-	/**
85
-	 * @param string $name
86
-	 * @param resource|string $data Initial payload
87
-	 *
88
-	 * @throws Forbidden
89
-	 *
90
-	 * @return never
91
-	 */
92
-	public function createFile($name, $data = null) {
93
-		throw new Forbidden('Cannot create tags by id');
94
-	}
95
-
96
-	/**
97
-	 * @param string $name
98
-	 *
99
-	 * @return never
100
-	 */
101
-	public function createDirectory($name) {
102
-		throw new Forbidden('Permission denied to create collections');
103
-	}
104
-
105
-	/**
106
-	 * @param string $name
107
-	 *
108
-	 * @return SystemTagNode
109
-	 */
110
-	public function getChild($name) {
111
-		try {
112
-			$tag = $this->tagManager->getTagsByIds([$name]);
113
-			$tag = current($tag);
114
-			if (!$this->tagManager->canUserSeeTag($tag, $this->userSession->getUser())) {
115
-				throw new NotFound('Tag with id ' . $name . ' not found');
116
-			}
117
-			return $this->makeNode($tag);
118
-		} catch (\InvalidArgumentException $e) {
119
-			throw new BadRequest('Invalid tag id', 0, $e);
120
-		} catch (TagNotFoundException $e) {
121
-			throw new NotFound('Tag with id ' . $name . ' not found', 0, $e);
122
-		}
123
-	}
124
-
125
-	/**
126
-	 * @return SystemTagNode[]
127
-	 *
128
-	 * @psalm-return array<SystemTagNode>
129
-	 */
130
-	public function getChildren() {
131
-		$visibilityFilter = true;
132
-		if ($this->isAdmin()) {
133
-			$visibilityFilter = null;
134
-		}
135
-
136
-		$tags = $this->tagManager->getAllTags($visibilityFilter);
137
-		return array_map(function ($tag) {
138
-			return $this->makeNode($tag);
139
-		}, $tags);
140
-	}
141
-
142
-	/**
143
-	 * @param string $name
144
-	 */
145
-	public function childExists($name) {
146
-		try {
147
-			$tag = $this->tagManager->getTagsByIds([$name]);
148
-			$tag = current($tag);
149
-			if (!$this->tagManager->canUserSeeTag($tag, $this->userSession->getUser())) {
150
-				return false;
151
-			}
152
-			return true;
153
-		} catch (\InvalidArgumentException $e) {
154
-			throw new BadRequest('Invalid tag id', 0, $e);
155
-		} catch (TagNotFoundException $e) {
156
-			return false;
157
-		}
158
-	}
159
-
160
-	/**
161
-	 * @return never
162
-	 */
163
-	public function delete() {
164
-		throw new Forbidden('Permission denied to delete this collection');
165
-	}
166
-
167
-	/**
168
-	 * @return string
169
-	 *
170
-	 * @psalm-return 'systemtags'
171
-	 */
172
-	public function getName() {
173
-		return 'systemtags';
174
-	}
175
-
176
-	/**
177
-	 * @return never
178
-	 */
179
-	public function setName($name) {
180
-		throw new Forbidden('Permission denied to rename this collection');
181
-	}
182
-
183
-	/**
184
-	 * Returns the last modification time, as a unix timestamp
185
-	 *
186
-	 * @return null
187
-	 */
188
-	public function getLastModified() {
189
-		return null;
190
-	}
191
-
192
-	/**
193
-	 * Create a sabre node for the given system tag
194
-	 *
195
-	 * @param ISystemTag $tag
196
-	 *
197
-	 * @return SystemTagNode
198
-	 */
199
-	private function makeNode(ISystemTag $tag) {
200
-		return new SystemTagNode($tag, $this->userSession->getUser(), $this->isAdmin(), $this->tagManager);
201
-	}
39
+    /**
40
+     * @var ISystemTagManager
41
+     */
42
+    private $tagManager;
43
+
44
+    /**
45
+     * @var IGroupManager
46
+     */
47
+    private $groupManager;
48
+
49
+    /**
50
+     * @var IUserSession
51
+     */
52
+    private $userSession;
53
+
54
+    /**
55
+     * SystemTagsByIdCollection constructor.
56
+     *
57
+     * @param ISystemTagManager $tagManager
58
+     * @param IUserSession $userSession
59
+     * @param IGroupManager $groupManager
60
+     */
61
+    public function __construct(
62
+        ISystemTagManager $tagManager,
63
+        IUserSession $userSession,
64
+        IGroupManager $groupManager
65
+    ) {
66
+        $this->tagManager = $tagManager;
67
+        $this->userSession = $userSession;
68
+        $this->groupManager = $groupManager;
69
+    }
70
+
71
+    /**
72
+     * Returns whether the currently logged in user is an administrator
73
+     *
74
+     * @return bool true if the user is an admin
75
+     */
76
+    private function isAdmin() {
77
+        $user = $this->userSession->getUser();
78
+        if ($user !== null) {
79
+            return $this->groupManager->isAdmin($user->getUID());
80
+        }
81
+        return false;
82
+    }
83
+
84
+    /**
85
+     * @param string $name
86
+     * @param resource|string $data Initial payload
87
+     *
88
+     * @throws Forbidden
89
+     *
90
+     * @return never
91
+     */
92
+    public function createFile($name, $data = null) {
93
+        throw new Forbidden('Cannot create tags by id');
94
+    }
95
+
96
+    /**
97
+     * @param string $name
98
+     *
99
+     * @return never
100
+     */
101
+    public function createDirectory($name) {
102
+        throw new Forbidden('Permission denied to create collections');
103
+    }
104
+
105
+    /**
106
+     * @param string $name
107
+     *
108
+     * @return SystemTagNode
109
+     */
110
+    public function getChild($name) {
111
+        try {
112
+            $tag = $this->tagManager->getTagsByIds([$name]);
113
+            $tag = current($tag);
114
+            if (!$this->tagManager->canUserSeeTag($tag, $this->userSession->getUser())) {
115
+                throw new NotFound('Tag with id ' . $name . ' not found');
116
+            }
117
+            return $this->makeNode($tag);
118
+        } catch (\InvalidArgumentException $e) {
119
+            throw new BadRequest('Invalid tag id', 0, $e);
120
+        } catch (TagNotFoundException $e) {
121
+            throw new NotFound('Tag with id ' . $name . ' not found', 0, $e);
122
+        }
123
+    }
124
+
125
+    /**
126
+     * @return SystemTagNode[]
127
+     *
128
+     * @psalm-return array<SystemTagNode>
129
+     */
130
+    public function getChildren() {
131
+        $visibilityFilter = true;
132
+        if ($this->isAdmin()) {
133
+            $visibilityFilter = null;
134
+        }
135
+
136
+        $tags = $this->tagManager->getAllTags($visibilityFilter);
137
+        return array_map(function ($tag) {
138
+            return $this->makeNode($tag);
139
+        }, $tags);
140
+    }
141
+
142
+    /**
143
+     * @param string $name
144
+     */
145
+    public function childExists($name) {
146
+        try {
147
+            $tag = $this->tagManager->getTagsByIds([$name]);
148
+            $tag = current($tag);
149
+            if (!$this->tagManager->canUserSeeTag($tag, $this->userSession->getUser())) {
150
+                return false;
151
+            }
152
+            return true;
153
+        } catch (\InvalidArgumentException $e) {
154
+            throw new BadRequest('Invalid tag id', 0, $e);
155
+        } catch (TagNotFoundException $e) {
156
+            return false;
157
+        }
158
+    }
159
+
160
+    /**
161
+     * @return never
162
+     */
163
+    public function delete() {
164
+        throw new Forbidden('Permission denied to delete this collection');
165
+    }
166
+
167
+    /**
168
+     * @return string
169
+     *
170
+     * @psalm-return 'systemtags'
171
+     */
172
+    public function getName() {
173
+        return 'systemtags';
174
+    }
175
+
176
+    /**
177
+     * @return never
178
+     */
179
+    public function setName($name) {
180
+        throw new Forbidden('Permission denied to rename this collection');
181
+    }
182
+
183
+    /**
184
+     * Returns the last modification time, as a unix timestamp
185
+     *
186
+     * @return null
187
+     */
188
+    public function getLastModified() {
189
+        return null;
190
+    }
191
+
192
+    /**
193
+     * Create a sabre node for the given system tag
194
+     *
195
+     * @param ISystemTag $tag
196
+     *
197
+     * @return SystemTagNode
198
+     */
199
+    private function makeNode(ISystemTag $tag) {
200
+        return new SystemTagNode($tag, $this->userSession->getUser(), $this->isAdmin(), $this->tagManager);
201
+    }
202 202
 }
Please login to merge, or discard this patch.
apps/dav/lib/SystemTag/SystemTagsObjectTypeCollection.php 1 patch
Indentation   +147 added lines, -147 removed lines patch added patch discarded remove patch
@@ -39,151 +39,151 @@
 block discarded – undo
39 39
  */
40 40
 class SystemTagsObjectTypeCollection implements ICollection {
41 41
 
42
-	/**
43
-	 * @var string
44
-	 */
45
-	private $objectType;
46
-
47
-	/**
48
-	 * @var ISystemTagManager
49
-	 */
50
-	private $tagManager;
51
-
52
-	/**
53
-	 * @var ISystemTagObjectMapper
54
-	 */
55
-	private $tagMapper;
56
-
57
-	/**
58
-	 * @var IGroupManager
59
-	 */
60
-	private $groupManager;
61
-
62
-	/**
63
-	 * @var IUserSession
64
-	 */
65
-	private $userSession;
66
-
67
-	/**
68
-	 * @var \Closure
69
-	 **/
70
-	protected $childExistsFunction;
71
-
72
-	/**
73
-	 * Constructor
74
-	 *
75
-	 * @param string $objectType object type
76
-	 * @param ISystemTagManager $tagManager
77
-	 * @param ISystemTagObjectMapper $tagMapper
78
-	 * @param IUserSession $userSession
79
-	 * @param IGroupManager $groupManager
80
-	 * @param \Closure $childExistsFunction
81
-	 */
82
-	public function __construct(
83
-		$objectType,
84
-		ISystemTagManager $tagManager,
85
-		ISystemTagObjectMapper $tagMapper,
86
-		IUserSession $userSession,
87
-		IGroupManager $groupManager,
88
-		\Closure $childExistsFunction
89
-	) {
90
-		$this->tagManager = $tagManager;
91
-		$this->tagMapper = $tagMapper;
92
-		$this->objectType = $objectType;
93
-		$this->userSession = $userSession;
94
-		$this->groupManager = $groupManager;
95
-		$this->childExistsFunction = $childExistsFunction;
96
-	}
97
-
98
-	/**
99
-	 * @param string $name
100
-	 * @param resource|string $data Initial payload
101
-	 *
102
-	 * @return never
103
-	 *
104
-	 * @throws Forbidden
105
-	 */
106
-	public function createFile($name, $data = null) {
107
-		throw new Forbidden('Permission denied to create nodes');
108
-	}
109
-
110
-	/**
111
-	 * @param string $name
112
-	 *
113
-	 * @throws Forbidden
114
-	 *
115
-	 * @return never
116
-	 */
117
-	public function createDirectory($name) {
118
-		throw new Forbidden('Permission denied to create collections');
119
-	}
120
-
121
-	/**
122
-	 * @param string $objectName
123
-	 *
124
-	 * @return SystemTagsObjectMappingCollection
125
-	 * @throws NotFound
126
-	 */
127
-	public function getChild($objectName) {
128
-		// make sure the object exists and is reachable
129
-		if (!$this->childExists($objectName)) {
130
-			throw new NotFound('Entity does not exist or is not available');
131
-		}
132
-		return new SystemTagsObjectMappingCollection(
133
-			$objectName,
134
-			$this->objectType,
135
-			$this->userSession->getUser(),
136
-			$this->tagManager,
137
-			$this->tagMapper
138
-		);
139
-	}
140
-
141
-	/**
142
-	 * @return never
143
-	 */
144
-	public function getChildren() {
145
-		// do not list object ids
146
-		throw new MethodNotAllowed();
147
-	}
148
-
149
-	/**
150
-	 * Checks if a child-node with the specified name exists
151
-	 *
152
-	 * @param string $name
153
-	 * @return bool
154
-	 */
155
-	public function childExists($name) {
156
-		return call_user_func($this->childExistsFunction, $name);
157
-	}
158
-
159
-	/**
160
-	 * @return never
161
-	 */
162
-	public function delete() {
163
-		throw new Forbidden('Permission denied to delete this collection');
164
-	}
165
-
166
-	public function getName() {
167
-		return $this->objectType;
168
-	}
169
-
170
-	/**
171
-	 * @param string $name
172
-	 *
173
-	 * @throws Forbidden
174
-	 *
175
-	 * @return never
176
-	 */
177
-	public function setName($name) {
178
-		throw new Forbidden('Permission denied to rename this collection');
179
-	}
180
-
181
-	/**
182
-	 * Returns the last modification time, as a unix timestamp
183
-	 *
184
-	 * @return null
185
-	 */
186
-	public function getLastModified() {
187
-		return null;
188
-	}
42
+    /**
43
+     * @var string
44
+     */
45
+    private $objectType;
46
+
47
+    /**
48
+     * @var ISystemTagManager
49
+     */
50
+    private $tagManager;
51
+
52
+    /**
53
+     * @var ISystemTagObjectMapper
54
+     */
55
+    private $tagMapper;
56
+
57
+    /**
58
+     * @var IGroupManager
59
+     */
60
+    private $groupManager;
61
+
62
+    /**
63
+     * @var IUserSession
64
+     */
65
+    private $userSession;
66
+
67
+    /**
68
+     * @var \Closure
69
+     **/
70
+    protected $childExistsFunction;
71
+
72
+    /**
73
+     * Constructor
74
+     *
75
+     * @param string $objectType object type
76
+     * @param ISystemTagManager $tagManager
77
+     * @param ISystemTagObjectMapper $tagMapper
78
+     * @param IUserSession $userSession
79
+     * @param IGroupManager $groupManager
80
+     * @param \Closure $childExistsFunction
81
+     */
82
+    public function __construct(
83
+        $objectType,
84
+        ISystemTagManager $tagManager,
85
+        ISystemTagObjectMapper $tagMapper,
86
+        IUserSession $userSession,
87
+        IGroupManager $groupManager,
88
+        \Closure $childExistsFunction
89
+    ) {
90
+        $this->tagManager = $tagManager;
91
+        $this->tagMapper = $tagMapper;
92
+        $this->objectType = $objectType;
93
+        $this->userSession = $userSession;
94
+        $this->groupManager = $groupManager;
95
+        $this->childExistsFunction = $childExistsFunction;
96
+    }
97
+
98
+    /**
99
+     * @param string $name
100
+     * @param resource|string $data Initial payload
101
+     *
102
+     * @return never
103
+     *
104
+     * @throws Forbidden
105
+     */
106
+    public function createFile($name, $data = null) {
107
+        throw new Forbidden('Permission denied to create nodes');
108
+    }
109
+
110
+    /**
111
+     * @param string $name
112
+     *
113
+     * @throws Forbidden
114
+     *
115
+     * @return never
116
+     */
117
+    public function createDirectory($name) {
118
+        throw new Forbidden('Permission denied to create collections');
119
+    }
120
+
121
+    /**
122
+     * @param string $objectName
123
+     *
124
+     * @return SystemTagsObjectMappingCollection
125
+     * @throws NotFound
126
+     */
127
+    public function getChild($objectName) {
128
+        // make sure the object exists and is reachable
129
+        if (!$this->childExists($objectName)) {
130
+            throw new NotFound('Entity does not exist or is not available');
131
+        }
132
+        return new SystemTagsObjectMappingCollection(
133
+            $objectName,
134
+            $this->objectType,
135
+            $this->userSession->getUser(),
136
+            $this->tagManager,
137
+            $this->tagMapper
138
+        );
139
+    }
140
+
141
+    /**
142
+     * @return never
143
+     */
144
+    public function getChildren() {
145
+        // do not list object ids
146
+        throw new MethodNotAllowed();
147
+    }
148
+
149
+    /**
150
+     * Checks if a child-node with the specified name exists
151
+     *
152
+     * @param string $name
153
+     * @return bool
154
+     */
155
+    public function childExists($name) {
156
+        return call_user_func($this->childExistsFunction, $name);
157
+    }
158
+
159
+    /**
160
+     * @return never
161
+     */
162
+    public function delete() {
163
+        throw new Forbidden('Permission denied to delete this collection');
164
+    }
165
+
166
+    public function getName() {
167
+        return $this->objectType;
168
+    }
169
+
170
+    /**
171
+     * @param string $name
172
+     *
173
+     * @throws Forbidden
174
+     *
175
+     * @return never
176
+     */
177
+    public function setName($name) {
178
+        throw new Forbidden('Permission denied to rename this collection');
179
+    }
180
+
181
+    /**
182
+     * Returns the last modification time, as a unix timestamp
183
+     *
184
+     * @return null
185
+     */
186
+    public function getLastModified() {
187
+        return null;
188
+    }
189 189
 }
Please login to merge, or discard this patch.
apps/dav/lib/SystemTag/SystemTagPlugin.php 1 patch
Indentation   +360 added lines, -360 removed lines patch added patch discarded remove patch
@@ -52,365 +52,365 @@
 block discarded – undo
52 52
  */
53 53
 class SystemTagPlugin extends \Sabre\DAV\ServerPlugin {
54 54
 
55
-	// namespace
56
-	public const NS_OWNCLOUD = 'http://owncloud.org/ns';
57
-	public const ID_PROPERTYNAME = '{http://owncloud.org/ns}id';
58
-	public const DISPLAYNAME_PROPERTYNAME = '{http://owncloud.org/ns}display-name';
59
-	public const USERVISIBLE_PROPERTYNAME = '{http://owncloud.org/ns}user-visible';
60
-	public const USERASSIGNABLE_PROPERTYNAME = '{http://owncloud.org/ns}user-assignable';
61
-	public const GROUPS_PROPERTYNAME = '{http://owncloud.org/ns}groups';
62
-	public const CANASSIGN_PROPERTYNAME = '{http://owncloud.org/ns}can-assign';
63
-	public const SYSTEM_TAGS_PROPERTYNAME = '{http://nextcloud.org/ns}system-tags';
64
-
65
-	/**
66
-	 * @var \Sabre\DAV\Server $server
67
-	 */
68
-	private $server;
69
-
70
-	/**
71
-	 * @var ISystemTagManager
72
-	 */
73
-	protected $tagManager;
74
-
75
-	/**
76
-	 * @var IUserSession
77
-	 */
78
-	protected $userSession;
79
-
80
-	/**
81
-	 * @var IGroupManager
82
-	 */
83
-	protected $groupManager;
84
-
85
-	/** @var array<int, string[]> */
86
-	private array $cachedTagMappings = [];
87
-	/** @var array<string, ISystemTag> */
88
-	private array $cachedTags = [];
89
-
90
-	private ISystemTagObjectMapper $tagMapper;
91
-
92
-	public function __construct(
93
-		ISystemTagManager $tagManager,
94
-		IGroupManager $groupManager,
95
-		IUserSession $userSession,
96
-		ISystemTagObjectMapper $tagMapper,
97
-	) {
98
-		$this->tagManager = $tagManager;
99
-		$this->userSession = $userSession;
100
-		$this->groupManager = $groupManager;
101
-		$this->tagMapper = $tagMapper;
102
-	}
103
-
104
-	/**
105
-	 * This initializes the plugin.
106
-	 *
107
-	 * This function is called by \Sabre\DAV\Server, after
108
-	 * addPlugin is called.
109
-	 *
110
-	 * This method should set up the required event subscriptions.
111
-	 *
112
-	 * @param \Sabre\DAV\Server $server
113
-	 * @return void
114
-	 */
115
-	public function initialize(\Sabre\DAV\Server $server) {
116
-		$server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc';
117
-
118
-		$server->protectedProperties[] = self::ID_PROPERTYNAME;
119
-
120
-		$server->on('propFind', [$this, 'handleGetProperties']);
121
-		$server->on('propPatch', [$this, 'handleUpdateProperties']);
122
-		$server->on('method:POST', [$this, 'httpPost']);
123
-
124
-		$this->server = $server;
125
-	}
126
-
127
-	/**
128
-	 * POST operation on system tag collections
129
-	 *
130
-	 * @param RequestInterface $request request object
131
-	 * @param ResponseInterface $response response object
132
-	 * @return null|false
133
-	 */
134
-	public function httpPost(RequestInterface $request, ResponseInterface $response) {
135
-		$path = $request->getPath();
136
-
137
-		// Making sure the node exists
138
-		$node = $this->server->tree->getNodeForPath($path);
139
-		if ($node instanceof SystemTagsByIdCollection || $node instanceof SystemTagsObjectMappingCollection) {
140
-			$data = $request->getBodyAsString();
141
-
142
-			$tag = $this->createTag($data, $request->getHeader('Content-Type'));
143
-
144
-			if ($node instanceof SystemTagsObjectMappingCollection) {
145
-				// also add to collection
146
-				$node->createFile($tag->getId());
147
-				$url = $request->getBaseUrl() . 'systemtags/';
148
-			} else {
149
-				$url = $request->getUrl();
150
-			}
151
-
152
-			if ($url[strlen($url) - 1] !== '/') {
153
-				$url .= '/';
154
-			}
155
-
156
-			$response->setHeader('Content-Location', $url . $tag->getId());
157
-
158
-			// created
159
-			$response->setStatus(201);
160
-			return false;
161
-		}
162
-	}
163
-
164
-	/**
165
-	 * Creates a new tag
166
-	 *
167
-	 * @param string $data JSON encoded string containing the properties of the tag to create
168
-	 * @param string $contentType content type of the data
169
-	 * @return ISystemTag newly created system tag
170
-	 *
171
-	 * @throws BadRequest if a field was missing
172
-	 * @throws Conflict if a tag with the same properties already exists
173
-	 * @throws UnsupportedMediaType if the content type is not supported
174
-	 */
175
-	private function createTag($data, $contentType = 'application/json') {
176
-		if (explode(';', $contentType)[0] === 'application/json') {
177
-			$data = json_decode($data, true, 512, JSON_THROW_ON_ERROR);
178
-		} else {
179
-			throw new UnsupportedMediaType();
180
-		}
181
-
182
-		if (!isset($data['name'])) {
183
-			throw new BadRequest('Missing "name" attribute');
184
-		}
185
-
186
-		$tagName = $data['name'];
187
-		$userVisible = true;
188
-		$userAssignable = true;
189
-
190
-		if (isset($data['userVisible'])) {
191
-			$userVisible = (bool)$data['userVisible'];
192
-		}
193
-
194
-		if (isset($data['userAssignable'])) {
195
-			$userAssignable = (bool)$data['userAssignable'];
196
-		}
197
-
198
-		$groups = [];
199
-		if (isset($data['groups'])) {
200
-			$groups = $data['groups'];
201
-			if (is_string($groups)) {
202
-				$groups = explode('|', $groups);
203
-			}
204
-		}
205
-
206
-		if ($userVisible === false || $userAssignable === false || !empty($groups)) {
207
-			if (!$this->userSession->isLoggedIn() || !$this->groupManager->isAdmin($this->userSession->getUser()->getUID())) {
208
-				throw new BadRequest('Not sufficient permissions');
209
-			}
210
-		}
211
-
212
-		try {
213
-			$tag = $this->tagManager->createTag($tagName, $userVisible, $userAssignable);
214
-			if (!empty($groups)) {
215
-				$this->tagManager->setTagGroups($tag, $groups);
216
-			}
217
-			return $tag;
218
-		} catch (TagAlreadyExistsException $e) {
219
-			throw new Conflict('Tag already exists', 0, $e);
220
-		}
221
-	}
222
-
223
-
224
-	/**
225
-	 * Retrieves system tag properties
226
-	 *
227
-	 * @param PropFind $propFind
228
-	 * @param \Sabre\DAV\INode $node
229
-	 *
230
-	 * @return void
231
-	 */
232
-	public function handleGetProperties(
233
-		PropFind $propFind,
234
-		\Sabre\DAV\INode $node
235
-	) {
236
-		if ($node instanceof Node) {
237
-			$this->propfindForFile($propFind, $node);
238
-			return;
239
-		}
240
-
241
-		if (!($node instanceof SystemTagNode) && !($node instanceof SystemTagMappingNode)) {
242
-			return;
243
-		}
244
-
245
-		$propFind->handle(self::ID_PROPERTYNAME, function () use ($node) {
246
-			return $node->getSystemTag()->getId();
247
-		});
248
-
249
-		$propFind->handle(self::DISPLAYNAME_PROPERTYNAME, function () use ($node) {
250
-			return $node->getSystemTag()->getName();
251
-		});
252
-
253
-		$propFind->handle(self::USERVISIBLE_PROPERTYNAME, function () use ($node) {
254
-			return $node->getSystemTag()->isUserVisible() ? 'true' : 'false';
255
-		});
256
-
257
-		$propFind->handle(self::USERASSIGNABLE_PROPERTYNAME, function () use ($node) {
258
-			// this is the tag's inherent property "is user assignable"
259
-			return $node->getSystemTag()->isUserAssignable() ? 'true' : 'false';
260
-		});
261
-
262
-		$propFind->handle(self::CANASSIGN_PROPERTYNAME, function () use ($node) {
263
-			// this is the effective permission for the current user
264
-			return $this->tagManager->canUserAssignTag($node->getSystemTag(), $this->userSession->getUser()) ? 'true' : 'false';
265
-		});
266
-
267
-		$propFind->handle(self::GROUPS_PROPERTYNAME, function () use ($node) {
268
-			if (!$this->groupManager->isAdmin($this->userSession->getUser()->getUID())) {
269
-				// property only available for admins
270
-				throw new Forbidden();
271
-			}
272
-			$groups = [];
273
-			// no need to retrieve groups for namespaces that don't qualify
274
-			if ($node->getSystemTag()->isUserVisible() && !$node->getSystemTag()->isUserAssignable()) {
275
-				$groups = $this->tagManager->getTagGroups($node->getSystemTag());
276
-			}
277
-			return implode('|', $groups);
278
-		});
279
-	}
280
-
281
-	private function propfindForFile(PropFind $propFind, Node $node): void {
282
-		if ($node instanceof Directory
283
-			&& $propFind->getDepth() !== 0
284
-			&& !is_null($propFind->getStatus(self::SYSTEM_TAGS_PROPERTYNAME))) {
285
-			$fileIds = [$node->getId()];
286
-
287
-			// note: pre-fetching only supported for depth <= 1
288
-			$folderContent = $node->getNode()->getDirectoryListing();
289
-			foreach ($folderContent as $info) {
290
-				$fileIds[] = $info->getId();
291
-			}
292
-
293
-			$tags = $this->tagMapper->getTagIdsForObjects($fileIds, 'files');
294
-
295
-			$this->cachedTagMappings = $this->cachedTagMappings + $tags;
296
-			$emptyFileIds = array_diff($fileIds, array_keys($tags));
297
-
298
-			// also cache the ones that were not found
299
-			foreach ($emptyFileIds as $fileId) {
300
-				$this->cachedTagMappings[$fileId] = [];
301
-			}
302
-		}
303
-
304
-		$propFind->handle(self::SYSTEM_TAGS_PROPERTYNAME, function () use ($node) {
305
-			$user = $this->userSession->getUser();
306
-			if ($user === null) {
307
-				return;
308
-			}
55
+    // namespace
56
+    public const NS_OWNCLOUD = 'http://owncloud.org/ns';
57
+    public const ID_PROPERTYNAME = '{http://owncloud.org/ns}id';
58
+    public const DISPLAYNAME_PROPERTYNAME = '{http://owncloud.org/ns}display-name';
59
+    public const USERVISIBLE_PROPERTYNAME = '{http://owncloud.org/ns}user-visible';
60
+    public const USERASSIGNABLE_PROPERTYNAME = '{http://owncloud.org/ns}user-assignable';
61
+    public const GROUPS_PROPERTYNAME = '{http://owncloud.org/ns}groups';
62
+    public const CANASSIGN_PROPERTYNAME = '{http://owncloud.org/ns}can-assign';
63
+    public const SYSTEM_TAGS_PROPERTYNAME = '{http://nextcloud.org/ns}system-tags';
64
+
65
+    /**
66
+     * @var \Sabre\DAV\Server $server
67
+     */
68
+    private $server;
69
+
70
+    /**
71
+     * @var ISystemTagManager
72
+     */
73
+    protected $tagManager;
74
+
75
+    /**
76
+     * @var IUserSession
77
+     */
78
+    protected $userSession;
79
+
80
+    /**
81
+     * @var IGroupManager
82
+     */
83
+    protected $groupManager;
84
+
85
+    /** @var array<int, string[]> */
86
+    private array $cachedTagMappings = [];
87
+    /** @var array<string, ISystemTag> */
88
+    private array $cachedTags = [];
89
+
90
+    private ISystemTagObjectMapper $tagMapper;
91
+
92
+    public function __construct(
93
+        ISystemTagManager $tagManager,
94
+        IGroupManager $groupManager,
95
+        IUserSession $userSession,
96
+        ISystemTagObjectMapper $tagMapper,
97
+    ) {
98
+        $this->tagManager = $tagManager;
99
+        $this->userSession = $userSession;
100
+        $this->groupManager = $groupManager;
101
+        $this->tagMapper = $tagMapper;
102
+    }
103
+
104
+    /**
105
+     * This initializes the plugin.
106
+     *
107
+     * This function is called by \Sabre\DAV\Server, after
108
+     * addPlugin is called.
109
+     *
110
+     * This method should set up the required event subscriptions.
111
+     *
112
+     * @param \Sabre\DAV\Server $server
113
+     * @return void
114
+     */
115
+    public function initialize(\Sabre\DAV\Server $server) {
116
+        $server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc';
117
+
118
+        $server->protectedProperties[] = self::ID_PROPERTYNAME;
119
+
120
+        $server->on('propFind', [$this, 'handleGetProperties']);
121
+        $server->on('propPatch', [$this, 'handleUpdateProperties']);
122
+        $server->on('method:POST', [$this, 'httpPost']);
123
+
124
+        $this->server = $server;
125
+    }
126
+
127
+    /**
128
+     * POST operation on system tag collections
129
+     *
130
+     * @param RequestInterface $request request object
131
+     * @param ResponseInterface $response response object
132
+     * @return null|false
133
+     */
134
+    public function httpPost(RequestInterface $request, ResponseInterface $response) {
135
+        $path = $request->getPath();
136
+
137
+        // Making sure the node exists
138
+        $node = $this->server->tree->getNodeForPath($path);
139
+        if ($node instanceof SystemTagsByIdCollection || $node instanceof SystemTagsObjectMappingCollection) {
140
+            $data = $request->getBodyAsString();
141
+
142
+            $tag = $this->createTag($data, $request->getHeader('Content-Type'));
143
+
144
+            if ($node instanceof SystemTagsObjectMappingCollection) {
145
+                // also add to collection
146
+                $node->createFile($tag->getId());
147
+                $url = $request->getBaseUrl() . 'systemtags/';
148
+            } else {
149
+                $url = $request->getUrl();
150
+            }
151
+
152
+            if ($url[strlen($url) - 1] !== '/') {
153
+                $url .= '/';
154
+            }
155
+
156
+            $response->setHeader('Content-Location', $url . $tag->getId());
157
+
158
+            // created
159
+            $response->setStatus(201);
160
+            return false;
161
+        }
162
+    }
163
+
164
+    /**
165
+     * Creates a new tag
166
+     *
167
+     * @param string $data JSON encoded string containing the properties of the tag to create
168
+     * @param string $contentType content type of the data
169
+     * @return ISystemTag newly created system tag
170
+     *
171
+     * @throws BadRequest if a field was missing
172
+     * @throws Conflict if a tag with the same properties already exists
173
+     * @throws UnsupportedMediaType if the content type is not supported
174
+     */
175
+    private function createTag($data, $contentType = 'application/json') {
176
+        if (explode(';', $contentType)[0] === 'application/json') {
177
+            $data = json_decode($data, true, 512, JSON_THROW_ON_ERROR);
178
+        } else {
179
+            throw new UnsupportedMediaType();
180
+        }
181
+
182
+        if (!isset($data['name'])) {
183
+            throw new BadRequest('Missing "name" attribute');
184
+        }
185
+
186
+        $tagName = $data['name'];
187
+        $userVisible = true;
188
+        $userAssignable = true;
189
+
190
+        if (isset($data['userVisible'])) {
191
+            $userVisible = (bool)$data['userVisible'];
192
+        }
193
+
194
+        if (isset($data['userAssignable'])) {
195
+            $userAssignable = (bool)$data['userAssignable'];
196
+        }
197
+
198
+        $groups = [];
199
+        if (isset($data['groups'])) {
200
+            $groups = $data['groups'];
201
+            if (is_string($groups)) {
202
+                $groups = explode('|', $groups);
203
+            }
204
+        }
205
+
206
+        if ($userVisible === false || $userAssignable === false || !empty($groups)) {
207
+            if (!$this->userSession->isLoggedIn() || !$this->groupManager->isAdmin($this->userSession->getUser()->getUID())) {
208
+                throw new BadRequest('Not sufficient permissions');
209
+            }
210
+        }
211
+
212
+        try {
213
+            $tag = $this->tagManager->createTag($tagName, $userVisible, $userAssignable);
214
+            if (!empty($groups)) {
215
+                $this->tagManager->setTagGroups($tag, $groups);
216
+            }
217
+            return $tag;
218
+        } catch (TagAlreadyExistsException $e) {
219
+            throw new Conflict('Tag already exists', 0, $e);
220
+        }
221
+    }
222
+
223
+
224
+    /**
225
+     * Retrieves system tag properties
226
+     *
227
+     * @param PropFind $propFind
228
+     * @param \Sabre\DAV\INode $node
229
+     *
230
+     * @return void
231
+     */
232
+    public function handleGetProperties(
233
+        PropFind $propFind,
234
+        \Sabre\DAV\INode $node
235
+    ) {
236
+        if ($node instanceof Node) {
237
+            $this->propfindForFile($propFind, $node);
238
+            return;
239
+        }
240
+
241
+        if (!($node instanceof SystemTagNode) && !($node instanceof SystemTagMappingNode)) {
242
+            return;
243
+        }
244
+
245
+        $propFind->handle(self::ID_PROPERTYNAME, function () use ($node) {
246
+            return $node->getSystemTag()->getId();
247
+        });
248
+
249
+        $propFind->handle(self::DISPLAYNAME_PROPERTYNAME, function () use ($node) {
250
+            return $node->getSystemTag()->getName();
251
+        });
252
+
253
+        $propFind->handle(self::USERVISIBLE_PROPERTYNAME, function () use ($node) {
254
+            return $node->getSystemTag()->isUserVisible() ? 'true' : 'false';
255
+        });
256
+
257
+        $propFind->handle(self::USERASSIGNABLE_PROPERTYNAME, function () use ($node) {
258
+            // this is the tag's inherent property "is user assignable"
259
+            return $node->getSystemTag()->isUserAssignable() ? 'true' : 'false';
260
+        });
261
+
262
+        $propFind->handle(self::CANASSIGN_PROPERTYNAME, function () use ($node) {
263
+            // this is the effective permission for the current user
264
+            return $this->tagManager->canUserAssignTag($node->getSystemTag(), $this->userSession->getUser()) ? 'true' : 'false';
265
+        });
266
+
267
+        $propFind->handle(self::GROUPS_PROPERTYNAME, function () use ($node) {
268
+            if (!$this->groupManager->isAdmin($this->userSession->getUser()->getUID())) {
269
+                // property only available for admins
270
+                throw new Forbidden();
271
+            }
272
+            $groups = [];
273
+            // no need to retrieve groups for namespaces that don't qualify
274
+            if ($node->getSystemTag()->isUserVisible() && !$node->getSystemTag()->isUserAssignable()) {
275
+                $groups = $this->tagManager->getTagGroups($node->getSystemTag());
276
+            }
277
+            return implode('|', $groups);
278
+        });
279
+    }
280
+
281
+    private function propfindForFile(PropFind $propFind, Node $node): void {
282
+        if ($node instanceof Directory
283
+            && $propFind->getDepth() !== 0
284
+            && !is_null($propFind->getStatus(self::SYSTEM_TAGS_PROPERTYNAME))) {
285
+            $fileIds = [$node->getId()];
286
+
287
+            // note: pre-fetching only supported for depth <= 1
288
+            $folderContent = $node->getNode()->getDirectoryListing();
289
+            foreach ($folderContent as $info) {
290
+                $fileIds[] = $info->getId();
291
+            }
292
+
293
+            $tags = $this->tagMapper->getTagIdsForObjects($fileIds, 'files');
294
+
295
+            $this->cachedTagMappings = $this->cachedTagMappings + $tags;
296
+            $emptyFileIds = array_diff($fileIds, array_keys($tags));
297
+
298
+            // also cache the ones that were not found
299
+            foreach ($emptyFileIds as $fileId) {
300
+                $this->cachedTagMappings[$fileId] = [];
301
+            }
302
+        }
303
+
304
+        $propFind->handle(self::SYSTEM_TAGS_PROPERTYNAME, function () use ($node) {
305
+            $user = $this->userSession->getUser();
306
+            if ($user === null) {
307
+                return;
308
+            }
309 309
 	
310
-			$tags = $this->getTagsForFile($node->getId(), $user);
311
-			return new SystemTagList($tags, $this->tagManager, $user);
312
-		});
313
-	}
314
-
315
-	/**
316
-	 * @param int $fileId
317
-	 * @return ISystemTag[]
318
-	 */
319
-	private function getTagsForFile(int $fileId, IUser $user): array {
320
-
321
-		if (isset($this->cachedTagMappings[$fileId])) {
322
-			$tagIds = $this->cachedTagMappings[$fileId];
323
-		} else {
324
-			$tags = $this->tagMapper->getTagIdsForObjects([$fileId], 'files');
325
-			$fileTags = current($tags);
326
-			if ($fileTags) {
327
-				$tagIds = $fileTags;
328
-			} else {
329
-				$tagIds = [];
330
-			}
331
-		}
332
-
333
-		$tags = array_filter(array_map(function(string $tagId) {
334
-			return $this->cachedTags[$tagId] ?? null;
335
-		}, $tagIds));
336
-
337
-		$uncachedTagIds = array_filter($tagIds, function(string $tagId): bool {
338
-			return !isset($this->cachedTags[$tagId]);
339
-		});
340
-
341
-		if (count($uncachedTagIds)) {
342
-			$retrievedTags = $this->tagManager->getTagsByIds($uncachedTagIds);
343
-			foreach ($retrievedTags as $tag) {
344
-				$this->cachedTags[$tag->getId()] = $tag;
345
-			}
346
-			$tags += $retrievedTags;
347
-		}
348
-
349
-		return array_filter($tags, function(ISystemTag $tag) use ($user) {
350
-			return $this->tagManager->canUserSeeTag($tag, $user);
351
-		});
352
-	}
353
-
354
-	/**
355
-	 * Updates tag attributes
356
-	 *
357
-	 * @param string $path
358
-	 * @param PropPatch $propPatch
359
-	 *
360
-	 * @return void
361
-	 */
362
-	public function handleUpdateProperties($path, PropPatch $propPatch) {
363
-		$node = $this->server->tree->getNodeForPath($path);
364
-		if (!($node instanceof SystemTagNode)) {
365
-			return;
366
-		}
367
-
368
-		$propPatch->handle([
369
-			self::DISPLAYNAME_PROPERTYNAME,
370
-			self::USERVISIBLE_PROPERTYNAME,
371
-			self::USERASSIGNABLE_PROPERTYNAME,
372
-			self::GROUPS_PROPERTYNAME,
373
-		], function ($props) use ($node) {
374
-			$tag = $node->getSystemTag();
375
-			$name = $tag->getName();
376
-			$userVisible = $tag->isUserVisible();
377
-			$userAssignable = $tag->isUserAssignable();
378
-
379
-			$updateTag = false;
380
-
381
-			if (isset($props[self::DISPLAYNAME_PROPERTYNAME])) {
382
-				$name = $props[self::DISPLAYNAME_PROPERTYNAME];
383
-				$updateTag = true;
384
-			}
385
-
386
-			if (isset($props[self::USERVISIBLE_PROPERTYNAME])) {
387
-				$propValue = $props[self::USERVISIBLE_PROPERTYNAME];
388
-				$userVisible = ($propValue !== 'false' && $propValue !== '0');
389
-				$updateTag = true;
390
-			}
391
-
392
-			if (isset($props[self::USERASSIGNABLE_PROPERTYNAME])) {
393
-				$propValue = $props[self::USERASSIGNABLE_PROPERTYNAME];
394
-				$userAssignable = ($propValue !== 'false' && $propValue !== '0');
395
-				$updateTag = true;
396
-			}
397
-
398
-			if (isset($props[self::GROUPS_PROPERTYNAME])) {
399
-				if (!$this->groupManager->isAdmin($this->userSession->getUser()->getUID())) {
400
-					// property only available for admins
401
-					throw new Forbidden();
402
-				}
403
-
404
-				$propValue = $props[self::GROUPS_PROPERTYNAME];
405
-				$groupIds = explode('|', $propValue);
406
-				$this->tagManager->setTagGroups($tag, $groupIds);
407
-			}
408
-
409
-			if ($updateTag) {
410
-				$node->update($name, $userVisible, $userAssignable);
411
-			}
412
-
413
-			return true;
414
-		});
415
-	}
310
+            $tags = $this->getTagsForFile($node->getId(), $user);
311
+            return new SystemTagList($tags, $this->tagManager, $user);
312
+        });
313
+    }
314
+
315
+    /**
316
+     * @param int $fileId
317
+     * @return ISystemTag[]
318
+     */
319
+    private function getTagsForFile(int $fileId, IUser $user): array {
320
+
321
+        if (isset($this->cachedTagMappings[$fileId])) {
322
+            $tagIds = $this->cachedTagMappings[$fileId];
323
+        } else {
324
+            $tags = $this->tagMapper->getTagIdsForObjects([$fileId], 'files');
325
+            $fileTags = current($tags);
326
+            if ($fileTags) {
327
+                $tagIds = $fileTags;
328
+            } else {
329
+                $tagIds = [];
330
+            }
331
+        }
332
+
333
+        $tags = array_filter(array_map(function(string $tagId) {
334
+            return $this->cachedTags[$tagId] ?? null;
335
+        }, $tagIds));
336
+
337
+        $uncachedTagIds = array_filter($tagIds, function(string $tagId): bool {
338
+            return !isset($this->cachedTags[$tagId]);
339
+        });
340
+
341
+        if (count($uncachedTagIds)) {
342
+            $retrievedTags = $this->tagManager->getTagsByIds($uncachedTagIds);
343
+            foreach ($retrievedTags as $tag) {
344
+                $this->cachedTags[$tag->getId()] = $tag;
345
+            }
346
+            $tags += $retrievedTags;
347
+        }
348
+
349
+        return array_filter($tags, function(ISystemTag $tag) use ($user) {
350
+            return $this->tagManager->canUserSeeTag($tag, $user);
351
+        });
352
+    }
353
+
354
+    /**
355
+     * Updates tag attributes
356
+     *
357
+     * @param string $path
358
+     * @param PropPatch $propPatch
359
+     *
360
+     * @return void
361
+     */
362
+    public function handleUpdateProperties($path, PropPatch $propPatch) {
363
+        $node = $this->server->tree->getNodeForPath($path);
364
+        if (!($node instanceof SystemTagNode)) {
365
+            return;
366
+        }
367
+
368
+        $propPatch->handle([
369
+            self::DISPLAYNAME_PROPERTYNAME,
370
+            self::USERVISIBLE_PROPERTYNAME,
371
+            self::USERASSIGNABLE_PROPERTYNAME,
372
+            self::GROUPS_PROPERTYNAME,
373
+        ], function ($props) use ($node) {
374
+            $tag = $node->getSystemTag();
375
+            $name = $tag->getName();
376
+            $userVisible = $tag->isUserVisible();
377
+            $userAssignable = $tag->isUserAssignable();
378
+
379
+            $updateTag = false;
380
+
381
+            if (isset($props[self::DISPLAYNAME_PROPERTYNAME])) {
382
+                $name = $props[self::DISPLAYNAME_PROPERTYNAME];
383
+                $updateTag = true;
384
+            }
385
+
386
+            if (isset($props[self::USERVISIBLE_PROPERTYNAME])) {
387
+                $propValue = $props[self::USERVISIBLE_PROPERTYNAME];
388
+                $userVisible = ($propValue !== 'false' && $propValue !== '0');
389
+                $updateTag = true;
390
+            }
391
+
392
+            if (isset($props[self::USERASSIGNABLE_PROPERTYNAME])) {
393
+                $propValue = $props[self::USERASSIGNABLE_PROPERTYNAME];
394
+                $userAssignable = ($propValue !== 'false' && $propValue !== '0');
395
+                $updateTag = true;
396
+            }
397
+
398
+            if (isset($props[self::GROUPS_PROPERTYNAME])) {
399
+                if (!$this->groupManager->isAdmin($this->userSession->getUser()->getUID())) {
400
+                    // property only available for admins
401
+                    throw new Forbidden();
402
+                }
403
+
404
+                $propValue = $props[self::GROUPS_PROPERTYNAME];
405
+                $groupIds = explode('|', $propValue);
406
+                $this->tagManager->setTagGroups($tag, $groupIds);
407
+            }
408
+
409
+            if ($updateTag) {
410
+                $node->update($name, $userVisible, $userAssignable);
411
+            }
412
+
413
+            return true;
414
+        });
415
+    }
416 416
 }
Please login to merge, or discard this patch.
apps/dav/lib/SystemTag/SystemTagsObjectMappingCollection.php 1 patch
Indentation   +186 added lines, -186 removed lines patch added patch discarded remove patch
@@ -41,190 +41,190 @@
 block discarded – undo
41 41
  */
42 42
 class SystemTagsObjectMappingCollection implements ICollection {
43 43
 
44
-	/**
45
-	 * @var string
46
-	 */
47
-	private $objectId;
48
-
49
-	/**
50
-	 * @var string
51
-	 */
52
-	private $objectType;
53
-
54
-	/**
55
-	 * @var ISystemTagManager
56
-	 */
57
-	private $tagManager;
58
-
59
-	/**
60
-	 * @var ISystemTagObjectMapper
61
-	 */
62
-	private $tagMapper;
63
-
64
-	/**
65
-	 * User
66
-	 *
67
-	 * @var IUser
68
-	 */
69
-	private $user;
70
-
71
-
72
-	/**
73
-	 * Constructor
74
-	 *
75
-	 * @param string $objectId object id
76
-	 * @param string $objectType object type
77
-	 * @param IUser $user user
78
-	 * @param ISystemTagManager $tagManager tag manager
79
-	 * @param ISystemTagObjectMapper $tagMapper tag mapper
80
-	 */
81
-	public function __construct(
82
-		$objectId,
83
-		$objectType,
84
-		IUser $user,
85
-		ISystemTagManager $tagManager,
86
-		ISystemTagObjectMapper $tagMapper
87
-	) {
88
-		$this->tagManager = $tagManager;
89
-		$this->tagMapper = $tagMapper;
90
-		$this->objectId = $objectId;
91
-		$this->objectType = $objectType;
92
-		$this->user = $user;
93
-	}
94
-
95
-	/**
96
-	 * @return void
97
-	 */
98
-	public function createFile($name, $data = null) {
99
-		$tagId = $name;
100
-		try {
101
-			$tags = $this->tagManager->getTagsByIds([$tagId]);
102
-			$tag = current($tags);
103
-			if (!$this->tagManager->canUserSeeTag($tag, $this->user)) {
104
-				throw new PreconditionFailed('Tag with id ' . $tagId . ' does not exist, cannot assign');
105
-			}
106
-			if (!$this->tagManager->canUserAssignTag($tag, $this->user)) {
107
-				throw new Forbidden('No permission to assign tag ' . $tagId);
108
-			}
109
-
110
-			$this->tagMapper->assignTags($this->objectId, $this->objectType, $tagId);
111
-		} catch (TagNotFoundException $e) {
112
-			throw new PreconditionFailed('Tag with id ' . $tagId . ' does not exist, cannot assign');
113
-		}
114
-	}
115
-
116
-	/**
117
-	 * @return never
118
-	 */
119
-	public function createDirectory($name) {
120
-		throw new Forbidden('Permission denied to create collections');
121
-	}
122
-
123
-	/**
124
-	 * @return SystemTagMappingNode
125
-	 */
126
-	public function getChild($tagName) {
127
-		try {
128
-			if ($this->tagMapper->haveTag([$this->objectId], $this->objectType, $tagName, true)) {
129
-				$tag = $this->tagManager->getTagsByIds([$tagName]);
130
-				$tag = current($tag);
131
-				if ($this->tagManager->canUserSeeTag($tag, $this->user)) {
132
-					return $this->makeNode($tag);
133
-				}
134
-			}
135
-			throw new NotFound('Tag with id ' . $tagName . ' not present for object ' . $this->objectId);
136
-		} catch (\InvalidArgumentException $e) {
137
-			throw new BadRequest('Invalid tag id', 0, $e);
138
-		} catch (TagNotFoundException $e) {
139
-			throw new NotFound('Tag with id ' . $tagName . ' not found', 0, $e);
140
-		}
141
-	}
142
-
143
-	/**
144
-	 * @return SystemTagMappingNode[]
145
-	 *
146
-	 * @psalm-return list<SystemTagMappingNode>
147
-	 */
148
-	public function getChildren() {
149
-		$tagIds = current($this->tagMapper->getTagIdsForObjects([$this->objectId], $this->objectType));
150
-		if (empty($tagIds)) {
151
-			return [];
152
-		}
153
-		$tags = $this->tagManager->getTagsByIds($tagIds);
154
-
155
-		// filter out non-visible tags
156
-		$tags = array_filter($tags, function ($tag) {
157
-			return $this->tagManager->canUserSeeTag($tag, $this->user);
158
-		});
159
-
160
-		return array_values(array_map(function ($tag) {
161
-			return $this->makeNode($tag);
162
-		}, $tags));
163
-	}
164
-
165
-	public function childExists($tagId) {
166
-		try {
167
-			$result = $this->tagMapper->haveTag([$this->objectId], $this->objectType, $tagId, true);
168
-
169
-			if ($result) {
170
-				$tags = $this->tagManager->getTagsByIds([$tagId]);
171
-				$tag = current($tags);
172
-				if (!$this->tagManager->canUserSeeTag($tag, $this->user)) {
173
-					return false;
174
-				}
175
-			}
176
-
177
-			return $result;
178
-		} catch (\InvalidArgumentException $e) {
179
-			throw new BadRequest('Invalid tag id', 0, $e);
180
-		} catch (TagNotFoundException $e) {
181
-			return false;
182
-		}
183
-	}
184
-
185
-	/**
186
-	 * @return never
187
-	 */
188
-	public function delete() {
189
-		throw new Forbidden('Permission denied to delete this collection');
190
-	}
191
-
192
-	public function getName() {
193
-		return $this->objectId;
194
-	}
195
-
196
-	/**
197
-	 * @return never
198
-	 */
199
-	public function setName($name) {
200
-		throw new Forbidden('Permission denied to rename this collection');
201
-	}
202
-
203
-	/**
204
-	 * Returns the last modification time, as a unix timestamp
205
-	 *
206
-	 * @return null
207
-	 */
208
-	public function getLastModified() {
209
-		return null;
210
-	}
211
-
212
-	/**
213
-	 * Create a sabre node for the mapping of the
214
-	 * given system tag to the collection's object
215
-	 *
216
-	 * @param ISystemTag $tag
217
-	 *
218
-	 * @return SystemTagMappingNode
219
-	 */
220
-	private function makeNode(ISystemTag $tag) {
221
-		return new SystemTagMappingNode(
222
-			$tag,
223
-			$this->objectId,
224
-			$this->objectType,
225
-			$this->user,
226
-			$this->tagManager,
227
-			$this->tagMapper
228
-		);
229
-	}
44
+    /**
45
+     * @var string
46
+     */
47
+    private $objectId;
48
+
49
+    /**
50
+     * @var string
51
+     */
52
+    private $objectType;
53
+
54
+    /**
55
+     * @var ISystemTagManager
56
+     */
57
+    private $tagManager;
58
+
59
+    /**
60
+     * @var ISystemTagObjectMapper
61
+     */
62
+    private $tagMapper;
63
+
64
+    /**
65
+     * User
66
+     *
67
+     * @var IUser
68
+     */
69
+    private $user;
70
+
71
+
72
+    /**
73
+     * Constructor
74
+     *
75
+     * @param string $objectId object id
76
+     * @param string $objectType object type
77
+     * @param IUser $user user
78
+     * @param ISystemTagManager $tagManager tag manager
79
+     * @param ISystemTagObjectMapper $tagMapper tag mapper
80
+     */
81
+    public function __construct(
82
+        $objectId,
83
+        $objectType,
84
+        IUser $user,
85
+        ISystemTagManager $tagManager,
86
+        ISystemTagObjectMapper $tagMapper
87
+    ) {
88
+        $this->tagManager = $tagManager;
89
+        $this->tagMapper = $tagMapper;
90
+        $this->objectId = $objectId;
91
+        $this->objectType = $objectType;
92
+        $this->user = $user;
93
+    }
94
+
95
+    /**
96
+     * @return void
97
+     */
98
+    public function createFile($name, $data = null) {
99
+        $tagId = $name;
100
+        try {
101
+            $tags = $this->tagManager->getTagsByIds([$tagId]);
102
+            $tag = current($tags);
103
+            if (!$this->tagManager->canUserSeeTag($tag, $this->user)) {
104
+                throw new PreconditionFailed('Tag with id ' . $tagId . ' does not exist, cannot assign');
105
+            }
106
+            if (!$this->tagManager->canUserAssignTag($tag, $this->user)) {
107
+                throw new Forbidden('No permission to assign tag ' . $tagId);
108
+            }
109
+
110
+            $this->tagMapper->assignTags($this->objectId, $this->objectType, $tagId);
111
+        } catch (TagNotFoundException $e) {
112
+            throw new PreconditionFailed('Tag with id ' . $tagId . ' does not exist, cannot assign');
113
+        }
114
+    }
115
+
116
+    /**
117
+     * @return never
118
+     */
119
+    public function createDirectory($name) {
120
+        throw new Forbidden('Permission denied to create collections');
121
+    }
122
+
123
+    /**
124
+     * @return SystemTagMappingNode
125
+     */
126
+    public function getChild($tagName) {
127
+        try {
128
+            if ($this->tagMapper->haveTag([$this->objectId], $this->objectType, $tagName, true)) {
129
+                $tag = $this->tagManager->getTagsByIds([$tagName]);
130
+                $tag = current($tag);
131
+                if ($this->tagManager->canUserSeeTag($tag, $this->user)) {
132
+                    return $this->makeNode($tag);
133
+                }
134
+            }
135
+            throw new NotFound('Tag with id ' . $tagName . ' not present for object ' . $this->objectId);
136
+        } catch (\InvalidArgumentException $e) {
137
+            throw new BadRequest('Invalid tag id', 0, $e);
138
+        } catch (TagNotFoundException $e) {
139
+            throw new NotFound('Tag with id ' . $tagName . ' not found', 0, $e);
140
+        }
141
+    }
142
+
143
+    /**
144
+     * @return SystemTagMappingNode[]
145
+     *
146
+     * @psalm-return list<SystemTagMappingNode>
147
+     */
148
+    public function getChildren() {
149
+        $tagIds = current($this->tagMapper->getTagIdsForObjects([$this->objectId], $this->objectType));
150
+        if (empty($tagIds)) {
151
+            return [];
152
+        }
153
+        $tags = $this->tagManager->getTagsByIds($tagIds);
154
+
155
+        // filter out non-visible tags
156
+        $tags = array_filter($tags, function ($tag) {
157
+            return $this->tagManager->canUserSeeTag($tag, $this->user);
158
+        });
159
+
160
+        return array_values(array_map(function ($tag) {
161
+            return $this->makeNode($tag);
162
+        }, $tags));
163
+    }
164
+
165
+    public function childExists($tagId) {
166
+        try {
167
+            $result = $this->tagMapper->haveTag([$this->objectId], $this->objectType, $tagId, true);
168
+
169
+            if ($result) {
170
+                $tags = $this->tagManager->getTagsByIds([$tagId]);
171
+                $tag = current($tags);
172
+                if (!$this->tagManager->canUserSeeTag($tag, $this->user)) {
173
+                    return false;
174
+                }
175
+            }
176
+
177
+            return $result;
178
+        } catch (\InvalidArgumentException $e) {
179
+            throw new BadRequest('Invalid tag id', 0, $e);
180
+        } catch (TagNotFoundException $e) {
181
+            return false;
182
+        }
183
+    }
184
+
185
+    /**
186
+     * @return never
187
+     */
188
+    public function delete() {
189
+        throw new Forbidden('Permission denied to delete this collection');
190
+    }
191
+
192
+    public function getName() {
193
+        return $this->objectId;
194
+    }
195
+
196
+    /**
197
+     * @return never
198
+     */
199
+    public function setName($name) {
200
+        throw new Forbidden('Permission denied to rename this collection');
201
+    }
202
+
203
+    /**
204
+     * Returns the last modification time, as a unix timestamp
205
+     *
206
+     * @return null
207
+     */
208
+    public function getLastModified() {
209
+        return null;
210
+    }
211
+
212
+    /**
213
+     * Create a sabre node for the mapping of the
214
+     * given system tag to the collection's object
215
+     *
216
+     * @param ISystemTag $tag
217
+     *
218
+     * @return SystemTagMappingNode
219
+     */
220
+    private function makeNode(ISystemTag $tag) {
221
+        return new SystemTagMappingNode(
222
+            $tag,
223
+            $this->objectId,
224
+            $this->objectType,
225
+            $this->user,
226
+            $this->tagManager,
227
+            $this->tagMapper
228
+        );
229
+    }
230 230
 }
Please login to merge, or discard this patch.
apps/dav/lib/SystemTag/SystemTagNode.php 1 patch
Indentation   +139 added lines, -139 removed lines patch added patch discarded remove patch
@@ -40,143 +40,143 @@
 block discarded – undo
40 40
  */
41 41
 class SystemTagNode implements \Sabre\DAV\INode {
42 42
 
43
-	/**
44
-	 * @var ISystemTag
45
-	 */
46
-	protected $tag;
47
-
48
-	/**
49
-	 * @var ISystemTagManager
50
-	 */
51
-	protected $tagManager;
52
-
53
-	/**
54
-	 * User
55
-	 *
56
-	 * @var IUser
57
-	 */
58
-	protected $user;
59
-
60
-	/**
61
-	 * Whether to allow permissions for admins
62
-	 *
63
-	 * @var bool
64
-	 */
65
-	protected $isAdmin;
66
-
67
-	/**
68
-	 * Sets up the node, expects a full path name
69
-	 *
70
-	 * @param ISystemTag $tag system tag
71
-	 * @param IUser $user user
72
-	 * @param bool $isAdmin whether to allow operations for admins
73
-	 * @param ISystemTagManager $tagManager tag manager
74
-	 */
75
-	public function __construct(ISystemTag $tag, IUser $user, $isAdmin, ISystemTagManager $tagManager) {
76
-		$this->tag = $tag;
77
-		$this->user = $user;
78
-		$this->isAdmin = $isAdmin;
79
-		$this->tagManager = $tagManager;
80
-	}
81
-
82
-	/**
83
-	 *  Returns the id of the tag
84
-	 *
85
-	 * @return string
86
-	 */
87
-	public function getName() {
88
-		return $this->tag->getId();
89
-	}
90
-
91
-	/**
92
-	 * Returns the system tag represented by this node
93
-	 *
94
-	 * @return ISystemTag system tag
95
-	 */
96
-	public function getSystemTag() {
97
-		return $this->tag;
98
-	}
99
-
100
-	/**
101
-	 * Renames the node
102
-	 *
103
-	 * @param string $name The new name
104
-	 *
105
-	 * @throws MethodNotAllowed not allowed to rename node
106
-	 *
107
-	 * @return never
108
-	 */
109
-	public function setName($name) {
110
-		throw new MethodNotAllowed();
111
-	}
112
-
113
-	/**
114
-	 * Update tag
115
-	 *
116
-	 * @param string $name new tag name
117
-	 * @param bool $userVisible user visible
118
-	 * @param bool $userAssignable user assignable
119
-	 *
120
-	 * @throws NotFound whenever the given tag id does not exist
121
-	 * @throws Forbidden whenever there is no permission to update said tag
122
-	 * @throws Conflict whenever a tag already exists with the given attributes
123
-	 */
124
-	public function update($name, $userVisible, $userAssignable): void {
125
-		try {
126
-			if (!$this->tagManager->canUserSeeTag($this->tag, $this->user)) {
127
-				throw new NotFound('Tag with id ' . $this->tag->getId() . ' does not exist');
128
-			}
129
-			if (!$this->tagManager->canUserAssignTag($this->tag, $this->user)) {
130
-				throw new Forbidden('No permission to update tag ' . $this->tag->getId());
131
-			}
132
-
133
-			// only admin is able to change permissions, regular users can only rename
134
-			if (!$this->isAdmin) {
135
-				// only renaming is allowed for regular users
136
-				if ($userVisible !== $this->tag->isUserVisible()
137
-					|| $userAssignable !== $this->tag->isUserAssignable()
138
-				) {
139
-					throw new Forbidden('No permission to update permissions for tag ' . $this->tag->getId());
140
-				}
141
-			}
142
-
143
-			$this->tagManager->updateTag($this->tag->getId(), $name, $userVisible, $userAssignable);
144
-		} catch (TagNotFoundException $e) {
145
-			throw new NotFound('Tag with id ' . $this->tag->getId() . ' does not exist');
146
-		} catch (TagAlreadyExistsException $e) {
147
-			throw new Conflict(
148
-				'Tag with the properties "' . $name . '", ' .
149
-				$userVisible . ', ' . $userAssignable . ' already exists'
150
-			);
151
-		}
152
-	}
153
-
154
-	/**
155
-	 * Returns null, not supported
156
-	 *
157
-	 * @return null
158
-	 */
159
-	public function getLastModified() {
160
-		return null;
161
-	}
162
-
163
-	/**
164
-	 * @return void
165
-	 */
166
-	public function delete() {
167
-		try {
168
-			if (!$this->isAdmin) {
169
-				throw new Forbidden('No permission to delete tag ' . $this->tag->getId());
170
-			}
171
-
172
-			if (!$this->tagManager->canUserSeeTag($this->tag, $this->user)) {
173
-				throw new NotFound('Tag with id ' . $this->tag->getId() . ' not found');
174
-			}
175
-
176
-			$this->tagManager->deleteTags($this->tag->getId());
177
-		} catch (TagNotFoundException $e) {
178
-			// can happen if concurrent deletion occurred
179
-			throw new NotFound('Tag with id ' . $this->tag->getId() . ' not found', 0, $e);
180
-		}
181
-	}
43
+    /**
44
+     * @var ISystemTag
45
+     */
46
+    protected $tag;
47
+
48
+    /**
49
+     * @var ISystemTagManager
50
+     */
51
+    protected $tagManager;
52
+
53
+    /**
54
+     * User
55
+     *
56
+     * @var IUser
57
+     */
58
+    protected $user;
59
+
60
+    /**
61
+     * Whether to allow permissions for admins
62
+     *
63
+     * @var bool
64
+     */
65
+    protected $isAdmin;
66
+
67
+    /**
68
+     * Sets up the node, expects a full path name
69
+     *
70
+     * @param ISystemTag $tag system tag
71
+     * @param IUser $user user
72
+     * @param bool $isAdmin whether to allow operations for admins
73
+     * @param ISystemTagManager $tagManager tag manager
74
+     */
75
+    public function __construct(ISystemTag $tag, IUser $user, $isAdmin, ISystemTagManager $tagManager) {
76
+        $this->tag = $tag;
77
+        $this->user = $user;
78
+        $this->isAdmin = $isAdmin;
79
+        $this->tagManager = $tagManager;
80
+    }
81
+
82
+    /**
83
+     *  Returns the id of the tag
84
+     *
85
+     * @return string
86
+     */
87
+    public function getName() {
88
+        return $this->tag->getId();
89
+    }
90
+
91
+    /**
92
+     * Returns the system tag represented by this node
93
+     *
94
+     * @return ISystemTag system tag
95
+     */
96
+    public function getSystemTag() {
97
+        return $this->tag;
98
+    }
99
+
100
+    /**
101
+     * Renames the node
102
+     *
103
+     * @param string $name The new name
104
+     *
105
+     * @throws MethodNotAllowed not allowed to rename node
106
+     *
107
+     * @return never
108
+     */
109
+    public function setName($name) {
110
+        throw new MethodNotAllowed();
111
+    }
112
+
113
+    /**
114
+     * Update tag
115
+     *
116
+     * @param string $name new tag name
117
+     * @param bool $userVisible user visible
118
+     * @param bool $userAssignable user assignable
119
+     *
120
+     * @throws NotFound whenever the given tag id does not exist
121
+     * @throws Forbidden whenever there is no permission to update said tag
122
+     * @throws Conflict whenever a tag already exists with the given attributes
123
+     */
124
+    public function update($name, $userVisible, $userAssignable): void {
125
+        try {
126
+            if (!$this->tagManager->canUserSeeTag($this->tag, $this->user)) {
127
+                throw new NotFound('Tag with id ' . $this->tag->getId() . ' does not exist');
128
+            }
129
+            if (!$this->tagManager->canUserAssignTag($this->tag, $this->user)) {
130
+                throw new Forbidden('No permission to update tag ' . $this->tag->getId());
131
+            }
132
+
133
+            // only admin is able to change permissions, regular users can only rename
134
+            if (!$this->isAdmin) {
135
+                // only renaming is allowed for regular users
136
+                if ($userVisible !== $this->tag->isUserVisible()
137
+                    || $userAssignable !== $this->tag->isUserAssignable()
138
+                ) {
139
+                    throw new Forbidden('No permission to update permissions for tag ' . $this->tag->getId());
140
+                }
141
+            }
142
+
143
+            $this->tagManager->updateTag($this->tag->getId(), $name, $userVisible, $userAssignable);
144
+        } catch (TagNotFoundException $e) {
145
+            throw new NotFound('Tag with id ' . $this->tag->getId() . ' does not exist');
146
+        } catch (TagAlreadyExistsException $e) {
147
+            throw new Conflict(
148
+                'Tag with the properties "' . $name . '", ' .
149
+                $userVisible . ', ' . $userAssignable . ' already exists'
150
+            );
151
+        }
152
+    }
153
+
154
+    /**
155
+     * Returns null, not supported
156
+     *
157
+     * @return null
158
+     */
159
+    public function getLastModified() {
160
+        return null;
161
+    }
162
+
163
+    /**
164
+     * @return void
165
+     */
166
+    public function delete() {
167
+        try {
168
+            if (!$this->isAdmin) {
169
+                throw new Forbidden('No permission to delete tag ' . $this->tag->getId());
170
+            }
171
+
172
+            if (!$this->tagManager->canUserSeeTag($this->tag, $this->user)) {
173
+                throw new NotFound('Tag with id ' . $this->tag->getId() . ' not found');
174
+            }
175
+
176
+            $this->tagManager->deleteTags($this->tag->getId());
177
+        } catch (TagNotFoundException $e) {
178
+            // can happen if concurrent deletion occurred
179
+            throw new NotFound('Tag with id ' . $this->tag->getId() . ' not found', 0, $e);
180
+        }
181
+    }
182 182
 }
Please login to merge, or discard this patch.