Passed
Push — master ( 35e3d4...f28691 )
by Morris
14:10
created
lib/public/Share/IShare.php 1 patch
Indentation   +417 added lines, -417 removed lines patch added patch discarded remove patch
@@ -39,421 +39,421 @@
 block discarded – undo
39 39
  */
40 40
 interface IShare {
41 41
 
42
-	/**
43
-	 * Set the internal id of the share
44
-	 * It is only allowed to set the internal id of a share once.
45
-	 * Attempts to override the internal id will result in an IllegalIDChangeException
46
-	 *
47
-	 * @param string $id
48
-	 * @return \OCP\Share\IShare
49
-	 * @throws IllegalIDChangeException
50
-	 * @throws \InvalidArgumentException
51
-	 * @since 9.1.0
52
-	 */
53
-	public function setId($id);
54
-
55
-	/**
56
-	 * Get the internal id of the share.
57
-	 *
58
-	 * @return string
59
-	 * @since 9.0.0
60
-	 */
61
-	public function getId();
62
-
63
-	/**
64
-	 * Get the full share id. This is the <providerid>:<internalid>.
65
-	 * The full id is unique in the system.
66
-	 *
67
-	 * @return string
68
-	 * @since 9.0.0
69
-	 * @throws \UnexpectedValueException If the fullId could not be constructed
70
-	 */
71
-	public function getFullId();
72
-
73
-	/**
74
-	 * Set the provider id of the share
75
-	 * It is only allowed to set the provider id of a share once.
76
-	 * Attempts to override the provider id will result in an IllegalIDChangeException
77
-	 *
78
-	 * @param string $id
79
-	 * @return \OCP\Share\IShare
80
-	 * @throws IllegalIDChangeException
81
-	 * @throws \InvalidArgumentException
82
-	 * @since 9.1.0
83
-	 */
84
-	public function setProviderId($id);
85
-
86
-	/**
87
-	 * Set the node of the file/folder that is shared
88
-	 *
89
-	 * @param Node $node
90
-	 * @return \OCP\Share\IShare The modified object
91
-	 * @since 9.0.0
92
-	 */
93
-	public function setNode(Node $node);
94
-
95
-	/**
96
-	 * Get the node of the file/folder that is shared
97
-	 *
98
-	 * @return File|Folder
99
-	 * @since 9.0.0
100
-	 * @throws NotFoundException
101
-	 */
102
-	public function getNode();
103
-
104
-	/**
105
-	 * Set file id for lazy evaluation of the node
106
-	 * @param int $fileId
107
-	 * @return \OCP\Share\IShare The modified object
108
-	 * @since 9.0.0
109
-	 */
110
-	public function setNodeId($fileId);
111
-
112
-	/**
113
-	 * Get the fileid of the node of this share
114
-	 * @return int
115
-	 * @since 9.0.0
116
-	 * @throws NotFoundException
117
-	 */
118
-	public function getNodeId();
119
-
120
-	/**
121
-	 * Set the type of node (file/folder)
122
-	 *
123
-	 * @param string $type
124
-	 * @return \OCP\Share\IShare The modified object
125
-	 * @since 9.0.0
126
-	 */
127
-	public function setNodeType($type);
128
-
129
-	/**
130
-	 * Get the type of node (file/folder)
131
-	 *
132
-	 * @return string
133
-	 * @since 9.0.0
134
-	 * @throws NotFoundException
135
-	 */
136
-	public function getNodeType();
137
-
138
-	/**
139
-	 * Set the shareType
140
-	 *
141
-	 * @param int $shareType
142
-	 * @return \OCP\Share\IShare The modified object
143
-	 * @since 9.0.0
144
-	 */
145
-	public function setShareType($shareType);
146
-
147
-	/**
148
-	 * Get the shareType
149
-	 *
150
-	 * @return int
151
-	 * @since 9.0.0
152
-	 */
153
-	public function getShareType();
154
-
155
-	/**
156
-	 * Set the receiver of this share.
157
-	 *
158
-	 * @param string $sharedWith
159
-	 * @return \OCP\Share\IShare The modified object
160
-	 * @since 9.0.0
161
-	 */
162
-	public function setSharedWith($sharedWith);
163
-
164
-	/**
165
-	 * Get the receiver of this share.
166
-	 *
167
-	 * @return string
168
-	 * @since 9.0.0
169
-	 */
170
-	public function getSharedWith();
171
-
172
-	/**
173
-	 * Set the display name of the receiver of this share.
174
-	 *
175
-	 * @param string $displayName
176
-	 * @return \OCP\Share\IShare The modified object
177
-	 * @since 14.0.0
178
-	 */
179
-	public function setSharedWithDisplayName($displayName);
180
-
181
-	/**
182
-	 * Get the display name of the receiver of this share.
183
-	 *
184
-	 * @return string
185
-	 * @since 14.0.0
186
-	 */
187
-	public function getSharedWithDisplayName();
188
-
189
-	/**
190
-	 * Set the avatar of the receiver of this share.
191
-	 *
192
-	 * @param string $src
193
-	 * @return \OCP\Share\IShare The modified object
194
-	 * @since 14.0.0
195
-	 */
196
-	public function setSharedWithAvatar($src);
197
-
198
-	/**
199
-	 * Get the avatar of the receiver of this share.
200
-	 *
201
-	 * @return string
202
-	 * @since 14.0.0
203
-	 */
204
-	public function getSharedWithAvatar();
205
-
206
-	/**
207
-	 * Set the permissions.
208
-	 * See \OCP\Constants::PERMISSION_*
209
-	 *
210
-	 * @param int $permissions
211
-	 * @return \OCP\Share\IShare The modified object
212
-	 * @since 9.0.0
213
-	 */
214
-	public function setPermissions($permissions);
215
-
216
-	/**
217
-	 * Get the share permissions
218
-	 * See \OCP\Constants::PERMISSION_*
219
-	 *
220
-	 * @return int
221
-	 * @since 9.0.0
222
-	 */
223
-	public function getPermissions();
224
-
225
-	/**
226
-	 * Attach a note to a share
227
-	 *
228
-	 * @param string $note
229
-	 * @return \OCP\Share\IShare The modified object
230
-	 * @since 14.0.0
231
-	 */
232
-	public function setNote($note);
233
-
234
-	/**
235
-	 * Get note attached to a share
236
-	 *
237
-	 * @return string
238
-	 * @since 14.0.0
239
-	 */
240
-	public function getNote();
241
-
242
-
243
-	/**
244
-	 * Set the expiration date
245
-	 *
246
-	 * @param null|\DateTime $expireDate
247
-	 * @return \OCP\Share\IShare The modified object
248
-	 * @since 9.0.0
249
-	 */
250
-	public function setExpirationDate($expireDate);
251
-
252
-	/**
253
-	 * Get the expiration date
254
-	 *
255
-	 * @return \DateTime
256
-	 * @since 9.0.0
257
-	 */
258
-	public function getExpirationDate();
259
-
260
-	/**
261
-	 * set a label for a share, some shares, e.g. public links can have a label
262
-	 *
263
-	 * @param string $label
264
-	 * @return \OCP\Share\IShare The modified object
265
-	 * @since 15.0.0
266
-	 */
267
-	public function setLabel($label);
268
-
269
-	/**
270
-	 * get label for the share, some shares, e.g. public links can have a label
271
-	 *
272
-	 * @return string
273
-	 * @since 15.0.0
274
-	 */
275
-	public function getLabel();
276
-
277
-	/**
278
-	 * Set the sharer of the path.
279
-	 *
280
-	 * @param string $sharedBy
281
-	 * @return \OCP\Share\IShare The modified object
282
-	 * @since 9.0.0
283
-	 */
284
-	public function setSharedBy($sharedBy);
285
-
286
-	/**
287
-	 * Get share sharer
288
-	 *
289
-	 * @return string
290
-	 * @since 9.0.0
291
-	 */
292
-	public function getSharedBy();
293
-
294
-	/**
295
-	 * Set the original share owner (who owns the path that is shared)
296
-	 *
297
-	 * @param string $shareOwner
298
-	 * @return \OCP\Share\IShare The modified object
299
-	 * @since 9.0.0
300
-	 */
301
-	public function setShareOwner($shareOwner);
302
-
303
-	/**
304
-	 * Get the original share owner (who owns the path that is shared)
305
-	 *
306
-	 * @return string
307
-	 * @since 9.0.0
308
-	 */
309
-	public function getShareOwner();
310
-
311
-	/**
312
-	 * Set the password for this share.
313
-	 * When the share is passed to the share manager to be created
314
-	 * or updated the password will be hashed.
315
-	 *
316
-	 * @param string $password
317
-	 * @return \OCP\Share\IShare The modified object
318
-	 * @since 9.0.0
319
-	 */
320
-	public function setPassword($password);
321
-
322
-	/**
323
-	 * Get the password of this share.
324
-	 * If this share is obtained via a shareprovider the password is
325
-	 * hashed.
326
-	 *
327
-	 * @return string
328
-	 * @since 9.0.0
329
-	 */
330
-	public function getPassword();
331
-
332
-
333
-	/**
334
-	 * Set if the recipient can start a conversation with the owner to get the
335
-	 * password using Nextcloud Talk.
336
-	 *
337
-	 * @param bool $sendPasswordByTalk
338
-	 * @return \OCP\Share\IShare The modified object
339
-	 * @since 14.0.0
340
-	 */
341
-	public function setSendPasswordByTalk(bool $sendPasswordByTalk);
342
-
343
-	/**
344
-	 * Get if the recipient can start a conversation with the owner to get the
345
-	 * password using Nextcloud Talk.
346
-	 * The returned value does not take into account other factors, like Talk
347
-	 * being enabled for the owner of the share or not; it just cover whether
348
-	 * the option is enabled for the share itself or not.
349
-	 *
350
-	 * @return bool
351
-	 * @since 14.0.0
352
-	 */
353
-	public function getSendPasswordByTalk(): bool;
354
-
355
-	/**
356
-	 * Set the public link token.
357
-	 *
358
-	 * @param string $token
359
-	 * @return \OCP\Share\IShare The modified object
360
-	 * @since 9.0.0
361
-	 */
362
-	public function setToken($token);
363
-
364
-	/**
365
-	 * Get the public link token.
366
-	 *
367
-	 * @return string
368
-	 * @since 9.0.0
369
-	 */
370
-	public function getToken();
371
-
372
-	/**
373
-	 * Set the target path of this share relative to the recipients user folder.
374
-	 *
375
-	 * @param string $target
376
-	 * @return \OCP\Share\IShare The modified object
377
-	 * @since 9.0.0
378
-	 */
379
-	public function setTarget($target);
380
-
381
-	/**
382
-	 * Get the target path of this share relative to the recipients user folder.
383
-	 *
384
-	 * @return string
385
-	 * @since 9.0.0
386
-	 */
387
-	public function getTarget();
388
-
389
-	/**
390
-	 * Set the time this share was created
391
-	 *
392
-	 * @param \DateTime $shareTime
393
-	 * @return \OCP\Share\IShare The modified object
394
-	 * @since 9.0.0
395
-	 */
396
-	public function setShareTime(\DateTime $shareTime);
397
-
398
-	/**
399
-	 * Get the timestamp this share was created
400
-	 *
401
-	 * @return \DateTime
402
-	 * @since 9.0.0
403
-	 */
404
-	public function getShareTime();
405
-
406
-	/**
407
-	 * Set if the recipient is informed by mail about the share.
408
-	 *
409
-	 * @param bool $mailSend
410
-	 * @return \OCP\Share\IShare The modified object
411
-	 * @since 9.0.0
412
-	 */
413
-	public function setMailSend($mailSend);
414
-
415
-	/**
416
-	 * Get if the recipient informed by mail about the share.
417
-	 *
418
-	 * @return bool
419
-	 * @since 9.0.0
420
-	 */
421
-	public function getMailSend();
422
-
423
-	/**
424
-	 * Set the cache entry for the shared node
425
-	 *
426
-	 * @param ICacheEntry $entry
427
-	 * @since 11.0.0
428
-	 */
429
-	public function setNodeCacheEntry(ICacheEntry $entry);
430
-
431
-	/**
432
-	 * Get the cache entry for the shared node
433
-	 *
434
-	 * @return null|ICacheEntry
435
-	 * @since 11.0.0
436
-	 */
437
-	public function getNodeCacheEntry();
438
-
439
-	/**
440
-	 * Sets a shares hide download state
441
-	 * This is mainly for public shares. It will signal that the share page should
442
-	 * hide download buttons etc.
443
-	 *
444
-	 * @param bool $ro
445
-	 * @return IShare
446
-	 * @since 15.0.0
447
-	 */
448
-	public function setHideDownload(bool $hide): IShare;
449
-
450
-	/**
451
-	 * Gets a shares hide download state
452
-	 * This is mainly for public shares. It will signal that the share page should
453
-	 * hide download buttons etc.
454
-	 *
455
-	 * @return bool
456
-	 * @since 15.0.0
457
-	 */
458
-	public function getHideDownload(): bool;
42
+    /**
43
+     * Set the internal id of the share
44
+     * It is only allowed to set the internal id of a share once.
45
+     * Attempts to override the internal id will result in an IllegalIDChangeException
46
+     *
47
+     * @param string $id
48
+     * @return \OCP\Share\IShare
49
+     * @throws IllegalIDChangeException
50
+     * @throws \InvalidArgumentException
51
+     * @since 9.1.0
52
+     */
53
+    public function setId($id);
54
+
55
+    /**
56
+     * Get the internal id of the share.
57
+     *
58
+     * @return string
59
+     * @since 9.0.0
60
+     */
61
+    public function getId();
62
+
63
+    /**
64
+     * Get the full share id. This is the <providerid>:<internalid>.
65
+     * The full id is unique in the system.
66
+     *
67
+     * @return string
68
+     * @since 9.0.0
69
+     * @throws \UnexpectedValueException If the fullId could not be constructed
70
+     */
71
+    public function getFullId();
72
+
73
+    /**
74
+     * Set the provider id of the share
75
+     * It is only allowed to set the provider id of a share once.
76
+     * Attempts to override the provider id will result in an IllegalIDChangeException
77
+     *
78
+     * @param string $id
79
+     * @return \OCP\Share\IShare
80
+     * @throws IllegalIDChangeException
81
+     * @throws \InvalidArgumentException
82
+     * @since 9.1.0
83
+     */
84
+    public function setProviderId($id);
85
+
86
+    /**
87
+     * Set the node of the file/folder that is shared
88
+     *
89
+     * @param Node $node
90
+     * @return \OCP\Share\IShare The modified object
91
+     * @since 9.0.0
92
+     */
93
+    public function setNode(Node $node);
94
+
95
+    /**
96
+     * Get the node of the file/folder that is shared
97
+     *
98
+     * @return File|Folder
99
+     * @since 9.0.0
100
+     * @throws NotFoundException
101
+     */
102
+    public function getNode();
103
+
104
+    /**
105
+     * Set file id for lazy evaluation of the node
106
+     * @param int $fileId
107
+     * @return \OCP\Share\IShare The modified object
108
+     * @since 9.0.0
109
+     */
110
+    public function setNodeId($fileId);
111
+
112
+    /**
113
+     * Get the fileid of the node of this share
114
+     * @return int
115
+     * @since 9.0.0
116
+     * @throws NotFoundException
117
+     */
118
+    public function getNodeId();
119
+
120
+    /**
121
+     * Set the type of node (file/folder)
122
+     *
123
+     * @param string $type
124
+     * @return \OCP\Share\IShare The modified object
125
+     * @since 9.0.0
126
+     */
127
+    public function setNodeType($type);
128
+
129
+    /**
130
+     * Get the type of node (file/folder)
131
+     *
132
+     * @return string
133
+     * @since 9.0.0
134
+     * @throws NotFoundException
135
+     */
136
+    public function getNodeType();
137
+
138
+    /**
139
+     * Set the shareType
140
+     *
141
+     * @param int $shareType
142
+     * @return \OCP\Share\IShare The modified object
143
+     * @since 9.0.0
144
+     */
145
+    public function setShareType($shareType);
146
+
147
+    /**
148
+     * Get the shareType
149
+     *
150
+     * @return int
151
+     * @since 9.0.0
152
+     */
153
+    public function getShareType();
154
+
155
+    /**
156
+     * Set the receiver of this share.
157
+     *
158
+     * @param string $sharedWith
159
+     * @return \OCP\Share\IShare The modified object
160
+     * @since 9.0.0
161
+     */
162
+    public function setSharedWith($sharedWith);
163
+
164
+    /**
165
+     * Get the receiver of this share.
166
+     *
167
+     * @return string
168
+     * @since 9.0.0
169
+     */
170
+    public function getSharedWith();
171
+
172
+    /**
173
+     * Set the display name of the receiver of this share.
174
+     *
175
+     * @param string $displayName
176
+     * @return \OCP\Share\IShare The modified object
177
+     * @since 14.0.0
178
+     */
179
+    public function setSharedWithDisplayName($displayName);
180
+
181
+    /**
182
+     * Get the display name of the receiver of this share.
183
+     *
184
+     * @return string
185
+     * @since 14.0.0
186
+     */
187
+    public function getSharedWithDisplayName();
188
+
189
+    /**
190
+     * Set the avatar of the receiver of this share.
191
+     *
192
+     * @param string $src
193
+     * @return \OCP\Share\IShare The modified object
194
+     * @since 14.0.0
195
+     */
196
+    public function setSharedWithAvatar($src);
197
+
198
+    /**
199
+     * Get the avatar of the receiver of this share.
200
+     *
201
+     * @return string
202
+     * @since 14.0.0
203
+     */
204
+    public function getSharedWithAvatar();
205
+
206
+    /**
207
+     * Set the permissions.
208
+     * See \OCP\Constants::PERMISSION_*
209
+     *
210
+     * @param int $permissions
211
+     * @return \OCP\Share\IShare The modified object
212
+     * @since 9.0.0
213
+     */
214
+    public function setPermissions($permissions);
215
+
216
+    /**
217
+     * Get the share permissions
218
+     * See \OCP\Constants::PERMISSION_*
219
+     *
220
+     * @return int
221
+     * @since 9.0.0
222
+     */
223
+    public function getPermissions();
224
+
225
+    /**
226
+     * Attach a note to a share
227
+     *
228
+     * @param string $note
229
+     * @return \OCP\Share\IShare The modified object
230
+     * @since 14.0.0
231
+     */
232
+    public function setNote($note);
233
+
234
+    /**
235
+     * Get note attached to a share
236
+     *
237
+     * @return string
238
+     * @since 14.0.0
239
+     */
240
+    public function getNote();
241
+
242
+
243
+    /**
244
+     * Set the expiration date
245
+     *
246
+     * @param null|\DateTime $expireDate
247
+     * @return \OCP\Share\IShare The modified object
248
+     * @since 9.0.0
249
+     */
250
+    public function setExpirationDate($expireDate);
251
+
252
+    /**
253
+     * Get the expiration date
254
+     *
255
+     * @return \DateTime
256
+     * @since 9.0.0
257
+     */
258
+    public function getExpirationDate();
259
+
260
+    /**
261
+     * set a label for a share, some shares, e.g. public links can have a label
262
+     *
263
+     * @param string $label
264
+     * @return \OCP\Share\IShare The modified object
265
+     * @since 15.0.0
266
+     */
267
+    public function setLabel($label);
268
+
269
+    /**
270
+     * get label for the share, some shares, e.g. public links can have a label
271
+     *
272
+     * @return string
273
+     * @since 15.0.0
274
+     */
275
+    public function getLabel();
276
+
277
+    /**
278
+     * Set the sharer of the path.
279
+     *
280
+     * @param string $sharedBy
281
+     * @return \OCP\Share\IShare The modified object
282
+     * @since 9.0.0
283
+     */
284
+    public function setSharedBy($sharedBy);
285
+
286
+    /**
287
+     * Get share sharer
288
+     *
289
+     * @return string
290
+     * @since 9.0.0
291
+     */
292
+    public function getSharedBy();
293
+
294
+    /**
295
+     * Set the original share owner (who owns the path that is shared)
296
+     *
297
+     * @param string $shareOwner
298
+     * @return \OCP\Share\IShare The modified object
299
+     * @since 9.0.0
300
+     */
301
+    public function setShareOwner($shareOwner);
302
+
303
+    /**
304
+     * Get the original share owner (who owns the path that is shared)
305
+     *
306
+     * @return string
307
+     * @since 9.0.0
308
+     */
309
+    public function getShareOwner();
310
+
311
+    /**
312
+     * Set the password for this share.
313
+     * When the share is passed to the share manager to be created
314
+     * or updated the password will be hashed.
315
+     *
316
+     * @param string $password
317
+     * @return \OCP\Share\IShare The modified object
318
+     * @since 9.0.0
319
+     */
320
+    public function setPassword($password);
321
+
322
+    /**
323
+     * Get the password of this share.
324
+     * If this share is obtained via a shareprovider the password is
325
+     * hashed.
326
+     *
327
+     * @return string
328
+     * @since 9.0.0
329
+     */
330
+    public function getPassword();
331
+
332
+
333
+    /**
334
+     * Set if the recipient can start a conversation with the owner to get the
335
+     * password using Nextcloud Talk.
336
+     *
337
+     * @param bool $sendPasswordByTalk
338
+     * @return \OCP\Share\IShare The modified object
339
+     * @since 14.0.0
340
+     */
341
+    public function setSendPasswordByTalk(bool $sendPasswordByTalk);
342
+
343
+    /**
344
+     * Get if the recipient can start a conversation with the owner to get the
345
+     * password using Nextcloud Talk.
346
+     * The returned value does not take into account other factors, like Talk
347
+     * being enabled for the owner of the share or not; it just cover whether
348
+     * the option is enabled for the share itself or not.
349
+     *
350
+     * @return bool
351
+     * @since 14.0.0
352
+     */
353
+    public function getSendPasswordByTalk(): bool;
354
+
355
+    /**
356
+     * Set the public link token.
357
+     *
358
+     * @param string $token
359
+     * @return \OCP\Share\IShare The modified object
360
+     * @since 9.0.0
361
+     */
362
+    public function setToken($token);
363
+
364
+    /**
365
+     * Get the public link token.
366
+     *
367
+     * @return string
368
+     * @since 9.0.0
369
+     */
370
+    public function getToken();
371
+
372
+    /**
373
+     * Set the target path of this share relative to the recipients user folder.
374
+     *
375
+     * @param string $target
376
+     * @return \OCP\Share\IShare The modified object
377
+     * @since 9.0.0
378
+     */
379
+    public function setTarget($target);
380
+
381
+    /**
382
+     * Get the target path of this share relative to the recipients user folder.
383
+     *
384
+     * @return string
385
+     * @since 9.0.0
386
+     */
387
+    public function getTarget();
388
+
389
+    /**
390
+     * Set the time this share was created
391
+     *
392
+     * @param \DateTime $shareTime
393
+     * @return \OCP\Share\IShare The modified object
394
+     * @since 9.0.0
395
+     */
396
+    public function setShareTime(\DateTime $shareTime);
397
+
398
+    /**
399
+     * Get the timestamp this share was created
400
+     *
401
+     * @return \DateTime
402
+     * @since 9.0.0
403
+     */
404
+    public function getShareTime();
405
+
406
+    /**
407
+     * Set if the recipient is informed by mail about the share.
408
+     *
409
+     * @param bool $mailSend
410
+     * @return \OCP\Share\IShare The modified object
411
+     * @since 9.0.0
412
+     */
413
+    public function setMailSend($mailSend);
414
+
415
+    /**
416
+     * Get if the recipient informed by mail about the share.
417
+     *
418
+     * @return bool
419
+     * @since 9.0.0
420
+     */
421
+    public function getMailSend();
422
+
423
+    /**
424
+     * Set the cache entry for the shared node
425
+     *
426
+     * @param ICacheEntry $entry
427
+     * @since 11.0.0
428
+     */
429
+    public function setNodeCacheEntry(ICacheEntry $entry);
430
+
431
+    /**
432
+     * Get the cache entry for the shared node
433
+     *
434
+     * @return null|ICacheEntry
435
+     * @since 11.0.0
436
+     */
437
+    public function getNodeCacheEntry();
438
+
439
+    /**
440
+     * Sets a shares hide download state
441
+     * This is mainly for public shares. It will signal that the share page should
442
+     * hide download buttons etc.
443
+     *
444
+     * @param bool $ro
445
+     * @return IShare
446
+     * @since 15.0.0
447
+     */
448
+    public function setHideDownload(bool $hide): IShare;
449
+
450
+    /**
451
+     * Gets a shares hide download state
452
+     * This is mainly for public shares. It will signal that the share page should
453
+     * hide download buttons etc.
454
+     *
455
+     * @return bool
456
+     * @since 15.0.0
457
+     */
458
+    public function getHideDownload(): bool;
459 459
 }
Please login to merge, or discard this patch.
lib/private/Share20/DefaultShareProvider.php 2 patches
Indentation   +1280 added lines, -1280 removed lines patch added patch discarded remove patch
@@ -58,1317 +58,1317 @@
 block discarded – undo
58 58
  */
