Completed
Pull Request — master (#3233)
by Christoph
14:57
created
apps/dav/lib/SystemTag/SystemTagPlugin.php 1 patch
Indentation   +276 added lines, -276 removed lines patch added patch discarded remove patch
@@ -49,280 +49,280 @@
 block discarded – undo
49 49
  */
50 50
 class SystemTagPlugin extends \Sabre\DAV\ServerPlugin {
51 51
 
52
-	// namespace
53
-	const NS_OWNCLOUD = 'http://owncloud.org/ns';
54
-	const ID_PROPERTYNAME = '{http://owncloud.org/ns}id';
55
-	const DISPLAYNAME_PROPERTYNAME = '{http://owncloud.org/ns}display-name';
56
-	const USERVISIBLE_PROPERTYNAME = '{http://owncloud.org/ns}user-visible';
57
-	const USERASSIGNABLE_PROPERTYNAME = '{http://owncloud.org/ns}user-assignable';
58
-	const GROUPS_PROPERTYNAME = '{http://owncloud.org/ns}groups';
59
-	const CANASSIGN_PROPERTYNAME = '{http://owncloud.org/ns}can-assign';
60
-
61
-	/**
62
-	 * @var \Sabre\DAV\Server $server
63
-	 */
64
-	private $server;
65
-
66
-	/**
67
-	 * @var ISystemTagManager
68
-	 */
69
-	protected $tagManager;
70
-
71
-	/**
72
-	 * @var IUserSession
73
-	 */
74
-	protected $userSession;
75
-
76
-	/**
77
-	 * @var IGroupManager
78
-	 */
79
-	protected $groupManager;
80
-
81
-	/**
82
-	 * @param ISystemTagManager $tagManager tag manager
83
-	 * @param IGroupManager $groupManager
84
-	 * @param IUserSession $userSession
85
-	 */
86
-	public function __construct(ISystemTagManager $tagManager,
87
-								IGroupManager $groupManager,
88
-								IUserSession $userSession) {
89
-		$this->tagManager = $tagManager;
90
-		$this->userSession = $userSession;
91
-		$this->groupManager = $groupManager;
92
-	}
93
-
94
-	/**
95
-	 * This initializes the plugin.
96
-	 *
97
-	 * This function is called by \Sabre\DAV\Server, after
98
-	 * addPlugin is called.
99
-	 *
100
-	 * This method should set up the required event subscriptions.
101
-	 *
102
-	 * @param \Sabre\DAV\Server $server
103
-	 * @return void
104
-	 */
105
-	public function initialize(\Sabre\DAV\Server $server) {
106
-
107
-		$server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc';
108
-
109
-		$server->protectedProperties[] = self::ID_PROPERTYNAME;
110
-
111
-		$server->on('propFind', array($this, 'handleGetProperties'));
112
-		$server->on('propPatch', array($this, 'handleUpdateProperties'));
113
-		$server->on('method:POST', [$this, 'httpPost']);
114
-
115
-		$this->server = $server;
116
-	}
117
-
118
-	/**
119
-	 * POST operation on system tag collections
120
-	 *
121
-	 * @param RequestInterface $request request object
122
-	 * @param ResponseInterface $response response object
123
-	 * @return null|false
124
-	 */
125
-	public function httpPost(RequestInterface $request, ResponseInterface $response) {
126
-		$path = $request->getPath();
127
-
128
-		// Making sure the node exists
129
-		$node = $this->server->tree->getNodeForPath($path);
130
-		if ($node instanceof SystemTagsByIdCollection || $node instanceof SystemTagsObjectMappingCollection) {
131
-			$data = $request->getBodyAsString();
132
-
133
-			$tag = $this->createTag($data, $request->getHeader('Content-Type'));
134
-
135
-			if ($node instanceof SystemTagsObjectMappingCollection) {
136
-				// also add to collection
137
-				$node->createFile($tag->getId());
138
-				$url = $request->getBaseUrl() . 'systemtags/';
139
-			} else {
140
-				$url = $request->getUrl();
141
-			}
142
-
143
-			if ($url[strlen($url) - 1] !== '/') {
144
-				$url .= '/';
145
-			}
146
-
147
-			$response->setHeader('Content-Location', $url . $tag->getId());
148
-
149
-			// created
150
-			$response->setStatus(201);
151
-			return false;
152
-		}
153
-	}
154
-
155
-	/**
156
-	 * Creates a new tag
157
-	 *
158
-	 * @param string $data JSON encoded string containing the properties of the tag to create
159
-	 * @param string $contentType content type of the data
160
-	 * @return ISystemTag newly created system tag
161
-	 *
162
-	 * @throws BadRequest if a field was missing
163
-	 * @throws Conflict if a tag with the same properties already exists
164
-	 * @throws UnsupportedMediaType if the content type is not supported
165
-	 */
166
-	private function createTag($data, $contentType = 'application/json') {
167
-		if (explode(';', $contentType)[0] === 'application/json') {
168
-			$data = json_decode($data, true);
169
-		} else {
170
-			throw new UnsupportedMediaType();
171
-		}
172
-
173
-		if (!isset($data['name'])) {
174
-			throw new BadRequest('Missing "name" attribute');
175
-		}
176
-
177
-		$tagName = $data['name'];
178
-		$userVisible = true;
179
-		$userAssignable = true;
180
-
181
-		if (isset($data['userVisible'])) {
182
-			$userVisible = (bool)$data['userVisible'];
183
-		}
184
-
185
-		if (isset($data['userAssignable'])) {
186
-			$userAssignable = (bool)$data['userAssignable'];
187
-		}
188
-
189
-		$groups = [];
190
-		if (isset($data['groups'])) {
191
-			$groups = $data['groups'];
192
-			if (is_string($groups)) {
193
-				$groups = explode('|', $groups);
194
-			}
195
-		}
196
-
197
-		if($userVisible === false || $userAssignable === false || !empty($groups)) {
198
-			if(!$this->userSession->isLoggedIn() || !$this->groupManager->isAdmin($this->userSession->getUser()->getUID())) {
199
-				throw new BadRequest('Not sufficient permissions');
200
-			}
201
-		}
202
-
203
-		try {
204
-			$tag = $this->tagManager->createTag($tagName, $userVisible, $userAssignable);
205
-			if (!empty($groups)) {
206
-				$this->tagManager->setTagGroups($tag, $groups);
207
-			}
208
-			return $tag;
209
-		} catch (TagAlreadyExistsException $e) {
210
-			throw new Conflict('Tag already exists', 0, $e);
211
-		}
212
-	}
213
-
214
-
215
-	/**
216
-	 * Retrieves system tag properties
217
-	 *
218
-	 * @param PropFind $propFind
219
-	 * @param \Sabre\DAV\INode $node
220
-	 */
221
-	public function handleGetProperties(
222
-		PropFind $propFind,
223
-		\Sabre\DAV\INode $node
224
-	) {
225
-		if (!($node instanceof SystemTagNode) && !($node instanceof SystemTagMappingNode)) {
226
-			return;
227
-		}
228
-
229
-		$propFind->handle(self::ID_PROPERTYNAME, function() use ($node) {
230
-			return $node->getSystemTag()->getId();
231
-		});
232
-
233
-		$propFind->handle(self::DISPLAYNAME_PROPERTYNAME, function() use ($node) {
234
-			return $node->getSystemTag()->getName();
235
-		});
236
-
237
-		$propFind->handle(self::USERVISIBLE_PROPERTYNAME, function() use ($node) {
238
-			return $node->getSystemTag()->isUserVisible() ? 'true' : 'false';
239
-		});
240
-
241
-		$propFind->handle(self::USERASSIGNABLE_PROPERTYNAME, function() use ($node) {
242
-			// this is the tag's inherent property "is user assignable"
243
-			return $node->getSystemTag()->isUserAssignable() ? 'true' : 'false';
244
-		});
245
-
246
-		$propFind->handle(self::CANASSIGN_PROPERTYNAME, function() use ($node) {
247
-			// this is the effective permission for the current user
248
-			return $this->tagManager->canUserAssignTag($node->getSystemTag(), $this->userSession->getUser()) ? 'true' : 'false';
249
-		});
250
-
251
-		$propFind->handle(self::GROUPS_PROPERTYNAME, function() use ($node) {
252
-			if (!$this->groupManager->isAdmin($this->userSession->getUser()->getUID())) {
253
-				// property only available for admins
254
-				throw new Forbidden();
255
-			}
256
-			$groups = [];
257
-			// no need to retrieve groups for namespaces that don't qualify
258
-			if ($node->getSystemTag()->isUserVisible() && !$node->getSystemTag()->isUserAssignable()) {
259
-				$groups = $this->tagManager->getTagGroups($node->getSystemTag());
260
-			}
261
-			return implode('|', $groups);
262
-		});
263
-	}
264
-
265
-	/**
266
-	 * Updates tag attributes
267
-	 *
268
-	 * @param string $path
269
-	 * @param PropPatch $propPatch
270
-	 *
271
-	 * @return void
272
-	 */
273
-	public function handleUpdateProperties($path, PropPatch $propPatch) {
274
-		$propPatch->handle([
275
-			self::DISPLAYNAME_PROPERTYNAME,
276
-			self::USERVISIBLE_PROPERTYNAME,
277
-			self::USERASSIGNABLE_PROPERTYNAME,
278
-			self::GROUPS_PROPERTYNAME,
279
-		], function($props) use ($path) {
280
-			$node = $this->server->tree->getNodeForPath($path);
281
-			if (!($node instanceof SystemTagNode)) {
282
-				return;
283
-			}
284
-
285
-			$tag = $node->getSystemTag();
286
-			$name = $tag->getName();
287
-			$userVisible = $tag->isUserVisible();
288
-			$userAssignable = $tag->isUserAssignable();
289
-
290
-			$updateTag = false;
291
-
292
-			if (isset($props[self::DISPLAYNAME_PROPERTYNAME])) {
293
-				$name = $props[self::DISPLAYNAME_PROPERTYNAME];
294
-				$updateTag = true;
295
-			}
296
-
297
-			if (isset($props[self::USERVISIBLE_PROPERTYNAME])) {
298
-				$propValue = $props[self::USERVISIBLE_PROPERTYNAME];
299
-				$userVisible = ($propValue !== 'false' && $propValue !== '0');
300
-				$updateTag = true;
301
-			}
302
-
303
-			if (isset($props[self::USERASSIGNABLE_PROPERTYNAME])) {
304
-				$propValue = $props[self::USERASSIGNABLE_PROPERTYNAME];
305
-				$userAssignable = ($propValue !== 'false' && $propValue !== '0');
306
-				$updateTag = true;
307
-			}
308
-
309
-			if (isset($props[self::GROUPS_PROPERTYNAME])) {
310
-				if (!$this->groupManager->isAdmin($this->userSession->getUser()->getUID())) {
311
-					// property only available for admins
312
-					throw new Forbidden();
313
-				}
314
-
315
-				$propValue = $props[self::GROUPS_PROPERTYNAME];
316
-				$groupIds = explode('|', $propValue);
317
-				$this->tagManager->setTagGroups($tag, $groupIds);
318
-			}
319
-
320
-			if ($updateTag) {
321
-				$node->update($name, $userVisible, $userAssignable);
322
-			}
323
-
324
-			return true;
325
-		});
326
-
327
-	}
52
+    // namespace
53
+    const NS_OWNCLOUD = 'http://owncloud.org/ns';
54
+    const ID_PROPERTYNAME = '{http://owncloud.org/ns}id';
55
+    const DISPLAYNAME_PROPERTYNAME = '{http://owncloud.org/ns}display-name';
56
+    const USERVISIBLE_PROPERTYNAME = '{http://owncloud.org/ns}user-visible';
57
+    const USERASSIGNABLE_PROPERTYNAME = '{http://owncloud.org/ns}user-assignable';
58
+    const GROUPS_PROPERTYNAME = '{http://owncloud.org/ns}groups';
59
+    const CANASSIGN_PROPERTYNAME = '{http://owncloud.org/ns}can-assign';
60
+
61
+    /**
62
+     * @var \Sabre\DAV\Server $server
63
+     */
64
+    private $server;
65
+
66
+    /**
67
+     * @var ISystemTagManager
68
+     */
69
+    protected $tagManager;
70
+
71
+    /**
72
+     * @var IUserSession
73
+     */
74
+    protected $userSession;
75
+
76
+    /**
77
+     * @var IGroupManager
78
+     */
79
+    protected $groupManager;
80
+
81
+    /**
82
+     * @param ISystemTagManager $tagManager tag manager
83
+     * @param IGroupManager $groupManager
84
+     * @param IUserSession $userSession
85
+     */
86
+    public function __construct(ISystemTagManager $tagManager,
87
+                                IGroupManager $groupManager,
88
+                                IUserSession $userSession) {
89
+        $this->tagManager = $tagManager;
90
+        $this->userSession = $userSession;
91
+        $this->groupManager = $groupManager;
92
+    }
93
+
94
+    /**
95
+     * This initializes the plugin.
96
+     *
97
+     * This function is called by \Sabre\DAV\Server, after
98
+     * addPlugin is called.
99
+     *
100
+     * This method should set up the required event subscriptions.
101
+     *
102
+     * @param \Sabre\DAV\Server $server
103
+     * @return void
104
+     */
105
+    public function initialize(\Sabre\DAV\Server $server) {
106
+
107
+        $server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc';
108
+
109
+        $server->protectedProperties[] = self::ID_PROPERTYNAME;
110
+
111
+        $server->on('propFind', array($this, 'handleGetProperties'));
112
+        $server->on('propPatch', array($this, 'handleUpdateProperties'));
113
+        $server->on('method:POST', [$this, 'httpPost']);
114
+
115
+        $this->server = $server;
116
+    }
117
+
118
+    /**
119
+     * POST operation on system tag collections
120
+     *
121
+     * @param RequestInterface $request request object
122
+     * @param ResponseInterface $response response object
123
+     * @return null|false
124
+     */
125
+    public function httpPost(RequestInterface $request, ResponseInterface $response) {
126
+        $path = $request->getPath();
127
+
128
+        // Making sure the node exists
129
+        $node = $this->server->tree->getNodeForPath($path);
130
+        if ($node instanceof SystemTagsByIdCollection || $node instanceof SystemTagsObjectMappingCollection) {
131
+            $data = $request->getBodyAsString();
132
+
133
+            $tag = $this->createTag($data, $request->getHeader('Content-Type'));
134
+
135
+            if ($node instanceof SystemTagsObjectMappingCollection) {
136
+                // also add to collection
137
+                $node->createFile($tag->getId());
138
+                $url = $request->getBaseUrl() . 'systemtags/';
139
+            } else {
140
+                $url = $request->getUrl();
141
+            }
142
+
143
+            if ($url[strlen($url) - 1] !== '/') {
144
+                $url .= '/';
145
+            }
146
+
147
+            $response->setHeader('Content-Location', $url . $tag->getId());
148
+
149
+            // created
150
+            $response->setStatus(201);
151
+            return false;
152
+        }
153
+    }
154
+
155
+    /**
156
+     * Creates a new tag
157
+     *
158
+     * @param string $data JSON encoded string containing the properties of the tag to create
159
+     * @param string $contentType content type of the data
160
+     * @return ISystemTag newly created system tag
161
+     *
162
+     * @throws BadRequest if a field was missing
163
+     * @throws Conflict if a tag with the same properties already exists
164
+     * @throws UnsupportedMediaType if the content type is not supported
165
+     */
166
+    private function createTag($data, $contentType = 'application/json') {
167
+        if (explode(';', $contentType)[0] === 'application/json') {
168
+            $data = json_decode($data, true);
169
+        } else {
170
+            throw new UnsupportedMediaType();
171
+        }
172
+
173
+        if (!isset($data['name'])) {
174
+            throw new BadRequest('Missing "name" attribute');
175
+        }
176
+
177
+        $tagName = $data['name'];
178
+        $userVisible = true;
179
+        $userAssignable = true;
180
+
181
+        if (isset($data['userVisible'])) {
182
+            $userVisible = (bool)$data['userVisible'];
183
+        }
184
+
185
+        if (isset($data['userAssignable'])) {
186
+            $userAssignable = (bool)$data['userAssignable'];
187
+        }
188
+
189
+        $groups = [];
190
+        if (isset($data['groups'])) {
191
+            $groups = $data['groups'];
192
+            if (is_string($groups)) {
193
+                $groups = explode('|', $groups);
194
+            }
195
+        }
196
+
197
+        if($userVisible === false || $userAssignable === false || !empty($groups)) {
198
+            if(!$this->userSession->isLoggedIn() || !$this->groupManager->isAdmin($this->userSession->getUser()->getUID())) {
199
+                throw new BadRequest('Not sufficient permissions');
200
+            }
201
+        }
202
+
203
+        try {
204
+            $tag = $this->tagManager->createTag($tagName, $userVisible, $userAssignable);
205
+            if (!empty($groups)) {
206
+                $this->tagManager->setTagGroups($tag, $groups);
207
+            }
208
+            return $tag;
209
+        } catch (TagAlreadyExistsException $e) {
210
+            throw new Conflict('Tag already exists', 0, $e);
211
+        }
212
+    }
213
+
214
+
215
+    /**
216
+     * Retrieves system tag properties
217
+     *
218
+     * @param PropFind $propFind
219
+     * @param \Sabre\DAV\INode $node
220
+     */
221
+    public function handleGetProperties(
222
+        PropFind $propFind,
223
+        \Sabre\DAV\INode $node
224
+    ) {
225
+        if (!($node instanceof SystemTagNode) && !($node instanceof SystemTagMappingNode)) {
226
+            return;
227
+        }
228
+
229
+        $propFind->handle(self::ID_PROPERTYNAME, function() use ($node) {
230
+            return $node->getSystemTag()->getId();
231
+        });
232
+
233
+        $propFind->handle(self::DISPLAYNAME_PROPERTYNAME, function() use ($node) {
234
+            return $node->getSystemTag()->getName();
235
+        });
236
+
237
+        $propFind->handle(self::USERVISIBLE_PROPERTYNAME, function() use ($node) {
238
+            return $node->getSystemTag()->isUserVisible() ? 'true' : 'false';
239
+        });
240
+
241
+        $propFind->handle(self::USERASSIGNABLE_PROPERTYNAME, function() use ($node) {
242
+            // this is the tag's inherent property "is user assignable"
243
+            return $node->getSystemTag()->isUserAssignable() ? 'true' : 'false';
244
+        });
245
+
246
+        $propFind->handle(self::CANASSIGN_PROPERTYNAME, function() use ($node) {
247
+            // this is the effective permission for the current user
248
+            return $this->tagManager->canUserAssignTag($node->getSystemTag(), $this->userSession->getUser()) ? 'true' : 'false';
249
+        });
250
+
251
+        $propFind->handle(self::GROUPS_PROPERTYNAME, function() use ($node) {
252
+            if (!$this->groupManager->isAdmin($this->userSession->getUser()->getUID())) {
253
+                // property only available for admins
254
+                throw new Forbidden();
255
+            }
256
+            $groups = [];
257
+            // no need to retrieve groups for namespaces that don't qualify
258
+            if ($node->getSystemTag()->isUserVisible() && !$node->getSystemTag()->isUserAssignable()) {
259
+                $groups = $this->tagManager->getTagGroups($node->getSystemTag());
260
+            }
261
+            return implode('|', $groups);
262
+        });
263
+    }
264
+
265
+    /**
266
+     * Updates tag attributes
267
+     *
268
+     * @param string $path
269
+     * @param PropPatch $propPatch
270
+     *
271
+     * @return void
272
+     */
273
+    public function handleUpdateProperties($path, PropPatch $propPatch) {
274
+        $propPatch->handle([
275
+            self::DISPLAYNAME_PROPERTYNAME,
276
+            self::USERVISIBLE_PROPERTYNAME,
277
+            self::USERASSIGNABLE_PROPERTYNAME,
278
+            self::GROUPS_PROPERTYNAME,
279
+        ], function($props) use ($path) {
280
+            $node = $this->server->tree->getNodeForPath($path);
281
+            if (!($node instanceof SystemTagNode)) {
282
+                return;
283
+            }
284
+
285
+            $tag = $node->getSystemTag();
286
+            $name = $tag->getName();
287
+            $userVisible = $tag->isUserVisible();
288
+            $userAssignable = $tag->isUserAssignable();
289
+
290
+            $updateTag = false;
291
+
292
+            if (isset($props[self::DISPLAYNAME_PROPERTYNAME])) {
293
+                $name = $props[self::DISPLAYNAME_PROPERTYNAME];
294
+                $updateTag = true;
295
+            }
296
+
297
+            if (isset($props[self::USERVISIBLE_PROPERTYNAME])) {
298
+                $propValue = $props[self::USERVISIBLE_PROPERTYNAME];
299
+                $userVisible = ($propValue !== 'false' && $propValue !== '0');
300
+                $updateTag = true;
301
+            }
302
+
303
+            if (isset($props[self::USERASSIGNABLE_PROPERTYNAME])) {
304
+                $propValue = $props[self::USERASSIGNABLE_PROPERTYNAME];
305
+                $userAssignable = ($propValue !== 'false' && $propValue !== '0');
306
+                $updateTag = true;
307
+            }
308
+
309
+            if (isset($props[self::GROUPS_PROPERTYNAME])) {
310
+                if (!$this->groupManager->isAdmin($this->userSession->getUser()->getUID())) {
311
+                    // property only available for admins
312
+                    throw new Forbidden();
313
+                }
314
+
315
+                $propValue = $props[self::GROUPS_PROPERTYNAME];
316
+                $groupIds = explode('|', $propValue);
317
+                $this->tagManager->setTagGroups($tag, $groupIds);
318
+            }
319
+
320
+            if ($updateTag) {
321
+                $node->update($name, $userVisible, $userAssignable);
322
+            }
323
+
324
+            return true;
325
+        });
326
+
327
+    }
328 328
 }
Please login to merge, or discard this patch.
apps/dav/lib/SystemTag/SystemTagsObjectMappingCollection.php 1 patch
Indentation   +165 added lines, -165 removed lines patch added patch discarded remove patch
@@ -39,169 +39,169 @@
 block discarded – undo
39 39
  */
40 40
 class SystemTagsObjectMappingCollection implements ICollection {
41 41
 
42
-	/**
43
-	 * @var string
44
-	 */
45
-	private $objectId;
46
-
47
-	/**
48
-	 * @var string
49
-	 */
50
-	private $objectType;
51
-
52
-	/**
53
-	 * @var ISystemTagManager
54
-	 */
55
-	private $tagManager;
56
-
57
-	/**
58
-	 * @var ISystemTagObjectMapper
59
-	 */
60
-	private $tagMapper;
61
-
62
-	/**
63
-	 * User
64
-	 *
65
-	 * @var IUser
66
-	 */
67
-	private $user;
68
-
69
-
70
-	/**
71
-	 * Constructor
72
-	 *
73
-	 * @param string $objectId object id
74
-	 * @param string $objectType object type
75
-	 * @param IUser $user user
76
-	 * @param ISystemTagManager $tagManager tag manager
77
-	 * @param ISystemTagObjectMapper $tagMapper tag mapper
78
-	 */
79
-	public function __construct(
80
-		$objectId,
81
-		$objectType,
82
-		IUser $user,
83
-		ISystemTagManager $tagManager,
84
-		ISystemTagObjectMapper $tagMapper
85
-	) {
86
-		$this->tagManager = $tagManager;
87
-		$this->tagMapper = $tagMapper;
88
-		$this->objectId = $objectId;
89
-		$this->objectType = $objectType;
90
-		$this->user = $user;
91
-	}
92
-
93
-	function createFile($tagId, $data = null) {
94
-		try {
95
-			$tags = $this->tagManager->getTagsByIds([$tagId]);
96
-			$tag = current($tags);
97
-			if (!$this->tagManager->canUserSeeTag($tag, $this->user)) {
98
-				throw new PreconditionFailed('Tag with id ' . $tagId . ' does not exist, cannot assign');
99
-			}
100
-			if (!$this->tagManager->canUserAssignTag($tag, $this->user)) {
101
-				throw new Forbidden('No permission to assign tag ' . $tagId);
102
-			}
103
-
104
-			$this->tagMapper->assignTags($this->objectId, $this->objectType, $tagId);
105
-		} catch (TagNotFoundException $e) {
106
-			throw new PreconditionFailed('Tag with id ' . $tagId . ' does not exist, cannot assign');
107
-		}
108
-	}
109
-
110
-	function createDirectory($name) {
111
-		throw new Forbidden('Permission denied to create collections');
112
-	}
113
-
114
-	function getChild($tagId) {
115
-		try {
116
-			if ($this->tagMapper->haveTag([$this->objectId], $this->objectType, $tagId, true)) {
117
-				$tag = $this->tagManager->getTagsByIds([$tagId]);
118
-				$tag = current($tag);
119
-				if ($this->tagManager->canUserSeeTag($tag, $this->user)) {
120
-					return $this->makeNode($tag);
121
-				}
122
-			}
123
-			throw new NotFound('Tag with id ' . $tagId . ' not present for object ' . $this->objectId);
124
-		} catch (\InvalidArgumentException $e) {
125
-			throw new BadRequest('Invalid tag id', 0, $e);
126
-		} catch (TagNotFoundException $e) {
127
-			throw new NotFound('Tag with id ' . $tagId . ' not found', 0, $e);
128
-		}
129
-	}
130
-
131
-	function getChildren() {
132
-		$tagIds = current($this->tagMapper->getTagIdsForObjects([$this->objectId], $this->objectType));
133
-		if (empty($tagIds)) {
134
-			return [];
135
-		}
136
-		$tags = $this->tagManager->getTagsByIds($tagIds);
137
-
138
-		// filter out non-visible tags
139
-		$tags = array_filter($tags, function($tag) {
140
-			return $this->tagManager->canUserSeeTag($tag, $this->user);
141
-		});
142
-
143
-		return array_values(array_map(function($tag) {
144
-			return $this->makeNode($tag);
145
-		}, $tags));
146
-	}
147
-
148
-	function childExists($tagId) {
149
-		try {
150
-			$result = ($this->tagMapper->haveTag([$this->objectId], $this->objectType, $tagId, true));
151
-
152
-			if ($result) {
153
-				$tags = $this->tagManager->getTagsByIds([$tagId]);
154
-				$tag = current($tags);
155
-				if (!$this->tagManager->canUserSeeTag($tag, $this->user)) {
156
-					return false;
157
-				}
158
-			}
159
-
160
-			return $result;
161
-		} catch (\InvalidArgumentException $e) {
162
-			throw new BadRequest('Invalid tag id', 0, $e);
163
-		} catch (TagNotFoundException $e) {
164
-			return false;
165
-		}
166
-	}
167
-
168
-	function delete() {
169
-		throw new Forbidden('Permission denied to delete this collection');
170
-	}
171
-
172
-	function getName() {
173
-		return $this->objectId;
174
-	}
175
-
176
-	function setName($name) {
177
-		throw new Forbidden('Permission denied to rename this collection');
178
-	}
179
-
180
-	/**
181
-	 * Returns the last modification time, as a unix timestamp
182
-	 *
183
-	 * @return int
184
-	 */
185
-	function getLastModified() {
186
-		return null;
187
-	}
188
-
189
-	/**
190
-	 * Create a sabre node for the mapping of the 
191
-	 * given system tag to the collection's object
192
-	 *
193
-	 * @param ISystemTag $tag
194
-	 *
195
-	 * @return SystemTagMappingNode
196
-	 */
197
-	private function makeNode(ISystemTag $tag) {
198
-		return new SystemTagMappingNode(
199
-			$tag,
200
-			$this->objectId,
201
-			$this->objectType,
202
-			$this->user,
203
-			$this->tagManager,
204
-			$this->tagMapper
205
-		);
206
-	}
42
+    /**
43
+     * @var string
44
+     */
45
+    private $objectId;
46
+
47
+    /**
48
+     * @var string
49
+     */
50
+    private $objectType;
51
+
52
+    /**
53
+     * @var ISystemTagManager
54
+     */
55
+    private $tagManager;
56
+
57
+    /**
58
+     * @var ISystemTagObjectMapper
59
+     */
60
+    private $tagMapper;
61
+
62
+    /**
63
+     * User
64
+     *
65
+     * @var IUser
66
+     */
67
+    private $user;
68
+
69
+
70
+    /**
71
+     * Constructor
72
+     *
73
+     * @param string $objectId object id
74
+     * @param string $objectType object type
75
+     * @param IUser $user user
76
+     * @param ISystemTagManager $tagManager tag manager
77
+     * @param ISystemTagObjectMapper $tagMapper tag mapper
78
+     */
79
+    public function __construct(
80
+        $objectId,
81
+        $objectType,
82
+        IUser $user,
83
+        ISystemTagManager $tagManager,
84
+        ISystemTagObjectMapper $tagMapper
85
+    ) {
86
+        $this->tagManager = $tagManager;
87
+        $this->tagMapper = $tagMapper;
88
+        $this->objectId = $objectId;
89
+        $this->objectType = $objectType;
90
+        $this->user = $user;
91
+    }
92
+
93
+    function createFile($tagId, $data = null) {
94
+        try {
95
+            $tags = $this->tagManager->getTagsByIds([$tagId]);
96
+            $tag = current($tags);
97
+            if (!$this->tagManager->canUserSeeTag($tag, $this->user)) {
98
+                throw new PreconditionFailed('Tag with id ' . $tagId . ' does not exist, cannot assign');
99
+            }
100
+            if (!$this->tagManager->canUserAssignTag($tag, $this->user)) {
101
+                throw new Forbidden('No permission to assign tag ' . $tagId);
102
+            }
103
+
104
+            $this->tagMapper->assignTags($this->objectId, $this->objectType, $tagId);
105
+        } catch (TagNotFoundException $e) {
106
+            throw new PreconditionFailed('Tag with id ' . $tagId . ' does not exist, cannot assign');
107
+        }
108
+    }
109
+
110
+    function createDirectory($name) {
111
+        throw new Forbidden('Permission denied to create collections');
112
+    }
113
+
114
+    function getChild($tagId) {
115
+        try {
116
+            if ($this->tagMapper->haveTag([$this->objectId], $this->objectType, $tagId, true)) {
117
+                $tag = $this->tagManager->getTagsByIds([$tagId]);
118
+                $tag = current($tag);
119
+                if ($this->tagManager->canUserSeeTag($tag, $this->user)) {
120
+                    return $this->makeNode($tag);
121
+                }
122
+            }
123
+            throw new NotFound('Tag with id ' . $tagId . ' not present for object ' . $this->objectId);
124
+        } catch (\InvalidArgumentException $e) {
125
+            throw new BadRequest('Invalid tag id', 0, $e);
126
+        } catch (TagNotFoundException $e) {
127
+            throw new NotFound('Tag with id ' . $tagId . ' not found', 0, $e);
128
+        }
129
+    }
130
+
131
+    function getChildren() {
132
+        $tagIds = current($this->tagMapper->getTagIdsForObjects([$this->objectId], $this->objectType));
133
+        if (empty($tagIds)) {
134
+            return [];
135
+        }
136
+        $tags = $this->tagManager->getTagsByIds($tagIds);
137
+
138
+        // filter out non-visible tags
139
+        $tags = array_filter($tags, function($tag) {
140
+            return $this->tagManager->canUserSeeTag($tag, $this->user);
141
+        });
142
+
143
+        return array_values(array_map(function($tag) {
144
+            return $this->makeNode($tag);
145
+        }, $tags));
146
+    }
147
+
148
+    function childExists($tagId) {
149
+        try {
150
+            $result = ($this->tagMapper->haveTag([$this->objectId], $this->objectType, $tagId, true));
151
+
152
+            if ($result) {
153
+                $tags = $this->tagManager->getTagsByIds([$tagId]);
154
+                $tag = current($tags);
155
+                if (!$this->tagManager->canUserSeeTag($tag, $this->user)) {
156
+                    return false;
157
+                }
158
+            }
159
+
160
+            return $result;
161
+        } catch (\InvalidArgumentException $e) {
162
+            throw new BadRequest('Invalid tag id', 0, $e);
163
+        } catch (TagNotFoundException $e) {
164
+            return false;
165
+        }
166
+    }
167
+
168
+    function delete() {
169
+        throw new Forbidden('Permission denied to delete this collection');
170
+    }
171
+
172
+    function getName() {
173
+        return $this->objectId;
174
+    }
175
+
176
+    function setName($name) {
177
+        throw new Forbidden('Permission denied to rename this collection');
178
+    }
179
+
180
+    /**
181
+     * Returns the last modification time, as a unix timestamp
182
+     *
183
+     * @return int
184
+     */
185
+    function getLastModified() {
186
+        return null;
187
+    }
188
+
189
+    /**
190
+     * Create a sabre node for the mapping of the 
191
+     * given system tag to the collection's object
192
+     *
193
+     * @param ISystemTag $tag
194
+     *
195
+     * @return SystemTagMappingNode
196
+     */
197
+    private function makeNode(ISystemTag $tag) {
198
+        return new SystemTagMappingNode(
199
+            $tag,
200
+            $this->objectId,
201
+            $this->objectType,
202
+            $this->user,
203
+            $this->tagManager,
204
+            $this->tagMapper
205
+        );
206
+    }
207 207
 }
Please login to merge, or discard this patch.
apps/dav/lib/SystemTag/SystemTagsRelationsCollection.php 1 patch
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -36,59 +36,59 @@
 block discarded – undo
36 36
 
37 37
 class SystemTagsRelationsCollection extends SimpleCollection {
38 38
 
39
-	/**
40
-	 * SystemTagsRelationsCollection constructor.
41
-	 *
42
-	 * @param ISystemTagManager $tagManager
43
-	 * @param ISystemTagObjectMapper $tagMapper
44
-	 * @param IUserSession $userSession
45
-	 * @param IGroupManager $groupManager
46
-	 * @param EventDispatcherInterface $dispatcher
47
-	 */
48
-	public function __construct(
49
-		ISystemTagManager $tagManager,
50
-		ISystemTagObjectMapper $tagMapper,
51
-		IUserSession $userSession,
52
-		IGroupManager $groupManager,
53
-		EventDispatcherInterface $dispatcher
54
-	) {
55
-		$children = [
56
-			new SystemTagsObjectTypeCollection(
57
-				'files',
58
-				$tagManager,
59
-				$tagMapper,
60
-				$userSession,
61
-				$groupManager,
62
-				function($name) {
63
-					$nodes = \OC::$server->getUserFolder()->getById(intval($name));
64
-					return !empty($nodes);
65
-				}
66
-			),
67
-		];
39
+    /**
40
+     * SystemTagsRelationsCollection constructor.
41
+     *
42
+     * @param ISystemTagManager $tagManager
43
+     * @param ISystemTagObjectMapper $tagMapper
44
+     * @param IUserSession $userSession
45
+     * @param IGroupManager $groupManager
46
+     * @param EventDispatcherInterface $dispatcher
47
+     */
48
+    public function __construct(
49
+        ISystemTagManager $tagManager,
50
+        ISystemTagObjectMapper $tagMapper,
51
+        IUserSession $userSession,
52
+        IGroupManager $groupManager,
53
+        EventDispatcherInterface $dispatcher
54
+    ) {
55
+        $children = [
56
+            new SystemTagsObjectTypeCollection(
57
+                'files',
58
+                $tagManager,
59
+                $tagMapper,
60
+                $userSession,
61
+                $groupManager,
62
+                function($name) {
63
+                    $nodes = \OC::$server->getUserFolder()->getById(intval($name));
64
+                    return !empty($nodes);
65
+                }
66
+            ),
67
+        ];
68 68
 
69
-		$event = new SystemTagsEntityEvent(SystemTagsEntityEvent::EVENT_ENTITY);
70
-		$dispatcher->dispatch(SystemTagsEntityEvent::EVENT_ENTITY, $event);
69
+        $event = new SystemTagsEntityEvent(SystemTagsEntityEvent::EVENT_ENTITY);
70
+        $dispatcher->dispatch(SystemTagsEntityEvent::EVENT_ENTITY, $event);
71 71
 
72
-		foreach ($event->getEntityCollections() as $entity => $entityExistsFunction) {
73
-			$children[] = new SystemTagsObjectTypeCollection(
74
-				$entity,
75
-				$tagManager,
76
-				$tagMapper,
77
-				$userSession,
78
-				$groupManager,
79
-				$entityExistsFunction
80
-			);
81
-		}
72
+        foreach ($event->getEntityCollections() as $entity => $entityExistsFunction) {
73
+            $children[] = new SystemTagsObjectTypeCollection(
74
+                $entity,
75
+                $tagManager,
76
+                $tagMapper,
77
+                $userSession,
78
+                $groupManager,
79
+                $entityExistsFunction
80
+            );
81
+        }
82 82
 
83
-		parent::__construct('root', $children);
84
-	}
83
+        parent::__construct('root', $children);
84
+    }
85 85
 
86
-	function getName() {
87
-		return 'systemtags-relations';
88
-	}
86
+    function getName() {
87
+        return 'systemtags-relations';
88
+    }
89 89
 
90
-	function setName($name) {
91
-		throw new Forbidden('Permission denied to rename this collection');
92
-	}
90
+    function setName($name) {
91
+        throw new Forbidden('Permission denied to rename this collection');
92
+    }
93 93
 
94 94
 }
Please login to merge, or discard this patch.
apps/dav/appinfo/v1/webdav.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -31,30 +31,30 @@
 block discarded – undo
31 31
 \OC_Util::obEnd();
32 32
 
33 33
 $serverFactory = new \OCA\DAV\Connector\Sabre\ServerFactory(
34
-	\OC::$server->getConfig(),
35
-	\OC::$server->getLogger(),
36
-	\OC::$server->getDatabaseConnection(),
37
-	\OC::$server->getUserSession(),
38
-	\OC::$server->getMountManager(),
39
-	\OC::$server->getTagManager(),
40
-	\OC::$server->getRequest(),
41
-	\OC::$server->getPreviewManager()
34
+    \OC::$server->getConfig(),
35
+    \OC::$server->getLogger(),
36
+    \OC::$server->getDatabaseConnection(),
37
+    \OC::$server->getUserSession(),
38
+    \OC::$server->getMountManager(),
39
+    \OC::$server->getTagManager(),
40
+    \OC::$server->getRequest(),
41
+    \OC::$server->getPreviewManager()
42 42
 );
43 43
 
44 44
 // Backends
45 45
 $authBackend = new \OCA\DAV\Connector\Sabre\Auth(
46
-	\OC::$server->getSession(),
47
-	\OC::$server->getUserSession(),
48
-	\OC::$server->getRequest(),
49
-	\OC::$server->getTwoFactorAuthManager(),
50
-	\OC::$server->getBruteForceThrottler(),
51
-	'principals/'
46
+    \OC::$server->getSession(),
47
+    \OC::$server->getUserSession(),
48
+    \OC::$server->getRequest(),
49
+    \OC::$server->getTwoFactorAuthManager(),
50
+    \OC::$server->getBruteForceThrottler(),
51
+    'principals/'
52 52
 );
53 53
 $requestUri = \OC::$server->getRequest()->getRequestUri();
54 54
 
55 55
 $server = $serverFactory->createServer($baseuri, $requestUri, $authBackend, function() {
56
-	// use the view for the logged in user
57
-	return \OC\Files\Filesystem::getView();
56
+    // use the view for the logged in user
57
+    return \OC\Files\Filesystem::getView();
58 58
 });
59 59
 
60 60
 // And off we go!
Please login to merge, or discard this patch.
apps/dav/appinfo/v1/carddav.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -35,17 +35,17 @@  discard block
 block discarded – undo
35 35
 use Sabre\CardDAV\Plugin;
36 36
 
37 37
 $authBackend = new Auth(
38
-	\OC::$server->getSession(),
39
-	\OC::$server->getUserSession(),
40
-	\OC::$server->getRequest(),
41
-	\OC::$server->getTwoFactorAuthManager(),
42
-	\OC::$server->getBruteForceThrottler(),
43
-	'principals/'
38
+    \OC::$server->getSession(),
39
+    \OC::$server->getUserSession(),
40
+    \OC::$server->getRequest(),
41
+    \OC::$server->getTwoFactorAuthManager(),
42
+    \OC::$server->getBruteForceThrottler(),
43
+    'principals/'
44 44
 );
45 45
 $principalBackend = new Principal(
46
-	\OC::$server->getUserManager(),
47
-	\OC::$server->getGroupManager(),
48
-	'principals/'
46
+    \OC::$server->getUserManager(),
47
+    \OC::$server->getGroupManager(),
48
+    'principals/'
49 49
 );
50 50
 $db = \OC::$server->getDatabaseConnection();
51 51
 $cardDavBackend = new CardDavBackend($db, $principalBackend, \OC::$server->getUserManager());
@@ -60,8 +60,8 @@  discard block
 block discarded – undo
60 60
 $addressBookRoot->disableListing = !$debugging; // Disable listing
61 61
 
62 62
 $nodes = array(
63
-	$principalCollection,
64
-	$addressBookRoot,
63
+    $principalCollection,
64
+    $addressBookRoot,
65 65
 );
66 66
 
67 67
 // Fire up server
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 
77 77
 $server->addPlugin(new LegacyDAVACL());
78 78
 if ($debugging) {
79
-	$server->addPlugin(new Sabre\DAV\Browser\Plugin());
79
+    $server->addPlugin(new Sabre\DAV\Browser\Plugin());
80 80
 }
81 81
 
82 82
 $server->addPlugin(new \Sabre\DAV\Sync\Plugin());
Please login to merge, or discard this patch.
apps/dav/appinfo/v1/caldav.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -33,17 +33,17 @@  discard block
 block discarded – undo
33 33
 use OCA\DAV\Connector\Sabre\Principal;
34 34
 
35 35
 $authBackend = new Auth(
36
-	\OC::$server->getSession(),
37
-	\OC::$server->getUserSession(),
38
-	\OC::$server->getRequest(),
39
-	\OC::$server->getTwoFactorAuthManager(),
40
-	\OC::$server->getBruteForceThrottler(),
41
-	'principals/'
36
+    \OC::$server->getSession(),
37
+    \OC::$server->getUserSession(),
38
+    \OC::$server->getRequest(),
39
+    \OC::$server->getTwoFactorAuthManager(),
40
+    \OC::$server->getBruteForceThrottler(),
41
+    'principals/'
42 42
 );
43 43
 $principalBackend = new Principal(
44
-	\OC::$server->getUserManager(),
45
-	\OC::$server->getGroupManager(),
46
-	'principals/'
44
+    \OC::$server->getUserManager(),
45
+    \OC::$server->getGroupManager(),
46
+    'principals/'
47 47
 );
48 48
 $db = \OC::$server->getDatabaseConnection();
49 49
 $userManager = \OC::$server->getUserManager();
@@ -61,8 +61,8 @@  discard block
 block discarded – undo
61 61
 $addressBookRoot->disableListing = !$debugging; // Disable listing
62 62
 
63 63
 $nodes = array(
64
-	$principalCollection,
65
-	$addressBookRoot,
64
+    $principalCollection,
65
+    $addressBookRoot,
66 66
 );
67 67
 
68 68
 // Fire up server
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 
79 79
 $server->addPlugin(new LegacyDAVACL());
80 80
 if ($debugging) {
81
-	$server->addPlugin(new Sabre\DAV\Browser\Plugin());
81
+    $server->addPlugin(new Sabre\DAV\Browser\Plugin());
82 82
 }
83 83
 
84 84
 $server->addPlugin(new \Sabre\DAV\Sync\Plugin());
Please login to merge, or discard this patch.
apps/dav/appinfo/v1/publicwebdav.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -38,20 +38,20 @@  discard block
 block discarded – undo
38 38
 
39 39
 // Backends
40 40
 $authBackend = new OCA\DAV\Connector\PublicAuth(
41
-	\OC::$server->getRequest(),
42
-	\OC::$server->getShareManager(),
43
-	\OC::$server->getSession()
41
+    \OC::$server->getRequest(),
42
+    \OC::$server->getShareManager(),
43
+    \OC::$server->getSession()
44 44
 );
45 45
 
46 46
 $serverFactory = new OCA\DAV\Connector\Sabre\ServerFactory(
47
-	\OC::$server->getConfig(),
48
-	\OC::$server->getLogger(),
49
-	\OC::$server->getDatabaseConnection(),
50
-	\OC::$server->getUserSession(),
51
-	\OC::$server->getMountManager(),
52
-	\OC::$server->getTagManager(),
53
-	\OC::$server->getRequest(),
54
-	\OC::$server->getPreviewManager()
47
+    \OC::$server->getConfig(),
48
+    \OC::$server->getLogger(),
49
+    \OC::$server->getDatabaseConnection(),
50
+    \OC::$server->getUserSession(),
51
+    \OC::$server->getMountManager(),
52
+    \OC::$server->getTagManager(),
53
+    \OC::$server->getRequest(),
54
+    \OC::$server->getPreviewManager()
55 55
 );
56 56
 
57 57
 $requestUri = \OC::$server->getRequest()->getRequestUri();
@@ -60,41 +60,41 @@  discard block
 block discarded – undo
60 60
 $filesDropPlugin = new \OCA\DAV\Files\Sharing\FilesDropPlugin();
61 61
 
62 62
 $server = $serverFactory->createServer($baseuri, $requestUri, $authBackend, function (\Sabre\DAV\Server $server) use ($authBackend, $linkCheckPlugin, $filesDropPlugin) {
63
-	$isAjax = (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest');
64
-	$federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application();
65
-	$federatedShareProvider = $federatedSharingApp->getFederatedShareProvider();
66
-	if ($federatedShareProvider->isOutgoingServer2serverShareEnabled() === false && !$isAjax) {
67
-		// this is what is thrown when trying to access a non-existing share
68
-		throw new \Sabre\DAV\Exception\NotAuthenticated();
69
-	}
70
-
71
-	$share = $authBackend->getShare();
72
-	$owner = $share->getShareOwner();
73
-	$isReadable = $share->getPermissions() & \OCP\Constants::PERMISSION_READ;
74
-	$fileId = $share->getNodeId();
75
-
76
-	// FIXME: should not add storage wrappers outside of preSetup, need to find a better way
77
-	$previousLog = \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false);
78
-	\OC\Files\Filesystem::addStorageWrapper('sharePermissions', function ($mountPoint, $storage) use ($share) {
79
-		return new \OC\Files\Storage\Wrapper\PermissionsMask(array('storage' => $storage, 'mask' => $share->getPermissions() | \OCP\Constants::PERMISSION_SHARE));
80
-	});
81
-	\OC\Files\Filesystem::logWarningWhenAddingStorageWrapper($previousLog);
82
-
83
-	OC_Util::setupFS($owner);
84
-	$ownerView = \OC\Files\Filesystem::getView();
85
-	$path = $ownerView->getPath($fileId);
86
-	$fileInfo = $ownerView->getFileInfo($path);
87
-	$linkCheckPlugin->setFileInfo($fileInfo);
88
-
89
-	// If not readble (files_drop) enable the filesdrop plugin
90
-	if (!$isReadable) {
91
-		$filesDropPlugin->enable();
92
-	}
93
-
94
-	$view = new \OC\Files\View($ownerView->getAbsolutePath($path));
95
-	$filesDropPlugin->setView($view);
96
-
97
-	return $view;
63
+    $isAjax = (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest');
64
+    $federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application();
65
+    $federatedShareProvider = $federatedSharingApp->getFederatedShareProvider();
66
+    if ($federatedShareProvider->isOutgoingServer2serverShareEnabled() === false && !$isAjax) {
67
+        // this is what is thrown when trying to access a non-existing share
68
+        throw new \Sabre\DAV\Exception\NotAuthenticated();
69
+    }
70
+
71
+    $share = $authBackend->getShare();
72
+    $owner = $share->getShareOwner();
73
+    $isReadable = $share->getPermissions() & \OCP\Constants::PERMISSION_READ;
74
+    $fileId = $share->getNodeId();
75
+
76
+    // FIXME: should not add storage wrappers outside of preSetup, need to find a better way
77
+    $previousLog = \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false);
78
+    \OC\Files\Filesystem::addStorageWrapper('sharePermissions', function ($mountPoint, $storage) use ($share) {
79
+        return new \OC\Files\Storage\Wrapper\PermissionsMask(array('storage' => $storage, 'mask' => $share->getPermissions() | \OCP\Constants::PERMISSION_SHARE));
80
+    });
81
+    \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper($previousLog);
82
+
83
+    OC_Util::setupFS($owner);
84
+    $ownerView = \OC\Files\Filesystem::getView();
85
+    $path = $ownerView->getPath($fileId);
86
+    $fileInfo = $ownerView->getFileInfo($path);
87
+    $linkCheckPlugin->setFileInfo($fileInfo);
88
+
89
+    // If not readble (files_drop) enable the filesdrop plugin
90
+    if (!$isReadable) {
91
+        $filesDropPlugin->enable();
92
+    }
93
+
94
+    $view = new \OC\Files\View($ownerView->getAbsolutePath($path));
95
+    $filesDropPlugin->setView($view);
96
+
97
+    return $view;
98 98
 });
99 99
 
100 100
 $server->addPlugin($linkCheckPlugin);
Please login to merge, or discard this patch.
apps/dav/appinfo/app.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -30,27 +30,27 @@
 block discarded – undo
30 30
 $app->registerHooks();
31 31
 
32 32
 \OC::$server->registerService('CardDAVSyncService', function() use ($app) {
33
-	return $app->getSyncService();
33
+    return $app->getSyncService();
34 34
 });
35 35
 
36 36
 $eventDispatcher = \OC::$server->getEventDispatcher();
37 37
 
38 38
 $eventDispatcher->addListener('OCP\Federation\TrustedServerEvent::remove',
39
-	function(GenericEvent $event) use ($app) {
40
-		/** @var CardDavBackend $cardDavBackend */
41
-		$cardDavBackend = $app->getContainer()->query(CardDavBackend::class);
42
-		$addressBookUri = $event->getSubject();
43
-		$addressBook = $cardDavBackend->getAddressBooksByUri('principals/system/system', $addressBookUri);
44
-		if (!is_null($addressBook)) {
45
-			$cardDavBackend->deleteAddressBook($addressBook['id']);
46
-		}
47
-	}
39
+    function(GenericEvent $event) use ($app) {
40
+        /** @var CardDavBackend $cardDavBackend */
41
+        $cardDavBackend = $app->getContainer()->query(CardDavBackend::class);
42
+        $addressBookUri = $event->getSubject();
43
+        $addressBook = $cardDavBackend->getAddressBooksByUri('principals/system/system', $addressBookUri);
44
+        if (!is_null($addressBook)) {
45
+            $cardDavBackend->deleteAddressBook($addressBook['id']);
46
+        }
47
+    }
48 48
 );
49 49
 
50 50
 $cm = \OC::$server->getContactsManager();
51 51
 $cm->register(function() use ($cm, $app) {
52
-	$user = \OC::$server->getUserSession()->getUser();
53
-	if (!is_null($user)) {
54
-		$app->setupContactsProvider($cm, $user->getUID());
55
-	}
52
+    $user = \OC::$server->getUserSession()->getUser();
53
+    if (!is_null($user)) {
54
+        $app->setupContactsProvider($cm, $user->getUID());
55
+    }
56 56
 });
Please login to merge, or discard this patch.
apps/dav/bin/chunkperf.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -23,8 +23,8 @@  discard block
 block discarded – undo
23 23
 require '../../../../3rdparty/autoload.php';
24 24
 
25 25
 if ($argc !== 6) {
26
-	echo "Invalid number of arguments" . PHP_EOL;
27
-	exit;
26
+    echo "Invalid number of arguments" . PHP_EOL;
27
+    exit;
28 28
 }
29 29
 
30 30
 /**
@@ -33,15 +33,15 @@  discard block
 block discarded – undo
33 33
  * @return mixed
34 34
  */
35 35
 function request($client, $method, $uploadUrl, $data = null, $headers = []) {
36
-	echo "$method $uploadUrl ... ";
37
-	$t0 = microtime(true);
38
-	$result = $client->request($method, $uploadUrl, $data, $headers);
39
-	$t1 = microtime(true);
40
-	echo $result['statusCode'] . " - " . ($t1 - $t0) . ' seconds' . PHP_EOL;
41
-	if (!in_array($result['statusCode'],  [200, 201])) {
42
-		echo $result['body'] . PHP_EOL;
43
-	}
44
-	return $result;
36
+    echo "$method $uploadUrl ... ";
37
+    $t0 = microtime(true);
38
+    $result = $client->request($method, $uploadUrl, $data, $headers);
39
+    $t1 = microtime(true);
40
+    echo $result['statusCode'] . " - " . ($t1 - $t0) . ' seconds' . PHP_EOL;
41
+    if (!in_array($result['statusCode'],  [200, 201])) {
42
+        echo $result['body'] . PHP_EOL;
43
+    }
44
+    return $result;
45 45
 }
46 46
 
47 47
 $baseUri = $argv[1];
@@ -51,9 +51,9 @@  discard block
 block discarded – undo
51 51
 $chunkSize = $argv[5] * 1024 * 1024;
52 52
 
53 53
 $client = new \Sabre\DAV\Client([
54
-	'baseUri' => $baseUri,
55
-	'userName' => $userName,
56
-	'password' => $password
54
+    'baseUri' => $baseUri,
55
+    'userName' => $userName,
56
+    'password' => $password
57 57
 ]);
58 58
 
59 59
 $transfer = uniqid('transfer', true);
@@ -66,12 +66,12 @@  discard block
 block discarded – undo
66 66
 
67 67
 $index = 0;
68 68
 while(!feof($stream)) {
69
-	request($client, 'PUT', "$uploadUrl/$index", fread($stream, $chunkSize));
70
-	$index++;
69
+    request($client, 'PUT', "$uploadUrl/$index", fread($stream, $chunkSize));
70
+    $index++;
71 71
 }
72 72
 
73 73
 $destination = pathinfo($file, PATHINFO_BASENAME);
74 74
 //echo "Moving $uploadUrl/.file to it's final destination $baseUri/files/$userName/$destination" . PHP_EOL;
75 75
 request($client, 'MOVE', "$uploadUrl/.file", null, [
76
-	'Destination' => "$baseUri/files/$userName/$destination"
76
+    'Destination' => "$baseUri/files/$userName/$destination"
77 77
 ]);
Please login to merge, or discard this patch.