59 59
 class DefaultShareProvider implements IShareProvider {
60 60
 
61
-	// Special share type for user modified group shares
62
-	const SHARE_TYPE_USERGROUP = 2;
63
-
64
-	/** @var IDBConnection */
65
-	private $dbConn;
66
-
67
-	/** @var IUserManager */
68
-	private $userManager;
69
-
70
-	/** @var IGroupManager */
71
-	private $groupManager;
72
-
73
-	/** @var IRootFolder */
74
-	private $rootFolder;
75
-
76
-	/** @var IMailer */
77
-	private $mailer;
78
-
79
-	/** @var Defaults */
80
-	private $defaults;
81
-
82
-	/** @var IL10N */
83
-	private $l;
84
-
85
-	/** @var IURLGenerator */
86
-	private $urlGenerator;
87
-
88
-	/**
89
-	 * DefaultShareProvider constructor.
90
-	 *
91
-	 * @param IDBConnection $connection
92
-	 * @param IUserManager $userManager
93
-	 * @param IGroupManager $groupManager
94
-	 * @param IRootFolder $rootFolder
95
-	 * @param IMailer $mailer ;
96
-	 * @param Defaults $defaults
97
-	 * @param IL10N $l
98
-	 * @param IURLGenerator $urlGenerator
99
-	 */
100
-	public function __construct(
101
-			IDBConnection $connection,
102
-			IUserManager $userManager,
103
-			IGroupManager $groupManager,
104
-			IRootFolder $rootFolder,
105
-			IMailer $mailer,
106
-			Defaults $defaults,
107
-			IL10N $l,
108
-			IURLGenerator $urlGenerator) {
109
-		$this->dbConn = $connection;
110
-		$this->userManager = $userManager;
111
-		$this->groupManager = $groupManager;
112
-		$this->rootFolder = $rootFolder;
113
-		$this->mailer = $mailer;
114
-		$this->defaults = $defaults;
115
-		$this->l = $l;
116
-		$this->urlGenerator = $urlGenerator;
117
-	}
118
-
119
-	/**
120
-	 * Return the identifier of this provider.
121
-	 *
122
-	 * @return string Containing only [a-zA-Z0-9]
123
-	 */
124
-	public function identifier() {
125
-		return 'ocinternal';
126
-	}
127
-
128
-	/**
129
-	 * Share a path
130
-	 *
131
-	 * @param \OCP\Share\IShare $share
132
-	 * @return \OCP\Share\IShare The share object
133
-	 * @throws ShareNotFound
134
-	 * @throws \Exception
135
-	 */
136
-	public function create(\OCP\Share\IShare $share) {
137
-		$qb = $this->dbConn->getQueryBuilder();
138
-
139
-		$qb->insert('share');
140
-		$qb->setValue('share_type', $qb->createNamedParameter($share->getShareType()));
141
-
142
-		if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
143
-			//Set the UID of the user we share with
144
-			$qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith()));
145
-		} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
146
-			//Set the GID of the group we share with
147
-			$qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith()));
148
-		} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
149
-			//set label for public link
150
-			$qb->setValue('label', $qb->createNamedParameter($share->getLabel()));
151
-			//Set the token of the share
152
-			$qb->setValue('token', $qb->createNamedParameter($share->getToken()));
153
-
154
-			//If a password is set store it
155
-			if ($share->getPassword() !== null) {
156
-				$qb->setValue('password', $qb->createNamedParameter($share->getPassword()));
157
-			}
158
-
159
-			//If an expiration date is set store it
160
-			if ($share->getExpirationDate() !== null) {
161
-				$qb->setValue('expiration', $qb->createNamedParameter($share->getExpirationDate(), 'datetime'));
162
-			}
163
-
164
-			if (method_exists($share, 'getParent')) {
165
-				$qb->setValue('parent', $qb->createNamedParameter($share->getParent()));
166
-			}
167
-		} else {
168
-			throw new \Exception('invalid share type!');
169
-		}
170
-
171
-		// Set what is shares
172
-		$qb->setValue('item_type', $qb->createParameter('itemType'));
173
-		if ($share->getNode() instanceof \OCP\Files\File) {
174
-			$qb->setParameter('itemType', 'file');
175
-		} else {
176
-			$qb->setParameter('itemType', 'folder');
177
-		}
178
-
179
-		// Set the file id
180
-		$qb->setValue('item_source', $qb->createNamedParameter($share->getNode()->getId()));
181
-		$qb->setValue('file_source', $qb->createNamedParameter($share->getNode()->getId()));
182
-
183
-		// set the permissions
184
-		$qb->setValue('permissions', $qb->createNamedParameter($share->getPermissions()));
185
-
186
-		// Set who created this share
187
-		$qb->setValue('uid_initiator', $qb->createNamedParameter($share->getSharedBy()));
188
-
189
-		// Set who is the owner of this file/folder (and this the owner of the share)
190
-		$qb->setValue('uid_owner', $qb->createNamedParameter($share->getShareOwner()));
191
-
192
-		// Set the file target
193
-		$qb->setValue('file_target', $qb->createNamedParameter($share->getTarget()));
194
-
195
-		// Set the time this share was created
196
-		$qb->setValue('stime', $qb->createNamedParameter(time()));
197
-
198
-		// insert the data and fetch the id of the share
199
-		$this->dbConn->beginTransaction();
200
-		$qb->execute();
201
-		$id = $this->dbConn->lastInsertId('*PREFIX*share');
202
-
203
-		// Now fetch the inserted share and create a complete share object
204
-		$qb = $this->dbConn->getQueryBuilder();
205
-		$qb->select('*')
206
-			->from('share')
207
-			->where($qb->expr()->eq('id', $qb->createNamedParameter($id)));
208
-
209
-		$cursor = $qb->execute();
210
-		$data = $cursor->fetch();
211
-		$this->dbConn->commit();
212
-		$cursor->closeCursor();
213
-
214
-		if ($data === false) {
215
-			throw new ShareNotFound();
216
-		}
217
-
218
-		$mailSendValue = $share->getMailSend();
219
-		$data['mail_send'] = ($mailSendValue === null) ? true : $mailSendValue;
220
-
221
-		$share = $this->createShare($data);
222
-		return $share;
223
-	}
224
-
225
-	/**
226
-	 * Update a share
227
-	 *
228
-	 * @param \OCP\Share\IShare $share
229
-	 * @return \OCP\Share\IShare The share object
230
-	 * @throws ShareNotFound
231
-	 * @throws \OCP\Files\InvalidPathException
232
-	 * @throws \OCP\Files\NotFoundException
233
-	 */
234
-	public function update(\OCP\Share\IShare $share) {
235
-
236
-		$originalShare = $this->getShareById($share->getId());
237
-
238
-		if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
239
-			/*
61
+    // Special share type for user modified group shares
62
+    const SHARE_TYPE_USERGROUP = 2;
63
+
64
+    /** @var IDBConnection */
65
+    private $dbConn;
66
+
67
+    /** @var IUserManager */
68
+    private $userManager;
69
+
70
+    /** @var IGroupManager */
71
+    private $groupManager;
72
+
73
+    /** @var IRootFolder */
74
+    private $rootFolder;
75
+
76
+    /** @var IMailer */
77
+    private $mailer;
78
+
79
+    /** @var Defaults */
80
+    private $defaults;
81
+
82
+    /** @var IL10N */
83
+    private $l;
84
+
85
+    /** @var IURLGenerator */
86
+    private $urlGenerator;
87
+
88
+    /**
89
+     * DefaultShareProvider constructor.
90
+     *
91
+     * @param IDBConnection $connection
92
+     * @param IUserManager $userManager
93
+     * @param IGroupManager $groupManager
94
+     * @param IRootFolder $rootFolder
95
+     * @param IMailer $mailer ;
96
+     * @param Defaults $defaults
97
+     * @param IL10N $l
98
+     * @param IURLGenerator $urlGenerator
99
+     */
100
+    public function __construct(
101
+            IDBConnection $connection,
102
+            IUserManager $userManager,
103
+            IGroupManager $groupManager,
104
+            IRootFolder $rootFolder,
105
+            IMailer $mailer,
106
+            Defaults $defaults,
107
+            IL10N $l,
108
+            IURLGenerator $urlGenerator) {
109
+        $this->dbConn = $connection;
110
+        $this->userManager = $userManager;
111
+        $this->groupManager = $groupManager;
112
+        $this->rootFolder = $rootFolder;
113
+        $this->mailer = $mailer;
114
+        $this->defaults = $defaults;
115
+        $this->l = $l;
116
+        $this->urlGenerator = $urlGenerator;
117
+    }
118
+
119
+    /**
120
+     * Return the identifier of this provider.
121
+     *
122
+     * @return string Containing only [a-zA-Z0-9]
123
+     */
124
+    public function identifier() {
125
+        return 'ocinternal';
126
+    }
127
+
128
+    /**
129
+     * Share a path
130
+     *
131
+     * @param \OCP\Share\IShare $share
132
+     * @return \OCP\Share\IShare The share object
133
+     * @throws ShareNotFound
134
+     * @throws \Exception
135
+     */
136
+    public function create(\OCP\Share\IShare $share) {
137
+        $qb = $this->dbConn->getQueryBuilder();
138
+
139
+        $qb->insert('share');
140
+        $qb->setValue('share_type', $qb->createNamedParameter($share->getShareType()));
141
+
142
+        if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
143
+            //Set the UID of the user we share with
144
+            $qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith()));
145
+        } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
146
+            //Set the GID of the group we share with
147
+            $qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith()));
148
+        } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
149
+            //set label for public link
150
+            $qb->setValue('label', $qb->createNamedParameter($share->getLabel()));
151
+            //Set the token of the share
152
+            $qb->setValue('token', $qb->createNamedParameter($share->getToken()));
153
+
154
+            //If a password is set store it
155
+            if ($share->getPassword() !== null) {
156
+                $qb->setValue('password', $qb->createNamedParameter($share->getPassword()));
157
+            }
158
+
159
+            //If an expiration date is set store it
160
+            if ($share->getExpirationDate() !== null) {
161
+                $qb->setValue('expiration', $qb->createNamedParameter($share->getExpirationDate(), 'datetime'));
162
+            }
163
+
164
+            if (method_exists($share, 'getParent')) {
165
+                $qb->setValue('parent', $qb->createNamedParameter($share->getParent()));
166
+            }
167
+        } else {
168
+            throw new \Exception('invalid share type!');
169
+        }
170
+
171
+        // Set what is shares
172
+        $qb->setValue('item_type', $qb->createParameter('itemType'));
173
+        if ($share->getNode() instanceof \OCP\Files\File) {
174
+            $qb->setParameter('itemType', 'file');
175
+        } else {
176
+            $qb->setParameter('itemType', 'folder');
177
+        }
178
+
179
+        // Set the file id
180
+        $qb->setValue('item_source', $qb->createNamedParameter($share->getNode()->getId()));
181
+        $qb->setValue('file_source', $qb->createNamedParameter($share->getNode()->getId()));
182
+
183
+        // set the permissions
184
+        $qb->setValue('permissions', $qb->createNamedParameter($share->getPermissions()));
185
+
186
+        // Set who created this share
187
+        $qb->setValue('uid_initiator', $qb->createNamedParameter($share->getSharedBy()));
188
+
189
+        // Set who is the owner of this file/folder (and this the owner of the share)
190
+        $qb->setValue('uid_owner', $qb->createNamedParameter($share->getShareOwner()));
191
+
192
+        // Set the file target
193
+        $qb->setValue('file_target', $qb->createNamedParameter($share->getTarget()));
194
+
195
+        // Set the time this share was created
196
+        $qb->setValue('stime', $qb->createNamedParameter(time()));
197
+
198
+        // insert the data and fetch the id of the share
199
+        $this->dbConn->beginTransaction();
200
+        $qb->execute();
201
+        $id = $this->dbConn->lastInsertId('*PREFIX*share');
202
+
203
+        // Now fetch the inserted share and create a complete share object
204
+        $qb = $this->dbConn->getQueryBuilder();
205
+        $qb->select('*')
206
+            ->from('share')
207
+            ->where($qb->expr()->eq('id', $qb->createNamedParameter($id)));
208
+
209
+        $cursor = $qb->execute();
210
+        $data = $cursor->fetch();
211
+        $this->dbConn->commit();
212
+        $cursor->closeCursor();
213
+
214
+        if ($data === false) {
215
+            throw new ShareNotFound();
216
+        }
217
+
218
+        $mailSendValue = $share->getMailSend();
219
+        $data['mail_send'] = ($mailSendValue === null) ? true : $mailSendValue;
220
+
221
+        $share = $this->createShare($data);
222
+        return $share;
223
+    }
224
+
225
+    /**
226
+     * Update a share
227
+     *
228
+     * @param \OCP\Share\IShare $share
229
+     * @return \OCP\Share\IShare The share object
230
+     * @throws ShareNotFound
231
+     * @throws \OCP\Files\InvalidPathException
232
+     * @throws \OCP\Files\NotFoundException
233
+     */
234
+    public function update(\OCP\Share\IShare $share) {
235
+
236
+        $originalShare = $this->getShareById($share->getId());
237
+
238
+        if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
239
+            /*
240 240
 			 * We allow updating the recipient on user shares.
241 241
 			 */
242
-			$qb = $this->dbConn->getQueryBuilder();
243
-			$qb->update('share')
244
-				->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
245
-				->set('share_with', $qb->createNamedParameter($share->getSharedWith()))
246
-				->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
247
-				->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
248
-				->set('permissions', $qb->createNamedParameter($share->getPermissions()))
249
-				->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
250
-				->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
251
-				->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))
252
-				->set('note', $qb->createNamedParameter($share->getNote()))
253
-				->execute();
254
-		} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
255
-			$qb = $this->dbConn->getQueryBuilder();
256
-			$qb->update('share')
257
-				->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
258
-				->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
259
-				->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
260
-				->set('permissions', $qb->createNamedParameter($share->getPermissions()))
261
-				->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
262
-				->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
263
-				->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))
264
-				->set('note', $qb->createNamedParameter($share->getNote()))
265
-				->execute();
266
-
267
-			/*
242
+            $qb = $this->dbConn->getQueryBuilder();
243
+            $qb->update('share')
244
+                ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
245
+                ->set('share_with', $qb->createNamedParameter($share->getSharedWith()))
246
+                ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
247
+                ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
248
+                ->set('permissions', $qb->createNamedParameter($share->getPermissions()))
249
+                ->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
250
+                ->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
251
+                ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))
252
+                ->set('note', $qb->createNamedParameter($share->getNote()))
253
+                ->execute();
254
+        } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
255
+            $qb = $this->dbConn->getQueryBuilder();
256
+            $qb->update('share')
257
+                ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
258
+                ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
259
+                ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
260
+                ->set('permissions', $qb->createNamedParameter($share->getPermissions()))
261
+                ->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
262
+                ->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
263
+                ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))
264
+                ->set('note', $qb->createNamedParameter($share->getNote()))
265
+                ->execute();
266
+
267
+            /*
268 268
 			 * Update all user defined group shares
269 269
 			 */
270
-			$qb = $this->dbConn->getQueryBuilder();
271
-			$qb->update('share')
272
-				->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
273
-				->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
274
-				->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
275
-				->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
276
-				->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
277
-				->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))
278
-				->set('note', $qb->createNamedParameter($share->getNote()))
279
-				->execute();
280
-
281
-			/*
270
+            $qb = $this->dbConn->getQueryBuilder();
271
+            $qb->update('share')
272
+                ->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
273
+                ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
274
+                ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
275
+                ->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
276
+                ->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
277
+                ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))
278
+                ->set('note', $qb->createNamedParameter($share->getNote()))
279
+                ->execute();
280
+
281
+            /*
282 282
 			 * Now update the permissions for all children that have not set it to 0
283 283
 			 */
284
-			$qb = $this->dbConn->getQueryBuilder();
285
-			$qb->update('share')
286
-				->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
287
-				->andWhere($qb->expr()->neq('permissions', $qb->createNamedParameter(0)))
288
-				->set('permissions', $qb->createNamedParameter($share->getPermissions()))
289
-				->execute();
290
-
291
-		} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
292
-			$qb = $this->dbConn->getQueryBuilder();
293
-			$qb->update('share')
294
-				->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
295
-				->set('password', $qb->createNamedParameter($share->getPassword()))
296
-				->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
297
-				->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
298
-				->set('permissions', $qb->createNamedParameter($share->getPermissions()))
299
-				->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
300
-				->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
301
-				->set('token', $qb->createNamedParameter($share->getToken()))
302
-				->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))
303
-				->set('note', $qb->createNamedParameter($share->getNote()))
304
-				->set('label', $qb->createNamedParameter($share->getLabel()))
305
-				->set('hide_download', $qb->createNamedParameter($share->getHideDownload() ? 1 : 0), IQueryBuilder::PARAM_INT)
306
-				->execute();
307
-		}
308
-
309
-		if ($originalShare->getNote() !== $share->getNote() && $share->getNote() !== '') {
310
-			$this->propagateNote($share);
311
-		}
312
-
313
-
314
-		return $share;
315
-	}
316
-
317
-	/**
318
-	 * Get all children of this share
319
-	 * FIXME: remove once https://github.com/owncloud/core/pull/21660 is in
320
-	 *
321
-	 * @param \OCP\Share\IShare $parent
322
-	 * @return \OCP\Share\IShare[]
323
-	 */
324
-	public function getChildren(\OCP\Share\IShare $parent) {
325
-		$children = [];
326
-
327
-		$qb = $this->dbConn->getQueryBuilder();
328
-		$qb->select('*')
329
-			->from('share')
330
-			->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId())))
331
-			->andWhere(
332
-				$qb->expr()->in(
333
-					'share_type',
334
-					$qb->createNamedParameter([
335
-						\OCP\Share::SHARE_TYPE_USER,
336
-						\OCP\Share::SHARE_TYPE_GROUP,
337
-						\OCP\Share::SHARE_TYPE_LINK,
338
-					], IQueryBuilder::PARAM_INT_ARRAY)
339
-				)
340
-			)
341
-			->andWhere($qb->expr()->orX(
342
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
343
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
344
-			))
345
-			->orderBy('id');
346
-
347
-		$cursor = $qb->execute();
348
-		while($data = $cursor->fetch()) {
349
-			$children[] = $this->createShare($data);
350
-		}
351
-		$cursor->closeCursor();
352
-
353
-		return $children;
354
-	}
355
-
356
-	/**
357
-	 * Delete a share
358
-	 *
359
-	 * @param \OCP\Share\IShare $share
360
-	 */
361
-	public function delete(\OCP\Share\IShare $share) {
362
-		$qb = $this->dbConn->getQueryBuilder();
363
-		$qb->delete('share')
364
-			->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())));
365
-
366
-		/*
284
+            $qb = $this->dbConn->getQueryBuilder();
285
+            $qb->update('share')
286
+                ->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
287
+                ->andWhere($qb->expr()->neq('permissions', $qb->createNamedParameter(0)))
288
+                ->set('permissions', $qb->createNamedParameter($share->getPermissions()))
289
+                ->execute();
290
+
291
+        } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
292
+            $qb = $this->dbConn->getQueryBuilder();
293
+            $qb->update('share')
294
+                ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
295
+                ->set('password', $qb->createNamedParameter($share->getPassword()))
296
+                ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
297
+                ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
298
+                ->set('permissions', $qb->createNamedParameter($share->getPermissions()))
299
+                ->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
300
+                ->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
301
+                ->set('token', $qb->createNamedParameter($share->getToken()))
302
+                ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))
303
+                ->set('note', $qb->createNamedParameter($share->getNote()))
304
+                ->set('label', $qb->createNamedParameter($share->getLabel()))
305
+                ->set('hide_download', $qb->createNamedParameter($share->getHideDownload() ? 1 : 0), IQueryBuilder::PARAM_INT)
306
+                ->execute();
307
+        }
308
+
309
+        if ($originalShare->getNote() !== $share->getNote() && $share->getNote() !== '') {
310
+            $this->propagateNote($share);
311
+        }
312
+
313
+
314
+        return $share;
315
+    }
316
+
317
+    /**
318
+     * Get all children of this share
319
+     * FIXME: remove once https://github.com/owncloud/core/pull/21660 is in
320
+     *
321
+     * @param \OCP\Share\IShare $parent
322
+     * @return \OCP\Share\IShare[]
323
+     */
324
+    public function getChildren(\OCP\Share\IShare $parent) {
325
+        $children = [];
326
+
327
+        $qb = $this->dbConn->getQueryBuilder();
328
+        $qb->select('*')
329
+            ->from('share')
330
+            ->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId())))
331
+            ->andWhere(
332
+                $qb->expr()->in(
333
+                    'share_type',
334
+                    $qb->createNamedParameter([
335
+                        \OCP\Share::SHARE_TYPE_USER,
336
+                        \OCP\Share::SHARE_TYPE_GROUP,
337
+                        \OCP\Share::SHARE_TYPE_LINK,
338
+                    ], IQueryBuilder::PARAM_INT_ARRAY)
339
+                )
340
+            )
341
+            ->andWhere($qb->expr()->orX(
342
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
343
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
344
+            ))
345
+            ->orderBy('id');
346
+
347
+        $cursor = $qb->execute();
348
+        while($data = $cursor->fetch()) {
349
+            $children[] = $this->createShare($data);
350
+        }
351
+        $cursor->closeCursor();
352
+
353
+        return $children;
354
+    }
355
+
356
+    /**
357
+     * Delete a share
358
+     *
359
+     * @param \OCP\Share\IShare $share
360
+     */
361
+    public function delete(\OCP\Share\IShare $share) {
362
+        $qb = $this->dbConn->getQueryBuilder();
363
+        $qb->delete('share')
364
+            ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())));
365
+
366
+        /*
367 367
 		 * If the share is a group share delete all possible
368 368
 		 * user defined groups shares.
369 369
 		 */
370
-		if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
371
-			$qb->orWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())));
372
-		}
373
-
374
-		$qb->execute();
375
-	}
376
-
377
-	/**
378
-	 * Unshare a share from the recipient. If this is a group share
379
-	 * this means we need a special entry in the share db.
380
-	 *
381
-	 * @param \OCP\Share\IShare $share
382
-	 * @param string $recipient UserId of recipient
383
-	 * @throws BackendError
384
-	 * @throws ProviderException
385
-	 */
386
-	public function deleteFromSelf(\OCP\Share\IShare $share, $recipient) {
387
-		if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
388
-
389
-			$group = $this->groupManager->get($share->getSharedWith());
390
-			$user = $this->userManager->get($recipient);
391
-
392
-			if (is_null($group)) {
393
-				throw new ProviderException('Group "' . $share->getSharedWith() . '" does not exist');
394
-			}
395
-
396
-			if (!$group->inGroup($user)) {
397
-				throw new ProviderException('Recipient not in receiving group');
398
-			}
399
-
400
-			// Try to fetch user specific share
401
-			$qb = $this->dbConn->getQueryBuilder();
402
-			$stmt = $qb->select('*')
403
-				->from('share')
404
-				->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)))
405
-				->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient)))
406
-				->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
407
-				->andWhere($qb->expr()->orX(
408
-					$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
409
-					$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
410
-				))
411
-				->execute();
412
-
413
-			$data = $stmt->fetch();
414
-
415
-			/*
370
+        if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
371
+            $qb->orWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())));
372
+        }
373
+
374
+        $qb->execute();
375
+    }
376
+
377
+    /**
378
+     * Unshare a share from the recipient. If this is a group share
379
+     * this means we need a special entry in the share db.
380
+     *
381
+     * @param \OCP\Share\IShare $share
382
+     * @param string $recipient UserId of recipient
383
+     * @throws BackendError
384
+     * @throws ProviderException
385
+     */
386
+    public function deleteFromSelf(\OCP\Share\IShare $share, $recipient) {
387
+        if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
388
+
389
+            $group = $this->groupManager->get($share->getSharedWith());
390
+            $user = $this->userManager->get($recipient);
391
+
392
+            if (is_null($group)) {
393
+                throw new ProviderException('Group "' . $share->getSharedWith() . '" does not exist');
394
+            }
395
+
396
+            if (!$group->inGroup($user)) {
397
+                throw new ProviderException('Recipient not in receiving group');
398
+            }
399
+
400
+            // Try to fetch user specific share
401
+            $qb = $this->dbConn->getQueryBuilder();
402
+            $stmt = $qb->select('*')
403
+                ->from('share')
404
+                ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)))
405
+                ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient)))
406
+                ->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
407
+                ->andWhere($qb->expr()->orX(
408
+                    $qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
409
+                    $qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
410
+                ))
411
+                ->execute();
412
+
413
+            $data = $stmt->fetch();
414
+
415
+            /*
416 416
 			 * Check if there already is a user specific group share.
417 417
 			 * If there is update it (if required).
418 418
 			 */
419
-			if ($data === false) {
420
-				$qb = $this->dbConn->getQueryBuilder();
421
-
422
-				$type = $share->getNodeType();
423
-
424
-				//Insert new share
425
-				$qb->insert('share')
426
-					->values([
427
-						'share_type' => $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP),
428
-						'share_with' => $qb->createNamedParameter($recipient),
429
-						'uid_owner' => $qb->createNamedParameter($share->getShareOwner()),
430
-						'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()),
431
-						'parent' => $qb->createNamedParameter($share->getId()),
432
-						'item_type' => $qb->createNamedParameter($type),
433
-						'item_source' => $qb->createNamedParameter($share->getNodeId()),
434
-						'file_source' => $qb->createNamedParameter($share->getNodeId()),
435
-						'file_target' => $qb->createNamedParameter($share->getTarget()),
436
-						'permissions' => $qb->createNamedParameter(0),
437
-						'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()),
438
-					])->execute();
439
-
440
-			} else if ($data['permissions'] !== 0) {
441
-
442
-				// Update existing usergroup share
443
-				$qb = $this->dbConn->getQueryBuilder();
444
-				$qb->update('share')
445
-					->set('permissions', $qb->createNamedParameter(0))
446
-					->where($qb->expr()->eq('id', $qb->createNamedParameter($data['id'])))
447
-					->execute();
448
-			}
449
-
450
-		} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
451
-
452
-			if ($share->getSharedWith() !== $recipient) {
453
-				throw new ProviderException('Recipient does not match');
454
-			}
455
-
456
-			// We can just delete user and link shares
457
-			$this->delete($share);
458
-		} else {
459
-			throw new ProviderException('Invalid shareType');
460
-		}
461
-	}
462
-
463
-	/**
464
-	 * @inheritdoc
465
-	 *
466
-	 * For now this only works for group shares
467
-	 * If this gets implemented for normal shares we have to extend it
468
-	 */
469
-	public function restore(IShare $share, string $recipient): IShare {
470
-		$qb = $this->dbConn->getQueryBuilder();
471
-		$qb->select('permissions')
472
-			->from('share')
473
-			->where(
474
-				$qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))
475
-			);
476
-		$cursor = $qb->execute();
477
-		$data = $cursor->fetch();
478
-		$cursor->closeCursor();
479
-
480
-		$originalPermission = $data['permissions'];
481
-
482
-		$qb = $this->dbConn->getQueryBuilder();
483
-		$qb->update('share')
484
-			->set('permissions', $qb->createNamedParameter($originalPermission))
485
-			->where(
486
-				$qb->expr()->eq('parent', $qb->createNamedParameter($share->getParent()))
487
-			)->andWhere(
488
-				$qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))
489
-			)->andWhere(
490
-				$qb->expr()->eq('share_with', $qb->createNamedParameter($recipient))
491
-			);
492
-
493
-		$qb->execute();
494
-
495
-		return $this->getShareById($share->getId(), $recipient);
496
-	}
497
-
498
-	/**
499
-	 * @inheritdoc
500
-	 */
501
-	public function move(\OCP\Share\IShare $share, $recipient) {
502
-		if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
503
-			// Just update the target
504
-			$qb = $this->dbConn->getQueryBuilder();
505
-			$qb->update('share')
506
-				->set('file_target', $qb->createNamedParameter($share->getTarget()))
507
-				->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
508
-				->execute();
509
-
510
-		} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
511
-
512
-			// Check if there is a usergroup share
513
-			$qb = $this->dbConn->getQueryBuilder();
514
-			$stmt = $qb->select('id')
515
-				->from('share')
516
-				->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)))
517
-				->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient)))
518
-				->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
519
-				->andWhere($qb->expr()->orX(
520
-					$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
521
-					$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
522
-				))
523
-				->setMaxResults(1)
524
-				->execute();
525
-
526
-			$data = $stmt->fetch();
527
-			$stmt->closeCursor();
528
-
529
-			if ($data === false) {
530
-				// No usergroup share yet. Create one.
531
-				$qb = $this->dbConn->getQueryBuilder();
532
-				$qb->insert('share')
533
-					->values([
534
-						'share_type' => $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP),
535
-						'share_with' => $qb->createNamedParameter($recipient),
536
-						'uid_owner' => $qb->createNamedParameter($share->getShareOwner()),
537
-						'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()),
538
-						'parent' => $qb->createNamedParameter($share->getId()),
539
-						'item_type' => $qb->createNamedParameter($share->getNodeType()),
540
-						'item_source' => $qb->createNamedParameter($share->getNodeId()),
541
-						'file_source' => $qb->createNamedParameter($share->getNodeId()),
542
-						'file_target' => $qb->createNamedParameter($share->getTarget()),
543
-						'permissions' => $qb->createNamedParameter($share->getPermissions()),
544
-						'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()),
545
-					])->execute();
546
-			} else {
547
-				// Already a usergroup share. Update it.
548
-				$qb = $this->dbConn->getQueryBuilder();
549
-				$qb->update('share')
550
-					->set('file_target', $qb->createNamedParameter($share->getTarget()))
551
-					->where($qb->expr()->eq('id', $qb->createNamedParameter($data['id'])))
552
-					->execute();
553
-			}
554
-		}
555
-
556
-		return $share;
557
-	}
558
-
559
-	public function getSharesInFolder($userId, Folder $node, $reshares) {
560
-		$qb = $this->dbConn->getQueryBuilder();
561
-		$qb->select('*')
562
-			->from('share', 's')
563
-			->andWhere($qb->expr()->orX(
564
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
565
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
566
-			));
567
-
568
-		$qb->andWhere($qb->expr()->orX(
569
-			$qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)),
570
-			$qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)),
571
-			$qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK))
572
-		));
573
-
574
-		/**
575
-		 * Reshares for this user are shares where they are the owner.
576
-		 */
577
-		if ($reshares === false) {
578
-			$qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)));
579
-		} else {
580
-			$qb->andWhere(
581
-				$qb->expr()->orX(
582
-					$qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
583
-					$qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))
584
-				)
585
-			);
586
-		}
587
-
588
-		$qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid'));
589
-		$qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId())));
590
-
591
-		$qb->orderBy('id');
592
-
593
-		$cursor = $qb->execute();
594
-		$shares = [];
595
-		while ($data = $cursor->fetch()) {
596
-			$shares[$data['fileid']][] = $this->createShare($data);
597
-		}
598
-		$cursor->closeCursor();
599
-
600
-		return $shares;
601
-	}
602
-
603
-	/**
604
-	 * @inheritdoc
605
-	 */
606
-	public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) {
607
-		$qb = $this->dbConn->getQueryBuilder();
608
-		$qb->select('*')
609
-			->from('share')
610
-			->andWhere($qb->expr()->orX(
611
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
612
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
613
-			));
614
-
615
-		$qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter($shareType)));
616
-
617
-		/**
618
-		 * Reshares for this user are shares where they are the owner.
619
-		 */
620
-		if ($reshares === false) {
621
-			$qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)));
622
-		} else {
623
-			$qb->andWhere(
624
-				$qb->expr()->orX(
625
-					$qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
626
-					$qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))
627
-				)
628
-			);
629
-		}
630
-
631
-		if ($node !== null) {
632
-			$qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId())));
633
-		}
634
-
635
-		if ($limit !== -1) {
636
-			$qb->setMaxResults($limit);
637
-		}
638
-
639
-		$qb->setFirstResult($offset);
640
-		$qb->orderBy('id');
641
-
642
-		$cursor = $qb->execute();
643
-		$shares = [];
644
-		while($data = $cursor->fetch()) {
645
-			$shares[] = $this->createShare($data);
646
-		}
647
-		$cursor->closeCursor();
648
-
649
-		return $shares;
650
-	}
651
-
652
-	/**
653
-	 * @inheritdoc
654
-	 */
655
-	public function getShareById($id, $recipientId = null) {
656
-		$qb = $this->dbConn->getQueryBuilder();
657
-
658
-		$qb->select('*')
659
-			->from('share')
660
-			->where($qb->expr()->eq('id', $qb->createNamedParameter($id)))
661
-			->andWhere(
662
-				$qb->expr()->in(
663
-					'share_type',
664
-					$qb->createNamedParameter([
665
-						\OCP\Share::SHARE_TYPE_USER,
666
-						\OCP\Share::SHARE_TYPE_GROUP,
667
-						\OCP\Share::SHARE_TYPE_LINK,
668
-					], IQueryBuilder::PARAM_INT_ARRAY)
669
-				)
670
-			)
671
-			->andWhere($qb->expr()->orX(
672
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
673
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
674
-			));
675
-
676
-		$cursor = $qb->execute();
677
-		$data = $cursor->fetch();
678
-		$cursor->closeCursor();
679
-
680
-		if ($data === false) {
681
-			throw new ShareNotFound();
682
-		}
683
-
684
-		try {
685
-			$share = $this->createShare($data);
686
-		} catch (InvalidShare $e) {
687
-			throw new ShareNotFound();
688
-		}
689
-
690
-		// If the recipient is set for a group share resolve to that user
691
-		if ($recipientId !== null && $share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
692
-			$share = $this->resolveGroupShares([$share], $recipientId)[0];
693
-		}
694
-
695
-		return $share;
696
-	}
697
-
698
-	/**
699
-	 * Get shares for a given path
700
-	 *
701
-	 * @param \OCP\Files\Node $path
702
-	 * @return \OCP\Share\IShare[]
703
-	 */
704
-	public function getSharesByPath(Node $path) {
705
-		$qb = $this->dbConn->getQueryBuilder();
706
-
707
-		$cursor = $qb->select('*')
708
-			->from('share')
709
-			->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId())))
710
-			->andWhere(
711
-				$qb->expr()->orX(
712
-					$qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)),
713
-					$qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))
714
-				)
715
-			)
716
-			->andWhere($qb->expr()->orX(
717
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
718
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
719
-			))
720
-			->execute();
721
-
722
-		$shares = [];
723
-		while($data = $cursor->fetch()) {
724
-			$shares[] = $this->createShare($data);
725
-		}
726
-		$cursor->closeCursor();
727
-
728
-		return $shares;
729
-	}
730
-
731
-	/**
732
-	 * Returns whether the given database result can be interpreted as
733
-	 * a share with accessible file (not trashed, not deleted)
734
-	 */
735
-	private function isAccessibleResult($data) {
736
-		// exclude shares leading to deleted file entries
737
-		if ($data['fileid'] === null) {
738
-			return false;
739
-		}
740
-
741
-		// exclude shares leading to trashbin on home storages
742
-		$pathSections = explode('/', $data['path'], 2);
743
-		// FIXME: would not detect rare md5'd home storage case properly
744
-		if ($pathSections[0] !== 'files'
745
-		    	&& in_array(explode(':', $data['storage_string_id'], 2)[0], array('home', 'object'))) {
746
-			return false;
747
-		}
748
-		return true;
749
-	}
750
-
751
-	/**
752
-	 * @inheritdoc
753
-	 */
754
-	public function getSharedWith($userId, $shareType, $node, $limit, $offset) {
755
-		/** @var Share[] $shares */
756
-		$shares = [];
757
-
758
-		if ($shareType === \OCP\Share::SHARE_TYPE_USER) {
759
-			//Get shares directly with this user
760
-			$qb = $this->dbConn->getQueryBuilder();
761
-			$qb->select('s.*',
762
-				'f.fileid', 'f.path', 'f.permissions AS f_permissions', 'f.storage', 'f.path_hash',
763
-				'f.parent AS f_parent', 'f.name', 'f.mimetype', 'f.mimepart', 'f.size', 'f.mtime', 'f.storage_mtime',
764
-				'f.encrypted', 'f.unencrypted_size', 'f.etag', 'f.checksum'
765
-			)
766
-				->selectAlias('st.id', 'storage_string_id')
767
-				->from('share', 's')
768
-				->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid'))
769
-				->leftJoin('f', 'storages', 'st', $qb->expr()->eq('f.storage', 'st.numeric_id'));
770
-
771
-			// Order by id
772
-			$qb->orderBy('s.id');
773
-
774
-			// Set limit and offset
775
-			if ($limit !== -1) {
776
-				$qb->setMaxResults($limit);
777
-			}
778
-			$qb->setFirstResult($offset);
779
-
780
-			$qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)))
781
-				->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId)))
782
-				->andWhere($qb->expr()->orX(
783
-					$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
784
-					$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
785
-				));
786
-
787
-			// Filter by node if provided
788
-			if ($node !== null) {
789
-				$qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId())));
790
-			}
791
-
792
-			$cursor = $qb->execute();
793
-
794
-			while($data = $cursor->fetch()) {
795
-				if ($this->isAccessibleResult($data)) {
796
-					$shares[] = $this->createShare($data);
797
-				}
798
-			}
799
-			$cursor->closeCursor();
800
-
801
-		} else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) {
802
-			$user = $this->userManager->get($userId);
803
-			$allGroups = $this->groupManager->getUserGroups($user);
804
-
805
-			/** @var Share[] $shares2 */
806
-			$shares2 = [];
807
-
808
-			$start = 0;
809
-			while(true) {
810
-				$groups = array_slice($allGroups, $start, 100);
811
-				$start += 100;
812
-
813
-				if ($groups === []) {
814
-					break;
815
-				}
816
-
817
-				$qb = $this->dbConn->getQueryBuilder();
818
-				$qb->select('s.*',
819
-					'f.fileid', 'f.path', 'f.permissions AS f_permissions', 'f.storage', 'f.path_hash',
820
-					'f.parent AS f_parent', 'f.name', 'f.mimetype', 'f.mimepart', 'f.size', 'f.mtime', 'f.storage_mtime',
821
-					'f.encrypted', 'f.unencrypted_size', 'f.etag', 'f.checksum'
822
-				)
823
-					->selectAlias('st.id', 'storage_string_id')
824
-					->from('share', 's')
825
-					->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid'))
826
-					->leftJoin('f', 'storages', 'st', $qb->expr()->eq('f.storage', 'st.numeric_id'))
827
-					->orderBy('s.id')
828
-					->setFirstResult(0);
829
-
830
-				if ($limit !== -1) {
831
-					$qb->setMaxResults($limit - count($shares));
832
-				}
833
-
834
-				// Filter by node if provided
835
-				if ($node !== null) {
836
-					$qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId())));
837
-				}
838
-
839
-
840
-				$groups = array_filter($groups, function($group) { return $group instanceof IGroup; });
841
-				$groups = array_map(function(IGroup $group) { return $group->getGID(); }, $groups);
842
-
843
-				$qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)))
844
-					->andWhere($qb->expr()->in('share_with', $qb->createNamedParameter(
845
-						$groups,
846
-						IQueryBuilder::PARAM_STR_ARRAY
847
-					)))
848
-					->andWhere($qb->expr()->orX(
849
-						$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
850
-						$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
851
-					));
852
-
853
-				$cursor = $qb->execute();
854
-				while($data = $cursor->fetch()) {
855
-					if ($offset > 0) {
856
-						$offset--;
857
-						continue;
858
-					}
859
-
860
-					if ($this->isAccessibleResult($data)) {
861
-						$shares2[] = $this->createShare($data);
862
-					}
863
-				}
864
-				$cursor->closeCursor();
865
-			}
866
-
867
-			/*
419
+            if ($data === false) {
420
+                $qb = $this->dbConn->getQueryBuilder();
421
+
422
+                $type = $share->getNodeType();
423
+
424
+                //Insert new share
425
+                $qb->insert('share')
426
+                    ->values([
427
+                        'share_type' => $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP),
428
+                        'share_with' => $qb->createNamedParameter($recipient),
429
+                        'uid_owner' => $qb->createNamedParameter($share->getShareOwner()),
430
+                        'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()),
431
+                        'parent' => $qb->createNamedParameter($share->getId()),
432
+                        'item_type' => $qb->createNamedParameter($type),
433
+                        'item_source' => $qb->createNamedParameter($share->getNodeId()),
434
+                        'file_source' => $qb->createNamedParameter($share->getNodeId()),
435
+                        'file_target' => $qb->createNamedParameter($share->getTarget()),
436
+                        'permissions' => $qb->createNamedParameter(0),
437
+                        'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()),
438
+                    ])->execute();
439
+
440
+            } else if ($data['permissions'] !== 0) {
441
+
442
+                // Update existing usergroup share
443
+                $qb = $this->dbConn->getQueryBuilder();
444
+                $qb->update('share')
445
+                    ->set('permissions', $qb->createNamedParameter(0))
446
+                    ->where($qb->expr()->eq('id', $qb->createNamedParameter($data['id'])))
447
+                    ->execute();
448
+            }
449
+
450
+        } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
451
+
452
+            if ($share->getSharedWith() !== $recipient) {
453
+                throw new ProviderException('Recipient does not match');
454
+            }
455
+
456
+            // We can just delete user and link shares
457
+            $this->delete($share);
458
+        } else {
459
+            throw new ProviderException('Invalid shareType');
460
+        }
461
+    }
462
+
463
+    /**
464
+     * @inheritdoc
465
+     *
466
+     * For now this only works for group shares
467
+     * If this gets implemented for normal shares we have to extend it
468
+     */
469
+    public function restore(IShare $share, string $recipient): IShare {
470
+        $qb = $this->dbConn->getQueryBuilder();
471
+        $qb->select('permissions')
472
+            ->from('share')
473
+            ->where(
474
+                $qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))
475
+            );
476
+        $cursor = $qb->execute();
477
+        $data = $cursor->fetch();
478
+        $cursor->closeCursor();
479
+
480
+        $originalPermission = $data['permissions'];
481
+
482
+        $qb = $this->dbConn->getQueryBuilder();
483
+        $qb->update('share')
484
+            ->set('permissions', $qb->createNamedParameter($originalPermission))
485
+            ->where(
486
+                $qb->expr()->eq('parent', $qb->createNamedParameter($share->getParent()))
487
+            )->andWhere(
488
+                $qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))
489
+            )->andWhere(
490
+                $qb->expr()->eq('share_with', $qb->createNamedParameter($recipient))
491
+            );
492
+
493
+        $qb->execute();
494
+
495
+        return $this->getShareById($share->getId(), $recipient);
496
+    }
497
+
498
+    /**
499
+     * @inheritdoc
500
+     */
501
+    public function move(\OCP\Share\IShare $share, $recipient) {
502
+        if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
503
+            // Just update the target
504
+            $qb = $this->dbConn->getQueryBuilder();
505
+            $qb->update('share')
506
+                ->set('file_target', $qb->createNamedParameter($share->getTarget()))
507
+                ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
508
+                ->execute();
509
+
510
+        } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
511
+
512
+            // Check if there is a usergroup share
513
+            $qb = $this->dbConn->getQueryBuilder();
514
+            $stmt = $qb->select('id')
515
+                ->from('share')
516
+                ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)))
517
+                ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient)))
518
+                ->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
519
+                ->andWhere($qb->expr()->orX(
520
+                    $qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
521
+                    $qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
522
+                ))
523
+                ->setMaxResults(1)
524
+                ->execute();
525
+
526
+            $data = $stmt->fetch();
527
+            $stmt->closeCursor();
528
+
529
+            if ($data === false) {
530
+                // No usergroup share yet. Create one.
531
+                $qb = $this->dbConn->getQueryBuilder();
532
+                $qb->insert('share')
533
+                    ->values([
534
+                        'share_type' => $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP),
535
+                        'share_with' => $qb->createNamedParameter($recipient),
536
+                        'uid_owner' => $qb->createNamedParameter($share->getShareOwner()),
537
+                        'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()),
538
+                        'parent' => $qb->createNamedParameter($share->getId()),
539
+                        'item_type' => $qb->createNamedParameter($share->getNodeType()),
540
+                        'item_source' => $qb->createNamedParameter($share->getNodeId()),
541
+                        'file_source' => $qb->createNamedParameter($share->getNodeId()),
542
+                        'file_target' => $qb->createNamedParameter($share->getTarget()),
543
+                        'permissions' => $qb->createNamedParameter($share->getPermissions()),
544
+                        'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()),
545
+                    ])->execute();
546
+            } else {
547
+                // Already a usergroup share. Update it.
548
+                $qb = $this->dbConn->getQueryBuilder();
549
+                $qb->update('share')
550
+                    ->set('file_target', $qb->createNamedParameter($share->getTarget()))
551
+                    ->where($qb->expr()->eq('id', $qb->createNamedParameter($data['id'])))
552
+                    ->execute();
553
+            }
554
+        }
555
+
556
+        return $share;
557
+    }
558
+
559
+    public function getSharesInFolder($userId, Folder $node, $reshares) {
560
+        $qb = $this->dbConn->getQueryBuilder();
561
+        $qb->select('*')
562
+            ->from('share', 's')
563
+            ->andWhere($qb->expr()->orX(
564
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
565
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
566
+            ));
567
+
568
+        $qb->andWhere($qb->expr()->orX(
569
+            $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)),
570
+            $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)),
571
+            $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK))
572
+        ));
573
+
574
+        /**
575
+         * Reshares for this user are shares where they are the owner.
576
+         */
577
+        if ($reshares === false) {
578
+            $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)));
579
+        } else {
580
+            $qb->andWhere(
581
+                $qb->expr()->orX(
582
+                    $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
583
+                    $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))
584
+                )
585
+            );
586
+        }
587
+
588
+        $qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid'));
589
+        $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId())));
590
+
591
+        $qb->orderBy('id');
592
+
593
+        $cursor = $qb->execute();
594
+        $shares = [];
595
+        while ($data = $cursor->fetch()) {
596
+            $shares[$data['fileid']][] = $this->createShare($data);
597
+        }
598
+        $cursor->closeCursor();
599
+
600
+        return $shares;
601
+    }
602
+
603
+    /**
604
+     * @inheritdoc
605
+     */
606
+    public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) {
607
+        $qb = $this->dbConn->getQueryBuilder();
608
+        $qb->select('*')
609
+            ->from('share')
610
+            ->andWhere($qb->expr()->orX(
611
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
612
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
613
+            ));
614
+
615
+        $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter($shareType)));
616
+
617
+        /**
618
+         * Reshares for this user are shares where they are the owner.
619
+         */
620
+        if ($reshares === false) {
621
+            $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)));
622
+        } else {
623
+            $qb->andWhere(
624
+                $qb->expr()->orX(
625
+                    $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
626
+                    $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))
627
+                )
628
+            );
629
+        }
630
+
631
+        if ($node !== null) {
632
+            $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId())));
633
+        }
634
+
635
+        if ($limit !== -1) {
636
+            $qb->setMaxResults($limit);
637
+        }
638
+
639
+        $qb->setFirstResult($offset);
640
+        $qb->orderBy('id');
641
+
642
+        $cursor = $qb->execute();
643
+        $shares = [];
644
+        while($data = $cursor->fetch()) {
645
+            $shares[] = $this->createShare($data);
646
+        }
647
+        $cursor->closeCursor();
648
+
649
+        return $shares;
650
+    }
651
+
652
+    /**
653
+     * @inheritdoc
654
+     */
655
+    public function getShareById($id, $recipientId = null) {
656
+        $qb = $this->dbConn->getQueryBuilder();
657
+
658
+        $qb->select('*')
659
+            ->from('share')
660
+            ->where($qb->expr()->eq('id', $qb->createNamedParameter($id)))
661
+            ->andWhere(
662
+                $qb->expr()->in(
663
+                    'share_type',
664
+                    $qb->createNamedParameter([
665
+                        \OCP\Share::SHARE_TYPE_USER,
666
+                        \OCP\Share::SHARE_TYPE_GROUP,
667
+                        \OCP\Share::SHARE_TYPE_LINK,
668
+                    ], IQueryBuilder::PARAM_INT_ARRAY)
669
+                )
670
+            )
671
+            ->andWhere($qb->expr()->orX(
672
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
673
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
674
+            ));
675
+
676
+        $cursor = $qb->execute();
677
+        $data = $cursor->fetch();
678
+        $cursor->closeCursor();
679
+
680
+        if ($data === false) {
681
+            throw new ShareNotFound();
682
+        }
683
+
684
+        try {
685
+            $share = $this->createShare($data);
686
+        } catch (InvalidShare $e) {
687
+            throw new ShareNotFound();
688
+        }
689
+
690
+        // If the recipient is set for a group share resolve to that user
691
+        if ($recipientId !== null && $share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
692
+            $share = $this->resolveGroupShares([$share], $recipientId)[0];
693
+        }
694
+
695
+        return $share;
696
+    }
697
+
698
+    /**
699
+     * Get shares for a given path
700
+     *
701
+     * @param \OCP\Files\Node $path
702
+     * @return \OCP\Share\IShare[]
703
+     */
704
+    public function getSharesByPath(Node $path) {
705
+        $qb = $this->dbConn->getQueryBuilder();
706
+
707
+        $cursor = $qb->select('*')
708
+            ->from('share')
709
+            ->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId())))
710
+            ->andWhere(
711
+                $qb->expr()->orX(
712
+                    $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)),
713
+                    $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))
714
+                )
715
+            )
716
+            ->andWhere($qb->expr()->orX(
717
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
718
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
719
+            ))
720
+            ->execute();
721
+
722
+        $shares = [];
723
+        while($data = $cursor->fetch()) {
724
+            $shares[] = $this->createShare($data);
725
+        }
726
+        $cursor->closeCursor();
727
+
728
+        return $shares;
729
+    }
730
+
731
+    /**
732
+     * Returns whether the given database result can be interpreted as
733
+     * a share with accessible file (not trashed, not deleted)
734
+     */
735
+    private function isAccessibleResult($data) {
736
+        // exclude shares leading to deleted file entries
737
+        if ($data['fileid'] === null) {
738
+            return false;
739
+        }
740
+
741
+        // exclude shares leading to trashbin on home storages
742
+        $pathSections = explode('/', $data['path'], 2);
743
+        // FIXME: would not detect rare md5'd home storage case properly
744
+        if ($pathSections[0] !== 'files'
745
+                && in_array(explode(':', $data['storage_string_id'], 2)[0], array('home', 'object'))) {
746
+            return false;
747
+        }
748
+        return true;
749
+    }
750
+
751
+    /**
752
+     * @inheritdoc
753
+     */
754
+    public function getSharedWith($userId, $shareType, $node, $limit, $offset) {
755
+        /** @var Share[] $shares */
756
+        $shares = [];
757
+
758
+        if ($shareType === \OCP\Share::SHARE_TYPE_USER) {
759
+            //Get shares directly with this user
760
+            $qb = $this->dbConn->getQueryBuilder();
761
+            $qb->select('s.*',
762
+                'f.fileid', 'f.path', 'f.permissions AS f_permissions', 'f.storage', 'f.path_hash',
763
+                'f.parent AS f_parent', 'f.name', 'f.mimetype', 'f.mimepart', 'f.size', 'f.mtime', 'f.storage_mtime',
764
+                'f.encrypted', 'f.unencrypted_size', 'f.etag', 'f.checksum'
765
+            )
766
+                ->selectAlias('st.id', 'storage_string_id')
767
+                ->from('share', 's')
768
+                ->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid'))
769
+                ->leftJoin('f', 'storages', 'st', $qb->expr()->eq('f.storage', 'st.numeric_id'));
770
+
771
+            // Order by id
772
+            $qb->orderBy('s.id');
773
+
774
+            // Set limit and offset
775
+            if ($limit !== -1) {
776
+                $qb->setMaxResults($limit);
777
+            }
778
+            $qb->setFirstResult($offset);
779
+
780
+            $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)))
781
+                ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId)))
782
+                ->andWhere($qb->expr()->orX(
783
+                    $qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
784
+                    $qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
785
+                ));
786
+
787
+            // Filter by node if provided
788
+            if ($node !== null) {
789
+                $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId())));
790
+            }
791
+
792
+            $cursor = $qb->execute();
793
+
794
+            while($data = $cursor->fetch()) {
795
+                if ($this->isAccessibleResult($data)) {
796
+                    $shares[] = $this->createShare($data);
797
+                }
798
+            }
799
+            $cursor->closeCursor();
800
+
801
+        } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) {
802
+            $user = $this->userManager->get($userId);
803
+            $allGroups = $this->groupManager->getUserGroups($user);
804
+
805
+            /** @var Share[] $shares2 */
806
+            $shares2 = [];
807
+
808
+            $start = 0;
809
+            while(true) {
810
+                $groups = array_slice($allGroups, $start, 100);
811
+                $start += 100;
812
+
813
+                if ($groups === []) {
814
+                    break;
815
+                }
816
+
817
+                $qb = $this->dbConn->getQueryBuilder();
818
+                $qb->select('s.*',
819
+                    'f.fileid', 'f.path', 'f.permissions AS f_permissions', 'f.storage', 'f.path_hash',
820
+                    'f.parent AS f_parent', 'f.name', 'f.mimetype', 'f.mimepart', 'f.size', 'f.mtime', 'f.storage_mtime',
821
+                    'f.encrypted', 'f.unencrypted_size', 'f.etag', 'f.checksum'
822
+                )
823
+                    ->selectAlias('st.id', 'storage_string_id')
824
+                    ->from('share', 's')
825
+                    ->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid'))
826
+                    ->leftJoin('f', 'storages', 'st', $qb->expr()->eq('f.storage', 'st.numeric_id'))
827
+                    ->orderBy('s.id')
828
+                    ->setFirstResult(0);
829
+
830
+                if ($limit !== -1) {
831
+                    $qb->setMaxResults($limit - count($shares));
832
+                }
833
+
834
+                // Filter by node if provided
835
+                if ($node !== null) {
836
+                    $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId())));
837
+                }
838
+
839
+
840
+                $groups = array_filter($groups, function($group) { return $group instanceof IGroup; });
841
+                $groups = array_map(function(IGroup $group) { return $group->getGID(); }, $groups);
842
+
843
+                $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)))
844
+                    ->andWhere($qb->expr()->in('share_with', $qb->createNamedParameter(
845
+                        $groups,
846
+                        IQueryBuilder::PARAM_STR_ARRAY
847
+                    )))
848
+                    ->andWhere($qb->expr()->orX(
849
+                        $qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
850
+                        $qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
851
+                    ));
852
+
853
+                $cursor = $qb->execute();
854
+                while($data = $cursor->fetch()) {
855
+                    if ($offset > 0) {
856
+                        $offset--;
857
+                        continue;
858
+                    }
859
+
860
+                    if ($this->isAccessibleResult($data)) {
861
+                        $shares2[] = $this->createShare($data);
862
+                    }
863
+                }
864
+                $cursor->closeCursor();
865
+            }
866
+
867
+            /*
868 868
  			 * Resolve all group shares to user specific shares
869 869
  			 */
870
-			$shares = $this->resolveGroupShares($shares2, $userId);
871
-		} else {
872
-			throw new BackendError('Invalid backend');
873
-		}
874
-
875
-
876
-		return $shares;
877
-	}
878
-
879
-	/**
880
-	 * Get a share by token
881
-	 *
882
-	 * @param string $token
883
-	 * @return \OCP\Share\IShare
884
-	 * @throws ShareNotFound
885
-	 */
886
-	public function getShareByToken($token) {
887
-		$qb = $this->dbConn->getQueryBuilder();
888
-
889
-		$cursor = $qb->select('*')
890
-			->from('share')
891
-			->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK)))
892
-			->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token)))
893
-			->andWhere($qb->expr()->orX(
894
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
895
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
896
-			))
897
-			->execute();
898
-
899
-		$data = $cursor->fetch();
900
-
901
-		if ($data === false) {
902
-			throw new ShareNotFound();
903
-		}
904
-
905
-		try {
906
-			$share = $this->createShare($data);
907
-		} catch (InvalidShare $e) {
908
-			throw new ShareNotFound();
909
-		}
910
-
911
-		return $share;
912
-	}
913
-
914
-	/**
915
-	 * Create a share object from an database row
916
-	 *
917
-	 * @param mixed[] $data
918
-	 * @return \OCP\Share\IShare
919
-	 * @throws InvalidShare
920
-	 */
921
-	private function createShare($data) {
922
-		$share = new Share($this->rootFolder, $this->userManager);
923
-		$share->setId((int)$data['id'])
924
-			->setShareType((int)$data['share_type'])
925
-			->setPermissions((int)$data['permissions'])
926
-			->setTarget($data['file_target'])
927
-			->setNote($data['note'])
928
-			->setMailSend((bool)$data['mail_send'])
929
-			->setLabel($data['label']);
930
-
931
-		$shareTime = new \DateTime();
932
-		$shareTime->setTimestamp((int)$data['stime']);
933
-		$share->setShareTime($shareTime);
934
-
935
-		if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
936
-			$share->setSharedWith($data['share_with']);
937
-		} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
938
-			$share->setSharedWith($data['share_with']);
939
-		} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
940
-			$share->setPassword($data['password']);
941
-			$share->setToken($data['token']);
942
-		}
943
-
944
-		$share->setSharedBy($data['uid_initiator']);
945
-		$share->setShareOwner($data['uid_owner']);
946
-
947
-		$share->setNodeId((int)$data['file_source']);
948
-		$share->setNodeType($data['item_type']);
949
-
950
-		if ($data['expiration'] !== null) {
951
-			$expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']);
952
-			$share->setExpirationDate($expiration);
953
-		}
954
-
955
-		if (isset($data['f_permissions'])) {
956
-			$entryData = $data;
957
-			$entryData['permissions'] = $entryData['f_permissions'];
958
-			$entryData['parent'] = $entryData['f_parent'];
959
-			$share->setNodeCacheEntry(Cache::cacheEntryFromData($entryData,
960
-				\OC::$server->getMimeTypeLoader()));
961
-		}
962
-
963
-		$share->setProviderId($this->identifier());
964
-		$share->setHideDownload((int)$data['hide_download'] === 1);
965
-
966
-		return $share;
967
-	}
968
-
969
-	/**
970
-	 * @param Share[] $shares
971
-	 * @param $userId
972
-	 * @return Share[] The updates shares if no update is found for a share return the original
973
-	 */
974
-	private function resolveGroupShares($shares, $userId) {
975
-		$result = [];
976
-
977
-		$start = 0;
978
-		while(true) {
979
-			/** @var Share[] $shareSlice */
980
-			$shareSlice = array_slice($shares, $start, 100);
981
-			$start += 100;
982
-
983
-			if ($shareSlice === []) {
984
-				break;
985
-			}
986
-
987
-			/** @var int[] $ids */
988
-			$ids = [];
989
-			/** @var Share[] $shareMap */
990
-			$shareMap = [];
991
-
992
-			foreach ($shareSlice as $share) {
993
-				$ids[] = (int)$share->getId();
994
-				$shareMap[$share->getId()] = $share;
995
-			}
996
-
997
-			$qb = $this->dbConn->getQueryBuilder();
998
-
999
-			$query = $qb->select('*')
1000
-				->from('share')
1001
-				->where($qb->expr()->in('parent', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY)))
1002
-				->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId)))
1003
-				->andWhere($qb->expr()->orX(
1004
-					$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
1005
-					$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
1006
-				));
1007
-
1008
-			$stmt = $query->execute();
1009
-
1010
-			while($data = $stmt->fetch()) {
1011
-				$shareMap[$data['parent']]->setPermissions((int)$data['permissions']);
1012
-				$shareMap[$data['parent']]->setTarget($data['file_target']);
1013
-				$shareMap[$data['parent']]->setParent($data['parent']);
1014
-			}
1015
-
1016
-			$stmt->closeCursor();
1017
-
1018
-			foreach ($shareMap as $share) {
1019
-				$result[] = $share;
1020
-			}
1021
-		}
1022
-
1023
-		return $result;
1024
-	}
1025
-
1026
-	/**
1027
-	 * A user is deleted from the system
1028
-	 * So clean up the relevant shares.
1029
-	 *
1030
-	 * @param string $uid
1031
-	 * @param int $shareType
1032
-	 */
1033
-	public function userDeleted($uid, $shareType) {
1034
-		$qb = $this->dbConn->getQueryBuilder();
1035
-
1036
-		$qb->delete('share');
1037
-
1038
-		if ($shareType === \OCP\Share::SHARE_TYPE_USER) {
1039
-			/*
870
+            $shares = $this->resolveGroupShares($shares2, $userId);
871
+        } else {
872
+            throw new BackendError('Invalid backend');
873
+        }
874
+
875
+
876
+        return $shares;
877
+    }
878
+
879
+    /**
880
+     * Get a share by token
881
+     *
882
+     * @param string $token
883
+     * @return \OCP\Share\IShare
884
+     * @throws ShareNotFound
885
+     */
886
+    public function getShareByToken($token) {
887
+        $qb = $this->dbConn->getQueryBuilder();
888
+
889
+        $cursor = $qb->select('*')
890
+            ->from('share')
891
+            ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK)))
892
+            ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token)))
893
+            ->andWhere($qb->expr()->orX(
894
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
895
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
896
+            ))
897
+            ->execute();
898
+
899
+        $data = $cursor->fetch();
900
+
901
+        if ($data === false) {
902
+            throw new ShareNotFound();
903
+        }
904
+
905
+        try {
906
+            $share = $this->createShare($data);
907
+        } catch (InvalidShare $e) {
908
+            throw new ShareNotFound();
909
+        }
910
+
911
+        return $share;
912
+    }
913
+
914
+    /**
915
+     * Create a share object from an database row
916
+     *
917
+     * @param mixed[] $data
918
+     * @return \OCP\Share\IShare
919
+     * @throws InvalidShare
920
+     */
921
+    private function createShare($data) {
922
+        $share = new Share($this->rootFolder, $this->userManager);
923
+        $share->setId((int)$data['id'])
924
+            ->setShareType((int)$data['share_type'])
925
+            ->setPermissions((int)$data['permissions'])
926
+            ->setTarget($data['file_target'])
927
+            ->setNote($data['note'])
928
+            ->setMailSend((bool)$data['mail_send'])
929
+            ->setLabel($data['label']);
930
+
931
+        $shareTime = new \DateTime();
932
+        $shareTime->setTimestamp((int)$data['stime']);
933
+        $share->setShareTime($shareTime);
934
+
935
+        if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
936
+            $share->setSharedWith($data['share_with']);
937
+        } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
938
+            $share->setSharedWith($data['share_with']);
939
+        } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
940
+            $share->setPassword($data['password']);
941
+            $share->setToken($data['token']);
942
+        }
943
+
944
+        $share->setSharedBy($data['uid_initiator']);
945
+        $share->setShareOwner($data['uid_owner']);
946
+
947
+        $share->setNodeId((int)$data['file_source']);
948
+        $share->setNodeType($data['item_type']);
949
+
950
+        if ($data['expiration'] !== null) {
951
+            $expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']);
952
+            $share->setExpirationDate($expiration);
953
+        }
954
+
955
+        if (isset($data['f_permissions'])) {
956
+            $entryData = $data;
957
+            $entryData['permissions'] = $entryData['f_permissions'];
958
+            $entryData['parent'] = $entryData['f_parent'];
959
+            $share->setNodeCacheEntry(Cache::cacheEntryFromData($entryData,
960
+                \OC::$server->getMimeTypeLoader()));
961
+        }
962
+
963
+        $share->setProviderId($this->identifier());
964
+        $share->setHideDownload((int)$data['hide_download'] === 1);
965
+
966
+        return $share;
967
+    }
968
+
969
+    /**
970
+     * @param Share[] $shares
971
+     * @param $userId
972
+     * @return Share[] The updates shares if no update is found for a share return the original
973
+     */
974
+    private function resolveGroupShares($shares, $userId) {
975
+        $result = [];
976
+
977
+        $start = 0;
978
+        while(true) {
979
+            /** @var Share[] $shareSlice */
980
+            $shareSlice = array_slice($shares, $start, 100);
981
+            $start += 100;
982
+
983
+            if ($shareSlice === []) {
984
+                break;
985
+            }
986
+
987
+            /** @var int[] $ids */
988
+            $ids = [];
989
+            /** @var Share[] $shareMap */
990
+            $shareMap = [];
991
+
992
+            foreach ($shareSlice as $share) {
993
+                $ids[] = (int)$share->getId();
994
+                $shareMap[$share->getId()] = $share;
995
+            }
996
+
997
+            $qb = $this->dbConn->getQueryBuilder();
998
+
999
+            $query = $qb->select('*')
1000
+                ->from('share')
1001
+                ->where($qb->expr()->in('parent', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY)))
1002
+                ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId)))
1003
+                ->andWhere($qb->expr()->orX(
1004
+                    $qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
1005
+                    $qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
1006
+                ));
1007
+
1008
+            $stmt = $query->execute();
1009
+
1010
+            while($data = $stmt->fetch()) {
1011
+                $shareMap[$data['parent']]->setPermissions((int)$data['permissions']);
1012
+                $shareMap[$data['parent']]->setTarget($data['file_target']);
1013
+                $shareMap[$data['parent']]->setParent($data['parent']);
1014
+            }
1015
+
1016
+            $stmt->closeCursor();
1017
+
1018
+            foreach ($shareMap as $share) {
1019
+                $result[] = $share;
1020
+            }
1021
+        }
1022
+
1023
+        return $result;
1024
+    }
1025
+
1026
+    /**
1027
+     * A user is deleted from the system
1028
+     * So clean up the relevant shares.
1029
+     *
1030
+     * @param string $uid
1031
+     * @param int $shareType
1032
+     */
1033
+    public function userDeleted($uid, $shareType) {
1034
+        $qb = $this->dbConn->getQueryBuilder();
1035
+
1036
+        $qb->delete('share');
1037
+
1038
+        if ($shareType === \OCP\Share::SHARE_TYPE_USER) {
1039
+            /*
1040 1040
 			 * Delete all user shares that are owned by this user
1041 1041
 			 * or that are received by this user
1042 1042
 			 */
1043 1043
 
1044
-			$qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)));
1044
+            $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)));
1045 1045
 
1046
-			$qb->andWhere(
1047
-				$qb->expr()->orX(
1048
-					$qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)),
1049
-					$qb->expr()->eq('share_with', $qb->createNamedParameter($uid))
1050
-				)
1051
-			);
1052
-		} else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) {
1053
-			/*
1046
+            $qb->andWhere(
1047
+                $qb->expr()->orX(
1048
+                    $qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)),
1049
+                    $qb->expr()->eq('share_with', $qb->createNamedParameter($uid))
1050
+                )
1051
+            );
1052
+        } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) {
1053
+            /*
1054 1054
 			 * Delete all group shares that are owned by this user
1055 1055
 			 * Or special user group shares that are received by this user
1056 1056
 			 */
1057
-			$qb->where(
1058
-				$qb->expr()->andX(
1059
-					$qb->expr()->orX(
1060
-						$qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)),
1061
-						$qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))
1062
-					),
1063
-					$qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid))
1064
-				)
1065
-			);
1066
-
1067
-			$qb->orWhere(
1068
-				$qb->expr()->andX(
1069
-					$qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)),
1070
-					$qb->expr()->eq('share_with', $qb->createNamedParameter($uid))
1071
-				)
1072
-			);
1073
-		} else if ($shareType === \OCP\Share::SHARE_TYPE_LINK) {
1074
-			/*
1057
+            $qb->where(
1058
+                $qb->expr()->andX(
1059
+                    $qb->expr()->orX(
1060
+                        $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)),
1061
+                        $qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))
1062
+                    ),
1063
+                    $qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid))
1064
+                )
1065
+            );
1066
+
1067
+            $qb->orWhere(
1068
+                $qb->expr()->andX(
1069
+                    $qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)),
1070
+                    $qb->expr()->eq('share_with', $qb->createNamedParameter($uid))
1071
+                )
1072
+            );
1073
+        } else if ($shareType === \OCP\Share::SHARE_TYPE_LINK) {
1074
+            /*
1075 1075
 			 * Delete all link shares owned by this user.
1076 1076
 			 * And all link shares initiated by this user (until #22327 is in)
1077 1077
 			 */
1078
-			$qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK)));
1079
-
1080
-			$qb->andWhere(
1081
-				$qb->expr()->orX(
1082
-					$qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)),
1083
-					$qb->expr()->eq('uid_initiator', $qb->createNamedParameter($uid))
1084
-				)
1085
-			);
1086
-		}
1087
-
1088
-		$qb->execute();
1089
-	}
1090
-
1091
-	/**
1092
-	 * Delete all shares received by this group. As well as any custom group
1093
-	 * shares for group members.
1094
-	 *
1095
-	 * @param string $gid
1096
-	 */
1097
-	public function groupDeleted($gid) {
1098
-		/*
1078
+            $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK)));
1079
+
1080
+            $qb->andWhere(
1081
+                $qb->expr()->orX(
1082
+                    $qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)),
1083
+                    $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($uid))
1084
+                )
1085
+            );
1086
+        }
1087
+
1088
+        $qb->execute();
1089
+    }
1090
+
1091
+    /**
1092
+     * Delete all shares received by this group. As well as any custom group
1093
+     * shares for group members.
1094
+     *
1095
+     * @param string $gid
1096
+     */
1097
+    public function groupDeleted($gid) {
1098
+        /*
1099 1099
 		 * First delete all custom group shares for group members
1100 1100
 		 */
1101
-		$qb = $this->dbConn->getQueryBuilder();
1102
-		$qb->select('id')
1103
-			->from('share')
1104
-			->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)))
1105
-			->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid)));
1106
-
1107
-		$cursor = $qb->execute();
1108
-		$ids = [];
1109
-		while($row = $cursor->fetch()) {
1110
-			$ids[] = (int)$row['id'];
1111
-		}
1112
-		$cursor->closeCursor();
1113
-
1114
-		if (!empty($ids)) {
1115
-			$chunks = array_chunk($ids, 100);
1116
-			foreach ($chunks as $chunk) {
1117
-				$qb->delete('share')
1118
-					->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)))
1119
-					->andWhere($qb->expr()->in('parent', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY)));
1120
-				$qb->execute();
1121
-			}
1122
-		}
1123
-
1124
-		/*
1101
+        $qb = $this->dbConn->getQueryBuilder();
1102
+        $qb->select('id')
1103
+            ->from('share')
1104
+            ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)))
1105
+            ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid)));
1106
+
1107
+        $cursor = $qb->execute();
1108
+        $ids = [];
1109
+        while($row = $cursor->fetch()) {
1110
+            $ids[] = (int)$row['id'];
1111
+        }
1112
+        $cursor->closeCursor();
1113
+
1114
+        if (!empty($ids)) {
1115
+            $chunks = array_chunk($ids, 100);
1116
+            foreach ($chunks as $chunk) {
1117
+                $qb->delete('share')
1118
+                    ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)))
1119
+                    ->andWhere($qb->expr()->in('parent', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY)));
1120
+                $qb->execute();
1121
+            }
1122
+        }
1123
+
1124
+        /*
1125 1125
 		 * Now delete all the group shares
1126 1126
 		 */
1127
-		$qb = $this->dbConn->getQueryBuilder();
1128
-		$qb->delete('share')
1129
-			->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)))
1130
-			->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid)));
1131
-		$qb->execute();
1132
-	}
1133
-
1134
-	/**
1135
-	 * Delete custom group shares to this group for this user
1136
-	 *
1137
-	 * @param string $uid
1138
-	 * @param string $gid
1139
-	 */
1140
-	public function userDeletedFromGroup($uid, $gid) {
1141
-		/*
1127
+        $qb = $this->dbConn->getQueryBuilder();
1128
+        $qb->delete('share')
1129
+            ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)))
1130
+            ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid)));
1131
+        $qb->execute();
1132
+    }
1133
+
1134
+    /**
1135
+     * Delete custom group shares to this group for this user
1136
+     *
1137
+     * @param string $uid
1138
+     * @param string $gid
1139
+     */
1140
+    public function userDeletedFromGroup($uid, $gid) {
1141
+        /*
1142 1142
 		 * Get all group shares
1143 1143
 		 */
1144
-		$qb = $this->dbConn->getQueryBuilder();
1145
-		$qb->select('id')
1146
-			->from('share')
1147
-			->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)))
1148
-			->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid)));
1149
-
1150
-		$cursor = $qb->execute();
1151
-		$ids = [];
1152
-		while($row = $cursor->fetch()) {
1153
-			$ids[] = (int)$row['id'];
1154
-		}
1155
-		$cursor->closeCursor();
1156
-
1157
-		if (!empty($ids)) {
1158
-			$chunks = array_chunk($ids, 100);
1159
-			foreach ($chunks as $chunk) {
1160
-				/*
1144
+        $qb = $this->dbConn->getQueryBuilder();
1145
+        $qb->select('id')
1146
+            ->from('share')
1147
+            ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)))
1148
+            ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid)));
1149
+
1150
+        $cursor = $qb->execute();
1151
+        $ids = [];
1152
+        while($row = $cursor->fetch()) {
1153
+            $ids[] = (int)$row['id'];
1154
+        }
1155
+        $cursor->closeCursor();
1156
+
1157
+        if (!empty($ids)) {
1158
+            $chunks = array_chunk($ids, 100);
1159
+            foreach ($chunks as $chunk) {
1160
+                /*
1161 1161
 				 * Delete all special shares wit this users for the found group shares
1162 1162
 				 */
1163
-				$qb->delete('share')
1164
-					->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)))
1165
-					->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($uid)))
1166
-					->andWhere($qb->expr()->in('parent', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY)));
1167
-				$qb->execute();
1168
-			}
1169
-		}
1170
-	}
1171
-
1172
-	/**
1173
-	 * @inheritdoc
1174
-	 */
1175
-	public function getAccessList($nodes, $currentAccess) {
1176
-		$ids = [];
1177
-		foreach ($nodes as $node) {
1178
-			$ids[] = $node->getId();
1179
-		}
1180
-
1181
-		$qb = $this->dbConn->getQueryBuilder();
1182
-
1183
-		$or = $qb->expr()->orX(
1184
-			$qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)),
1185
-			$qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)),
1186
-			$qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK))
1187
-		);
1188
-
1189
-		if ($currentAccess) {
1190
-			$or->add($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)));
1191
-		}
1192
-
1193
-		$qb->select('id', 'parent', 'share_type', 'share_with', 'file_source', 'file_target', 'permissions')
1194
-			->from('share')
1195
-			->where(
1196
-				$or
1197
-			)
1198
-			->andWhere($qb->expr()->in('file_source', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY)))
1199
-			->andWhere($qb->expr()->orX(
1200
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
1201
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
1202
-			));
1203
-		$cursor = $qb->execute();
1204
-
1205
-		$users = [];
1206
-		$link = false;
1207
-		while($row = $cursor->fetch()) {
1208
-			$type = (int)$row['share_type'];
1209
-			if ($type === \OCP\Share::SHARE_TYPE_USER) {
1210
-				$uid = $row['share_with'];
1211
-				$users[$uid] = isset($users[$uid]) ? $users[$uid] : [];
1212
-				$users[$uid][$row['id']] = $row;
1213
-			} else if ($type === \OCP\Share::SHARE_TYPE_GROUP) {
1214
-				$gid = $row['share_with'];
1215
-				$group = $this->groupManager->get($gid);
1216
-
1217
-				if ($group === null) {
1218
-					continue;
1219
-				}
1220
-
1221
-				$userList = $group->getUsers();
1222
-				foreach ($userList as $user) {
1223
-					$uid = $user->getUID();
1224
-					$users[$uid] = isset($users[$uid]) ? $users[$uid] : [];
1225
-					$users[$uid][$row['id']] = $row;
1226
-				}
1227
-			} else if ($type === \OCP\Share::SHARE_TYPE_LINK) {
1228
-				$link = true;
1229
-			} else if ($type === self::SHARE_TYPE_USERGROUP && $currentAccess === true) {
1230
-				$uid = $row['share_with'];
1231
-				$users[$uid] = isset($users[$uid]) ? $users[$uid] : [];
1232
-				$users[$uid][$row['id']] = $row;
1233
-			}
1234
-		}
1235
-		$cursor->closeCursor();
1236
-
1237
-		if ($currentAccess === true) {
1238
-			$users = array_map([$this, 'filterSharesOfUser'], $users);
1239
-			$users = array_filter($users);
1240
-		} else {
1241
-			$users = array_keys($users);
1242
-		}
1243
-
1244
-		return ['users' => $users, 'public' => $link];
1245
-	}
1246
-
1247
-	/**
1248
-	 * For each user the path with the fewest slashes is returned
1249
-	 * @param array $shares
1250
-	 * @return array
1251
-	 */
1252
-	protected function filterSharesOfUser(array $shares) {
1253
-		// Group shares when the user has a share exception
1254
-		foreach ($shares as $id => $share) {
1255
-			$type = (int) $share['share_type'];
1256
-			$permissions = (int) $share['permissions'];
1257
-
1258
-			if ($type === self::SHARE_TYPE_USERGROUP) {
1259
-				unset($shares[$share['parent']]);
1260
-
1261
-				if ($permissions === 0) {
1262
-					unset($shares[$id]);
1263
-				}
1264
-			}
1265
-		}
1266
-
1267
-		$best = [];
1268
-		$bestDepth = 0;
1269
-		foreach ($shares as $id => $share) {
1270
-			$depth = substr_count($share['file_target'], '/');
1271
-			if (empty($best) || $depth < $bestDepth) {
1272
-				$bestDepth = $depth;
1273
-				$best = [
1274
-					'node_id' => $share['file_source'],
1275
-					'node_path' => $share['file_target'],
1276
-				];
1277
-			}
1278
-		}
1279
-
1280
-		return $best;
1281
-	}
1282
-
1283
-	/**
1284
-	 * propagate notes to the recipients
1285
-	 *
1286
-	 * @param IShare $share
1287
-	 * @throws \OCP\Files\NotFoundException
1288
-	 */
1289
-	private function propagateNote(IShare $share) {
1290
-		if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
1291
-			$user = $this->userManager->get($share->getSharedWith());
1292
-			$this->sendNote([$user], $share);
1293
-		} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
1294
-			$group = $this->groupManager->get($share->getSharedWith());
1295
-			$groupMembers = $group->getUsers();
1296
-			$this->sendNote($groupMembers, $share);
1297
-		}
1298
-	}
1299
-
1300
-	/**
1301
-	 * send note by mail
1302
-	 *
1303
-	 * @param array $recipients
1304
-	 * @param IShare $share
1305
-	 * @throws \OCP\Files\NotFoundException
1306
-	 */
1307
-	private function sendNote(array $recipients, IShare $share) {
1308
-
1309
-		$toList = [];
1310
-
1311
-		foreach ($recipients as $recipient) {
1312
-			/** @var IUser $recipient */
1313
-			$email = $recipient->getEMailAddress();
1314
-			if ($email) {
1315
-				$toList[$email] = $recipient->getDisplayName();
1316
-			}
1317
-		}
1318
-
1319
-		if (!empty($toList)) {
1320
-
1321
-			$filename = $share->getNode()->getName();
1322
-			$initiator = $share->getSharedBy();
1323
-			$note = $share->getNote();
1324
-
1325
-			$initiatorUser = $this->userManager->get($initiator);
1326
-			$initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator;
1327
-			$initiatorEmailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null;
1328
-			$plainHeading = $this->l->t('%1$s shared »%2$s« with you and wants to add:', [$initiatorDisplayName, $filename]);
1329
-			$htmlHeading = $this->l->t('%1$s shared »%2$s« with you and wants to add', [$initiatorDisplayName, $filename]);
1330
-			$message = $this->mailer->createMessage();
1331
-
1332
-			$emailTemplate = $this->mailer->createEMailTemplate('defaultShareProvider.sendNote');
1333
-
1334
-			$emailTemplate->setSubject($this->l->t('»%s« added a note to a file shared with you', [$initiatorDisplayName]));
1335
-			$emailTemplate->addHeader();
1336
-			$emailTemplate->addHeading($htmlHeading, $plainHeading);
1337
-			$emailTemplate->addBodyText(htmlspecialchars($note), $note);
1338
-
1339
-			$link = $this->urlGenerator->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $share->getNode()->getId()]);
1340
-			$emailTemplate->addBodyButton(
1341
-				$this->l->t('Open »%s«', [$filename]),
1342
-				$link
1343
-			);
1344
-
1345
-
1346
-			// The "From" contains the sharers name
1347
-			$instanceName = $this->defaults->getName();
1348
-			$senderName = $this->l->t(
1349
-				'%1$s via %2$s',
1350
-				[
1351
-					$initiatorDisplayName,
1352
-					$instanceName
1353
-				]
1354
-			);
1355
-			$message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]);
1356
-			if ($initiatorEmailAddress !== null) {
1357
-				$message->setReplyTo([$initiatorEmailAddress => $initiatorDisplayName]);
1358
-				$emailTemplate->addFooter($instanceName . ' - ' . $this->defaults->getSlogan());
1359
-			} else {
1360
-				$emailTemplate->addFooter();
1361
-			}
1362
-
1363
-			if (count($toList) === 1) {
1364
-				$message->setTo($toList);
1365
-			} else {
1366
-				$message->setTo([]);
1367
-				$message->setBcc($toList);
1368
-			}
1369
-			$message->useTemplate($emailTemplate);
1370
-			$this->mailer->send($message);
1371
-		}
1372
-
1373
-	}
1163
+                $qb->delete('share')
1164
+                    ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)))
1165
+                    ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($uid)))
1166
+                    ->andWhere($qb->expr()->in('parent', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY)));
1167
+                $qb->execute();
1168
+            }
1169
+        }
1170
+    }
1171
+
1172
+    /**
1173
+     * @inheritdoc
1174
+     */
1175
+    public function getAccessList($nodes, $currentAccess) {
1176
+        $ids = [];
1177
+        foreach ($nodes as $node) {
1178
+            $ids[] = $node->getId();
1179
+        }
1180
+
1181
+        $qb = $this->dbConn->getQueryBuilder();
1182
+
1183
+        $or = $qb->expr()->orX(
1184
+            $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)),
1185
+            $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)),
1186
+            $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK))
1187
+        );
1188
+
1189
+        if ($currentAccess) {
1190
+            $or->add($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)));
1191
+        }
1192
+
1193
+        $qb->select('id', 'parent', 'share_type', 'share_with', 'file_source', 'file_target', 'permissions')
1194
+            ->from('share')
1195
+            ->where(
1196
+                $or
1197
+            )
1198
+            ->andWhere($qb->expr()->in('file_source', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY)))
1199
+            ->andWhere($qb->expr()->orX(
1200
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
1201
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
1202
+            ));
1203
+        $cursor = $qb->execute();
1204
+
1205
+        $users = [];
1206
+        $link = false;
1207
+        while($row = $cursor->fetch()) {
1208
+            $type = (int)$row['share_type'];
1209
+            if ($type === \OCP\Share::SHARE_TYPE_USER) {
1210
+                $uid = $row['share_with'];
1211
+                $users[$uid] = isset($users[$uid]) ? $users[$uid] : [];
1212
+                $users[$uid][$row['id']] = $row;
1213
+            } else if ($type === \OCP\Share::SHARE_TYPE_GROUP) {
1214
+                $gid = $row['share_with'];
1215
+                $group = $this->groupManager->get($gid);
1216
+
1217
+                if ($group === null) {
1218
+                    continue;
1219
+                }
1220
+
1221
+                $userList = $group->getUsers();
1222
+                foreach ($userList as $user) {
1223
+                    $uid = $user->getUID();
1224
+                    $users[$uid] = isset($users[$uid]) ? $users[$uid] : [];
1225
+                    $users[$uid][$row['id']] = $row;
1226
+                }
1227
+            } else if ($type === \OCP\Share::SHARE_TYPE_LINK) {
1228
+                $link = true;
1229
+            } else if ($type === self::SHARE_TYPE_USERGROUP && $currentAccess === true) {
1230
+                $uid = $row['share_with'];
1231
+                $users[$uid] = isset($users[$uid]) ? $users[$uid] : [];
1232
+                $users[$uid][$row['id']] = $row;
1233
+            }
1234
+        }
1235
+        $cursor->closeCursor();
1236
+
1237
+        if ($currentAccess === true) {
1238
+            $users = array_map([$this, 'filterSharesOfUser'], $users);
1239
+            $users = array_filter($users);
1240
+        } else {
1241
+            $users = array_keys($users);
1242
+        }
1243
+
1244
+        return ['users' => $users, 'public' => $link];
1245
+    }
1246
+
1247
+    /**
1248
+     * For each user the path with the fewest slashes is returned
1249
+     * @param array $shares
1250
+     * @return array
1251
+     */
1252
+    protected function filterSharesOfUser(array $shares) {
1253
+        // Group shares when the user has a share exception
1254
+        foreach ($shares as $id => $share) {
1255
+            $type = (int) $share['share_type'];
1256
+            $permissions = (int) $share['permissions'];
1257
+
1258
+            if ($type === self::SHARE_TYPE_USERGROUP) {
1259
+                unset($shares[$share['parent']]);
1260
+
1261
+                if ($permissions === 0) {
1262
+                    unset($shares[$id]);
1263
+                }
1264
+            }
1265
+        }
1266
+
1267
+        $best = [];
1268
+        $bestDepth = 0;
1269
+        foreach ($shares as $id => $share) {
1270
+            $depth = substr_count($share['file_target'], '/');
1271
+            if (empty($best) || $depth < $bestDepth) {
1272
+                $bestDepth = $depth;
1273
+                $best = [
1274
+                    'node_id' => $share['file_source'],
1275
+                    'node_path' => $share['file_target'],
1276
+                ];
1277
+            }
1278
+        }
1279
+
1280
+        return $best;
1281
+    }
1282
+
1283
+    /**
1284
+     * propagate notes to the recipients
1285
+     *
1286
+     * @param IShare $share
1287
+     * @throws \OCP\Files\NotFoundException
1288
+     */
1289
+    private function propagateNote(IShare $share) {
1290
+        if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
1291
+            $user = $this->userManager->get($share->getSharedWith());
1292
+            $this->sendNote([$user], $share);
1293
+        } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
1294
+            $group = $this->groupManager->get($share->getSharedWith());
1295
+            $groupMembers = $group->getUsers();
1296
+            $this->sendNote($groupMembers, $share);
1297
+        }
1298
+    }
1299
+
1300
+    /**
1301
+     * send note by mail
1302
+     *
1303
+     * @param array $recipients
1304
+     * @param IShare $share
1305
+     * @throws \OCP\Files\NotFoundException
1306
+     */
1307
+    private function sendNote(array $recipients, IShare $share) {
1308
+
1309
+        $toList = [];
1310
+
1311
+        foreach ($recipients as $recipient) {
1312
+            /** @var IUser $recipient */
1313
+            $email = $recipient->getEMailAddress();
1314
+            if ($email) {
1315
+                $toList[$email] = $recipient->getDisplayName();
1316
+            }
1317
+        }
1318
+
1319
+        if (!empty($toList)) {
1320
+
1321
+            $filename = $share->getNode()->getName();
1322
+            $initiator = $share->getSharedBy();
1323
+            $note = $share->getNote();
1324
+
1325
+            $initiatorUser = $this->userManager->get($initiator);
1326
+            $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator;
1327
+            $initiatorEmailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null;
1328
+            $plainHeading = $this->l->t('%1$s shared »%2$s« with you and wants to add:', [$initiatorDisplayName, $filename]);
1329
+            $htmlHeading = $this->l->t('%1$s shared »%2$s« with you and wants to add', [$initiatorDisplayName, $filename]);
1330
+            $message = $this->mailer->createMessage();
1331
+
1332
+            $emailTemplate = $this->mailer->createEMailTemplate('defaultShareProvider.sendNote');
1333
+
1334
+            $emailTemplate->setSubject($this->l->t('»%s« added a note to a file shared with you', [$initiatorDisplayName]));
1335
+            $emailTemplate->addHeader();
1336
+            $emailTemplate->addHeading($htmlHeading, $plainHeading);
1337
+            $emailTemplate->addBodyText(htmlspecialchars($note), $note);
1338
+
1339
+            $link = $this->urlGenerator->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $share->getNode()->getId()]);
1340
+            $emailTemplate->addBodyButton(
1341
+                $this->l->t('Open »%s«', [$filename]),
1342
+                $link
1343
+            );
1344
+
1345
+
1346
+            // The "From" contains the sharers name
1347
+            $instanceName = $this->defaults->getName();
1348
+            $senderName = $this->l->t(
1349
+                '%1$s via %2$s',
1350
+                [
1351
+                    $initiatorDisplayName,
1352
+                    $instanceName
1353
+                ]
1354
+            );
1355
+            $message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]);
1356
+            if ($initiatorEmailAddress !== null) {
1357
+                $message->setReplyTo([$initiatorEmailAddress => $initiatorDisplayName]);
1358
+                $emailTemplate->addFooter($instanceName . ' - ' . $this->defaults->getSlogan());
1359
+            } else {
1360
+                $emailTemplate->addFooter();
1361
+            }
1362
+
1363
+            if (count($toList) === 1) {
1364
+                $message->setTo($toList);
1365
+            } else {
1366
+                $message->setTo([]);
1367
+                $message->setBcc($toList);
1368
+            }
1369
+            $message->useTemplate($emailTemplate);
1370
+            $this->mailer->send($message);
1371
+        }
1372
+
1373
+    }
1374 1374
 }
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
 			->orderBy('id');
346 346
 
347 347
 		$cursor = $qb->execute();
348
-		while($data = $cursor->fetch()) {
348
+		while ($data = $cursor->fetch()) {
349 349
 			$children[] = $this->createShare($data);
350 350
 		}
351 351
 		$cursor->closeCursor();
@@ -390,7 +390,7 @@  discard block
 block discarded – undo
390 390
 			$user = $this->userManager->get($recipient);
391 391
 
392 392
 			if (is_null($group)) {
393
-				throw new ProviderException('Group "' . $share->getSharedWith() . '" does not exist');
393
+				throw new ProviderException('Group "'.$share->getSharedWith().'" does not exist');
394 394
 			}
395 395
 
396 396
 			if (!$group->inGroup($user)) {
@@ -585,7 +585,7 @@  discard block
 block discarded – undo
585 585
 			);
586 586
 		}
587 587
 
588
-		$qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid'));
588
+		$qb->innerJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid'));
589 589
 		$qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId())));
590 590
 
591 591
 		$qb->orderBy('id');
@@ -641,7 +641,7 @@  discard block
 block discarded – undo
641 641
 
642 642
 		$cursor = $qb->execute();
643 643
 		$shares = [];
644
-		while($data = $cursor->fetch()) {
644
+		while ($data = $cursor->fetch()) {
645 645
 			$shares[] = $this->createShare($data);
646 646
 		}
647 647
 		$cursor->closeCursor();
@@ -720,7 +720,7 @@  discard block
 block discarded – undo
720 720
 			->execute();
721 721
 
722 722
 		$shares = [];
723
-		while($data = $cursor->fetch()) {
723
+		while ($data = $cursor->fetch()) {
724 724
 			$shares[] = $this->createShare($data);
725 725
 		}
726 726
 		$cursor->closeCursor();
@@ -791,7 +791,7 @@  discard block
 block discarded – undo
791 791
 
792 792
 			$cursor = $qb->execute();
793 793
 
794
-			while($data = $cursor->fetch()) {
794
+			while ($data = $cursor->fetch()) {
795 795
 				if ($this->isAccessibleResult($data)) {
796 796
 					$shares[] = $this->createShare($data);
797 797
 				}
@@ -806,7 +806,7 @@  discard block
 block discarded – undo
806 806
 			$shares2 = [];
807 807
 
808 808
 			$start = 0;
809
-			while(true) {
809
+			while (true) {
810 810
 				$groups = array_slice($allGroups, $start, 100);
811 811
 				$start += 100;
812 812
 
@@ -851,7 +851,7 @@  discard block
 block discarded – undo
851 851
 					));
852 852
 
853 853
 				$cursor = $qb->execute();
854
-				while($data = $cursor->fetch()) {
854
+				while ($data = $cursor->fetch()) {
855 855
 					if ($offset > 0) {
856 856
 						$offset--;
857 857
 						continue;
@@ -920,16 +920,16 @@  discard block
 block discarded – undo
920 920
 	 */
921 921
 	private function createShare($data) {
922 922
 		$share = new Share($this->rootFolder, $this->userManager);
923
-		$share->setId((int)$data['id'])
924
-			->setShareType((int)$data['share_type'])
925
-			->setPermissions((int)$data['permissions'])
923
+		$share->setId((int) $data['id'])
924
+			->setShareType((int) $data['share_type'])
925
+			->setPermissions((int) $data['permissions'])
926 926
 			->setTarget($data['file_target'])
927 927
 			->setNote($data['note'])
928
-			->setMailSend((bool)$data['mail_send'])
928
+			->setMailSend((bool) $data['mail_send'])
929 929
 			->setLabel($data['label']);
930 930
 
931 931
 		$shareTime = new \DateTime();
932
-		$shareTime->setTimestamp((int)$data['stime']);
932
+		$shareTime->setTimestamp((int) $data['stime']);
933 933
 		$share->setShareTime($shareTime);
934 934
 
935 935
 		if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
@@ -944,7 +944,7 @@  discard block
 block discarded – undo
944 944
 		$share->setSharedBy($data['uid_initiator']);
945 945
 		$share->setShareOwner($data['uid_owner']);
946 946
 
947
-		$share->setNodeId((int)$data['file_source']);
947
+		$share->setNodeId((int) $data['file_source']);
948 948
 		$share->setNodeType($data['item_type']);
949 949
 
950 950
 		if ($data['expiration'] !== null) {
@@ -961,7 +961,7 @@  discard block
 block discarded – undo
961 961
 		}
962 962
 
963 963
 		$share->setProviderId($this->identifier());
964
-		$share->setHideDownload((int)$data['hide_download'] === 1);
964
+		$share->setHideDownload((int) $data['hide_download'] === 1);
965 965
 
966 966
 		return $share;
967 967
 	}
@@ -975,7 +975,7 @@  discard block
 block discarded – undo
975 975
 		$result = [];
976 976
 
977 977
 		$start = 0;
978
-		while(true) {
978
+		while (true) {
979 979
 			/** @var Share[] $shareSlice */
980 980
 			$shareSlice = array_slice($shares, $start, 100);
981 981
 			$start += 100;
@@ -990,7 +990,7 @@  discard block
 block discarded – undo
990 990
 			$shareMap = [];
991 991
 
992 992
 			foreach ($shareSlice as $share) {
993
-				$ids[] = (int)$share->getId();
993
+				$ids[] = (int) $share->getId();
994 994
 				$shareMap[$share->getId()] = $share;
995 995
 			}
996 996
 
@@ -1007,8 +1007,8 @@  discard block
 block discarded – undo
1007 1007
 
1008 1008
 			$stmt = $query->execute();
1009 1009
 
1010
-			while($data = $stmt->fetch()) {
1011
-				$shareMap[$data['parent']]->setPermissions((int)$data['permissions']);
1010
+			while ($data = $stmt->fetch()) {
1011
+				$shareMap[$data['parent']]->setPermissions((int) $data['permissions']);
1012 1012
 				$shareMap[$data['parent']]->setTarget($data['file_target']);
1013 1013
 				$shareMap[$data['parent']]->setParent($data['parent']);
1014 1014
 			}
@@ -1106,8 +1106,8 @@  discard block
 block discarded – undo
1106 1106
 
1107 1107
 		$cursor = $qb->execute();
1108 1108
 		$ids = [];
1109
-		while($row = $cursor->fetch()) {
1110
-			$ids[] = (int)$row['id'];
1109
+		while ($row = $cursor->fetch()) {
1110
+			$ids[] = (int) $row['id'];
1111 1111
 		}
1112 1112
 		$cursor->closeCursor();
1113 1113
 
@@ -1149,8 +1149,8 @@  discard block
 block discarded – undo
1149 1149
 
1150 1150
 		$cursor = $qb->execute();
1151 1151
 		$ids = [];
1152
-		while($row = $cursor->fetch()) {
1153
-			$ids[] = (int)$row['id'];
1152
+		while ($row = $cursor->fetch()) {
1153
+			$ids[] = (int) $row['id'];
1154 1154
 		}
1155 1155
 		$cursor->closeCursor();
1156 1156
 
@@ -1204,8 +1204,8 @@  discard block
 block discarded – undo
1204 1204
 
1205 1205
 		$users = [];
1206 1206
 		$link = false;
1207
-		while($row = $cursor->fetch()) {
1208
-			$type = (int)$row['share_type'];
1207
+		while ($row = $cursor->fetch()) {
1208
+			$type = (int) $row['share_type'];
1209 1209
 			if ($type === \OCP\Share::SHARE_TYPE_USER) {
1210 1210
 				$uid = $row['share_with'];
1211 1211
 				$users[$uid] = isset($users[$uid]) ? $users[$uid] : [];
@@ -1355,7 +1355,7 @@  discard block
 block discarded – undo
1355 1355
 			$message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]);
1356 1356
 			if ($initiatorEmailAddress !== null) {
1357 1357
 				$message->setReplyTo([$initiatorEmailAddress => $initiatorDisplayName]);
1358
-				$emailTemplate->addFooter($instanceName . ' - ' . $this->defaults->getSlogan());
1358
+				$emailTemplate->addFooter($instanceName.' - '.$this->defaults->getSlogan());
1359 1359
 			} else {
1360 1360
 				$emailTemplate->addFooter();
1361 1361
 			}
Please login to merge, or discard this patch.
lib/private/Share20/Share.php 1 patch
Indentation   +510 added lines, -510 removed lines patch added patch discarded remove patch
@@ -34,514 +34,514 @@
 block discarded – undo
34 34
 
35 35
 class Share implements \OCP\Share\IShare {
36 36
 
37
-	/** @var string */
38
-	private $id;
39
-	/** @var string */
40
-	private $providerId;
41
-	/** @var Node */
42
-	private $node;
43
-	/** @var int */
44
-	private $fileId;
45
-	/** @var string */
46
-	private $nodeType;
47
-	/** @var int */
48
-	private $shareType;
49
-	/** @var string */
50
-	private $sharedWith;
51
-	/** @var string */
52
-	private $sharedWithDisplayName;
53
-	/** @var string */
54
-	private $sharedWithAvatar;
55
-	/** @var string */
56
-	private $sharedBy;
57
-	/** @var string */
58
-	private $shareOwner;
59
-	/** @var int */
60
-	private $permissions;
61
-	/** @var string */
62
-	private $note = '';
63
-	/** @var \DateTime */
64
-	private $expireDate;
65
-	/** @var string */
66
-	private $password;
67
-	/** @var bool */
68
-	private $sendPasswordByTalk = false;
69
-	/** @var string */
70
-	private $token;
71
-	/** @var int */
72
-	private $parent;
73
-	/** @var string */
74
-	private $target;
75
-	/** @var \DateTime */
76
-	private $shareTime;
77
-	/** @var bool */
78
-	private $mailSend;
79
-	/** @var string */
80
-	private $label = '';
81
-
82
-	/** @var IRootFolder */
83
-	private $rootFolder;
84
-
85
-	/** @var IUserManager */
86
-	private $userManager;
87
-
88
-	/** @var ICacheEntry|null */
89
-	private $nodeCacheEntry;
90
-
91
-	/** @var bool */
92
-	private $hideDownload = false;
93
-
94
-	public function __construct(IRootFolder $rootFolder, IUserManager $userManager) {
95
-		$this->rootFolder = $rootFolder;
96
-		$this->userManager = $userManager;
97
-	}
98
-
99
-	/**
100
-	 * @inheritdoc
101
-	 */
102
-	public function setId($id) {
103
-		if (is_int($id)) {
104
-			$id = (string)$id;
105
-		}
106
-
107
-		if(!is_string($id)) {
108
-			throw new \InvalidArgumentException('String expected.');
109
-		}
110
-
111
-		if ($this->id !== null) {
112
-			throw new IllegalIDChangeException('Not allowed to assign a new internal id to a share');
113
-		}
114
-
115
-		$this->id = trim($id);
116
-		return $this;
117
-	}
118
-
119
-	/**
120
-	 * @inheritdoc
121
-	 */
122
-	public function getId() {
123
-		return $this->id;
124
-	}
125
-
126
-	/**
127
-	 * @inheritdoc
128
-	 */
129
-	public function getFullId() {
130
-		if ($this->providerId === null || $this->id === null) {
131
-			throw new \UnexpectedValueException;
132
-		}
133
-		return $this->providerId . ':' . $this->id;
134
-	}
135
-
136
-	/**
137
-	 * @inheritdoc
138
-	 */
139
-	public function setProviderId($id) {
140
-		if(!is_string($id)) {
141
-			throw new \InvalidArgumentException('String expected.');
142
-		}
143
-
144
-		if ($this->providerId !== null) {
145
-			throw new IllegalIDChangeException('Not allowed to assign a new provider id to a share');
146
-		}
147
-
148
-		$this->providerId = trim($id);
149
-		return $this;
150
-	}
151
-
152
-	/**
153
-	 * @inheritdoc
154
-	 */
155
-	public function setNode(Node $node) {
156
-		$this->fileId = null;
157
-		$this->nodeType = null;
158
-		$this->node = $node;
159
-		return $this;
160
-	}
161
-
162
-	/**
163
-	 * @inheritdoc
164
-	 */
165
-	public function getNode() {
166
-		if ($this->node === null) {
167
-
168
-			if ($this->shareOwner === null || $this->fileId === null) {
169
-				throw new NotFoundException();
170
-			}
171
-
172
-			// for federated shares the owner can be a remote user, in this
173
-			// case we use the initiator
174
-			if($this->userManager->userExists($this->shareOwner)) {
175
-				$userFolder = $this->rootFolder->getUserFolder($this->shareOwner);
176
-			} else {
177
-				$userFolder = $this->rootFolder->getUserFolder($this->sharedBy);
178
-			}
179
-
180
-			$nodes = $userFolder->getById($this->fileId);
181
-			if (empty($nodes)) {
182
-				throw new NotFoundException('Node for share not found, fileid: ' . $this->fileId);
183
-			}
184
-
185
-			$this->node = $nodes[0];
186
-		}
187
-
188
-		return $this->node;
189
-	}
190
-
191
-	/**
192
-	 * @inheritdoc
193
-	 */
194
-	public function setNodeId($fileId) {
195
-		$this->node = null;
196
-		$this->fileId = $fileId;
197
-		return $this;
198
-	}
199
-
200
-	/**
201
-	 * @inheritdoc
202
-	 */
203
-	public function getNodeId() {
204
-		if ($this->fileId === null) {
205
-			$this->fileId = $this->getNode()->getId();
206
-		}
207
-
208
-		return $this->fileId;
209
-	}
210
-
211
-	/**
212
-	 * @inheritdoc
213
-	 */
214
-	public function setNodeType($type) {
215
-		if ($type !== 'file' && $type !== 'folder') {
216
-			throw new \InvalidArgumentException();
217
-		}
218
-
219
-		$this->nodeType = $type;
220
-		return $this;
221
-	}
222
-
223
-	/**
224
-	 * @inheritdoc
225
-	 */
226
-	public function getNodeType() {
227
-		if ($this->nodeType === null) {
228
-			$node = $this->getNode();
229
-			$this->nodeType = $node instanceof File ? 'file' : 'folder';
230
-		}
231
-
232
-		return $this->nodeType;
233
-	}
234
-
235
-	/**
236
-	 * @inheritdoc
237
-	 */
238
-	public function setShareType($shareType) {
239
-		$this->shareType = $shareType;
240
-		return $this;
241
-	}
242
-
243
-	/**
244
-	 * @inheritdoc
245
-	 */
246
-	public function getShareType() {
247
-		return $this->shareType;
248
-	}
249
-
250
-	/**
251
-	 * @inheritdoc
252
-	 */
253
-	public function setSharedWith($sharedWith) {
254
-		if (!is_string($sharedWith)) {
255
-			throw new \InvalidArgumentException();
256
-		}
257
-		$this->sharedWith = $sharedWith;
258
-		return $this;
259
-	}
260
-
261
-	/**
262
-	 * @inheritdoc
263
-	 */
264
-	public function getSharedWith() {
265
-		return $this->sharedWith;
266
-	}
267
-
268
-	/**
269
-	 * @inheritdoc
270
-	 */
271
-	public function setSharedWithDisplayName($displayName) {
272
-		if (!is_string($displayName)) {
273
-			throw new \InvalidArgumentException();
274
-		}
275
-		$this->sharedWithDisplayName = $displayName;
276
-		return $this;
277
-	}
278
-
279
-	/**
280
-	 * @inheritdoc
281
-	 */
282
-	public function getSharedWithDisplayName() {
283
-		return $this->sharedWithDisplayName;
284
-	}
285
-
286
-	/**
287
-	 * @inheritdoc
288
-	 */
289
-	public function setSharedWithAvatar($src) {
290
-		if (!is_string($src)) {
291
-			throw new \InvalidArgumentException();
292
-		}
293
-		$this->sharedWithAvatar = $src;
294
-		return $this;
295
-	}
296
-
297
-	/**
298
-	 * @inheritdoc
299
-	 */
300
-	public function getSharedWithAvatar() {
301
-		return $this->sharedWithAvatar;
302
-	}
303
-
304
-	/**
305
-	 * @inheritdoc
306
-	 */
307
-	public function setPermissions($permissions) {
308
-		//TODO checkes
309
-
310
-		$this->permissions = $permissions;
311
-		return $this;
312
-	}
313
-
314
-	/**
315
-	 * @inheritdoc
316
-	 */
317
-	public function getPermissions() {
318
-		return $this->permissions;
319
-	}
320
-
321
-	/**
322
-	 * @inheritdoc
323
-	 */
324
-	public function setNote($note) {
325
-		$this->note = $note;
326
-		return $this;
327
-	}
328
-
329
-	/**
330
-	 * @inheritdoc
331
-	 */
332
-	public function getNote() {
333
-		if (is_string($this->note)) {
334
-			return $this->note;
335
-		}
336
-		return '';
337
-	}
338
-
339
-	/**
340
-	 * @inheritdoc
341
-	 */
342
-	public function setLabel($label) {
343
-		$this->label = $label;
344
-		return $this;
345
-	}
346
-
347
-	/**
348
-	 * @inheritdoc
349
-	 */
350
-	public function getLabel() {
351
-		return $this->label;
352
-	}
353
-
354
-	/**
355
-	 * @inheritdoc
356
-	 */
357
-	public function setExpirationDate($expireDate) {
358
-		//TODO checks
359
-
360
-		$this->expireDate = $expireDate;
361
-		return $this;
362
-	}
363
-
364
-	/**
365
-	 * @inheritdoc
366
-	 */
367
-	public function getExpirationDate() {
368
-		return $this->expireDate;
369
-	}
370
-
371
-	/**
372
-	 * @inheritdoc
373
-	 */
374
-	public function setSharedBy($sharedBy) {
375
-		if (!is_string($sharedBy)) {
376
-			throw new \InvalidArgumentException();
377
-		}
378
-		//TODO checks
379
-		$this->sharedBy = $sharedBy;
380
-
381
-		return $this;
382
-	}
383
-
384
-	/**
385
-	 * @inheritdoc
386
-	 */
387
-	public function getSharedBy() {
388
-		//TODO check if set
389
-		return $this->sharedBy;
390
-	}
391
-
392
-	/**
393
-	 * @inheritdoc
394
-	 */
395
-	public function setShareOwner($shareOwner) {
396
-		if (!is_string($shareOwner)) {
397
-			throw new \InvalidArgumentException();
398
-		}
399
-		//TODO checks
400
-
401
-		$this->shareOwner = $shareOwner;
402
-		return $this;
403
-	}
404
-
405
-	/**
406
-	 * @inheritdoc
407
-	 */
408
-	public function getShareOwner() {
409
-		//TODO check if set
410
-		return $this->shareOwner;
411
-	}
412
-
413
-	/**
414
-	 * @inheritdoc
415
-	 */
416
-	public function setPassword($password) {
417
-		$this->password = $password;
418
-		return $this;
419
-	}
420
-
421
-	/**
422
-	 * @inheritdoc
423
-	 */
424
-	public function getPassword() {
425
-		return $this->password;
426
-	}
427
-
428
-	/**
429
-	 * @inheritdoc
430
-	 */
431
-	public function setSendPasswordByTalk(bool $sendPasswordByTalk) {
432
-		$this->sendPasswordByTalk = $sendPasswordByTalk;
433
-		return $this;
434
-	}
435
-
436
-	/**
437
-	 * @inheritdoc
438
-	 */
439
-	public function getSendPasswordByTalk(): bool {
440
-		return $this->sendPasswordByTalk;
441
-	}
442
-
443
-	/**
444
-	 * @inheritdoc
445
-	 */
446
-	public function setToken($token) {
447
-		$this->token = $token;
448
-		return $this;
449
-	}
450
-
451
-	/**
452
-	 * @inheritdoc
453
-	 */
454
-	public function getToken() {
455
-		return $this->token;
456
-	}
457
-
458
-	/**
459
-	 * Set the parent of this share
460
-	 *
461
-	 * @param int parent
462
-	 * @return \OCP\Share\IShare
463
-	 * @deprecated The new shares do not have parents. This is just here for legacy reasons.
464
-	 */
465
-	public function setParent($parent) {
466
-		$this->parent = $parent;
467
-		return $this;
468
-	}
469
-
470
-	/**
471
-	 * Get the parent of this share.
472
-	 *
473
-	 * @return int
474
-	 * @deprecated The new shares do not have parents. This is just here for legacy reasons.
475
-	 */
476
-	public function getParent() {
477
-		return $this->parent;
478
-	}
479
-
480
-	/**
481
-	 * @inheritdoc
482
-	 */
483
-	public function setTarget($target) {
484
-		$this->target = $target;
485
-		return $this;
486
-	}
487
-
488
-	/**
489
-	 * @inheritdoc
490
-	 */
491
-	public function getTarget() {
492
-		return $this->target;
493
-	}
494
-
495
-	/**
496
-	 * @inheritdoc
497
-	 */
498
-	public function setShareTime(\DateTime $shareTime) {
499
-		$this->shareTime = $shareTime;
500
-		return $this;
501
-	}
502
-
503
-	/**
504
-	 * @inheritdoc
505
-	 */
506
-	public function getShareTime() {
507
-		return $this->shareTime;
508
-	}
509
-
510
-	/**
511
-	 * @inheritdoc
512
-	 */
513
-	public function setMailSend($mailSend) {
514
-		$this->mailSend = $mailSend;
515
-		return $this;
516
-	}
517
-
518
-	/**
519
-	 * @inheritdoc
520
-	 */
521
-	public function getMailSend() {
522
-		return $this->mailSend;
523
-	}
524
-
525
-	/**
526
-	 * @inheritdoc
527
-	 */
528
-	public function setNodeCacheEntry(ICacheEntry $entry) {
529
-		$this->nodeCacheEntry = $entry;
530
-	}
531
-
532
-	/**
533
-	 * @inheritdoc
534
-	 */
535
-	public function getNodeCacheEntry() {
536
-		return $this->nodeCacheEntry;
537
-	}
538
-
539
-	public function setHideDownload(bool $hide): IShare {
540
-		$this->hideDownload = $hide;
541
-		return $this;
542
-	}
543
-
544
-	public function getHideDownload(): bool {
545
-		return $this->hideDownload;
546
-	}
37
+    /** @var string */
38
+    private $id;
39
+    /** @var string */
40
+    private $providerId;
41
+    /** @var Node */
42
+    private $node;
43
+    /** @var int */
44
+    private $fileId;
45
+    /** @var string */
46
+    private $nodeType;
47
+    /** @var int */
48
+    private $shareType;
49
+    /** @var string */
50
+    private $sharedWith;
51
+    /** @var string */
52
+    private $sharedWithDisplayName;
53
+    /** @var string */
54
+    private $sharedWithAvatar;
55
+    /** @var string */
56
+    private $sharedBy;
57
+    /** @var string */
58
+    private $shareOwner;
59
+    /** @var int */
60
+    private $permissions;
61
+    /** @var string */
62
+    private $note = '';
63
+    /** @var \DateTime */
64
+    private $expireDate;
65
+    /** @var string */
66
+    private $password;
67
+    /** @var bool */
68
+    private $sendPasswordByTalk = false;
69
+    /** @var string */
70
+    private $token;
71
+    /** @var int */
72
+    private $parent;
73
+    /** @var string */
74
+    private $target;
75
+    /** @var \DateTime */
76
+    private $shareTime;
77
+    /** @var bool */
78
+    private $mailSend;
79
+    /** @var string */
80
+    private $label = '';
81
+
82
+    /** @var IRootFolder */
83
+    private $rootFolder;
84
+
85
+    /** @var IUserManager */
86
+    private $userManager;
87
+
88
+    /** @var ICacheEntry|null */
89
+    private $nodeCacheEntry;
90
+
91
+    /** @var bool */
92
+    private $hideDownload = false;
93
+
94
+    public function __construct(IRootFolder $rootFolder, IUserManager $userManager) {
95
+        $this->rootFolder = $rootFolder;
96
+        $this->userManager = $userManager;
97
+    }
98
+
99
+    /**
100
+     * @inheritdoc
101
+     */
102
+    public function setId($id) {
103
+        if (is_int($id)) {
104
+            $id = (string)$id;
105
+        }
106
+
107
+        if(!is_string($id)) {
108
+            throw new \InvalidArgumentException('String expected.');
109
+        }
110
+
111
+        if ($this->id !== null) {
112
+            throw new IllegalIDChangeException('Not allowed to assign a new internal id to a share');
113
+        }
114
+
115
+        $this->id = trim($id);
116
+        return $this;
117
+    }
118
+
119
+    /**
120
+     * @inheritdoc
121
+     */
122
+    public function getId() {
123
+        return $this->id;
124
+    }
125
+
126
+    /**
127
+     * @inheritdoc
128
+     */
129
+    public function getFullId() {
130
+        if ($this->providerId === null || $this->id === null) {
131
+            throw new \UnexpectedValueException;
132
+        }
133
+        return $this->providerId . ':' . $this->id;
134
+    }
135
+
136
+    /**
137
+     * @inheritdoc
138
+     */
139
+    public function setProviderId($id) {
140
+        if(!is_string($id)) {
141
+            throw new \InvalidArgumentException('String expected.');
142
+        }
143
+
144
+        if ($this->providerId !== null) {
145
+            throw new IllegalIDChangeException('Not allowed to assign a new provider id to a share');
146
+        }
147
+
148
+        $this->providerId = trim($id);
149
+        return $this;
150
+    }
151
+
152
+    /**
153
+     * @inheritdoc
154
+     */
155
+    public function setNode(Node $node) {
156
+        $this->fileId = null;
157
+        $this->nodeType = null;
158
+        $this->node = $node;
159
+        return $this;
160
+    }
161
+
162
+    /**
163
+     * @inheritdoc
164
+     */
165
+    public function getNode() {
166
+        if ($this->node === null) {
167
+
168
+            if ($this->shareOwner === null || $this->fileId === null) {
169
+                throw new NotFoundException();
170
+            }
171
+
172
+            // for federated shares the owner can be a remote user, in this
173
+            // case we use the initiator
174
+            if($this->userManager->userExists($this->shareOwner)) {
175
+                $userFolder = $this->rootFolder->getUserFolder($this->shareOwner);
176
+            } else {
177
+                $userFolder = $this->rootFolder->getUserFolder($this->sharedBy);
178
+            }
179
+
180
+            $nodes = $userFolder->getById($this->fileId);
181
+            if (empty($nodes)) {
182
+                throw new NotFoundException('Node for share not found, fileid: ' . $this->fileId);
183
+            }
184
+
185
+            $this->node = $nodes[0];
186
+        }
187
+
188
+        return $this->node;
189
+    }
190
+
191
+    /**
192
+     * @inheritdoc
193
+     */
194
+    public function setNodeId($fileId) {
195
+        $this->node = null;
196
+        $this->fileId = $fileId;
197
+        return $this;
198
+    }
199
+
200
+    /**
201
+     * @inheritdoc
202
+     */
203
+    public function getNodeId() {
204
+        if ($this->fileId === null) {
205
+            $this->fileId = $this->getNode()->getId();
206
+        }
207
+
208
+        return $this->fileId;
209
+    }
210
+
211
+    /**
212
+     * @inheritdoc
213
+     */
214
+    public function setNodeType($type) {
215
+        if ($type !== 'file' && $type !== 'folder') {
216
+            throw new \InvalidArgumentException();
217
+        }
218
+
219
+        $this->nodeType = $type;
220
+        return $this;
221
+    }
222
+
223
+    /**
224
+     * @inheritdoc
225
+     */
226
+    public function getNodeType() {
227
+        if ($this->nodeType === null) {
228
+            $node = $this->getNode();
229
+            $this->nodeType = $node instanceof File ? 'file' : 'folder';
230
+        }
231
+
232
+        return $this->nodeType;
233
+    }
234
+
235
+    /**
236
+     * @inheritdoc
237
+     */
238
+    public function setShareType($shareType) {
239
+        $this->shareType = $shareType;
240
+        return $this;
241
+    }
242
+
243
+    /**
244
+     * @inheritdoc
245
+     */
246
+    public function getShareType() {
247
+        return $this->shareType;
248
+    }
249
+
250
+    /**
251
+     * @inheritdoc
252
+     */
253
+    public function setSharedWith($sharedWith) {
254
+        if (!is_string($sharedWith)) {
255
+            throw new \InvalidArgumentException();
256
+        }
257
+        $this->sharedWith = $sharedWith;
258
+        return $this;
259
+    }
260
+
261
+    /**
262
+     * @inheritdoc
263
+     */
264
+    public function getSharedWith() {
265
+        return $this->sharedWith;
266
+    }
267
+
268
+    /**
269
+     * @inheritdoc
270
+     */
271
+    public function setSharedWithDisplayName($displayName) {
272
+        if (!is_string($displayName)) {
273
+            throw new \InvalidArgumentException();
274
+        }
275
+        $this->sharedWithDisplayName = $displayName;
276
+        return $this;
277
+    }
278
+
279
+    /**
280
+     * @inheritdoc
281
+     */
282
+    public function getSharedWithDisplayName() {
283
+        return $this->sharedWithDisplayName;
284
+    }
285
+
286
+    /**
287
+     * @inheritdoc
288
+     */
289
+    public function setSharedWithAvatar($src) {
290
+        if (!is_string($src)) {
291
+            throw new \InvalidArgumentException();
292
+        }
293
+        $this->sharedWithAvatar = $src;
294
+        return $this;
295
+    }
296
+
297
+    /**
298
+     * @inheritdoc
299
+     */
300
+    public function getSharedWithAvatar() {
301
+        return $this->sharedWithAvatar;
302
+    }
303
+
304
+    /**
305
+     * @inheritdoc
306
+     */
307
+    public function setPermissions($permissions) {
308
+        //TODO checkes
309
+
310
+        $this->permissions = $permissions;
311
+        return $this;
312
+    }
313
+
314
+    /**
315
+     * @inheritdoc
316
+     */
317
+    public function getPermissions() {
318
+        return $this->permissions;
319
+    }
320
+
321
+    /**
322
+     * @inheritdoc
323
+     */
324
+    public function setNote($note) {
325
+        $this->note = $note;
326
+        return $this;
327
+    }
328
+
329
+    /**
330
+     * @inheritdoc
331
+     */
332
+    public function getNote() {
333
+        if (is_string($this->note)) {
334
+            return $this->note;
335
+        }
336
+        return '';
337
+    }
338
+
339
+    /**
340
+     * @inheritdoc
341
+     */
342
+    public function setLabel($label) {
343
+        $this->label = $label;
344
+        return $this;
345
+    }
346
+
347
+    /**
348
+     * @inheritdoc
349
+     */
350
+    public function getLabel() {
351
+        return $this->label;
352
+    }
353
+
354
+    /**
355
+     * @inheritdoc
356
+     */
357
+    public function setExpirationDate($expireDate) {
358
+        //TODO checks
359
+
360
+        $this->expireDate = $expireDate;
361
+        return $this;
362
+    }
363
+
364
+    /**
365
+     * @inheritdoc
366
+     */
367
+    public function getExpirationDate() {
368
+        return $this->expireDate;
369
+    }
370
+
371
+    /**
372
+     * @inheritdoc
373
+     */
374
+    public function setSharedBy($sharedBy) {
375
+        if (!is_string($sharedBy)) {
376
+            throw new \InvalidArgumentException();
377
+        }
378
+        //TODO checks
379
+        $this->sharedBy = $sharedBy;
380
+
381
+        return $this;
382
+    }
383
+
384
+    /**
385
+     * @inheritdoc
386
+     */
387
+    public function getSharedBy() {
388
+        //TODO check if set
389
+        return $this->sharedBy;
390
+    }
391
+
392
+    /**
393
+     * @inheritdoc
394
+     */
395
+    public function setShareOwner($shareOwner) {
396
+        if (!is_string($shareOwner)) {
397
+            throw new \InvalidArgumentException();
398
+        }
399
+        //TODO checks
400
+
401
+        $this->shareOwner = $shareOwner;
402
+        return $this;
403
+    }
404
+
405
+    /**
406
+     * @inheritdoc
407
+     */
408
+    public function getShareOwner() {
409
+        //TODO check if set
410
+        return $this->shareOwner;
411
+    }
412
+
413
+    /**
414
+     * @inheritdoc
415
+     */
416
+    public function setPassword($password) {
417
+        $this->password = $password;
418
+        return $this;
419
+    }
420
+
421
+    /**
422
+     * @inheritdoc
423
+     */
424
+    public function getPassword() {
425
+        return $this->password;
426
+    }
427
+
428
+    /**
429
+     * @inheritdoc
430
+     */
431
+    public function setSendPasswordByTalk(bool $sendPasswordByTalk) {
432
+        $this->sendPasswordByTalk = $sendPasswordByTalk;
433
+        return $this;
434
+    }
435
+
436
+    /**
437
+     * @inheritdoc
438
+     */
439
+    public function getSendPasswordByTalk(): bool {
440
+        return $this->sendPasswordByTalk;
441
+    }
442
+
443
+    /**
444
+     * @inheritdoc
445
+     */
446
+    public function setToken($token) {
447
+        $this->token = $token;
448
+        return $this;
449
+    }
450
+
451
+    /**
452
+     * @inheritdoc
453
+     */
454
+    public function getToken() {
455
+        return $this->token;
456
+    }
457
+
458
+    /**
459
+     * Set the parent of this share
460
+     *
461
+     * @param int parent
462
+     * @return \OCP\Share\IShare
463
+     * @deprecated The new shares do not have parents. This is just here for legacy reasons.
464
+     */
465
+    public function setParent($parent) {
466
+        $this->parent = $parent;
467
+        return $this;
468
+    }
469
+
470
+    /**
471
+     * Get the parent of this share.
472
+     *
473
+     * @return int
474
+     * @deprecated The new shares do not have parents. This is just here for legacy reasons.
475
+     */
476
+    public function getParent() {
477
+        return $this->parent;
478
+    }
479
+
480
+    /**
481
+     * @inheritdoc
482
+     */
483
+    public function setTarget($target) {
484
+        $this->target = $target;
485
+        return $this;
486
+    }
487
+
488
+    /**
489
+     * @inheritdoc
490
+     */
491
+    public function getTarget() {
492
+        return $this->target;
493
+    }
494
+
495
+    /**
496
+     * @inheritdoc
497
+     */
498
+    public function setShareTime(\DateTime $shareTime) {
499
+        $this->shareTime = $shareTime;
500
+        return $this;
501
+    }
502
+
503
+    /**
504
+     * @inheritdoc
505
+     */
506
+    public function getShareTime() {
507
+        return $this->shareTime;
508
+    }
509
+
510
+    /**
511
+     * @inheritdoc
512
+     */
513
+    public function setMailSend($mailSend) {
514
+        $this->mailSend = $mailSend;
515
+        return $this;
516
+    }
517
+
518
+    /**
519
+     * @inheritdoc
520
+     */
521
+    public function getMailSend() {
522
+        return $this->mailSend;
523
+    }
524
+
525
+    /**
526
+     * @inheritdoc
527
+     */
528
+    public function setNodeCacheEntry(ICacheEntry $entry) {
529
+        $this->nodeCacheEntry = $entry;
530
+    }
531
+
532
+    /**
533
+     * @inheritdoc
534
+     */
535
+    public function getNodeCacheEntry() {
536
+        return $this->nodeCacheEntry;
537
+    }
538
+
539
+    public function setHideDownload(bool $hide): IShare {
540
+        $this->hideDownload = $hide;
541
+        return $this;
542
+    }
543
+
544
+    public function getHideDownload(): bool {
545
+        return $this->hideDownload;
546
+    }
547 547
 }
Please login to merge, or discard this patch.
core/Migrations/Version15000Date20181029084625.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -31,23 +31,23 @@
 block discarded – undo
31 31
 
32 32
 class Version15000Date20181029084625 extends SimpleMigrationStep {
33 33
 
34
-	/**
35
-	 * @param IOutput $output
36
-	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
37
-	 * @param array $options
38
-	 * @return null|ISchemaWrapper
39
-	 */
40
-	public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
41
-		/** @var ISchemaWrapper $schema */
42
-		$schema = $schemaClosure();
34
+    /**
35
+     * @param IOutput $output
36
+     * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
37
+     * @param array $options
38
+     * @return null|ISchemaWrapper
39
+     */
40
+    public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
41
+        /** @var ISchemaWrapper $schema */
42
+        $schema = $schemaClosure();
43 43
 
44
-		$table = $schema->getTable('share');
45
-		$table->addColumn('label', 'string', [
46
-			'notnull' => false,
47
-			'length' => 255,
48
-		]);
44
+        $table = $schema->getTable('share');
45
+        $table->addColumn('label', 'string', [
46
+            'notnull' => false,
47
+            'length' => 255,
48
+        ]);
49 49
 
50
-		return $schema;
51
-	}
50
+        return $schema;
51
+    }
52 52
 
53 53
 }
Please login to merge, or discard this patch.
apps/files_sharing/lib/Controller/ShareAPIController.php 1 patch
Indentation   +1030 added lines, -1030 removed lines patch added patch discarded remove patch
@@ -66,1040 +66,1040 @@
 block discarded – undo
66 66
  */
67 67
 class ShareAPIController extends OCSController {
68 68
 
69
-	/** @var IManager */
70
-	private $shareManager;
71
-	/** @var IGroupManager */
72
-	private $groupManager;
73
-	/** @var IUserManager */
74
-	private $userManager;
75
-	/** @var IRootFolder */
76
-	private $rootFolder;
77
-	/** @var IURLGenerator */
78
-	private $urlGenerator;
79
-	/** @var string */
80
-	private $currentUser;
81
-	/** @var IL10N */
82
-	private $l;
83
-	/** @var \OCP\Files\Node */
84
-	private $lockedNode;
85
-	/** @var IConfig */
86
-	private $config;
87
-	/** @var IAppManager */
88
-	private $appManager;
89
-	/** @var IServerContainer */
90
-	private $serverContainer;
91
-
92
-	/**
93
-	 * Share20OCS constructor.
94
-	 *
95
-	 * @param string $appName
96
-	 * @param IRequest $request
97
-	 * @param IManager $shareManager
98
-	 * @param IGroupManager $groupManager
99
-	 * @param IUserManager $userManager
100
-	 * @param IRootFolder $rootFolder
101
-	 * @param IURLGenerator $urlGenerator
102
-	 * @param string $userId
103
-	 * @param IL10N $l10n
104
-	 * @param IConfig $config
105
-	 * @param IAppManager $appManager
106
-	 * @param IServerContainer $serverContainer
107
-	 */
108
-	public function __construct(
109
-		string $appName,
110
-		IRequest $request,
111
-		IManager $shareManager,
112
-		IGroupManager $groupManager,
113
-		IUserManager $userManager,
114
-		IRootFolder $rootFolder,
115
-		IURLGenerator $urlGenerator,
116
-		string $userId = null,
117
-		IL10N $l10n,
118
-		IConfig $config,
119
-		IAppManager $appManager,
120
-		IServerContainer $serverContainer
121
-	) {
122
-		parent::__construct($appName, $request);
123
-
124
-		$this->shareManager = $shareManager;
125
-		$this->userManager = $userManager;
126
-		$this->groupManager = $groupManager;
127
-		$this->request = $request;
128
-		$this->rootFolder = $rootFolder;
129
-		$this->urlGenerator = $urlGenerator;
130
-		$this->currentUser = $userId;
131
-		$this->l = $l10n;
132
-		$this->config = $config;
133
-		$this->appManager = $appManager;
134
-		$this->serverContainer = $serverContainer;
135
-	}
136
-
137
-	/**
138
-	 * Convert an IShare to an array for OCS output
139
-	 *
140
-	 * @param \OCP\Share\IShare $share
141
-	 * @param Node|null $recipientNode
142
-	 * @return array
143
-	 * @throws NotFoundException In case the node can't be resolved.
144
-	 *
145
-	 * @suppress PhanUndeclaredClassMethod
146
-	 */
147
-	protected function formatShare(\OCP\Share\IShare $share, Node $recipientNode = null): array {
148
-		$sharedBy = $this->userManager->get($share->getSharedBy());
149
-		$shareOwner = $this->userManager->get($share->getShareOwner());
150
-
151
-		$result = [
152
-			'id' => $share->getId(),
153
-			'share_type' => $share->getShareType(),
154
-			'uid_owner' => $share->getSharedBy(),
155
-			'displayname_owner' => $sharedBy !== null ? $sharedBy->getDisplayName() : $share->getSharedBy(),
156
-			'permissions' => $share->getPermissions(),
157
-			'stime' => $share->getShareTime()->getTimestamp(),
158
-			'parent' => null,
159
-			'expiration' => null,
160
-			'token' => null,
161
-			'uid_file_owner' => $share->getShareOwner(),
162
-			'note' => $share->getNote(),
163
-			'label' => $share->getLabel(),
164
-			'displayname_file_owner' => $shareOwner !== null ? $shareOwner->getDisplayName() : $share->getShareOwner(),
165
-		];
166
-
167
-		$userFolder = $this->rootFolder->getUserFolder($this->currentUser);
168
-		if ($recipientNode) {
169
-			$node = $recipientNode;
170
-		} else {
171
-			$nodes = $userFolder->getById($share->getNodeId());
172
-			if (empty($nodes)) {
173
-				// fallback to guessing the path
174
-				$node = $userFolder->get($share->getTarget());
175
-				if ($node === null || $share->getTarget() === '') {
176
-					throw new NotFoundException();
177
-				}
178
-			} else {
179
-				$node = $nodes[0];
180
-			}
181
-		}
182
-
183
-		$result['path'] = $userFolder->getRelativePath($node->getPath());
184
-		if ($node instanceOf \OCP\Files\Folder) {
185
-			$result['item_type'] = 'folder';
186
-		} else {
187
-			$result['item_type'] = 'file';
188
-		}
189
-		$result['mimetype'] = $node->getMimetype();
190
-		$result['storage_id'] = $node->getStorage()->getId();
191
-		$result['storage'] = $node->getStorage()->getCache()->getNumericStorageId();
192
-		$result['item_source'] = $node->getId();
193
-		$result['file_source'] = $node->getId();
194
-		$result['file_parent'] = $node->getParent()->getId();
195
-		$result['file_target'] = $share->getTarget();
196
-
197
-		$expiration = $share->getExpirationDate();
198
-		if ($expiration !== null) {
199
-			$result['expiration'] = $expiration->format('Y-m-d 00:00:00');
200
-		}
201
-
202
-		if ($share->getShareType() === Share::SHARE_TYPE_USER) {
203
-			$sharedWith = $this->userManager->get($share->getSharedWith());
204
-			$result['share_with'] = $share->getSharedWith();
205
-			$result['share_with_displayname'] = $sharedWith !== null ? $sharedWith->getDisplayName() : $share->getSharedWith();
206
-		} else if ($share->getShareType() === Share::SHARE_TYPE_GROUP) {
207
-			$group = $this->groupManager->get($share->getSharedWith());
208
-			$result['share_with'] = $share->getSharedWith();
209
-			$result['share_with_displayname'] = $group !== null ? $group->getDisplayName() : $share->getSharedWith();
210
-		} else if ($share->getShareType() === Share::SHARE_TYPE_LINK) {
211
-
212
-			$result['share_with'] = $share->getPassword();
213
-			$result['share_with_displayname'] = $share->getPassword();
214
-
215
-			$result['token'] = $share->getToken();
216
-			$result['url'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $share->getToken()]);
217
-
218
-		} else if ($share->getShareType() === Share::SHARE_TYPE_REMOTE || $share->getShareType() === Share::SHARE_TYPE_REMOTE_GROUP) {
219
-			$result['share_with'] = $share->getSharedWith();
220
-			$result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'CLOUD');
221
-			$result['token'] = $share->getToken();
222
-		} else if ($share->getShareType() === Share::SHARE_TYPE_EMAIL) {
223
-			$result['share_with'] = $share->getSharedWith();
224
-			$result['password'] = $share->getPassword();
225
-			$result['send_password_by_talk'] = $share->getSendPasswordByTalk();
226
-			$result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'EMAIL');
227
-			$result['token'] = $share->getToken();
228
-		} else if ($share->getShareType() === Share::SHARE_TYPE_CIRCLE) {
229
-			// getSharedWith() returns either "name (type, owner)" or
230
-			// "name (type, owner) [id]", depending on the Circles app version.
231
-			$hasCircleId = (substr($share->getSharedWith(), -1) === ']');
232
-
233
-			$result['share_with_displayname'] = $share->getSharedWithDisplayName();
234
-			if (empty($result['share_with_displayname'])) {
235
-				$displayNameLength = ($hasCircleId? strrpos($share->getSharedWith(), ' '): strlen($share->getSharedWith()));
236
-				$result['share_with_displayname'] = substr($share->getSharedWith(), 0, $displayNameLength);
237
-			}
238
-
239
-			$result['share_with_avatar'] = $share->getSharedWithAvatar();
240
-
241
-			$shareWithStart = ($hasCircleId? strrpos($share->getSharedWith(), '[') + 1: 0);
242
-			$shareWithLength = ($hasCircleId? -1: strpos($share->getSharedWith(), ' '));
243
-			$result['share_with'] = substr($share->getSharedWith(), $shareWithStart, $shareWithLength);
244
-		} else if ($share->getShareType() === Share::SHARE_TYPE_ROOM) {
245
-			$result['share_with'] = $share->getSharedWith();
246
-			$result['share_with_displayname'] = '';
247
-
248
-			try {
249
-				$result = array_merge($result, $this->getRoomShareHelper()->formatShare($share));
250
-			} catch (QueryException $e) {
251
-			}
252
-		}
253
-
254
-
255
-		$result['mail_send'] = $share->getMailSend() ? 1 : 0;
256
-		$result['hide_download'] = $share->getHideDownload() ? 1 : 0;
257
-
258
-		return $result;
259
-	}
260
-
261
-	/**
262
-	 * Check if one of the users address books knows the exact property, if
263
-	 * yes we return the full name.
264
-	 *
265
-	 * @param string $query
266
-	 * @param string $property
267
-	 * @return string
268
-	 */
269
-	private function getDisplayNameFromAddressBook(string $query, string $property): string {
270
-		// FIXME: If we inject the contacts manager it gets initialized bofore any address books are registered
271
-		$result = \OC::$server->getContactsManager()->search($query, [$property]);
272
-		foreach ($result as $r) {
273
-			foreach($r[$property] as $value) {
274
-				if ($value === $query) {
275
-					return $r['FN'];
276
-				}
277
-			}
278
-		}
279
-
280
-		return $query;
281
-	}
282
-
283
-	/**
284
-	 * Get a specific share by id
285
-	 *
286
-	 * @NoAdminRequired
287
-	 *
288
-	 * @param string $id
289
-	 * @return DataResponse
290
-	 * @throws OCSNotFoundException
291
-	 */
292
-	public function getShare(string $id): DataResponse {
293
-		try {
294
-			$share = $this->getShareById($id);
295
-		} catch (ShareNotFound $e) {
296
-			throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
297
-		}
298
-
299
-		if ($this->canAccessShare($share)) {
300
-			try {
301
-				$share = $this->formatShare($share);
302
-				return new DataResponse([$share]);
303
-			} catch (NotFoundException $e) {
304
-				//Fall trough
305
-			}
306
-		}
307
-
308
-		throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
309
-	}
310
-
311
-	/**
312
-	 * Delete a share
313
-	 *
314
-	 * @NoAdminRequired
315
-	 *
316
-	 * @param string $id
317
-	 * @return DataResponse
318
-	 * @throws OCSNotFoundException
319
-	 */
320
-	public function deleteShare(string $id): DataResponse {
321
-		try {
322
-			$share = $this->getShareById($id);
323
-		} catch (ShareNotFound $e) {
324
-			throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
325
-		}
326
-
327
-		try {
328
-			$this->lock($share->getNode());
329
-		} catch (LockedException $e) {
330
-			throw new OCSNotFoundException($this->l->t('could not delete share'));
331
-		}
332
-
333
-		if (!$this->canAccessShare($share)) {
334
-			throw new OCSNotFoundException($this->l->t('Could not delete share'));
335
-		}
336
-
337
-		if (($share->getShareType() === Share::SHARE_TYPE_GROUP ||
338
-				$share->getShareType() === Share::SHARE_TYPE_ROOM) &&
339
-			$share->getShareOwner() !== $this->currentUser &&
340
-			$share->getSharedBy() !== $this->currentUser) {
341
-			$this->shareManager->deleteFromSelf($share, $this->currentUser);
342
-		} else {
343
-			$this->shareManager->deleteShare($share);
344
-		}
345
-
346
-		return new DataResponse();
347
-	}
348
-
349
-	/**
350
-	 * @NoAdminRequired
351
-	 *
352
-	 * @param string $path
353
-	 * @param int $permissions
354
-	 * @param int $shareType
355
-	 * @param string $shareWith
356
-	 * @param string $publicUpload
357
-	 * @param string $password
358
-	 * @param string $sendPasswordByTalk
359
-	 * @param string $expireDate
360
-	 * @param string $label
361
-	 *
362
-	 * @return DataResponse
363
-	 * @throws NotFoundException
364
-	 * @throws OCSBadRequestException
365
-	 * @throws OCSException
366
-	 * @throws OCSForbiddenException
367
-	 * @throws OCSNotFoundException
368
-	 * @throws \OCP\Files\InvalidPathException
369
-	 * @suppress PhanUndeclaredClassMethod
370
-	 */
371
-	public function createShare(
372
-		string $path = null,
373
-		int $permissions = null,
374
-		int $shareType = -1,
375
-		string $shareWith = null,
376
-		string $publicUpload = 'false',
377
-		string $password = '',
378
-		string $sendPasswordByTalk = null,
379
-		string $expireDate = '',
380
-		string $label = ''
381
-	): DataResponse {
382
-		$share = $this->shareManager->newShare();
383
-
384
-		if ($permissions === null) {
385
-			$permissions = $this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL);
386
-		}
387
-
388
-		// Verify path
389
-		if ($path === null) {
390
-			throw new OCSNotFoundException($this->l->t('Please specify a file or folder path'));
391
-		}
392
-
393
-		$userFolder = $this->rootFolder->getUserFolder($this->currentUser);
394
-		try {
395
-			$path = $userFolder->get($path);
396
-		} catch (NotFoundException $e) {
397
-			throw new OCSNotFoundException($this->l->t('Wrong path, file/folder doesn\'t exist'));
398
-		}
399
-
400
-		$share->setNode($path);
401
-
402
-		try {
403
-			$this->lock($share->getNode());
404
-		} catch (LockedException $e) {
405
-			throw new OCSNotFoundException($this->l->t('Could not create share'));
406
-		}
407
-
408
-		if ($permissions < 0 || $permissions > Constants::PERMISSION_ALL) {
409
-			throw new OCSNotFoundException($this->l->t('invalid permissions'));
410
-		}
411
-
412
-		// Shares always require read permissions
413
-		$permissions |= Constants::PERMISSION_READ;
414
-
415
-		if ($path instanceof \OCP\Files\File) {
416
-			// Single file shares should never have delete or create permissions
417
-			$permissions &= ~Constants::PERMISSION_DELETE;
418
-			$permissions &= ~Constants::PERMISSION_CREATE;
419
-		}
420
-
421
-		/*
69
+    /** @var IManager */
70
+    private $shareManager;
71
+    /** @var IGroupManager */
72
+    private $groupManager;
73
+    /** @var IUserManager */
74
+    private $userManager;
75
+    /** @var IRootFolder */
76
+    private $rootFolder;
77
+    /** @var IURLGenerator */
78
+    private $urlGenerator;
79
+    /** @var string */
80
+    private $currentUser;
81
+    /** @var IL10N */
82
+    private $l;
83
+    /** @var \OCP\Files\Node */
84
+    private $lockedNode;
85
+    /** @var IConfig */
86
+    private $config;
87
+    /** @var IAppManager */
88
+    private $appManager;
89
+    /** @var IServerContainer */
90
+    private $serverContainer;
91
+
92
+    /**
93
+     * Share20OCS constructor.
94
+     *
95
+     * @param string $appName
96
+     * @param IRequest $request
97
+     * @param IManager $shareManager
98
+     * @param IGroupManager $groupManager
99
+     * @param IUserManager $userManager
100
+     * @param IRootFolder $rootFolder
101
+     * @param IURLGenerator $urlGenerator
102
+     * @param string $userId
103
+     * @param IL10N $l10n
104
+     * @param IConfig $config
105
+     * @param IAppManager $appManager
106
+     * @param IServerContainer $serverContainer
107
+     */
108
+    public function __construct(
109
+        string $appName,
110
+        IRequest $request,
111
+        IManager $shareManager,
112
+        IGroupManager $groupManager,
113
+        IUserManager $userManager,
114
+        IRootFolder $rootFolder,
115
+        IURLGenerator $urlGenerator,
116
+        string $userId = null,
117
+        IL10N $l10n,
118
+        IConfig $config,
119
+        IAppManager $appManager,
120
+        IServerContainer $serverContainer
121
+    ) {
122
+        parent::__construct($appName, $request);
123
+
124
+        $this->shareManager = $shareManager;
125
+        $this->userManager = $userManager;
126
+        $this->groupManager = $groupManager;
127
+        $this->request = $request;
128
+        $this->rootFolder = $rootFolder;
129
+        $this->urlGenerator = $urlGenerator;
130
+        $this->currentUser = $userId;
131
+        $this->l = $l10n;
132
+        $this->config = $config;
133
+        $this->appManager = $appManager;
134
+        $this->serverContainer = $serverContainer;
135
+    }
136
+
137
+    /**
138
+     * Convert an IShare to an array for OCS output
139
+     *
140
+     * @param \OCP\Share\IShare $share
141
+     * @param Node|null $recipientNode
142
+     * @return array
143
+     * @throws NotFoundException In case the node can't be resolved.
144
+     *
145
+     * @suppress PhanUndeclaredClassMethod
146
+     */
147
+    protected function formatShare(\OCP\Share\IShare $share, Node $recipientNode = null): array {
148
+        $sharedBy = $this->userManager->get($share->getSharedBy());
149
+        $shareOwner = $this->userManager->get($share->getShareOwner());
150
+
151
+        $result = [
152
+            'id' => $share->getId(),
153
+            'share_type' => $share->getShareType(),
154
+            'uid_owner' => $share->getSharedBy(),
155
+            'displayname_owner' => $sharedBy !== null ? $sharedBy->getDisplayName() : $share->getSharedBy(),
156
+            'permissions' => $share->getPermissions(),
157
+            'stime' => $share->getShareTime()->getTimestamp(),
158
+            'parent' => null,
159
+            'expiration' => null,
160
+            'token' => null,
161
+            'uid_file_owner' => $share->getShareOwner(),
162
+            'note' => $share->getNote(),
163
+            'label' => $share->getLabel(),
164
+            'displayname_file_owner' => $shareOwner !== null ? $shareOwner->getDisplayName() : $share->getShareOwner(),
165
+        ];
166
+
167
+        $userFolder = $this->rootFolder->getUserFolder($this->currentUser);
168
+        if ($recipientNode) {
169
+            $node = $recipientNode;
170
+        } else {
171
+            $nodes = $userFolder->getById($share->getNodeId());
172
+            if (empty($nodes)) {
173
+                // fallback to guessing the path
174
+                $node = $userFolder->get($share->getTarget());
175
+                if ($node === null || $share->getTarget() === '') {
176
+                    throw new NotFoundException();
177
+                }
178
+            } else {
179
+                $node = $nodes[0];
180
+            }
181
+        }
182
+
183
+        $result['path'] = $userFolder->getRelativePath($node->getPath());
184
+        if ($node instanceOf \OCP\Files\Folder) {
185
+            $result['item_type'] = 'folder';
186
+        } else {
187
+            $result['item_type'] = 'file';
188
+        }
189
+        $result['mimetype'] = $node->getMimetype();
190
+        $result['storage_id'] = $node->getStorage()->getId();
191
+        $result['storage'] = $node->getStorage()->getCache()->getNumericStorageId();
192
+        $result['item_source'] = $node->getId();
193
+        $result['file_source'] = $node->getId();
194
+        $result['file_parent'] = $node->getParent()->getId();
195
+        $result['file_target'] = $share->getTarget();
196
+
197
+        $expiration = $share->getExpirationDate();
198
+        if ($expiration !== null) {
199
+            $result['expiration'] = $expiration->format('Y-m-d 00:00:00');
200
+        }
201
+
202
+        if ($share->getShareType() === Share::SHARE_TYPE_USER) {
203
+            $sharedWith = $this->userManager->get($share->getSharedWith());
204
+            $result['share_with'] = $share->getSharedWith();
205
+            $result['share_with_displayname'] = $sharedWith !== null ? $sharedWith->getDisplayName() : $share->getSharedWith();
206
+        } else if ($share->getShareType() === Share::SHARE_TYPE_GROUP) {
207
+            $group = $this->groupManager->get($share->getSharedWith());
208
+            $result['share_with'] = $share->getSharedWith();
209
+            $result['share_with_displayname'] = $group !== null ? $group->getDisplayName() : $share->getSharedWith();
210
+        } else if ($share->getShareType() === Share::SHARE_TYPE_LINK) {
211
+
212
+            $result['share_with'] = $share->getPassword();
213
+            $result['share_with_displayname'] = $share->getPassword();
214
+
215
+            $result['token'] = $share->getToken();
216
+            $result['url'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $share->getToken()]);
217
+
218
+        } else if ($share->getShareType() === Share::SHARE_TYPE_REMOTE || $share->getShareType() === Share::SHARE_TYPE_REMOTE_GROUP) {
219
+            $result['share_with'] = $share->getSharedWith();
220
+            $result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'CLOUD');
221
+            $result['token'] = $share->getToken();
222
+        } else if ($share->getShareType() === Share::SHARE_TYPE_EMAIL) {
223
+            $result['share_with'] = $share->getSharedWith();
224
+            $result['password'] = $share->getPassword();
225
+            $result['send_password_by_talk'] = $share->getSendPasswordByTalk();
226
+            $result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'EMAIL');
227
+            $result['token'] = $share->getToken();
228
+        } else if ($share->getShareType() === Share::SHARE_TYPE_CIRCLE) {
229
+            // getSharedWith() returns either "name (type, owner)" or
230
+            // "name (type, owner) [id]", depending on the Circles app version.
231
+            $hasCircleId = (substr($share->getSharedWith(), -1) === ']');
232
+
233
+            $result['share_with_displayname'] = $share->getSharedWithDisplayName();
234
+            if (empty($result['share_with_displayname'])) {
235
+                $displayNameLength = ($hasCircleId? strrpos($share->getSharedWith(), ' '): strlen($share->getSharedWith()));
236
+                $result['share_with_displayname'] = substr($share->getSharedWith(), 0, $displayNameLength);
237
+            }
238
+
239
+            $result['share_with_avatar'] = $share->getSharedWithAvatar();
240
+
241
+            $shareWithStart = ($hasCircleId? strrpos($share->getSharedWith(), '[') + 1: 0);
242
+            $shareWithLength = ($hasCircleId? -1: strpos($share->getSharedWith(), ' '));
243
+            $result['share_with'] = substr($share->getSharedWith(), $shareWithStart, $shareWithLength);
244
+        } else if ($share->getShareType() === Share::SHARE_TYPE_ROOM) {
245
+            $result['share_with'] = $share->getSharedWith();
246
+            $result['share_with_displayname'] = '';
247
+
248
+            try {
249
+                $result = array_merge($result, $this->getRoomShareHelper()->formatShare($share));
250
+            } catch (QueryException $e) {
251
+            }
252
+        }
253
+
254
+
255
+        $result['mail_send'] = $share->getMailSend() ? 1 : 0;
256
+        $result['hide_download'] = $share->getHideDownload() ? 1 : 0;
257
+
258
+        return $result;
259
+    }
260
+
261
+    /**
262
+     * Check if one of the users address books knows the exact property, if
263
+     * yes we return the full name.
264
+     *
265
+     * @param string $query
266
+     * @param string $property
267
+     * @return string
268
+     */
269
+    private function getDisplayNameFromAddressBook(string $query, string $property): string {
270
+        // FIXME: If we inject the contacts manager it gets initialized bofore any address books are registered
271
+        $result = \OC::$server->getContactsManager()->search($query, [$property]);
272
+        foreach ($result as $r) {
273
+            foreach($r[$property] as $value) {
274
+                if ($value === $query) {
275
+                    return $r['FN'];
276
+                }
277
+            }
278
+        }
279
+
280
+        return $query;
281
+    }
282
+
283
+    /**
284
+     * Get a specific share by id
285
+     *
286
+     * @NoAdminRequired
287
+     *
288
+     * @param string $id
289
+     * @return DataResponse
290
+     * @throws OCSNotFoundException
291
+     */
292
+    public function getShare(string $id): DataResponse {
293
+        try {
294
+            $share = $this->getShareById($id);
295
+        } catch (ShareNotFound $e) {
296
+            throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
297
+        }
298
+
299
+        if ($this->canAccessShare($share)) {
300
+            try {
301
+                $share = $this->formatShare($share);
302
+                return new DataResponse([$share]);
303
+            } catch (NotFoundException $e) {
304
+                //Fall trough
305
+            }
306
+        }
307
+
308
+        throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
309
+    }
310
+
311
+    /**
312
+     * Delete a share
313
+     *
314
+     * @NoAdminRequired
315
+     *
316
+     * @param string $id
317
+     * @return DataResponse
318
+     * @throws OCSNotFoundException
319
+     */
320
+    public function deleteShare(string $id): DataResponse {
321
+        try {
322
+            $share = $this->getShareById($id);
323
+        } catch (ShareNotFound $e) {
324
+            throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
325
+        }
326
+
327
+        try {
328
+            $this->lock($share->getNode());
329
+        } catch (LockedException $e) {
330
+            throw new OCSNotFoundException($this->l->t('could not delete share'));
331
+        }
332
+
333
+        if (!$this->canAccessShare($share)) {
334
+            throw new OCSNotFoundException($this->l->t('Could not delete share'));
335
+        }
336
+
337
+        if (($share->getShareType() === Share::SHARE_TYPE_GROUP ||
338
+                $share->getShareType() === Share::SHARE_TYPE_ROOM) &&
339
+            $share->getShareOwner() !== $this->currentUser &&
340
+            $share->getSharedBy() !== $this->currentUser) {
341
+            $this->shareManager->deleteFromSelf($share, $this->currentUser);
342
+        } else {
343
+            $this->shareManager->deleteShare($share);
344
+        }
345
+
346
+        return new DataResponse();
347
+    }
348
+
349
+    /**
350
+     * @NoAdminRequired
351
+     *
352
+     * @param string $path
353
+     * @param int $permissions
354
+     * @param int $shareType
355
+     * @param string $shareWith
356
+     * @param string $publicUpload
357
+     * @param string $password
358
+     * @param string $sendPasswordByTalk
359
+     * @param string $expireDate
360
+     * @param string $label
361
+     *
362
+     * @return DataResponse
363
+     * @throws NotFoundException
364
+     * @throws OCSBadRequestException
365
+     * @throws OCSException
366
+     * @throws OCSForbiddenException
367
+     * @throws OCSNotFoundException
368
+     * @throws \OCP\Files\InvalidPathException
369
+     * @suppress PhanUndeclaredClassMethod
370
+     */
371
+    public function createShare(
372
+        string $path = null,
373
+        int $permissions = null,
374
+        int $shareType = -1,
375
+        string $shareWith = null,
376
+        string $publicUpload = 'false',
377
+        string $password = '',
378
+        string $sendPasswordByTalk = null,
379
+        string $expireDate = '',
380
+        string $label = ''
381
+    ): DataResponse {
382
+        $share = $this->shareManager->newShare();
383
+
384
+        if ($permissions === null) {
385
+            $permissions = $this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL);
386
+        }
387
+
388
+        // Verify path
389
+        if ($path === null) {
390
+            throw new OCSNotFoundException($this->l->t('Please specify a file or folder path'));
391
+        }
392
+
393
+        $userFolder = $this->rootFolder->getUserFolder($this->currentUser);
394
+        try {
395
+            $path = $userFolder->get($path);
396
+        } catch (NotFoundException $e) {
397
+            throw new OCSNotFoundException($this->l->t('Wrong path, file/folder doesn\'t exist'));
398
+        }
399
+
400
+        $share->setNode($path);
401
+
402
+        try {
403
+            $this->lock($share->getNode());
404
+        } catch (LockedException $e) {
405
+            throw new OCSNotFoundException($this->l->t('Could not create share'));
406
+        }
407
+
408
+        if ($permissions < 0 || $permissions > Constants::PERMISSION_ALL) {
409
+            throw new OCSNotFoundException($this->l->t('invalid permissions'));
410
+        }
411
+
412
+        // Shares always require read permissions
413
+        $permissions |= Constants::PERMISSION_READ;
414
+
415
+        if ($path instanceof \OCP\Files\File) {
416
+            // Single file shares should never have delete or create permissions
417
+            $permissions &= ~Constants::PERMISSION_DELETE;
418
+            $permissions &= ~Constants::PERMISSION_CREATE;
419
+        }
420
+
421
+        /*
422 422
 		 * Hack for https://github.com/owncloud/core/issues/22587
423 423
 		 * We check the permissions via webdav. But the permissions of the mount point
424 424
 		 * do not equal the share permissions. Here we fix that for federated mounts.
425 425
 		 */
426
-		if ($path->getStorage()->instanceOfStorage(Storage::class)) {
427
-			$permissions &= ~($permissions & ~$path->getPermissions());
428
-		}
429
-
430
-		if ($shareType === Share::SHARE_TYPE_USER) {
431
-			// Valid user is required to share
432
-			if ($shareWith === null || !$this->userManager->userExists($shareWith)) {
433
-				throw new OCSNotFoundException($this->l->t('Please specify a valid user'));
434
-			}
435
-			$share->setSharedWith($shareWith);
436
-			$share->setPermissions($permissions);
437
-		} else if ($shareType === Share::SHARE_TYPE_GROUP) {
438
-			if (!$this->shareManager->allowGroupSharing()) {
439
-				throw new OCSNotFoundException($this->l->t('Group sharing is disabled by the administrator'));
440
-			}
441
-
442
-			// Valid group is required to share
443
-			if ($shareWith === null || !$this->groupManager->groupExists($shareWith)) {
444
-				throw new OCSNotFoundException($this->l->t('Please specify a valid group'));
445
-			}
446
-			$share->setSharedWith($shareWith);
447
-			$share->setPermissions($permissions);
448
-		} else if ($shareType === Share::SHARE_TYPE_LINK) {
449
-			//Can we even share links?
450
-			if (!$this->shareManager->shareApiAllowLinks()) {
451
-				throw new OCSNotFoundException($this->l->t('Public link sharing is disabled by the administrator'));
452
-			}
453
-
454
-			if ($publicUpload === 'true') {
455
-				// Check if public upload is allowed
456
-				if (!$this->shareManager->shareApiLinkAllowPublicUpload()) {
457
-					throw new OCSForbiddenException($this->l->t('Public upload disabled by the administrator'));
458
-				}
459
-
460
-				// Public upload can only be set for folders
461
-				if ($path instanceof \OCP\Files\File) {
462
-					throw new OCSNotFoundException($this->l->t('Public upload is only possible for publicly shared folders'));
463
-				}
464
-
465
-				$share->setPermissions(
466
-					Constants::PERMISSION_READ |
467
-					Constants::PERMISSION_CREATE |
468
-					Constants::PERMISSION_UPDATE |
469
-					Constants::PERMISSION_DELETE
470
-				);
471
-			} else {
472
-				$share->setPermissions(Constants::PERMISSION_READ);
473
-			}
474
-
475
-			// Set password
476
-			if ($password !== '') {
477
-				$share->setPassword($password);
478
-			}
479
-
480
-			if (!empty($label)) {
481
-				$share->setLabel($label);
482
-			}
483
-
484
-			//Expire date
485
-			if ($expireDate !== '') {
486
-				try {
487
-					$expireDate = $this->parseDate($expireDate);
488
-					$share->setExpirationDate($expireDate);
489
-				} catch (\Exception $e) {
490
-					throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD'));
491
-				}
492
-			}
493
-
494
-		} else if ($shareType === Share::SHARE_TYPE_REMOTE) {
495
-			if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) {
496
-				throw new OCSForbiddenException($this->l->t('Sharing %1$s failed because the back end does not allow shares from type %2$s', [$path->getPath(), $shareType]));
497
-			}
498
-
499
-			$share->setSharedWith($shareWith);
500
-			$share->setPermissions($permissions);
501
-		}  else if ($shareType === Share::SHARE_TYPE_REMOTE_GROUP) {
502
-			if (!$this->shareManager->outgoingServer2ServerGroupSharesAllowed()) {
503
-				throw new OCSForbiddenException($this->l->t('Sharing %1$s failed because the back end does not allow shares from type %2$s', [$path->getPath(), $shareType]));
504
-			}
505
-
506
-			$share->setSharedWith($shareWith);
507
-			$share->setPermissions($permissions);
508
-		} else if ($shareType === Share::SHARE_TYPE_EMAIL) {
509
-			if ($share->getNodeType() === 'file') {
510
-				$share->setPermissions(Constants::PERMISSION_READ);
511
-			} else {
512
-				$share->setPermissions($permissions);
513
-			}
514
-			$share->setSharedWith($shareWith);
515
-
516
-			if ($sendPasswordByTalk === 'true') {
517
-				if (!$this->appManager->isEnabledForUser('spreed')) {
518
-					throw new OCSForbiddenException($this->l->t('Sharing %s sending the password by Nextcloud Talk failed because Nextcloud Talk is not enabled', [$path->getPath()]));
519
-				}
520
-
521
-				$share->setSendPasswordByTalk(true);
522
-			}
523
-		} else if ($shareType === Share::SHARE_TYPE_CIRCLE) {
524
-			if (!\OC::$server->getAppManager()->isEnabledForUser('circles') || !class_exists('\OCA\Circles\ShareByCircleProvider')) {
525
-				throw new OCSNotFoundException($this->l->t('You cannot share to a Circle if the app is not enabled'));
526
-			}
527
-
528
-			$circle = \OCA\Circles\Api\v1\Circles::detailsCircle($shareWith);
529
-
530
-			// Valid circle is required to share
531
-			if ($circle === null) {
532
-				throw new OCSNotFoundException($this->l->t('Please specify a valid circle'));
533
-			}
534
-			$share->setSharedWith($shareWith);
535
-			$share->setPermissions($permissions);
536
-		} else if ($shareType === Share::SHARE_TYPE_ROOM) {
537
-			try {
538
-				$this->getRoomShareHelper()->createShare($share, $shareWith, $permissions, $expireDate);
539
-			} catch (QueryException $e) {
540
-				throw new OCSForbiddenException($this->l->t('Sharing %s failed because the back end does not support room shares', [$path->getPath()]));
541
-			}
542
-		} else {
543
-			throw new OCSBadRequestException($this->l->t('Unknown share type'));
544
-		}
545
-
546
-		$share->setShareType($shareType);
547
-		$share->setSharedBy($this->currentUser);
548
-
549
-		try {
550
-			$share = $this->shareManager->createShare($share);
551
-		} catch (GenericShareException $e) {
552
-			$code = $e->getCode() === 0 ? 403 : $e->getCode();
553
-			throw new OCSException($e->getHint(), $code);
554
-		} catch (\Exception $e) {
555
-			throw new OCSForbiddenException($e->getMessage(), $e);
556
-		}
557
-
558
-		$output = $this->formatShare($share);
559
-
560
-		return new DataResponse($output);
561
-	}
562
-
563
-	/**
564
-	 * @param \OCP\Files\File|\OCP\Files\Folder $node
565
-	 * @param boolean $includeTags
566
-	 * @return DataResponse
567
-	 */
568
-	private function getSharedWithMe($node = null, bool $includeTags): DataResponse {
569
-
570
-		$userShares = $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_USER, $node, -1, 0);
571
-		$groupShares = $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_GROUP, $node, -1, 0);
572
-		$circleShares = $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_CIRCLE, $node, -1, 0);
573
-		$roomShares = $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_ROOM, $node, -1, 0);
574
-
575
-		$shares = array_merge($userShares, $groupShares, $circleShares, $roomShares);
576
-
577
-		$shares = array_filter($shares, function (IShare $share) {
578
-			return $share->getShareOwner() !== $this->currentUser;
579
-		});
580
-
581
-		$formatted = [];
582
-		foreach ($shares as $share) {
583
-			if ($this->canAccessShare($share)) {
584
-				try {
585
-					$formatted[] = $this->formatShare($share);
586
-				} catch (NotFoundException $e) {
587
-					// Ignore this share
588
-				}
589
-			}
590
-		}
591
-
592
-		if ($includeTags) {
593
-			$formatted = Helper::populateTags($formatted, 'file_source', \OC::$server->getTagManager());
594
-		}
595
-
596
-		return new DataResponse($formatted);
597
-	}
598
-
599
-	/**
600
-	 * @param \OCP\Files\Folder $folder
601
-	 * @return DataResponse
602
-	 * @throws OCSBadRequestException
603
-	 */
604
-	private function getSharesInDir(Node $folder): DataResponse {
605
-		if (!($folder instanceof \OCP\Files\Folder)) {
606
-			throw new OCSBadRequestException($this->l->t('Not a directory'));
607
-		}
608
-
609
-		$nodes = $folder->getDirectoryListing();
610
-		/** @var \OCP\Share\IShare[] $shares */
611
-		$shares = [];
612
-		foreach ($nodes as $node) {
613
-			$shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_USER, $node, false, -1, 0));
614
-			$shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_GROUP, $node, false, -1, 0));
615
-			$shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_LINK, $node, false, -1, 0));
616
-			if($this->shareManager->shareProviderExists(Share::SHARE_TYPE_EMAIL)) {
617
-				$shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_EMAIL, $node, false, -1, 0));
618
-			}
619
-			if ($this->shareManager->outgoingServer2ServerSharesAllowed()) {
620
-				$shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_REMOTE, $node, false, -1, 0));
621
-			}
622
-			$shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_ROOM, $node, false, -1, 0));
623
-		}
624
-
625
-		$formatted = [];
626
-		foreach ($shares as $share) {
627
-			try {
628
-				$formatted[] = $this->formatShare($share);
629
-			} catch (NotFoundException $e) {
630
-				//Ignore this share
631
-			}
632
-		}
633
-
634
-		return new DataResponse($formatted);
635
-	}
636
-
637
-	/**
638
-	 * The getShares function.
639
-	 *
640
-	 * @NoAdminRequired
641
-	 *
642
-	 * @param string $shared_with_me
643
-	 * @param string $reshares
644
-	 * @param string $subfiles
645
-	 * @param string $path
646
-	 *
647
-	 * - Get shares by the current user
648
-	 * - Get shares by the current user and reshares (?reshares=true)
649
-	 * - Get shares with the current user (?shared_with_me=true)
650
-	 * - Get shares for a specific path (?path=...)
651
-	 * - Get all shares in a folder (?subfiles=true&path=..)
652
-	 *
653
-	 * @return DataResponse
654
-	 * @throws OCSNotFoundException
655
-	 */
656
-	public function getShares(
657
-		string $shared_with_me = 'false',
658
-		string $reshares = 'false',
659
-		string $subfiles = 'false',
660
-		string $path = null,
661
-		string $include_tags = 'false'
662
-	): DataResponse {
663
-
664
-		if ($path !== null) {
665
-			$userFolder = $this->rootFolder->getUserFolder($this->currentUser);
666
-			try {
667
-				$path = $userFolder->get($path);
668
-				$this->lock($path);
669
-			} catch (\OCP\Files\NotFoundException $e) {
670
-				throw new OCSNotFoundException($this->l->t('Wrong path, file/folder doesn\'t exist'));
671
-			} catch (LockedException $e) {
672
-				throw new OCSNotFoundException($this->l->t('Could not lock path'));
673
-			}
674
-		}
675
-
676
-		$include_tags = $include_tags === 'true';
677
-
678
-		if ($shared_with_me === 'true') {
679
-			$result = $this->getSharedWithMe($path, $include_tags);
680
-			return $result;
681
-		}
682
-
683
-		if ($subfiles === 'true') {
684
-			$result = $this->getSharesInDir($path);
685
-			return $result;
686
-		}
687
-
688
-		if ($reshares === 'true') {
689
-			$reshares = true;
690
-		} else {
691
-			$reshares = false;
692
-		}
693
-
694
-		// Get all shares
695
-		$userShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_USER, $path, $reshares, -1, 0);
696
-		$groupShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_GROUP, $path, $reshares, -1, 0);
697
-		$linkShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_LINK, $path, $reshares, -1, 0);
698
-		if ($this->shareManager->shareProviderExists(Share::SHARE_TYPE_EMAIL)) {
699
-			$mailShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_EMAIL, $path, $reshares, -1, 0);
700
-		} else {
701
-			$mailShares = [];
702
-		}
703
-		if ($this->shareManager->shareProviderExists(Share::SHARE_TYPE_CIRCLE)) {
704
-			$circleShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_CIRCLE, $path, $reshares, -1, 0);
705
-		} else {
706
-			$circleShares = [];
707
-		}
708
-		$roomShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_ROOM, $path, $reshares, -1, 0);
709
-
710
-		$shares = array_merge($userShares, $groupShares, $linkShares, $mailShares, $circleShares, $roomShares);
711
-
712
-		if ($this->shareManager->outgoingServer2ServerSharesAllowed()) {
713
-			$federatedShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_REMOTE, $path, $reshares, -1, 0);
714
-			$shares = array_merge($shares, $federatedShares);
715
-		}
716
-
717
-		if ($this->shareManager->outgoingServer2ServerGroupSharesAllowed()) {
718
-			$federatedShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_REMOTE_GROUP, $path, $reshares, -1, 0);
719
-			$shares = array_merge($shares, $federatedShares);
720
-		}
721
-
722
-		$formatted = [];
723
-		foreach ($shares as $share) {
724
-			try {
725
-				$formatted[] = $this->formatShare($share, $path);
726
-			} catch (NotFoundException $e) {
727
-				//Ignore share
728
-			}
729
-		}
730
-
731
-		if ($include_tags) {
732
-			$formatted = Helper::populateTags($formatted, 'file_source', \OC::$server->getTagManager());
733
-		}
734
-
735
-		return new DataResponse($formatted);
736
-	}
737
-
738
-	/**
739
-	 * @NoAdminRequired
740
-	 *
741
-	 * @param string $id
742
-	 * @param int $permissions
743
-	 * @param string $password
744
-	 * @param string $sendPasswordByTalk
745
-	 * @param string $publicUpload
746
-	 * @param string $expireDate
747
-	 * @param string $note
748
-	 * @param string $label
749
-	 * @param string $hideDownload
750
-	 * @return DataResponse
751
-	 * @throws LockedException
752
-	 * @throws NotFoundException
753
-	 * @throws OCSBadRequestException
754
-	 * @throws OCSForbiddenException
755
-	 * @throws OCSNotFoundException
756
-	 */
757
-	public function updateShare(
758
-		string $id,
759
-		int $permissions = null,
760
-		string $password = null,
761
-		string $sendPasswordByTalk = null,
762
-		string $publicUpload = null,
763
-		string $expireDate = null,
764
-		string $note = null,
765
-		string $label = null,
766
-		string $hideDownload = null
767
-	): DataResponse {
768
-		try {
769
-			$share = $this->getShareById($id);
770
-		} catch (ShareNotFound $e) {
771
-			throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
772
-		}
773
-
774
-		$this->lock($share->getNode());
775
-
776
-		if (!$this->canAccessShare($share, false)) {
777
-			throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
778
-		}
779
-
780
-		if ($permissions === null &&
781
-			$password === null &&
782
-			$sendPasswordByTalk === null &&
783
-			$publicUpload === null &&
784
-			$expireDate === null &&
785
-			$note === null &&
786
-			$label === null &&
787
-			$hideDownload === null
788
-		) {
789
-			throw new OCSBadRequestException($this->l->t('Wrong or no update parameter given'));
790
-		}
791
-
792
-		if($note !== null) {
793
-			$share->setNote($note);
794
-		}
795
-
796
-		/*
426
+        if ($path->getStorage()->instanceOfStorage(Storage::class)) {
427
+            $permissions &= ~($permissions & ~$path->getPermissions());
428
+        }
429
+
430
+        if ($shareType === Share::SHARE_TYPE_USER) {
431
+            // Valid user is required to share
432
+            if ($shareWith === null || !$this->userManager->userExists($shareWith)) {
433
+                throw new OCSNotFoundException($this->l->t('Please specify a valid user'));
434
+            }
435
+            $share->setSharedWith($shareWith);
436
+            $share->setPermissions($permissions);
437
+        } else if ($shareType === Share::SHARE_TYPE_GROUP) {
438
+            if (!$this->shareManager->allowGroupSharing()) {
439
+                throw new OCSNotFoundException($this->l->t('Group sharing is disabled by the administrator'));
440
+            }
441
+
442
+            // Valid group is required to share
443
+            if ($shareWith === null || !$this->groupManager->groupExists($shareWith)) {
444
+                throw new OCSNotFoundException($this->l->t('Please specify a valid group'));
445
+            }
446
+            $share->setSharedWith($shareWith);
447
+            $share->setPermissions($permissions);
448
+        } else if ($shareType === Share::SHARE_TYPE_LINK) {
449
+            //Can we even share links?
450
+            if (!$this->shareManager->shareApiAllowLinks()) {
451
+                throw new OCSNotFoundException($this->l->t('Public link sharing is disabled by the administrator'));
452
+            }
453
+
454
+            if ($publicUpload === 'true') {
455
+                // Check if public upload is allowed
456
+                if (!$this->shareManager->shareApiLinkAllowPublicUpload()) {
457
+                    throw new OCSForbiddenException($this->l->t('Public upload disabled by the administrator'));
458
+                }
459
+
460
+                // Public upload can only be set for folders
461
+                if ($path instanceof \OCP\Files\File) {
462
+                    throw new OCSNotFoundException($this->l->t('Public upload is only possible for publicly shared folders'));
463
+                }
464
+
465
+                $share->setPermissions(
466
+                    Constants::PERMISSION_READ |
467
+                    Constants::PERMISSION_CREATE |
468
+                    Constants::PERMISSION_UPDATE |
469
+                    Constants::PERMISSION_DELETE
470
+                );
471
+            } else {
472
+                $share->setPermissions(Constants::PERMISSION_READ);
473
+            }
474
+
475
+            // Set password
476
+            if ($password !== '') {
477
+                $share->setPassword($password);
478
+            }
479
+
480
+            if (!empty($label)) {
481
+                $share->setLabel($label);
482
+            }
483
+
484
+            //Expire date
485
+            if ($expireDate !== '') {
486
+                try {
487
+                    $expireDate = $this->parseDate($expireDate);
488
+                    $share->setExpirationDate($expireDate);
489
+                } catch (\Exception $e) {
490
+                    throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD'));
491
+                }
492
+            }
493
+
494
+        } else if ($shareType === Share::SHARE_TYPE_REMOTE) {
495
+            if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) {
496
+                throw new OCSForbiddenException($this->l->t('Sharing %1$s failed because the back end does not allow shares from type %2$s', [$path->getPath(), $shareType]));
497
+            }
498
+
499
+            $share->setSharedWith($shareWith);
500
+            $share->setPermissions($permissions);
501
+        }  else if ($shareType === Share::SHARE_TYPE_REMOTE_GROUP) {
502
+            if (!$this->shareManager->outgoingServer2ServerGroupSharesAllowed()) {
503
+                throw new OCSForbiddenException($this->l->t('Sharing %1$s failed because the back end does not allow shares from type %2$s', [$path->getPath(), $shareType]));
504
+            }
505
+
506
+            $share->setSharedWith($shareWith);
507
+            $share->setPermissions($permissions);
508
+        } else if ($shareType === Share::SHARE_TYPE_EMAIL) {
509
+            if ($share->getNodeType() === 'file') {
510
+                $share->setPermissions(Constants::PERMISSION_READ);
511
+            } else {
512
+                $share->setPermissions($permissions);
513
+            }
514
+            $share->setSharedWith($shareWith);
515
+
516
+            if ($sendPasswordByTalk === 'true') {
517
+                if (!$this->appManager->isEnabledForUser('spreed')) {
518
+                    throw new OCSForbiddenException($this->l->t('Sharing %s sending the password by Nextcloud Talk failed because Nextcloud Talk is not enabled', [$path->getPath()]));
519
+                }
520
+
521
+                $share->setSendPasswordByTalk(true);
522
+            }
523
+        } else if ($shareType === Share::SHARE_TYPE_CIRCLE) {
524
+            if (!\OC::$server->getAppManager()->isEnabledForUser('circles') || !class_exists('\OCA\Circles\ShareByCircleProvider')) {
525
+                throw new OCSNotFoundException($this->l->t('You cannot share to a Circle if the app is not enabled'));
526
+            }
527
+
528
+            $circle = \OCA\Circles\Api\v1\Circles::detailsCircle($shareWith);
529
+
530
+            // Valid circle is required to share
531
+            if ($circle === null) {
532
+                throw new OCSNotFoundException($this->l->t('Please specify a valid circle'));
533
+            }
534
+            $share->setSharedWith($shareWith);
535
+            $share->setPermissions($permissions);
536
+        } else if ($shareType === Share::SHARE_TYPE_ROOM) {
537
+            try {
538
+                $this->getRoomShareHelper()->createShare($share, $shareWith, $permissions, $expireDate);
539
+            } catch (QueryException $e) {
540
+                throw new OCSForbiddenException($this->l->t('Sharing %s failed because the back end does not support room shares', [$path->getPath()]));
541
+            }
542
+        } else {
543
+            throw new OCSBadRequestException($this->l->t('Unknown share type'));
544
+        }
545
+
546
+        $share->setShareType($shareType);
547
+        $share->setSharedBy($this->currentUser);
548
+
549
+        try {
550
+            $share = $this->shareManager->createShare($share);
551
+        } catch (GenericShareException $e) {
552
+            $code = $e->getCode() === 0 ? 403 : $e->getCode();
553
+            throw new OCSException($e->getHint(), $code);
554
+        } catch (\Exception $e) {
555
+            throw new OCSForbiddenException($e->getMessage(), $e);
556
+        }
557
+
558
+        $output = $this->formatShare($share);
559
+
560
+        return new DataResponse($output);
561
+    }
562
+
563
+    /**
564
+     * @param \OCP\Files\File|\OCP\Files\Folder $node
565
+     * @param boolean $includeTags
566
+     * @return DataResponse
567
+     */
568
+    private function getSharedWithMe($node = null, bool $includeTags): DataResponse {
569
+
570
+        $userShares = $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_USER, $node, -1, 0);
571
+        $groupShares = $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_GROUP, $node, -1, 0);
572
+        $circleShares = $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_CIRCLE, $node, -1, 0);
573
+        $roomShares = $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_ROOM, $node, -1, 0);
574
+
575
+        $shares = array_merge($userShares, $groupShares, $circleShares, $roomShares);
576
+
577
+        $shares = array_filter($shares, function (IShare $share) {
578
+            return $share->getShareOwner() !== $this->currentUser;
579
+        });
580
+
581
+        $formatted = [];
582
+        foreach ($shares as $share) {
583
+            if ($this->canAccessShare($share)) {
584
+                try {
585
+                    $formatted[] = $this->formatShare($share);
586
+                } catch (NotFoundException $e) {
587
+                    // Ignore this share
588
+                }
589
+            }
590
+        }
591
+
592
+        if ($includeTags) {
593
+            $formatted = Helper::populateTags($formatted, 'file_source', \OC::$server->getTagManager());
594
+        }
595
+
596
+        return new DataResponse($formatted);
597
+    }
598
+
599
+    /**
600
+     * @param \OCP\Files\Folder $folder
601
+     * @return DataResponse
602
+     * @throws OCSBadRequestException
603
+     */
604
+    private function getSharesInDir(Node $folder): DataResponse {
605
+        if (!($folder instanceof \OCP\Files\Folder)) {
606
+            throw new OCSBadRequestException($this->l->t('Not a directory'));
607
+        }
608
+
609
+        $nodes = $folder->getDirectoryListing();
610
+        /** @var \OCP\Share\IShare[] $shares */
611
+        $shares = [];
612
+        foreach ($nodes as $node) {
613
+            $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_USER, $node, false, -1, 0));
614
+            $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_GROUP, $node, false, -1, 0));
615
+            $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_LINK, $node, false, -1, 0));
616
+            if($this->shareManager->shareProviderExists(Share::SHARE_TYPE_EMAIL)) {
617
+                $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_EMAIL, $node, false, -1, 0));
618
+            }
619
+            if ($this->shareManager->outgoingServer2ServerSharesAllowed()) {
620
+                $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_REMOTE, $node, false, -1, 0));
621
+            }
622
+            $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_ROOM, $node, false, -1, 0));
623
+        }
624
+
625
+        $formatted = [];
626
+        foreach ($shares as $share) {
627
+            try {
628
+                $formatted[] = $this->formatShare($share);
629
+            } catch (NotFoundException $e) {
630
+                //Ignore this share
631
+            }
632
+        }
633
+
634
+        return new DataResponse($formatted);
635
+    }
636
+
637
+    /**
638
+     * The getShares function.
639
+     *
640
+     * @NoAdminRequired
641
+     *
642
+     * @param string $shared_with_me
643
+     * @param string $reshares
644
+     * @param string $subfiles
645
+     * @param string $path
646
+     *
647
+     * - Get shares by the current user
648
+     * - Get shares by the current user and reshares (?reshares=true)
649
+     * - Get shares with the current user (?shared_with_me=true)
650
+     * - Get shares for a specific path (?path=...)
651
+     * - Get all shares in a folder (?subfiles=true&path=..)
652
+     *
653
+     * @return DataResponse
654
+     * @throws OCSNotFoundException
655
+     */
656
+    public function getShares(
657
+        string $shared_with_me = 'false',
658
+        string $reshares = 'false',
659
+        string $subfiles = 'false',
660
+        string $path = null,
661
+        string $include_tags = 'false'
662
+    ): DataResponse {
663
+
664
+        if ($path !== null) {
665
+            $userFolder = $this->rootFolder->getUserFolder($this->currentUser);
666
+            try {
667
+                $path = $userFolder->get($path);
668
+                $this->lock($path);
669
+            } catch (\OCP\Files\NotFoundException $e) {
670
+                throw new OCSNotFoundException($this->l->t('Wrong path, file/folder doesn\'t exist'));
671
+            } catch (LockedException $e) {
672
+                throw new OCSNotFoundException($this->l->t('Could not lock path'));
673
+            }
674
+        }
675
+
676
+        $include_tags = $include_tags === 'true';
677
+
678
+        if ($shared_with_me === 'true') {
679
+            $result = $this->getSharedWithMe($path, $include_tags);
680
+            return $result;
681
+        }
682
+
683
+        if ($subfiles === 'true') {
684
+            $result = $this->getSharesInDir($path);
685
+            return $result;
686
+        }
687
+
688
+        if ($reshares === 'true') {
689
+            $reshares = true;
690
+        } else {
691
+            $reshares = false;
692
+        }
693
+
694
+        // Get all shares
695
+        $userShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_USER, $path, $reshares, -1, 0);
696
+        $groupShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_GROUP, $path, $reshares, -1, 0);
697
+        $linkShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_LINK, $path, $reshares, -1, 0);
698
+        if ($this->shareManager->shareProviderExists(Share::SHARE_TYPE_EMAIL)) {
699
+            $mailShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_EMAIL, $path, $reshares, -1, 0);
700
+        } else {
701
+            $mailShares = [];
702
+        }
703
+        if ($this->shareManager->shareProviderExists(Share::SHARE_TYPE_CIRCLE)) {
704
+            $circleShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_CIRCLE, $path, $reshares, -1, 0);
705
+        } else {
706
+            $circleShares = [];
707
+        }
708
+        $roomShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_ROOM, $path, $reshares, -1, 0);
709
+
710
+        $shares = array_merge($userShares, $groupShares, $linkShares, $mailShares, $circleShares, $roomShares);
711
+
712
+        if ($this->shareManager->outgoingServer2ServerSharesAllowed()) {
713
+            $federatedShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_REMOTE, $path, $reshares, -1, 0);
714
+            $shares = array_merge($shares, $federatedShares);
715
+        }
716
+
717
+        if ($this->shareManager->outgoingServer2ServerGroupSharesAllowed()) {
718
+            $federatedShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_REMOTE_GROUP, $path, $reshares, -1, 0);
719
+            $shares = array_merge($shares, $federatedShares);
720
+        }
721
+
722
+        $formatted = [];
723
+        foreach ($shares as $share) {
724
+            try {
725
+                $formatted[] = $this->formatShare($share, $path);
726
+            } catch (NotFoundException $e) {
727
+                //Ignore share
728
+            }
729
+        }
730
+
731
+        if ($include_tags) {
732
+            $formatted = Helper::populateTags($formatted, 'file_source', \OC::$server->getTagManager());
733
+        }
734
+
735
+        return new DataResponse($formatted);
736
+    }
737
+
738
+    /**
739
+     * @NoAdminRequired
740
+     *
741
+     * @param string $id
742
+     * @param int $permissions
743
+     * @param string $password
744
+     * @param string $sendPasswordByTalk
745
+     * @param string $publicUpload
746
+     * @param string $expireDate
747
+     * @param string $note
748
+     * @param string $label
749
+     * @param string $hideDownload
750
+     * @return DataResponse
751
+     * @throws LockedException
752
+     * @throws NotFoundException
753
+     * @throws OCSBadRequestException
754
+     * @throws OCSForbiddenException
755
+     * @throws OCSNotFoundException
756
+     */
757
+    public function updateShare(
758
+        string $id,
759
+        int $permissions = null,
760
+        string $password = null,
761
+        string $sendPasswordByTalk = null,
762
+        string $publicUpload = null,
763
+        string $expireDate = null,
764
+        string $note = null,
765
+        string $label = null,
766
+        string $hideDownload = null
767
+    ): DataResponse {
768
+        try {
769
+            $share = $this->getShareById($id);
770
+        } catch (ShareNotFound $e) {
771
+            throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
772
+        }
773
+
774
+        $this->lock($share->getNode());
775
+
776
+        if (!$this->canAccessShare($share, false)) {
777
+            throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
778
+        }
779
+
780
+        if ($permissions === null &&
781
+            $password === null &&
782
+            $sendPasswordByTalk === null &&
783
+            $publicUpload === null &&
784
+            $expireDate === null &&
785
+            $note === null &&
786
+            $label === null &&
787
+            $hideDownload === null
788
+        ) {
789
+            throw new OCSBadRequestException($this->l->t('Wrong or no update parameter given'));
790
+        }
791
+
792
+        if($note !== null) {
793
+            $share->setNote($note);
794
+        }
795
+
796
+        /*
797 797
 		 * expirationdate, password and publicUpload only make sense for link shares
798 798
 		 */
799
-		if ($share->getShareType() === Share::SHARE_TYPE_LINK) {
800
-
801
-			// Update hide download state
802
-			if ($hideDownload === 'true') {
803
-				$share->setHideDownload(true);
804
-			} else if ($hideDownload === 'false') {
805
-				$share->setHideDownload(false);
806
-			}
807
-
808
-			$newPermissions = null;
809
-			if ($publicUpload === 'true') {
810
-				$newPermissions = Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE;
811
-			} else if ($publicUpload === 'false') {
812
-				$newPermissions = Constants::PERMISSION_READ;
813
-			}
814
-
815
-			if ($permissions !== null) {
816
-				$newPermissions = (int)$permissions;
817
-				$newPermissions = $newPermissions & ~Constants::PERMISSION_SHARE;
818
-			}
819
-
820
-			if ($newPermissions !== null &&
821
-				!in_array($newPermissions, [
822
-					Constants::PERMISSION_READ,
823
-					Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE, // legacy
824
-					Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE, // correct
825
-					Constants::PERMISSION_CREATE, // hidden file list
826
-					Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE, // allow to edit single files
827
-				], true)
828
-			) {
829
-				throw new OCSBadRequestException($this->l->t('Can\'t change permissions for public share links'));
830
-			}
831
-
832
-			if (
833
-				// legacy
834
-				$newPermissions === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE) ||
835
-				// correct
836
-				$newPermissions === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE)
837
-			) {
838
-				if (!$this->shareManager->shareApiLinkAllowPublicUpload()) {
839
-					throw new OCSForbiddenException($this->l->t('Public upload disabled by the administrator'));
840
-				}
841
-
842
-				if (!($share->getNode() instanceof \OCP\Files\Folder)) {
843
-					throw new OCSBadRequestException($this->l->t('Public upload is only possible for publicly shared folders'));
844
-				}
845
-
846
-				// normalize to correct public upload permissions
847
-				$newPermissions = Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE;
848
-			}
849
-
850
-			if ($newPermissions !== null) {
851
-				$share->setPermissions($newPermissions);
852
-				$permissions = $newPermissions;
853
-			}
854
-
855
-			if ($expireDate === '') {
856
-				$share->setExpirationDate(null);
857
-			} else if ($expireDate !== null) {
858
-				try {
859
-					$expireDate = $this->parseDate($expireDate);
860
-				} catch (\Exception $e) {
861
-					throw new OCSBadRequestException($e->getMessage(), $e);
862
-				}
863
-				$share->setExpirationDate($expireDate);
864
-			}
865
-
866
-			if ($password === '') {
867
-				$share->setPassword(null);
868
-			} else if ($password !== null) {
869
-				$share->setPassword($password);
870
-			}
871
-
872
-			if ($label !== null) {
873
-				$share->setLabel($label);
874
-			}
875
-
876
-		} else {
877
-			if ($permissions !== null) {
878
-				$permissions = (int)$permissions;
879
-				$share->setPermissions($permissions);
880
-			}
881
-
882
-			if ($share->getShareType() === Share::SHARE_TYPE_EMAIL) {
883
-				if ($password === '') {
884
-					$share->setPassword(null);
885
-				} else if ($password !== null) {
886
-					$share->setPassword($password);
887
-				}
888
-
889
-				if ($sendPasswordByTalk === 'true') {
890
-					if (!$this->appManager->isEnabledForUser('spreed')) {
891
-						throw new OCSForbiddenException($this->l->t('Sharing sending the password by Nextcloud Talk failed because Nextcloud Talk is not enabled'));
892
-					}
893
-
894
-					$share->setSendPasswordByTalk(true);
895
-				} else {
896
-					$share->setSendPasswordByTalk(false);
897
-				}
898
-			}
899
-
900
-			if ($expireDate === '') {
901
-				$share->setExpirationDate(null);
902
-			} else if ($expireDate !== null) {
903
-				try {
904
-					$expireDate = $this->parseDate($expireDate);
905
-				} catch (\Exception $e) {
906
-					throw new OCSBadRequestException($e->getMessage(), $e);
907
-				}
908
-				$share->setExpirationDate($expireDate);
909
-			}
910
-
911
-		}
912
-
913
-		if ($permissions !== null && $share->getShareOwner() !== $this->currentUser) {
914
-			/* Check if this is an incomming share */
915
-			$incomingShares = $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_USER, $share->getNode(), -1, 0);
916
-			$incomingShares = array_merge($incomingShares, $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_GROUP, $share->getNode(), -1, 0));
917
-			$incomingShares = array_merge($incomingShares, $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_ROOM, $share->getNode(), -1, 0));
918
-
919
-			/** @var \OCP\Share\IShare[] $incomingShares */
920
-			if (!empty($incomingShares)) {
921
-				$maxPermissions = 0;
922
-				foreach ($incomingShares as $incomingShare) {
923
-					$maxPermissions |= $incomingShare->getPermissions();
924
-				}
925
-
926
-				if ($share->getPermissions() & ~$maxPermissions) {
927
-					throw new OCSNotFoundException($this->l->t('Cannot increase permissions'));
928
-				}
929
-			}
930
-		}
931
-
932
-
933
-		try {
934
-			$share = $this->shareManager->updateShare($share);
935
-		} catch (\Exception $e) {
936
-			throw new OCSBadRequestException($e->getMessage(), $e);
937
-		}
938
-
939
-		return new DataResponse($this->formatShare($share));
940
-	}
941
-
942
-	/**
943
-	 * @suppress PhanUndeclaredClassMethod
944
-	 */
945
-	protected function canAccessShare(\OCP\Share\IShare $share, bool $checkGroups = true): bool {
946
-		// A file with permissions 0 can't be accessed by us. So Don't show it
947
-		if ($share->getPermissions() === 0) {
948
-			return false;
949
-		}
950
-
951
-		// Owner of the file and the sharer of the file can always get share
952
-		if ($share->getShareOwner() === $this->currentUser ||
953
-			$share->getSharedBy() === $this->currentUser
954
-		) {
955
-			return true;
956
-		}
957
-
958
-		// If the share is shared with you (or a group you are a member of)
959
-		if ($share->getShareType() === Share::SHARE_TYPE_USER &&
960
-			$share->getSharedWith() === $this->currentUser
961
-		) {
962
-			return true;
963
-		}
964
-
965
-		if ($checkGroups && $share->getShareType() === Share::SHARE_TYPE_GROUP) {
966
-			$sharedWith = $this->groupManager->get($share->getSharedWith());
967
-			$user = $this->userManager->get($this->currentUser);
968
-			if ($user !== null && $sharedWith !== null && $sharedWith->inGroup($user)) {
969
-				return true;
970
-			}
971
-		}
972
-
973
-		if ($share->getShareType() === Share::SHARE_TYPE_CIRCLE) {
974
-			// TODO: have a sanity check like above?
975
-			return true;
976
-		}
977
-
978
-		if ($share->getShareType() === Share::SHARE_TYPE_ROOM) {
979
-			try {
980
-				return $this->getRoomShareHelper()->canAccessShare($share, $this->currentUser);
981
-			} catch (QueryException $e) {
982
-				return false;
983
-			}
984
-		}
985
-
986
-		return false;
987
-	}
988
-
989
-	/**
990
-	 * Make sure that the passed date is valid ISO 8601
991
-	 * So YYYY-MM-DD
992
-	 * If not throw an exception
993
-	 *
994
-	 * @param string $expireDate
995
-	 *
996
-	 * @throws \Exception
997
-	 * @return \DateTime
998
-	 */
999
-	private function parseDate(string $expireDate): \DateTime {
1000
-		try {
1001
-			$date = new \DateTime($expireDate);
1002
-		} catch (\Exception $e) {
1003
-			throw new \Exception('Invalid date. Format must be YYYY-MM-DD');
1004
-		}
1005
-
1006
-		if ($date === false) {
1007
-			throw new \Exception('Invalid date. Format must be YYYY-MM-DD');
1008
-		}
1009
-
1010
-		$date->setTime(0, 0, 0);
1011
-
1012
-		return $date;
1013
-	}
1014
-
1015
-	/**
1016
-	 * Since we have multiple providers but the OCS Share API v1 does
1017
-	 * not support this we need to check all backends.
1018
-	 *
1019
-	 * @param string $id
1020
-	 * @return \OCP\Share\IShare
1021
-	 * @throws ShareNotFound
1022
-	 */
1023
-	private function getShareById(string $id): IShare {
1024
-		$share = null;
1025
-
1026
-		// First check if it is an internal share.
1027
-		try {
1028
-			$share = $this->shareManager->getShareById('ocinternal:' . $id, $this->currentUser);
1029
-			return $share;
1030
-		} catch (ShareNotFound $e) {
1031
-			// Do nothing, just try the other share type
1032
-		}
1033
-
1034
-
1035
-		try {
1036
-			if ($this->shareManager->shareProviderExists(Share::SHARE_TYPE_CIRCLE)) {
1037
-				$share = $this->shareManager->getShareById('ocCircleShare:' . $id, $this->currentUser);
1038
-				return $share;
1039
-			}
1040
-		} catch (ShareNotFound $e) {
1041
-			// Do nothing, just try the other share type
1042
-		}
1043
-
1044
-		try {
1045
-			if ($this->shareManager->shareProviderExists(Share::SHARE_TYPE_EMAIL)) {
1046
-				$share = $this->shareManager->getShareById('ocMailShare:' . $id, $this->currentUser);
1047
-				return $share;
1048
-			}
1049
-		} catch (ShareNotFound $e) {
1050
-			// Do nothing, just try the other share type
1051
-		}
1052
-
1053
-		try {
1054
-			$share = $this->shareManager->getShareById('ocRoomShare:' . $id, $this->currentUser);
1055
-			return $share;
1056
-		} catch (ShareNotFound $e) {
1057
-			// Do nothing, just try the other share type
1058
-		}
1059
-
1060
-		if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) {
1061
-			throw new ShareNotFound();
1062
-		}
1063
-		$share = $this->shareManager->getShareById('ocFederatedSharing:' . $id, $this->currentUser);
1064
-
1065
-		return $share;
1066
-	}
1067
-
1068
-	/**
1069
-	 * Lock a Node
1070
-	 *
1071
-	 * @param \OCP\Files\Node $node
1072
-	 * @throws LockedException
1073
-	 */
1074
-	private function lock(\OCP\Files\Node $node) {
1075
-		$node->lock(ILockingProvider::LOCK_SHARED);
1076
-		$this->lockedNode = $node;
1077
-	}
1078
-
1079
-	/**
1080
-	 * Cleanup the remaining locks
1081
-	 * @throws @LockedException
1082
-	 */
1083
-	public function cleanup() {
1084
-		if ($this->lockedNode !== null) {
1085
-			$this->lockedNode->unlock(ILockingProvider::LOCK_SHARED);
1086
-		}
1087
-	}
1088
-
1089
-	/**
1090
-	 * Returns the helper of ShareAPIController for room shares.
1091
-	 *
1092
-	 * If the Talk application is not enabled or the helper is not available
1093
-	 * a QueryException is thrown instead.
1094
-	 *
1095
-	 * @return \OCA\Spreed\Share\Helper\ShareAPIController
1096
-	 * @throws QueryException
1097
-	 */
1098
-	private function getRoomShareHelper() {
1099
-		if (!$this->appManager->isEnabledForUser('spreed')) {
1100
-			throw new QueryException();
1101
-		}
1102
-
1103
-		return $this->serverContainer->query('\OCA\Spreed\Share\Helper\ShareAPIController');
1104
-	}
799
+        if ($share->getShareType() === Share::SHARE_TYPE_LINK) {
800
+
801
+            // Update hide download state
802
+            if ($hideDownload === 'true') {
803
+                $share->setHideDownload(true);
804
+            } else if ($hideDownload === 'false') {
805
+                $share->setHideDownload(false);
806
+            }
807
+
808
+            $newPermissions = null;
809
+            if ($publicUpload === 'true') {
810
+                $newPermissions = Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE;
811
+            } else if ($publicUpload === 'false') {
812
+                $newPermissions = Constants::PERMISSION_READ;
813
+            }
814
+
815
+            if ($permissions !== null) {
816
+                $newPermissions = (int)$permissions;
817
+                $newPermissions = $newPermissions & ~Constants::PERMISSION_SHARE;
818
+            }
819
+
820
+            if ($newPermissions !== null &&
821
+                !in_array($newPermissions, [
822
+                    Constants::PERMISSION_READ,
823
+                    Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE, // legacy
824
+                    Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE, // correct
825
+                    Constants::PERMISSION_CREATE, // hidden file list
826
+                    Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE, // allow to edit single files
827
+                ], true)
828
+            ) {
829
+                throw new OCSBadRequestException($this->l->t('Can\'t change permissions for public share links'));
830
+            }
831
+
832
+            if (
833
+                // legacy
834
+                $newPermissions === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE) ||
835
+                // correct
836
+                $newPermissions === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE)
837
+            ) {
838
+                if (!$this->shareManager->shareApiLinkAllowPublicUpload()) {
839
+                    throw new OCSForbiddenException($this->l->t('Public upload disabled by the administrator'));
840
+                }
841
+
842
+                if (!($share->getNode() instanceof \OCP\Files\Folder)) {
843
+                    throw new OCSBadRequestException($this->l->t('Public upload is only possible for publicly shared folders'));
844
+                }
845
+
846
+                // normalize to correct public upload permissions
847
+                $newPermissions = Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE;
848
+            }
849
+
850
+            if ($newPermissions !== null) {
851
+                $share->setPermissions($newPermissions);
852
+                $permissions = $newPermissions;
853
+            }
854
+
855
+            if ($expireDate === '') {
856
+                $share->setExpirationDate(null);
857
+            } else if ($expireDate !== null) {
858
+                try {
859
+                    $expireDate = $this->parseDate($expireDate);
860
+                } catch (\Exception $e) {
861
+                    throw new OCSBadRequestException($e->getMessage(), $e);
862
+                }
863
+                $share->setExpirationDate($expireDate);
864
+            }
865
+
866
+            if ($password === '') {
867
+                $share->setPassword(null);
868
+            } else if ($password !== null) {
869
+                $share->setPassword($password);
870
+            }
871
+
872
+            if ($label !== null) {
873
+                $share->setLabel($label);
874
+            }
875
+
876
+        } else {
877
+            if ($permissions !== null) {
878
+                $permissions = (int)$permissions;
879
+                $share->setPermissions($permissions);
880
+            }
881
+
882
+            if ($share->getShareType() === Share::SHARE_TYPE_EMAIL) {
883
+                if ($password === '') {
884
+                    $share->setPassword(null);
885
+                } else if ($password !== null) {
886
+                    $share->setPassword($password);
887
+                }
888
+
889
+                if ($sendPasswordByTalk === 'true') {
890
+                    if (!$this->appManager->isEnabledForUser('spreed')) {
891
+                        throw new OCSForbiddenException($this->l->t('Sharing sending the password by Nextcloud Talk failed because Nextcloud Talk is not enabled'));
892
+                    }
893
+
894
+                    $share->setSendPasswordByTalk(true);
895
+                } else {
896
+                    $share->setSendPasswordByTalk(false);
897
+                }
898
+            }
899
+
900
+            if ($expireDate === '') {
901
+                $share->setExpirationDate(null);
902
+            } else if ($expireDate !== null) {
903
+                try {
904
+                    $expireDate = $this->parseDate($expireDate);
905
+                } catch (\Exception $e) {
906
+                    throw new OCSBadRequestException($e->getMessage(), $e);
907
+                }
908
+                $share->setExpirationDate($expireDate);
909
+            }
910
+
911
+        }
912
+
913
+        if ($permissions !== null && $share->getShareOwner() !== $this->currentUser) {
914
+            /* Check if this is an incomming share */
915
+            $incomingShares = $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_USER, $share->getNode(), -1, 0);
916
+            $incomingShares = array_merge($incomingShares, $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_GROUP, $share->getNode(), -1, 0));
917
+            $incomingShares = array_merge($incomingShares, $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_ROOM, $share->getNode(), -1, 0));
918
+
919
+            /** @var \OCP\Share\IShare[] $incomingShares */
920
+            if (!empty($incomingShares)) {
921
+                $maxPermissions = 0;
922
+                foreach ($incomingShares as $incomingShare) {
923
+                    $maxPermissions |= $incomingShare->getPermissions();
924
+                }
925
+
926
+                if ($share->getPermissions() & ~$maxPermissions) {
927
+                    throw new OCSNotFoundException($this->l->t('Cannot increase permissions'));
928
+                }
929
+            }
930
+        }
931
+
932
+
933
+        try {
934
+            $share = $this->shareManager->updateShare($share);
935
+        } catch (\Exception $e) {
936
+            throw new OCSBadRequestException($e->getMessage(), $e);
937
+        }
938
+
939
+        return new DataResponse($this->formatShare($share));
940
+    }
941
+
942
+    /**
943
+     * @suppress PhanUndeclaredClassMethod
944
+     */
945
+    protected function canAccessShare(\OCP\Share\IShare $share, bool $checkGroups = true): bool {
946
+        // A file with permissions 0 can't be accessed by us. So Don't show it
947
+        if ($share->getPermissions() === 0) {
948
+            return false;
949
+        }
950
+
951
+        // Owner of the file and the sharer of the file can always get share
952
+        if ($share->getShareOwner() === $this->currentUser ||
953
+            $share->getSharedBy() === $this->currentUser
954
+        ) {
955
+            return true;
956
+        }
957
+
958
+        // If the share is shared with you (or a group you are a member of)
959
+        if ($share->getShareType() === Share::SHARE_TYPE_USER &&
960
+            $share->getSharedWith() === $this->currentUser
961
+        ) {
962
+            return true;
963
+        }
964
+
965
+        if ($checkGroups && $share->getShareType() === Share::SHARE_TYPE_GROUP) {
966
+            $sharedWith = $this->groupManager->get($share->getSharedWith());
967
+            $user = $this->userManager->get($this->currentUser);
968
+            if ($user !== null && $sharedWith !== null && $sharedWith->inGroup($user)) {
969
+                return true;
970
+            }
971
+        }
972
+
973
+        if ($share->getShareType() === Share::SHARE_TYPE_CIRCLE) {
974
+            // TODO: have a sanity check like above?
975
+            return true;
976
+        }
977
+
978
+        if ($share->getShareType() === Share::SHARE_TYPE_ROOM) {
979
+            try {
980
+                return $this->getRoomShareHelper()->canAccessShare($share, $this->currentUser);
981
+            } catch (QueryException $e) {
982
+                return false;
983
+            }
984
+        }
985
+
986
+        return false;
987
+    }
988
+
989
+    /**
990
+     * Make sure that the passed date is valid ISO 8601
991
+     * So YYYY-MM-DD
992
+     * If not throw an exception
993
+     *
994
+     * @param string $expireDate
995
+     *
996
+     * @throws \Exception
997
+     * @return \DateTime
998
+     */
999
+    private function parseDate(string $expireDate): \DateTime {
1000
+        try {
1001
+            $date = new \DateTime($expireDate);
1002
+        } catch (\Exception $e) {
1003
+            throw new \Exception('Invalid date. Format must be YYYY-MM-DD');
1004
+        }
1005
+
1006
+        if ($date === false) {
1007
+            throw new \Exception('Invalid date. Format must be YYYY-MM-DD');
1008
+        }
1009
+
1010
+        $date->setTime(0, 0, 0);
1011
+
1012
+        return $date;
1013
+    }
1014
+
1015
+    /**
1016
+     * Since we have multiple providers but the OCS Share API v1 does
1017
+     * not support this we need to check all backends.
1018
+     *
1019
+     * @param string $id
1020
+     * @return \OCP\Share\IShare
1021
+     * @throws ShareNotFound
1022
+     */
1023
+    private function getShareById(string $id): IShare {
1024
+        $share = null;
1025
+
1026
+        // First check if it is an internal share.
1027
+        try {
1028
+            $share = $this->shareManager->getShareById('ocinternal:' . $id, $this->currentUser);
1029
+            return $share;
1030
+        } catch (ShareNotFound $e) {
1031
+            // Do nothing, just try the other share type
1032
+        }
1033
+
1034
+
1035
+        try {
1036
+            if ($this->shareManager->shareProviderExists(Share::SHARE_TYPE_CIRCLE)) {
1037
+                $share = $this->shareManager->getShareById('ocCircleShare:' . $id, $this->currentUser);
1038
+                return $share;
1039
+            }
1040
+        } catch (ShareNotFound $e) {
1041
+            // Do nothing, just try the other share type
1042
+        }
1043
+
1044
+        try {
1045
+            if ($this->shareManager->shareProviderExists(Share::SHARE_TYPE_EMAIL)) {
1046
+                $share = $this->shareManager->getShareById('ocMailShare:' . $id, $this->currentUser);
1047
+                return $share;
1048
+            }
1049
+        } catch (ShareNotFound $e) {
1050
+            // Do nothing, just try the other share type
1051
+        }
1052
+
1053
+        try {
1054
+            $share = $this->shareManager->getShareById('ocRoomShare:' . $id, $this->currentUser);
1055
+            return $share;
1056
+        } catch (ShareNotFound $e) {
1057
+            // Do nothing, just try the other share type
1058
+        }
1059
+
1060
+        if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) {
1061
+            throw new ShareNotFound();
1062
+        }
1063
+        $share = $this->shareManager->getShareById('ocFederatedSharing:' . $id, $this->currentUser);
1064
+
1065
+        return $share;
1066
+    }
1067
+
1068
+    /**
1069
+     * Lock a Node
1070
+     *
1071
+     * @param \OCP\Files\Node $node
1072
+     * @throws LockedException
1073
+     */
1074
+    private function lock(\OCP\Files\Node $node) {
1075
+        $node->lock(ILockingProvider::LOCK_SHARED);
1076
+        $this->lockedNode = $node;
1077
+    }
1078
+
1079
+    /**
1080
+     * Cleanup the remaining locks
1081
+     * @throws @LockedException
1082
+     */
1083
+    public function cleanup() {
1084
+        if ($this->lockedNode !== null) {
1085
+            $this->lockedNode->unlock(ILockingProvider::LOCK_SHARED);
1086
+        }
1087
+    }
1088
+
1089
+    /**
1090
+     * Returns the helper of ShareAPIController for room shares.
1091
+     *
1092
+     * If the Talk application is not enabled or the helper is not available
1093
+     * a QueryException is thrown instead.
1094
+     *
1095
+     * @return \OCA\Spreed\Share\Helper\ShareAPIController
1096
+     * @throws QueryException
1097
+     */
1098
+    private function getRoomShareHelper() {
1099
+        if (!$this->appManager->isEnabledForUser('spreed')) {
1100
+            throw new QueryException();
1101
+        }
1102
+
1103
+        return $this->serverContainer->query('\OCA\Spreed\Share\Helper\ShareAPIController');
1104
+    }
1105 1105
 }
Please login to merge, or discard this patch.