Completed
Push — master ( 143145...82021b )
by Morris
38:23 queued 15:00
created
lib/private/Share20/Share.php 1 patch
Indentation   +444 added lines, -444 removed lines patch added patch discarded remove patch
@@ -32,448 +32,448 @@
 block discarded – undo
32 32
 
33 33
 class Share implements \OCP\Share\IShare {
34 34
 
35
-	/** @var string */
36
-	private $id;
37
-	/** @var string */
38
-	private $providerId;
39
-	/** @var Node */
40
-	private $node;
41
-	/** @var int */
42
-	private $fileId;
43
-	/** @var string */
44
-	private $nodeType;
45
-	/** @var int */
46
-	private $shareType;
47
-	/** @var string */
48
-	private $sharedWith;
49
-	/** @var string */
50
-	private $sharedWithDisplayName;
51
-	/** @var string */
52
-	private $sharedWithAvatar;
53
-	/** @var string */
54
-	private $sharedBy;
55
-	/** @var string */
56
-	private $shareOwner;
57
-	/** @var int */
58
-	private $permissions;
59
-	/** @var \DateTime */
60
-	private $expireDate;
61
-	/** @var string */
62
-	private $password;
63
-	/** @var string */
64
-	private $token;
65
-	/** @var int */
66
-	private $parent;
67
-	/** @var string */
68
-	private $target;
69
-	/** @var \DateTime */
70
-	private $shareTime;
71
-	/** @var bool */
72
-	private $mailSend;
73
-
74
-	/** @var IRootFolder */
75
-	private $rootFolder;
76
-
77
-	/** @var IUserManager */
78
-	private $userManager;
79
-
80
-	/** @var ICacheEntry|null */
81
-	private $nodeCacheEntry;
82
-
83
-	public function __construct(IRootFolder $rootFolder, IUserManager $userManager) {
84
-		$this->rootFolder = $rootFolder;
85
-		$this->userManager = $userManager;
86
-	}
87
-
88
-	/**
89
-	 * @inheritdoc
90
-	 */
91
-	public function setId($id) {
92
-		if (is_int($id)) {
93
-			$id = (string)$id;
94
-		}
95
-
96
-		if(!is_string($id)) {
97
-			throw new \InvalidArgumentException('String expected.');
98
-		}
99
-
100
-		if ($this->id !== null) {
101
-			throw new IllegalIDChangeException('Not allowed to assign a new internal id to a share');
102
-		}
103
-
104
-		$this->id = trim($id);
105
-		return $this;
106
-	}
107
-
108
-	/**
109
-	 * @inheritdoc
110
-	 */
111
-	public function getId() {
112
-		return $this->id;
113
-	}
114
-
115
-	/**
116
-	 * @inheritdoc
117
-	 */
118
-	public function getFullId() {
119
-		if ($this->providerId === null || $this->id === null) {
120
-			throw new \UnexpectedValueException;
121
-		}
122
-		return $this->providerId . ':' . $this->id;
123
-	}
124
-
125
-	/**
126
-	 * @inheritdoc
127
-	 */
128
-	public function setProviderId($id) {
129
-		if(!is_string($id)) {
130
-			throw new \InvalidArgumentException('String expected.');
131
-		}
132
-
133
-		if ($this->providerId !== null) {
134
-			throw new IllegalIDChangeException('Not allowed to assign a new provider id to a share');
135
-		}
136
-
137
-		$this->providerId = trim($id);
138
-		return $this;
139
-	}
140
-
141
-	/**
142
-	 * @inheritdoc
143
-	 */
144
-	public function setNode(Node $node) {
145
-		$this->fileId = null;
146
-		$this->nodeType = null;
147
-		$this->node = $node;
148
-		return $this;
149
-	}
150
-
151
-	/**
152
-	 * @inheritdoc
153
-	 */
154
-	public function getNode() {
155
-		if ($this->node === null) {
156
-
157
-			if ($this->shareOwner === null || $this->fileId === null) {
158
-				throw new NotFoundException();
159
-			}
160
-
161
-			// for federated shares the owner can be a remote user, in this
162
-			// case we use the initiator
163
-			if($this->userManager->userExists($this->shareOwner)) {
164
-				$userFolder = $this->rootFolder->getUserFolder($this->shareOwner);
165
-			} else {
166
-				$userFolder = $this->rootFolder->getUserFolder($this->sharedBy);
167
-			}
168
-
169
-			$nodes = $userFolder->getById($this->fileId);
170
-			if (empty($nodes)) {
171
-				throw new NotFoundException('Node for share not found, fileid: ' . $this->fileId);
172
-			}
173
-
174
-			$this->node = $nodes[0];
175
-		}
176
-
177
-		return $this->node;
178
-	}
179
-
180
-	/**
181
-	 * @inheritdoc
182
-	 */
183
-	public function setNodeId($fileId) {
184
-		$this->node = null;
185
-		$this->fileId = $fileId;
186
-		return $this;
187
-	}
188
-
189
-	/**
190
-	 * @inheritdoc
191
-	 */
192
-	public function getNodeId() {
193
-		if ($this->fileId === null) {
194
-			$this->fileId = $this->getNode()->getId();
195
-		}
196
-
197
-		return $this->fileId;
198
-	}
199
-
200
-	/**
201
-	 * @inheritdoc
202
-	 */
203
-	public function setNodeType($type) {
204
-		if ($type !== 'file' && $type !== 'folder') {
205
-			throw new \InvalidArgumentException();
206
-		}
207
-
208
-		$this->nodeType = $type;
209
-		return $this;
210
-	}
211
-
212
-	/**
213
-	 * @inheritdoc
214
-	 */
215
-	public function getNodeType() {
216
-		if ($this->nodeType === null) {
217
-			$node = $this->getNode();
218
-			$this->nodeType = $node instanceof File ? 'file' : 'folder';
219
-		}
220
-
221
-		return $this->nodeType;
222
-	}
223
-
224
-	/**
225
-	 * @inheritdoc
226
-	 */
227
-	public function setShareType($shareType) {
228
-		$this->shareType = $shareType;
229
-		return $this;
230
-	}
231
-
232
-	/**
233
-	 * @inheritdoc
234
-	 */
235
-	public function getShareType() {
236
-		return $this->shareType;
237
-	}
238
-
239
-	/**
240
-	 * @inheritdoc
241
-	 */
242
-	public function setSharedWith($sharedWith) {
243
-		if (!is_string($sharedWith)) {
244
-			throw new \InvalidArgumentException();
245
-		}
246
-		$this->sharedWith = $sharedWith;
247
-		return $this;
248
-	}
249
-
250
-	/**
251
-	 * @inheritdoc
252
-	 */
253
-	public function getSharedWith() {
254
-		return $this->sharedWith;
255
-	}
256
-
257
-	/**
258
-	 * @inheritdoc
259
-	 */
260
-	public function setSharedWithDisplayName($displayName) {
261
-		if (!is_string($displayName)) {
262
-			throw new \InvalidArgumentException();
263
-		}
264
-		$this->sharedWithDisplayName = $displayName;
265
-		return $this;
266
-	}
267
-
268
-	/**
269
-	 * @inheritdoc
270
-	 */
271
-	public function getSharedWithDisplayName() {
272
-		return $this->sharedWithDisplayName;
273
-	}
274
-
275
-	/**
276
-	 * @inheritdoc
277
-	 */
278
-	public function setSharedWithAvatar($src) {
279
-		if (!is_string($src)) {
280
-			throw new \InvalidArgumentException();
281
-		}
282
-		$this->sharedWithAvatar = $src;
283
-		return $this;
284
-	}
285
-
286
-	/**
287
-	 * @inheritdoc
288
-	 */
289
-	public function getSharedWithAvatar() {
290
-		return $this->sharedWithAvatar;
291
-	}
292
-
293
-	/**
294
-	 * @inheritdoc
295
-	 */
296
-	public function setPermissions($permissions) {
297
-		//TODO checkes
298
-
299
-		$this->permissions = $permissions;
300
-		return $this;
301
-	}
302
-
303
-	/**
304
-	 * @inheritdoc
305
-	 */
306
-	public function getPermissions() {
307
-		return $this->permissions;
308
-	}
309
-
310
-	/**
311
-	 * @inheritdoc
312
-	 */
313
-	public function setExpirationDate($expireDate) {
314
-		//TODO checks
315
-
316
-		$this->expireDate = $expireDate;
317
-		return $this;
318
-	}
319
-
320
-	/**
321
-	 * @inheritdoc
322
-	 */
323
-	public function getExpirationDate() {
324
-		return $this->expireDate;
325
-	}
326
-
327
-	/**
328
-	 * @inheritdoc
329
-	 */
330
-	public function setSharedBy($sharedBy) {
331
-		if (!is_string($sharedBy)) {
332
-			throw new \InvalidArgumentException();
333
-		}
334
-		//TODO checks
335
-		$this->sharedBy = $sharedBy;
336
-
337
-		return $this;
338
-	}
339
-
340
-	/**
341
-	 * @inheritdoc
342
-	 */
343
-	public function getSharedBy() {
344
-		//TODO check if set
345
-		return $this->sharedBy;
346
-	}
347
-
348
-	/**
349
-	 * @inheritdoc
350
-	 */
351
-	public function setShareOwner($shareOwner) {
352
-		if (!is_string($shareOwner)) {
353
-			throw new \InvalidArgumentException();
354
-		}
355
-		//TODO checks
356
-
357
-		$this->shareOwner = $shareOwner;
358
-		return $this;
359
-	}
360
-
361
-	/**
362
-	 * @inheritdoc
363
-	 */
364
-	public function getShareOwner() {
365
-		//TODO check if set
366
-		return $this->shareOwner;
367
-	}
368
-
369
-	/**
370
-	 * @inheritdoc
371
-	 */
372
-	public function setPassword($password) {
373
-		$this->password = $password;
374
-		return $this;
375
-	}
376
-
377
-	/**
378
-	 * @inheritdoc
379
-	 */
380
-	public function getPassword() {
381
-		return $this->password;
382
-	}
383
-
384
-	/**
385
-	 * @inheritdoc
386
-	 */
387
-	public function setToken($token) {
388
-		$this->token = $token;
389
-		return $this;
390
-	}
391
-
392
-	/**
393
-	 * @inheritdoc
394
-	 */
395
-	public function getToken() {
396
-		return $this->token;
397
-	}
398
-
399
-	/**
400
-	 * Set the parent of this share
401
-	 *
402
-	 * @param int parent
403
-	 * @return \OCP\Share\IShare
404
-	 * @deprecated The new shares do not have parents. This is just here for legacy reasons.
405
-	 */
406
-	public function setParent($parent) {
407
-		$this->parent = $parent;
408
-		return $this;
409
-	}
410
-
411
-	/**
412
-	 * Get the parent of this share.
413
-	 *
414
-	 * @return int
415
-	 * @deprecated The new shares do not have parents. This is just here for legacy reasons.
416
-	 */
417
-	public function getParent() {
418
-		return $this->parent;
419
-	}
420
-
421
-	/**
422
-	 * @inheritdoc
423
-	 */
424
-	public function setTarget($target) {
425
-		$this->target = $target;
426
-		return $this;
427
-	}
428
-
429
-	/**
430
-	 * @inheritdoc
431
-	 */
432
-	public function getTarget() {
433
-		return $this->target;
434
-	}
435
-
436
-	/**
437
-	 * @inheritdoc
438
-	 */
439
-	public function setShareTime(\DateTime $shareTime) {
440
-		$this->shareTime = $shareTime;
441
-		return $this;
442
-	}
443
-
444
-	/**
445
-	 * @inheritdoc
446
-	 */
447
-	public function getShareTime() {
448
-		return $this->shareTime;
449
-	}
450
-
451
-	/**
452
-	 * @inheritdoc
453
-	 */
454
-	public function setMailSend($mailSend) {
455
-		$this->mailSend = $mailSend;
456
-		return $this;
457
-	}
458
-
459
-	/**
460
-	 * @inheritdoc
461
-	 */
462
-	public function getMailSend() {
463
-		return $this->mailSend;
464
-	}
465
-
466
-	/**
467
-	 * @inheritdoc
468
-	 */
469
-	public function setNodeCacheEntry(ICacheEntry $entry) {
470
-		$this->nodeCacheEntry = $entry;
471
-	}
472
-
473
-	/**
474
-	 * @inheritdoc
475
-	 */
476
-	public function getNodeCacheEntry() {
477
-		return $this->nodeCacheEntry;
478
-	}
35
+    /** @var string */
36
+    private $id;
37
+    /** @var string */
38
+    private $providerId;
39
+    /** @var Node */
40
+    private $node;
41
+    /** @var int */
42
+    private $fileId;
43
+    /** @var string */
44
+    private $nodeType;
45
+    /** @var int */
46
+    private $shareType;
47
+    /** @var string */
48
+    private $sharedWith;
49
+    /** @var string */
50
+    private $sharedWithDisplayName;
51
+    /** @var string */
52
+    private $sharedWithAvatar;
53
+    /** @var string */
54
+    private $sharedBy;
55
+    /** @var string */
56
+    private $shareOwner;
57
+    /** @var int */
58
+    private $permissions;
59
+    /** @var \DateTime */
60
+    private $expireDate;
61
+    /** @var string */
62
+    private $password;
63
+    /** @var string */
64
+    private $token;
65
+    /** @var int */
66
+    private $parent;
67
+    /** @var string */
68
+    private $target;
69
+    /** @var \DateTime */
70
+    private $shareTime;
71
+    /** @var bool */
72
+    private $mailSend;
73
+
74
+    /** @var IRootFolder */
75
+    private $rootFolder;
76
+
77
+    /** @var IUserManager */
78
+    private $userManager;
79
+
80
+    /** @var ICacheEntry|null */
81
+    private $nodeCacheEntry;
82
+
83
+    public function __construct(IRootFolder $rootFolder, IUserManager $userManager) {
84
+        $this->rootFolder = $rootFolder;
85
+        $this->userManager = $userManager;
86
+    }
87
+
88
+    /**
89
+     * @inheritdoc
90
+     */
91
+    public function setId($id) {
92
+        if (is_int($id)) {
93
+            $id = (string)$id;
94
+        }
95
+
96
+        if(!is_string($id)) {
97
+            throw new \InvalidArgumentException('String expected.');
98
+        }
99
+
100
+        if ($this->id !== null) {
101
+            throw new IllegalIDChangeException('Not allowed to assign a new internal id to a share');
102
+        }
103
+
104
+        $this->id = trim($id);
105
+        return $this;
106
+    }
107
+
108
+    /**
109
+     * @inheritdoc
110
+     */
111
+    public function getId() {
112
+        return $this->id;
113
+    }
114
+
115
+    /**
116
+     * @inheritdoc
117
+     */
118
+    public function getFullId() {
119
+        if ($this->providerId === null || $this->id === null) {
120
+            throw new \UnexpectedValueException;
121
+        }
122
+        return $this->providerId . ':' . $this->id;
123
+    }
124
+
125
+    /**
126
+     * @inheritdoc
127
+     */
128
+    public function setProviderId($id) {
129
+        if(!is_string($id)) {
130
+            throw new \InvalidArgumentException('String expected.');
131
+        }
132
+
133
+        if ($this->providerId !== null) {
134
+            throw new IllegalIDChangeException('Not allowed to assign a new provider id to a share');
135
+        }
136
+
137
+        $this->providerId = trim($id);
138
+        return $this;
139
+    }
140
+
141
+    /**
142
+     * @inheritdoc
143
+     */
144
+    public function setNode(Node $node) {
145
+        $this->fileId = null;
146
+        $this->nodeType = null;
147
+        $this->node = $node;
148
+        return $this;
149
+    }
150
+
151
+    /**
152
+     * @inheritdoc
153
+     */
154
+    public function getNode() {
155
+        if ($this->node === null) {
156
+
157
+            if ($this->shareOwner === null || $this->fileId === null) {
158
+                throw new NotFoundException();
159
+            }
160
+
161
+            // for federated shares the owner can be a remote user, in this
162
+            // case we use the initiator
163
+            if($this->userManager->userExists($this->shareOwner)) {
164
+                $userFolder = $this->rootFolder->getUserFolder($this->shareOwner);
165
+            } else {
166
+                $userFolder = $this->rootFolder->getUserFolder($this->sharedBy);
167
+            }
168
+
169
+            $nodes = $userFolder->getById($this->fileId);
170
+            if (empty($nodes)) {
171
+                throw new NotFoundException('Node for share not found, fileid: ' . $this->fileId);
172
+            }
173
+
174
+            $this->node = $nodes[0];
175
+        }
176
+
177
+        return $this->node;
178
+    }
179
+
180
+    /**
181
+     * @inheritdoc
182
+     */
183
+    public function setNodeId($fileId) {
184
+        $this->node = null;
185
+        $this->fileId = $fileId;
186
+        return $this;
187
+    }
188
+
189
+    /**
190
+     * @inheritdoc
191
+     */
192
+    public function getNodeId() {
193
+        if ($this->fileId === null) {
194
+            $this->fileId = $this->getNode()->getId();
195
+        }
196
+
197
+        return $this->fileId;
198
+    }
199
+
200
+    /**
201
+     * @inheritdoc
202
+     */
203
+    public function setNodeType($type) {
204
+        if ($type !== 'file' && $type !== 'folder') {
205
+            throw new \InvalidArgumentException();
206
+        }
207
+
208
+        $this->nodeType = $type;
209
+        return $this;
210
+    }
211
+
212
+    /**
213
+     * @inheritdoc
214
+     */
215
+    public function getNodeType() {
216
+        if ($this->nodeType === null) {
217
+            $node = $this->getNode();
218
+            $this->nodeType = $node instanceof File ? 'file' : 'folder';
219
+        }
220
+
221
+        return $this->nodeType;
222
+    }
223
+
224
+    /**
225
+     * @inheritdoc
226
+     */
227
+    public function setShareType($shareType) {
228
+        $this->shareType = $shareType;
229
+        return $this;
230
+    }
231
+
232
+    /**
233
+     * @inheritdoc
234
+     */
235
+    public function getShareType() {
236
+        return $this->shareType;
237
+    }
238
+
239
+    /**
240
+     * @inheritdoc
241
+     */
242
+    public function setSharedWith($sharedWith) {
243
+        if (!is_string($sharedWith)) {
244
+            throw new \InvalidArgumentException();
245
+        }
246
+        $this->sharedWith = $sharedWith;
247
+        return $this;
248
+    }
249
+
250
+    /**
251
+     * @inheritdoc
252
+     */
253
+    public function getSharedWith() {
254
+        return $this->sharedWith;
255
+    }
256
+
257
+    /**
258
+     * @inheritdoc
259
+     */
260
+    public function setSharedWithDisplayName($displayName) {
261
+        if (!is_string($displayName)) {
262
+            throw new \InvalidArgumentException();
263
+        }
264
+        $this->sharedWithDisplayName = $displayName;
265
+        return $this;
266
+    }
267
+
268
+    /**
269
+     * @inheritdoc
270
+     */
271
+    public function getSharedWithDisplayName() {
272
+        return $this->sharedWithDisplayName;
273
+    }
274
+
275
+    /**
276
+     * @inheritdoc
277
+     */
278
+    public function setSharedWithAvatar($src) {
279
+        if (!is_string($src)) {
280
+            throw new \InvalidArgumentException();
281
+        }
282
+        $this->sharedWithAvatar = $src;
283
+        return $this;
284
+    }
285
+
286
+    /**
287
+     * @inheritdoc
288
+     */
289
+    public function getSharedWithAvatar() {
290
+        return $this->sharedWithAvatar;
291
+    }
292
+
293
+    /**
294
+     * @inheritdoc
295
+     */
296
+    public function setPermissions($permissions) {
297
+        //TODO checkes
298
+
299
+        $this->permissions = $permissions;
300
+        return $this;
301
+    }
302
+
303
+    /**
304
+     * @inheritdoc
305
+     */
306
+    public function getPermissions() {
307
+        return $this->permissions;
308
+    }
309
+
310
+    /**
311
+     * @inheritdoc
312
+     */
313
+    public function setExpirationDate($expireDate) {
314
+        //TODO checks
315
+
316
+        $this->expireDate = $expireDate;
317
+        return $this;
318
+    }
319
+
320
+    /**
321
+     * @inheritdoc
322
+     */
323
+    public function getExpirationDate() {
324
+        return $this->expireDate;
325
+    }
326
+
327
+    /**
328
+     * @inheritdoc
329
+     */
330
+    public function setSharedBy($sharedBy) {
331
+        if (!is_string($sharedBy)) {
332
+            throw new \InvalidArgumentException();
333
+        }
334
+        //TODO checks
335
+        $this->sharedBy = $sharedBy;
336
+
337
+        return $this;
338
+    }
339
+
340
+    /**
341
+     * @inheritdoc
342
+     */
343
+    public function getSharedBy() {
344
+        //TODO check if set
345
+        return $this->sharedBy;
346
+    }
347
+
348
+    /**
349
+     * @inheritdoc
350
+     */
351
+    public function setShareOwner($shareOwner) {
352
+        if (!is_string($shareOwner)) {
353
+            throw new \InvalidArgumentException();
354
+        }
355
+        //TODO checks
356
+
357
+        $this->shareOwner = $shareOwner;
358
+        return $this;
359
+    }
360
+
361
+    /**
362
+     * @inheritdoc
363
+     */
364
+    public function getShareOwner() {
365
+        //TODO check if set
366
+        return $this->shareOwner;
367
+    }
368
+
369
+    /**
370
+     * @inheritdoc
371
+     */
372
+    public function setPassword($password) {
373
+        $this->password = $password;
374
+        return $this;
375
+    }
376
+
377
+    /**
378
+     * @inheritdoc
379
+     */
380
+    public function getPassword() {
381
+        return $this->password;
382
+    }
383
+
384
+    /**
385
+     * @inheritdoc
386
+     */
387
+    public function setToken($token) {
388
+        $this->token = $token;
389
+        return $this;
390
+    }
391
+
392
+    /**
393
+     * @inheritdoc
394
+     */
395
+    public function getToken() {
396
+        return $this->token;
397
+    }
398
+
399
+    /**
400
+     * Set the parent of this share
401
+     *
402
+     * @param int parent
403
+     * @return \OCP\Share\IShare
404
+     * @deprecated The new shares do not have parents. This is just here for legacy reasons.
405
+     */
406
+    public function setParent($parent) {
407
+        $this->parent = $parent;
408
+        return $this;
409
+    }
410
+
411
+    /**
412
+     * Get the parent of this share.
413
+     *
414
+     * @return int
415
+     * @deprecated The new shares do not have parents. This is just here for legacy reasons.
416
+     */
417
+    public function getParent() {
418
+        return $this->parent;
419
+    }
420
+
421
+    /**
422
+     * @inheritdoc
423
+     */
424
+    public function setTarget($target) {
425
+        $this->target = $target;
426
+        return $this;
427
+    }
428
+
429
+    /**
430
+     * @inheritdoc
431
+     */
432
+    public function getTarget() {
433
+        return $this->target;
434
+    }
435
+
436
+    /**
437
+     * @inheritdoc
438
+     */
439
+    public function setShareTime(\DateTime $shareTime) {
440
+        $this->shareTime = $shareTime;
441
+        return $this;
442
+    }
443
+
444
+    /**
445
+     * @inheritdoc
446
+     */
447
+    public function getShareTime() {
448
+        return $this->shareTime;
449
+    }
450
+
451
+    /**
452
+     * @inheritdoc
453
+     */
454
+    public function setMailSend($mailSend) {
455
+        $this->mailSend = $mailSend;
456
+        return $this;
457
+    }
458
+
459
+    /**
460
+     * @inheritdoc
461
+     */
462
+    public function getMailSend() {
463
+        return $this->mailSend;
464
+    }
465
+
466
+    /**
467
+     * @inheritdoc
468
+     */
469
+    public function setNodeCacheEntry(ICacheEntry $entry) {
470
+        $this->nodeCacheEntry = $entry;
471
+    }
472
+
473
+    /**
474
+     * @inheritdoc
475
+     */
476
+    public function getNodeCacheEntry() {
477
+        return $this->nodeCacheEntry;
478
+    }
479 479
 }
Please login to merge, or discard this patch.
lib/public/Share/IShare.php 1 patch
Indentation   +338 added lines, -338 removed lines patch added patch discarded remove patch
@@ -39,342 +39,342 @@
 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
-	 * Set the expiration date
227
-	 *
228
-	 * @param null|\DateTime $expireDate
229
-	 * @return \OCP\Share\IShare The modified object
230
-	 * @since 9.0.0
231
-	 */
232
-	public function setExpirationDate($expireDate);
233
-
234
-	/**
235
-	 * Get the expiration date
236
-	 *
237
-	 * @return \DateTime
238
-	 * @since 9.0.0
239
-	 */
240
-	public function getExpirationDate();
241
-
242
-	/**
243
-	 * Set the sharer of the path.
244
-	 *
245
-	 * @param string $sharedBy
246
-	 * @return \OCP\Share\IShare The modified object
247
-	 * @since 9.0.0
248
-	 */
249
-	public function setSharedBy($sharedBy);
250
-
251
-	/**
252
-	 * Get share sharer
253
-	 *
254
-	 * @return string
255
-	 * @since 9.0.0
256
-	 */
257
-	public function getSharedBy();
258
-
259
-	/**
260
-	 * Set the original share owner (who owns the path that is shared)
261
-	 *
262
-	 * @param string $shareOwner
263
-	 * @return \OCP\Share\IShare The modified object
264
-	 * @since 9.0.0
265
-	 */
266
-	public function setShareOwner($shareOwner);
267
-
268
-	/**
269
-	 * Get the original share owner (who owns the path that is shared)
270
-	 *
271
-	 * @return string
272
-	 * @since 9.0.0
273
-	 */
274
-	public function getShareOwner();
275
-
276
-	/**
277
-	 * Set the password for this share.
278
-	 * When the share is passed to the share manager to be created
279
-	 * or updated the password will be hashed.
280
-	 *
281
-	 * @param string $password
282
-	 * @return \OCP\Share\IShare The modified object
283
-	 * @since 9.0.0
284
-	 */
285
-	public function setPassword($password);
286
-
287
-	/**
288
-	 * Get the password of this share.
289
-	 * If this share is obtained via a shareprovider the password is
290
-	 * hashed.
291
-	 *
292
-	 * @return string
293
-	 * @since 9.0.0
294
-	 */
295
-	public function getPassword();
296
-
297
-	/**
298
-	 * Set the public link token.
299
-	 *
300
-	 * @param string $token
301
-	 * @return \OCP\Share\IShare The modified object
302
-	 * @since 9.0.0
303
-	 */
304
-	public function setToken($token);
305
-
306
-	/**
307
-	 * Get the public link token.
308
-	 *
309
-	 * @return string
310
-	 * @since 9.0.0
311
-	 */
312
-	public function getToken();
313
-
314
-	/**
315
-	 * Set the target path of this share relative to the recipients user folder.
316
-	 *
317
-	 * @param string $target
318
-	 * @return \OCP\Share\IShare The modified object
319
-	 * @since 9.0.0
320
-	 */
321
-	public function setTarget($target);
322
-
323
-	/**
324
-	 * Get the target path of this share relative to the recipients user folder.
325
-	 *
326
-	 * @return string
327
-	 * @since 9.0.0
328
-	 */
329
-	public function getTarget();
330
-
331
-	/**
332
-	 * Set the time this share was created
333
-	 *
334
-	 * @param \DateTime $shareTime
335
-	 * @return \OCP\Share\IShare The modified object
336
-	 * @since 9.0.0
337
-	 */
338
-	public function setShareTime(\DateTime $shareTime);
339
-
340
-	/**
341
-	 * Get the timestamp this share was created
342
-	 *
343
-	 * @return \DateTime
344
-	 * @since 9.0.0
345
-	 */
346
-	public function getShareTime();
347
-
348
-	/**
349
-	 * Set if the recipient is informed by mail about the share.
350
-	 *
351
-	 * @param bool $mailSend
352
-	 * @return \OCP\Share\IShare The modified object
353
-	 * @since 9.0.0
354
-	 */
355
-	public function setMailSend($mailSend);
356
-
357
-	/**
358
-	 * Get if the recipient informed by mail about the share.
359
-	 *
360
-	 * @return bool
361
-	 * @since 9.0.0
362
-	 */
363
-	public function getMailSend();
364
-
365
-	/**
366
-	 * Set the cache entry for the shared node
367
-	 *
368
-	 * @param ICacheEntry $entry
369
-	 * @since 11.0.0
370
-	 */
371
-	public function setNodeCacheEntry(ICacheEntry $entry);
372
-
373
-	/**
374
-	 * Get the cache entry for the shared node
375
-	 *
376
-	 * @return null|ICacheEntry
377
-	 * @since 11.0.0
378
-	 */
379
-	public function getNodeCacheEntry();
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
+     * Set the expiration date
227
+     *
228
+     * @param null|\DateTime $expireDate
229
+     * @return \OCP\Share\IShare The modified object
230
+     * @since 9.0.0
231
+     */
232
+    public function setExpirationDate($expireDate);
233
+
234
+    /**
235
+     * Get the expiration date
236
+     *
237
+     * @return \DateTime
238
+     * @since 9.0.0
239
+     */
240
+    public function getExpirationDate();
241
+
242
+    /**
243
+     * Set the sharer of the path.
244
+     *
245
+     * @param string $sharedBy
246
+     * @return \OCP\Share\IShare The modified object
247
+     * @since 9.0.0
248
+     */
249
+    public function setSharedBy($sharedBy);
250
+
251
+    /**
252
+     * Get share sharer
253
+     *
254
+     * @return string
255
+     * @since 9.0.0
256
+     */
257
+    public function getSharedBy();
258
+
259
+    /**
260
+     * Set the original share owner (who owns the path that is shared)
261
+     *
262
+     * @param string $shareOwner
263
+     * @return \OCP\Share\IShare The modified object
264
+     * @since 9.0.0
265
+     */
266
+    public function setShareOwner($shareOwner);
267
+
268
+    /**
269
+     * Get the original share owner (who owns the path that is shared)
270
+     *
271
+     * @return string
272
+     * @since 9.0.0
273
+     */
274
+    public function getShareOwner();
275
+
276
+    /**
277
+     * Set the password for this share.
278
+     * When the share is passed to the share manager to be created
279
+     * or updated the password will be hashed.
280
+     *
281
+     * @param string $password
282
+     * @return \OCP\Share\IShare The modified object
283
+     * @since 9.0.0
284
+     */
285
+    public function setPassword($password);
286
+
287
+    /**
288
+     * Get the password of this share.
289
+     * If this share is obtained via a shareprovider the password is
290
+     * hashed.
291
+     *
292
+     * @return string
293
+     * @since 9.0.0
294
+     */
295
+    public function getPassword();
296
+
297
+    /**
298
+     * Set the public link token.
299
+     *
300
+     * @param string $token
301
+     * @return \OCP\Share\IShare The modified object
302
+     * @since 9.0.0
303
+     */
304
+    public function setToken($token);
305
+
306
+    /**
307
+     * Get the public link token.
308
+     *
309
+     * @return string
310
+     * @since 9.0.0
311
+     */
312
+    public function getToken();
313
+
314
+    /**
315
+     * Set the target path of this share relative to the recipients user folder.
316
+     *
317
+     * @param string $target
318
+     * @return \OCP\Share\IShare The modified object
319
+     * @since 9.0.0
320
+     */
321
+    public function setTarget($target);
322
+
323
+    /**
324
+     * Get the target path of this share relative to the recipients user folder.
325
+     *
326
+     * @return string
327
+     * @since 9.0.0
328
+     */
329
+    public function getTarget();
330
+
331
+    /**
332
+     * Set the time this share was created
333
+     *
334
+     * @param \DateTime $shareTime
335
+     * @return \OCP\Share\IShare The modified object
336
+     * @since 9.0.0
337
+     */
338
+    public function setShareTime(\DateTime $shareTime);
339
+
340
+    /**
341
+     * Get the timestamp this share was created
342
+     *
343
+     * @return \DateTime
344
+     * @since 9.0.0
345
+     */
346
+    public function getShareTime();
347
+
348
+    /**
349
+     * Set if the recipient is informed by mail about the share.
350
+     *
351
+     * @param bool $mailSend
352
+     * @return \OCP\Share\IShare The modified object
353
+     * @since 9.0.0
354
+     */
355
+    public function setMailSend($mailSend);
356
+
357
+    /**
358
+     * Get if the recipient informed by mail about the share.
359
+     *
360
+     * @return bool
361
+     * @since 9.0.0
362
+     */
363
+    public function getMailSend();
364
+
365
+    /**
366
+     * Set the cache entry for the shared node
367
+     *
368
+     * @param ICacheEntry $entry
369
+     * @since 11.0.0
370
+     */
371
+    public function setNodeCacheEntry(ICacheEntry $entry);
372
+
373
+    /**
374
+     * Get the cache entry for the shared node
375
+     *
376
+     * @return null|ICacheEntry
377
+     * @since 11.0.0
378
+     */
379
+    public function getNodeCacheEntry();
380 380
 }
Please login to merge, or discard this patch.
apps/files_sharing/lib/Controller/ShareAPIController.php 2 patches
Indentation   +906 added lines, -906 removed lines patch added patch discarded remove patch
@@ -63,919 +63,919 @@
 block discarded – undo
63 63
  */
64 64
 class ShareAPIController extends OCSController {
65 65
 
66
-	/** @var IManager */
67
-	private $shareManager;
68
-	/** @var IGroupManager */
69
-	private $groupManager;
70
-	/** @var IUserManager */
71
-	private $userManager;
72
-	/** @var IRootFolder */
73
-	private $rootFolder;
74
-	/** @var IURLGenerator */
75
-	private $urlGenerator;
76
-	/** @var string */
77
-	private $currentUser;
78
-	/** @var IL10N */
79
-	private $l;
80
-	/** @var \OCP\Files\Node */
81
-	private $lockedNode;
82
-	/** @var IConfig */
83
-	private $config;
84
-
85
-	/**
86
-	 * Share20OCS constructor.
87
-	 *
88
-	 * @param string $appName
89
-	 * @param IRequest $request
90
-	 * @param IManager $shareManager
91
-	 * @param IGroupManager $groupManager
92
-	 * @param IUserManager $userManager
93
-	 * @param IRootFolder $rootFolder
94
-	 * @param IURLGenerator $urlGenerator
95
-	 * @param string $userId
96
-	 * @param IL10N $l10n
97
-	 * @param IConfig $config
98
-	 */
99
-	public function __construct(
100
-		string $appName,
101
-		IRequest $request,
102
-		IManager $shareManager,
103
-		IGroupManager $groupManager,
104
-		IUserManager $userManager,
105
-		IRootFolder $rootFolder,
106
-		IURLGenerator $urlGenerator,
107
-		string $userId,
108
-		IL10N $l10n,
109
-		IConfig $config
110
-	) {
111
-		parent::__construct($appName, $request);
112
-
113
-		$this->shareManager = $shareManager;
114
-		$this->userManager = $userManager;
115
-		$this->groupManager = $groupManager;
116
-		$this->request = $request;
117
-		$this->rootFolder = $rootFolder;
118
-		$this->urlGenerator = $urlGenerator;
119
-		$this->currentUser = $userId;
120
-		$this->l = $l10n;
121
-		$this->config = $config;
122
-	}
123
-
124
-	/**
125
-	 * Convert an IShare to an array for OCS output
126
-	 *
127
-	 * @param \OCP\Share\IShare $share
128
-	 * @param Node|null $recipientNode
129
-	 * @return array
130
-	 * @throws NotFoundException In case the node can't be resolved.
131
-	 */
132
-	protected function formatShare(\OCP\Share\IShare $share, Node $recipientNode = null): array {
133
-		$sharedBy = $this->userManager->get($share->getSharedBy());
134
-		$shareOwner = $this->userManager->get($share->getShareOwner());
135
-
136
-		$result = [
137
-			'id' => $share->getId(),
138
-			'share_type' => $share->getShareType(),
139
-			'uid_owner' => $share->getSharedBy(),
140
-			'displayname_owner' => $sharedBy !== null ? $sharedBy->getDisplayName() : $share->getSharedBy(),
141
-			'permissions' => $share->getPermissions(),
142
-			'stime' => $share->getShareTime()->getTimestamp(),
143
-			'parent' => null,
144
-			'expiration' => null,
145
-			'token' => null,
146
-			'uid_file_owner' => $share->getShareOwner(),
147
-			'displayname_file_owner' => $shareOwner !== null ? $shareOwner->getDisplayName() : $share->getShareOwner(),
148
-		];
149
-
150
-		$userFolder = $this->rootFolder->getUserFolder($this->currentUser);
151
-		if ($recipientNode) {
152
-			$node = $recipientNode;
153
-		} else {
154
-			$nodes = $userFolder->getById($share->getNodeId());
155
-			if (empty($nodes)) {
156
-				// fallback to guessing the path
157
-				$node = $userFolder->get($share->getTarget());
158
-				if ($node === null || $share->getTarget() === '') {
159
-					throw new NotFoundException();
160
-				}
161
-			} else {
162
-				$node = $nodes[0];
163
-			}
164
-		}
165
-
166
-		$result['path'] = $userFolder->getRelativePath($node->getPath());
167
-		if ($node instanceOf \OCP\Files\Folder) {
168
-			$result['item_type'] = 'folder';
169
-		} else {
170
-			$result['item_type'] = 'file';
171
-		}
172
-		$result['mimetype'] = $node->getMimetype();
173
-		$result['storage_id'] = $node->getStorage()->getId();
174
-		$result['storage'] = $node->getStorage()->getCache()->getNumericStorageId();
175
-		$result['item_source'] = $node->getId();
176
-		$result['file_source'] = $node->getId();
177
-		$result['file_parent'] = $node->getParent()->getId();
178
-		$result['file_target'] = $share->getTarget();
179
-
180
-		$expiration = $share->getExpirationDate();
181
-		if ($expiration !== null) {
182
-			$result['expiration'] = $expiration->format('Y-m-d 00:00:00');
183
-		}
184
-
185
-		if ($share->getShareType() === Share::SHARE_TYPE_USER) {
186
-			$sharedWith = $this->userManager->get($share->getSharedWith());
187
-			$result['share_with'] = $share->getSharedWith();
188
-			$result['share_with_displayname'] = $sharedWith !== null ? $sharedWith->getDisplayName() : $share->getSharedWith();
189
-		} else if ($share->getShareType() === Share::SHARE_TYPE_GROUP) {
190
-			$group = $this->groupManager->get($share->getSharedWith());
191
-			$result['share_with'] = $share->getSharedWith();
192
-			$result['share_with_displayname'] = $group !== null ? $group->getDisplayName() : $share->getSharedWith();
193
-		} else if ($share->getShareType() === Share::SHARE_TYPE_LINK) {
194
-
195
-			$result['share_with'] = $share->getPassword();
196
-			$result['share_with_displayname'] = $share->getPassword();
197
-
198
-			$result['token'] = $share->getToken();
199
-			$result['url'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $share->getToken()]);
200
-
201
-		} else if ($share->getShareType() === Share::SHARE_TYPE_REMOTE || $share->getShareType() === Share::SHARE_TYPE_REMOTE_GROUP) {
202
-			$result['share_with'] = $share->getSharedWith();
203
-			$result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'CLOUD');
204
-			$result['token'] = $share->getToken();
205
-		} else if ($share->getShareType() === Share::SHARE_TYPE_EMAIL) {
206
-			$result['share_with'] = $share->getSharedWith();
207
-			$result['password'] = $share->getPassword();
208
-			$result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'EMAIL');
209
-			$result['token'] = $share->getToken();
210
-		} else if ($share->getShareType() === Share::SHARE_TYPE_CIRCLE) {
211
-			// getSharedWith() returns either "name (type, owner)" or
212
-			// "name (type, owner) [id]", depending on the Circles app version.
213
-			$hasCircleId = (substr($share->getSharedWith(), -1) === ']');
214
-
215
-			$result['share_with_displayname'] = $share->getSharedWithDisplayName();
216
-			if (empty($result['share_with_displayname'])) {
217
-				$displayNameLength = ($hasCircleId? strrpos($share->getSharedWith(), ' '): strlen($share->getSharedWith()));
218
-				$result['share_with_displayname'] = substr($share->getSharedWith(), 0, $displayNameLength);
219
-			}
220
-
221
-			$result['share_with_avatar'] = $share->getSharedWithAvatar();
222
-
223
-			$shareWithStart = ($hasCircleId? strrpos($share->getSharedWith(), '[') + 1: 0);
224
-			$shareWithLength = ($hasCircleId? -1: strpos($share->getSharedWith(), ' '));
225
-			$result['share_with'] = substr($share->getSharedWith(), $shareWithStart, $shareWithLength);
226
-		}
227
-
228
-
229
-		$result['mail_send'] = $share->getMailSend() ? 1 : 0;
230
-
231
-		return $result;
232
-	}
233
-
234
-	/**
235
-	 * Check if one of the users address books knows the exact property, if
236
-	 * yes we return the full name.
237
-	 *
238
-	 * @param string $query
239
-	 * @param string $property
240
-	 * @return string
241
-	 */
242
-	private function getDisplayNameFromAddressBook(string $query, string $property): string {
243
-		// FIXME: If we inject the contacts manager it gets initialized bofore any address books are registered
244
-		$result = \OC::$server->getContactsManager()->search($query, [$property]);
245
-		foreach ($result as $r) {
246
-			foreach($r[$property] as $value) {
247
-				if ($value === $query) {
248
-					return $r['FN'];
249
-				}
250
-			}
251
-		}
252
-
253
-		return $query;
254
-	}
255
-
256
-	/**
257
-	 * Get a specific share by id
258
-	 *
259
-	 * @NoAdminRequired
260
-	 *
261
-	 * @param string $id
262
-	 * @return DataResponse
263
-	 * @throws OCSNotFoundException
264
-	 */
265
-	public function getShare(string $id): DataResponse {
266
-		try {
267
-			$share = $this->getShareById($id);
268
-		} catch (ShareNotFound $e) {
269
-			throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
270
-		}
271
-
272
-		if ($this->canAccessShare($share)) {
273
-			try {
274
-				$share = $this->formatShare($share);
275
-				return new DataResponse([$share]);
276
-			} catch (NotFoundException $e) {
277
-				//Fall trough
278
-			}
279
-		}
280
-
281
-		throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
282
-	}
283
-
284
-	/**
285
-	 * Delete a share
286
-	 *
287
-	 * @NoAdminRequired
288
-	 *
289
-	 * @param string $id
290
-	 * @return DataResponse
291
-	 * @throws OCSNotFoundException
292
-	 */
293
-	public function deleteShare(string $id): DataResponse {
294
-		try {
295
-			$share = $this->getShareById($id);
296
-		} catch (ShareNotFound $e) {
297
-			throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
298
-		}
299
-
300
-		try {
301
-			$this->lock($share->getNode());
302
-		} catch (LockedException $e) {
303
-			throw new OCSNotFoundException($this->l->t('could not delete share'));
304
-		}
305
-
306
-		if (!$this->canAccessShare($share)) {
307
-			throw new OCSNotFoundException($this->l->t('Could not delete share'));
308
-		}
309
-
310
-		if ($share->getShareType() === Share::SHARE_TYPE_GROUP &&
311
-			$share->getShareOwner() !== $this->currentUser &&
312
-			$share->getSharedBy() !== $this->currentUser) {
313
-			$this->shareManager->deleteFromSelf($share, $this->currentUser);
314
-		} else {
315
-			$this->shareManager->deleteShare($share);
316
-		}
317
-
318
-		return new DataResponse();
319
-	}
320
-
321
-	/**
322
-	 * @NoAdminRequired
323
-	 *
324
-	 * @param string $path
325
-	 * @param int $permissions
326
-	 * @param int $shareType
327
-	 * @param string $shareWith
328
-	 * @param string $publicUpload
329
-	 * @param string $password
330
-	 * @param string $expireDate
331
-	 *
332
-	 * @return DataResponse
333
-	 * @throws OCSNotFoundException
334
-	 * @throws OCSForbiddenException
335
-	 * @throws OCSBadRequestException
336
-	 * @throws OCSException
337
-	 *
338
-	 * @suppress PhanUndeclaredClassMethod
339
-	 */
340
-	public function createShare(
341
-		string $path = null,
342
-		int $permissions = null,
343
-		int $shareType = -1,
344
-		string $shareWith = null,
345
-		string $publicUpload = 'false',
346
-		string $password = '',
347
-		string $expireDate = ''
348
-	): DataResponse {
349
-		$share = $this->shareManager->newShare();
350
-
351
-		if ($permissions === null) {
352
-			$permissions = $this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL);
353
-		}
354
-
355
-		// Verify path
356
-		if ($path === null) {
357
-			throw new OCSNotFoundException($this->l->t('Please specify a file or folder path'));
358
-		}
359
-
360
-		$userFolder = $this->rootFolder->getUserFolder($this->currentUser);
361
-		try {
362
-			$path = $userFolder->get($path);
363
-		} catch (NotFoundException $e) {
364
-			throw new OCSNotFoundException($this->l->t('Wrong path, file/folder doesn\'t exist'));
365
-		}
366
-
367
-		$share->setNode($path);
368
-
369
-		try {
370
-			$this->lock($share->getNode());
371
-		} catch (LockedException $e) {
372
-			throw new OCSNotFoundException($this->l->t('Could not create share'));
373
-		}
374
-
375
-		if ($permissions < 0 || $permissions > Constants::PERMISSION_ALL) {
376
-			throw new OCSNotFoundException($this->l->t('invalid permissions'));
377
-		}
378
-
379
-		// Shares always require read permissions
380
-		$permissions |= Constants::PERMISSION_READ;
381
-
382
-		if ($path instanceof \OCP\Files\File) {
383
-			// Single file shares should never have delete or create permissions
384
-			$permissions &= ~Constants::PERMISSION_DELETE;
385
-			$permissions &= ~Constants::PERMISSION_CREATE;
386
-		}
387
-
388
-		/*
66
+    /** @var IManager */
67
+    private $shareManager;
68
+    /** @var IGroupManager */
69
+    private $groupManager;
70
+    /** @var IUserManager */
71
+    private $userManager;
72
+    /** @var IRootFolder */
73
+    private $rootFolder;
74
+    /** @var IURLGenerator */
75
+    private $urlGenerator;
76
+    /** @var string */
77
+    private $currentUser;
78
+    /** @var IL10N */
79
+    private $l;
80
+    /** @var \OCP\Files\Node */
81
+    private $lockedNode;
82
+    /** @var IConfig */
83
+    private $config;
84
+
85
+    /**
86
+     * Share20OCS constructor.
87
+     *
88
+     * @param string $appName
89
+     * @param IRequest $request
90
+     * @param IManager $shareManager
91
+     * @param IGroupManager $groupManager
92
+     * @param IUserManager $userManager
93
+     * @param IRootFolder $rootFolder
94
+     * @param IURLGenerator $urlGenerator
95
+     * @param string $userId
96
+     * @param IL10N $l10n
97
+     * @param IConfig $config
98
+     */
99
+    public function __construct(
100
+        string $appName,
101
+        IRequest $request,
102
+        IManager $shareManager,
103
+        IGroupManager $groupManager,
104
+        IUserManager $userManager,
105
+        IRootFolder $rootFolder,
106
+        IURLGenerator $urlGenerator,
107
+        string $userId,
108
+        IL10N $l10n,
109
+        IConfig $config
110
+    ) {
111
+        parent::__construct($appName, $request);
112
+
113
+        $this->shareManager = $shareManager;
114
+        $this->userManager = $userManager;
115
+        $this->groupManager = $groupManager;
116
+        $this->request = $request;
117
+        $this->rootFolder = $rootFolder;
118
+        $this->urlGenerator = $urlGenerator;
119
+        $this->currentUser = $userId;
120
+        $this->l = $l10n;
121
+        $this->config = $config;
122
+    }
123
+
124
+    /**
125
+     * Convert an IShare to an array for OCS output
126
+     *
127
+     * @param \OCP\Share\IShare $share
128
+     * @param Node|null $recipientNode
129
+     * @return array
130
+     * @throws NotFoundException In case the node can't be resolved.
131
+     */
132
+    protected function formatShare(\OCP\Share\IShare $share, Node $recipientNode = null): array {
133
+        $sharedBy = $this->userManager->get($share->getSharedBy());
134
+        $shareOwner = $this->userManager->get($share->getShareOwner());
135
+
136
+        $result = [
137
+            'id' => $share->getId(),
138
+            'share_type' => $share->getShareType(),
139
+            'uid_owner' => $share->getSharedBy(),
140
+            'displayname_owner' => $sharedBy !== null ? $sharedBy->getDisplayName() : $share->getSharedBy(),
141
+            'permissions' => $share->getPermissions(),
142
+            'stime' => $share->getShareTime()->getTimestamp(),
143
+            'parent' => null,
144
+            'expiration' => null,
145
+            'token' => null,
146
+            'uid_file_owner' => $share->getShareOwner(),
147
+            'displayname_file_owner' => $shareOwner !== null ? $shareOwner->getDisplayName() : $share->getShareOwner(),
148
+        ];
149
+
150
+        $userFolder = $this->rootFolder->getUserFolder($this->currentUser);
151
+        if ($recipientNode) {
152
+            $node = $recipientNode;
153
+        } else {
154
+            $nodes = $userFolder->getById($share->getNodeId());
155
+            if (empty($nodes)) {
156
+                // fallback to guessing the path
157
+                $node = $userFolder->get($share->getTarget());
158
+                if ($node === null || $share->getTarget() === '') {
159
+                    throw new NotFoundException();
160
+                }
161
+            } else {
162
+                $node = $nodes[0];
163
+            }
164
+        }
165
+
166
+        $result['path'] = $userFolder->getRelativePath($node->getPath());
167
+        if ($node instanceOf \OCP\Files\Folder) {
168
+            $result['item_type'] = 'folder';
169
+        } else {
170
+            $result['item_type'] = 'file';
171
+        }
172
+        $result['mimetype'] = $node->getMimetype();
173
+        $result['storage_id'] = $node->getStorage()->getId();
174
+        $result['storage'] = $node->getStorage()->getCache()->getNumericStorageId();
175
+        $result['item_source'] = $node->getId();
176
+        $result['file_source'] = $node->getId();
177
+        $result['file_parent'] = $node->getParent()->getId();
178
+        $result['file_target'] = $share->getTarget();
179
+
180
+        $expiration = $share->getExpirationDate();
181
+        if ($expiration !== null) {
182
+            $result['expiration'] = $expiration->format('Y-m-d 00:00:00');
183
+        }
184
+
185
+        if ($share->getShareType() === Share::SHARE_TYPE_USER) {
186
+            $sharedWith = $this->userManager->get($share->getSharedWith());
187
+            $result['share_with'] = $share->getSharedWith();
188
+            $result['share_with_displayname'] = $sharedWith !== null ? $sharedWith->getDisplayName() : $share->getSharedWith();
189
+        } else if ($share->getShareType() === Share::SHARE_TYPE_GROUP) {
190
+            $group = $this->groupManager->get($share->getSharedWith());
191
+            $result['share_with'] = $share->getSharedWith();
192
+            $result['share_with_displayname'] = $group !== null ? $group->getDisplayName() : $share->getSharedWith();
193
+        } else if ($share->getShareType() === Share::SHARE_TYPE_LINK) {
194
+
195
+            $result['share_with'] = $share->getPassword();
196
+            $result['share_with_displayname'] = $share->getPassword();
197
+
198
+            $result['token'] = $share->getToken();
199
+            $result['url'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $share->getToken()]);
200
+
201
+        } else if ($share->getShareType() === Share::SHARE_TYPE_REMOTE || $share->getShareType() === Share::SHARE_TYPE_REMOTE_GROUP) {
202
+            $result['share_with'] = $share->getSharedWith();
203
+            $result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'CLOUD');
204
+            $result['token'] = $share->getToken();
205
+        } else if ($share->getShareType() === Share::SHARE_TYPE_EMAIL) {
206
+            $result['share_with'] = $share->getSharedWith();
207
+            $result['password'] = $share->getPassword();
208
+            $result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'EMAIL');
209
+            $result['token'] = $share->getToken();
210
+        } else if ($share->getShareType() === Share::SHARE_TYPE_CIRCLE) {
211
+            // getSharedWith() returns either "name (type, owner)" or
212
+            // "name (type, owner) [id]", depending on the Circles app version.
213
+            $hasCircleId = (substr($share->getSharedWith(), -1) === ']');
214
+
215
+            $result['share_with_displayname'] = $share->getSharedWithDisplayName();
216
+            if (empty($result['share_with_displayname'])) {
217
+                $displayNameLength = ($hasCircleId? strrpos($share->getSharedWith(), ' '): strlen($share->getSharedWith()));
218
+                $result['share_with_displayname'] = substr($share->getSharedWith(), 0, $displayNameLength);
219
+            }
220
+
221
+            $result['share_with_avatar'] = $share->getSharedWithAvatar();
222
+
223
+            $shareWithStart = ($hasCircleId? strrpos($share->getSharedWith(), '[') + 1: 0);
224
+            $shareWithLength = ($hasCircleId? -1: strpos($share->getSharedWith(), ' '));
225
+            $result['share_with'] = substr($share->getSharedWith(), $shareWithStart, $shareWithLength);
226
+        }
227
+
228
+
229
+        $result['mail_send'] = $share->getMailSend() ? 1 : 0;
230
+
231
+        return $result;
232
+    }
233
+
234
+    /**
235
+     * Check if one of the users address books knows the exact property, if
236
+     * yes we return the full name.
237
+     *
238
+     * @param string $query
239
+     * @param string $property
240
+     * @return string
241
+     */
242
+    private function getDisplayNameFromAddressBook(string $query, string $property): string {
243
+        // FIXME: If we inject the contacts manager it gets initialized bofore any address books are registered
244
+        $result = \OC::$server->getContactsManager()->search($query, [$property]);
245
+        foreach ($result as $r) {
246
+            foreach($r[$property] as $value) {
247
+                if ($value === $query) {
248
+                    return $r['FN'];
249
+                }
250
+            }
251
+        }
252
+
253
+        return $query;
254
+    }
255
+
256
+    /**
257
+     * Get a specific share by id
258
+     *
259
+     * @NoAdminRequired
260
+     *
261
+     * @param string $id
262
+     * @return DataResponse
263
+     * @throws OCSNotFoundException
264
+     */
265
+    public function getShare(string $id): DataResponse {
266
+        try {
267
+            $share = $this->getShareById($id);
268
+        } catch (ShareNotFound $e) {
269
+            throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
270
+        }
271
+
272
+        if ($this->canAccessShare($share)) {
273
+            try {
274
+                $share = $this->formatShare($share);
275
+                return new DataResponse([$share]);
276
+            } catch (NotFoundException $e) {
277
+                //Fall trough
278
+            }
279
+        }
280
+
281
+        throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
282
+    }
283
+
284
+    /**
285
+     * Delete a share
286
+     *
287
+     * @NoAdminRequired
288
+     *
289
+     * @param string $id
290
+     * @return DataResponse
291
+     * @throws OCSNotFoundException
292
+     */
293
+    public function deleteShare(string $id): DataResponse {
294
+        try {
295
+            $share = $this->getShareById($id);
296
+        } catch (ShareNotFound $e) {
297
+            throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
298
+        }
299
+
300
+        try {
301
+            $this->lock($share->getNode());
302
+        } catch (LockedException $e) {
303
+            throw new OCSNotFoundException($this->l->t('could not delete share'));
304
+        }
305
+
306
+        if (!$this->canAccessShare($share)) {
307
+            throw new OCSNotFoundException($this->l->t('Could not delete share'));
308
+        }
309
+
310
+        if ($share->getShareType() === Share::SHARE_TYPE_GROUP &&
311
+            $share->getShareOwner() !== $this->currentUser &&
312
+            $share->getSharedBy() !== $this->currentUser) {
313
+            $this->shareManager->deleteFromSelf($share, $this->currentUser);
314
+        } else {
315
+            $this->shareManager->deleteShare($share);
316
+        }
317
+
318
+        return new DataResponse();
319
+    }
320
+
321
+    /**
322
+     * @NoAdminRequired
323
+     *
324
+     * @param string $path
325
+     * @param int $permissions
326
+     * @param int $shareType
327
+     * @param string $shareWith
328
+     * @param string $publicUpload
329
+     * @param string $password
330
+     * @param string $expireDate
331
+     *
332
+     * @return DataResponse
333
+     * @throws OCSNotFoundException
334
+     * @throws OCSForbiddenException
335
+     * @throws OCSBadRequestException
336
+     * @throws OCSException
337
+     *
338
+     * @suppress PhanUndeclaredClassMethod
339
+     */
340
+    public function createShare(
341
+        string $path = null,
342
+        int $permissions = null,
343
+        int $shareType = -1,
344
+        string $shareWith = null,
345
+        string $publicUpload = 'false',
346
+        string $password = '',
347
+        string $expireDate = ''
348
+    ): DataResponse {
349
+        $share = $this->shareManager->newShare();
350
+
351
+        if ($permissions === null) {
352
+            $permissions = $this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL);
353
+        }
354
+
355
+        // Verify path
356
+        if ($path === null) {
357
+            throw new OCSNotFoundException($this->l->t('Please specify a file or folder path'));
358
+        }
359
+
360
+        $userFolder = $this->rootFolder->getUserFolder($this->currentUser);
361
+        try {
362
+            $path = $userFolder->get($path);
363
+        } catch (NotFoundException $e) {
364
+            throw new OCSNotFoundException($this->l->t('Wrong path, file/folder doesn\'t exist'));
365
+        }
366
+
367
+        $share->setNode($path);
368
+
369
+        try {
370
+            $this->lock($share->getNode());
371
+        } catch (LockedException $e) {
372
+            throw new OCSNotFoundException($this->l->t('Could not create share'));
373
+        }
374
+
375
+        if ($permissions < 0 || $permissions > Constants::PERMISSION_ALL) {
376
+            throw new OCSNotFoundException($this->l->t('invalid permissions'));
377
+        }
378
+
379
+        // Shares always require read permissions
380
+        $permissions |= Constants::PERMISSION_READ;
381
+
382
+        if ($path instanceof \OCP\Files\File) {
383
+            // Single file shares should never have delete or create permissions
384
+            $permissions &= ~Constants::PERMISSION_DELETE;
385
+            $permissions &= ~Constants::PERMISSION_CREATE;
386
+        }
387
+
388
+        /*
389 389
 		 * Hack for https://github.com/owncloud/core/issues/22587
390 390
 		 * We check the permissions via webdav. But the permissions of the mount point
391 391
 		 * do not equal the share permissions. Here we fix that for federated mounts.
392 392
 		 */
393
-		if ($path->getStorage()->instanceOfStorage(Storage::class)) {
394
-			$permissions &= ~($permissions & ~$path->getPermissions());
395
-		}
396
-
397
-		if ($shareType === Share::SHARE_TYPE_USER) {
398
-			// Valid user is required to share
399
-			if ($shareWith === null || !$this->userManager->userExists($shareWith)) {
400
-				throw new OCSNotFoundException($this->l->t('Please specify a valid user'));
401
-			}
402
-			$share->setSharedWith($shareWith);
403
-			$share->setPermissions($permissions);
404
-		} else if ($shareType === Share::SHARE_TYPE_GROUP) {
405
-			if (!$this->shareManager->allowGroupSharing()) {
406
-				throw new OCSNotFoundException($this->l->t('Group sharing is disabled by the administrator'));
407
-			}
408
-
409
-			// Valid group is required to share
410
-			if ($shareWith === null || !$this->groupManager->groupExists($shareWith)) {
411
-				throw new OCSNotFoundException($this->l->t('Please specify a valid group'));
412
-			}
413
-			$share->setSharedWith($shareWith);
414
-			$share->setPermissions($permissions);
415
-		} else if ($shareType === Share::SHARE_TYPE_LINK) {
416
-			//Can we even share links?
417
-			if (!$this->shareManager->shareApiAllowLinks()) {
418
-				throw new OCSNotFoundException($this->l->t('Public link sharing is disabled by the administrator'));
419
-			}
420
-
421
-			/*
393
+        if ($path->getStorage()->instanceOfStorage(Storage::class)) {
394
+            $permissions &= ~($permissions & ~$path->getPermissions());
395
+        }
396
+
397
+        if ($shareType === Share::SHARE_TYPE_USER) {
398
+            // Valid user is required to share
399
+            if ($shareWith === null || !$this->userManager->userExists($shareWith)) {
400
+                throw new OCSNotFoundException($this->l->t('Please specify a valid user'));
401
+            }
402
+            $share->setSharedWith($shareWith);
403
+            $share->setPermissions($permissions);
404
+        } else if ($shareType === Share::SHARE_TYPE_GROUP) {
405
+            if (!$this->shareManager->allowGroupSharing()) {
406
+                throw new OCSNotFoundException($this->l->t('Group sharing is disabled by the administrator'));
407
+            }
408
+
409
+            // Valid group is required to share
410
+            if ($shareWith === null || !$this->groupManager->groupExists($shareWith)) {
411
+                throw new OCSNotFoundException($this->l->t('Please specify a valid group'));
412
+            }
413
+            $share->setSharedWith($shareWith);
414
+            $share->setPermissions($permissions);
415
+        } else if ($shareType === Share::SHARE_TYPE_LINK) {
416
+            //Can we even share links?
417
+            if (!$this->shareManager->shareApiAllowLinks()) {
418
+                throw new OCSNotFoundException($this->l->t('Public link sharing is disabled by the administrator'));
419
+            }
420
+
421
+            /*
422 422
 			 * For now we only allow 1 link share.
423 423
 			 * Return the existing link share if this is a duplicate
424 424
 			 */
425
-			$existingShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_LINK, $path, false, 1, 0);
426
-			if (!empty($existingShares)) {
427
-				return new DataResponse($this->formatShare($existingShares[0]));
428
-			}
429
-
430
-			if ($publicUpload === 'true') {
431
-				// Check if public upload is allowed
432
-				if (!$this->shareManager->shareApiLinkAllowPublicUpload()) {
433
-					throw new OCSForbiddenException($this->l->t('Public upload disabled by the administrator'));
434
-				}
435
-
436
-				// Public upload can only be set for folders
437
-				if ($path instanceof \OCP\Files\File) {
438
-					throw new OCSNotFoundException($this->l->t('Public upload is only possible for publicly shared folders'));
439
-				}
440
-
441
-				$share->setPermissions(
442
-					Constants::PERMISSION_READ |
443
-					Constants::PERMISSION_CREATE |
444
-					Constants::PERMISSION_UPDATE |
445
-					Constants::PERMISSION_DELETE
446
-				);
447
-			} else {
448
-				$share->setPermissions(Constants::PERMISSION_READ);
449
-			}
450
-
451
-			// Set password
452
-			if ($password !== '') {
453
-				$share->setPassword($password);
454
-			}
455
-
456
-			//Expire date
457
-			if ($expireDate !== '') {
458
-				try {
459
-					$expireDate = $this->parseDate($expireDate);
460
-					$share->setExpirationDate($expireDate);
461
-				} catch (\Exception $e) {
462
-					throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD'));
463
-				}
464
-			}
465
-
466
-		} else if ($shareType === Share::SHARE_TYPE_REMOTE) {
467
-			if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) {
468
-				throw new OCSForbiddenException($this->l->t('Sharing %s failed because the back end does not allow shares from type %s', [$path->getPath(), $shareType]));
469
-			}
470
-
471
-			$share->setSharedWith($shareWith);
472
-			$share->setPermissions($permissions);
473
-		}  else if ($shareType === Share::SHARE_TYPE_REMOTE_GROUP) {
474
-			if (!$this->shareManager->outgoingServer2ServerGroupSharesAllowed()) {
475
-				throw new OCSForbiddenException($this->l->t('Sharing %s failed because the back end does not allow shares from type %s', [$path->getPath(), $shareType]));
476
-			}
477
-
478
-			$share->setSharedWith($shareWith);
479
-			$share->setPermissions($permissions);
480
-		} else if ($shareType === Share::SHARE_TYPE_EMAIL) {
481
-			if ($share->getNodeType() === 'file') {
482
-				$share->setPermissions(Constants::PERMISSION_READ);
483
-			} else {
484
-				$share->setPermissions($permissions);
485
-			}
486
-			$share->setSharedWith($shareWith);
487
-		} else if ($shareType === Share::SHARE_TYPE_CIRCLE) {
488
-			if (!\OC::$server->getAppManager()->isEnabledForUser('circles') || !class_exists('\OCA\Circles\ShareByCircleProvider')) {
489
-				throw new OCSNotFoundException($this->l->t('You cannot share to a Circle if the app is not enabled'));
490
-			}
491
-
492
-			$circle = \OCA\Circles\Api\v1\Circles::detailsCircle($shareWith);
493
-
494
-			// Valid circle is required to share
495
-			if ($circle === null) {
496
-				throw new OCSNotFoundException($this->l->t('Please specify a valid circle'));
497
-			}
498
-			$share->setSharedWith($shareWith);
499
-			$share->setPermissions($permissions);
500
-		} else {
501
-			throw new OCSBadRequestException($this->l->t('Unknown share type'));
502
-		}
503
-
504
-		$share->setShareType($shareType);
505
-		$share->setSharedBy($this->currentUser);
506
-
507
-		try {
508
-			$share = $this->shareManager->createShare($share);
509
-		} catch (GenericShareException $e) {
510
-			$code = $e->getCode() === 0 ? 403 : $e->getCode();
511
-			throw new OCSException($e->getHint(), $code);
512
-		} catch (\Exception $e) {
513
-			throw new OCSForbiddenException($e->getMessage(), $e);
514
-		}
515
-
516
-		$output = $this->formatShare($share);
517
-
518
-		return new DataResponse($output);
519
-	}
520
-
521
-	/**
522
-	 * @param \OCP\Files\File|\OCP\Files\Folder $node
523
-	 * @param boolean $includeTags
524
-	 * @return DataResponse
525
-	 */
526
-	private function getSharedWithMe($node = null, bool $includeTags): DataResponse {
527
-
528
-		$userShares = $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_USER, $node, -1, 0);
529
-		$groupShares = $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_GROUP, $node, -1, 0);
530
-		$circleShares = $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_CIRCLE, $node, -1, 0);
531
-
532
-		$shares = array_merge($userShares, $groupShares, $circleShares);
533
-
534
-		$shares = array_filter($shares, function (IShare $share) {
535
-			return $share->getShareOwner() !== $this->currentUser;
536
-		});
537
-
538
-		$formatted = [];
539
-		foreach ($shares as $share) {
540
-			if ($this->canAccessShare($share)) {
541
-				try {
542
-					$formatted[] = $this->formatShare($share);
543
-				} catch (NotFoundException $e) {
544
-					// Ignore this share
545
-				}
546
-			}
547
-		}
548
-
549
-		if ($includeTags) {
550
-			$formatted = Helper::populateTags($formatted, 'file_source', \OC::$server->getTagManager());
551
-		}
552
-
553
-		return new DataResponse($formatted);
554
-	}
555
-
556
-	/**
557
-	 * @param \OCP\Files\Folder $folder
558
-	 * @return DataResponse
559
-	 * @throws OCSBadRequestException
560
-	 */
561
-	private function getSharesInDir(Node $folder): DataResponse {
562
-		if (!($folder instanceof \OCP\Files\Folder)) {
563
-			throw new OCSBadRequestException($this->l->t('Not a directory'));
564
-		}
565
-
566
-		$nodes = $folder->getDirectoryListing();
567
-		/** @var \OCP\Share\IShare[] $shares */
568
-		$shares = [];
569
-		foreach ($nodes as $node) {
570
-			$shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_USER, $node, false, -1, 0));
571
-			$shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_GROUP, $node, false, -1, 0));
572
-			$shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_LINK, $node, false, -1, 0));
573
-			if($this->shareManager->shareProviderExists(Share::SHARE_TYPE_EMAIL)) {
574
-				$shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_EMAIL, $node, false, -1, 0));
575
-			}
576
-			if ($this->shareManager->outgoingServer2ServerSharesAllowed()) {
577
-				$shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_REMOTE, $node, false, -1, 0));
578
-			}
579
-		}
580
-
581
-		$formatted = [];
582
-		foreach ($shares as $share) {
583
-			try {
584
-				$formatted[] = $this->formatShare($share);
585
-			} catch (NotFoundException $e) {
586
-				//Ignore this share
587
-			}
588
-		}
589
-
590
-		return new DataResponse($formatted);
591
-	}
592
-
593
-	/**
594
-	 * The getShares function.
595
-	 *
596
-	 * @NoAdminRequired
597
-	 *
598
-	 * @param string $shared_with_me
599
-	 * @param string $reshares
600
-	 * @param string $subfiles
601
-	 * @param string $path
602
-	 *
603
-	 * - Get shares by the current user
604
-	 * - Get shares by the current user and reshares (?reshares=true)
605
-	 * - Get shares with the current user (?shared_with_me=true)
606
-	 * - Get shares for a specific path (?path=...)
607
-	 * - Get all shares in a folder (?subfiles=true&path=..)
608
-	 *
609
-	 * @return DataResponse
610
-	 * @throws OCSNotFoundException
611
-	 */
612
-	public function getShares(
613
-		string $shared_with_me = 'false',
614
-		string $reshares = 'false',
615
-		string $subfiles = 'false',
616
-		string $path = null,
617
-		string $include_tags = 'false'
618
-	): DataResponse {
619
-
620
-		if ($path !== null) {
621
-			$userFolder = $this->rootFolder->getUserFolder($this->currentUser);
622
-			try {
623
-				$path = $userFolder->get($path);
624
-				$this->lock($path);
625
-			} catch (\OCP\Files\NotFoundException $e) {
626
-				throw new OCSNotFoundException($this->l->t('Wrong path, file/folder doesn\'t exist'));
627
-			} catch (LockedException $e) {
628
-				throw new OCSNotFoundException($this->l->t('Could not lock path'));
629
-			}
630
-		}
631
-
632
-		$include_tags = $include_tags === 'true';
633
-
634
-		if ($shared_with_me === 'true') {
635
-			$result = $this->getSharedWithMe($path, $include_tags);
636
-			return $result;
637
-		}
638
-
639
-		if ($subfiles === 'true') {
640
-			$result = $this->getSharesInDir($path);
641
-			return $result;
642
-		}
643
-
644
-		if ($reshares === 'true') {
645
-			$reshares = true;
646
-		} else {
647
-			$reshares = false;
648
-		}
649
-
650
-		// Get all shares
651
-		$userShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_USER, $path, $reshares, -1, 0);
652
-		$groupShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_GROUP, $path, $reshares, -1, 0);
653
-		$linkShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_LINK, $path, $reshares, -1, 0);
654
-		if ($this->shareManager->shareProviderExists(Share::SHARE_TYPE_EMAIL)) {
655
-			$mailShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_EMAIL, $path, $reshares, -1, 0);
656
-		} else {
657
-			$mailShares = [];
658
-		}
659
-		if ($this->shareManager->shareProviderExists(Share::SHARE_TYPE_CIRCLE)) {
660
-			$circleShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_CIRCLE, $path, $reshares, -1, 0);
661
-		} else {
662
-			$circleShares = [];
663
-		}
664
-
665
-		$shares = array_merge($userShares, $groupShares, $linkShares, $mailShares, $circleShares);
666
-
667
-		if ($this->shareManager->outgoingServer2ServerSharesAllowed()) {
668
-			$federatedShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_REMOTE, $path, $reshares, -1, 0);
669
-			$shares = array_merge($shares, $federatedShares);
670
-		}
671
-
672
-		if ($this->shareManager->outgoingServer2ServerGroupSharesAllowed()) {
673
-			$federatedShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_REMOTE_GROUP, $path, $reshares, -1, 0);
674
-			$shares = array_merge($shares, $federatedShares);
675
-		}
676
-
677
-		$formatted = [];
678
-		foreach ($shares as $share) {
679
-			try {
680
-				$formatted[] = $this->formatShare($share, $path);
681
-			} catch (NotFoundException $e) {
682
-				//Ignore share
683
-			}
684
-		}
685
-
686
-		if ($include_tags) {
687
-			$formatted = Helper::populateTags($formatted, 'file_source', \OC::$server->getTagManager());
688
-		}
689
-
690
-		return new DataResponse($formatted);
691
-	}
692
-
693
-	/**
694
-	 * @NoAdminRequired
695
-	 *
696
-	 * @param string $id
697
-	 * @param int $permissions
698
-	 * @param string $password
699
-	 * @param string $publicUpload
700
-	 * @param string $expireDate
701
-	 * @return DataResponse
702
-	 * @throws OCSNotFoundException
703
-	 * @throws OCSBadRequestException
704
-	 * @throws OCSForbiddenException
705
-	 */
706
-	public function updateShare(
707
-		string $id,
708
-		int $permissions = null,
709
-		string $password = null,
710
-		string $publicUpload = null,
711
-		string $expireDate = null
712
-	): DataResponse {
713
-		try {
714
-			$share = $this->getShareById($id);
715
-		} catch (ShareNotFound $e) {
716
-			throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
717
-		}
718
-
719
-		$this->lock($share->getNode());
720
-
721
-		if (!$this->canAccessShare($share, false)) {
722
-			throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
723
-		}
724
-
725
-		if ($permissions === null && $password === null && $publicUpload === null && $expireDate === null) {
726
-			throw new OCSBadRequestException($this->l->t('Wrong or no update parameter given'));
727
-		}
728
-
729
-		/*
425
+            $existingShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_LINK, $path, false, 1, 0);
426
+            if (!empty($existingShares)) {
427
+                return new DataResponse($this->formatShare($existingShares[0]));
428
+            }
429
+
430
+            if ($publicUpload === 'true') {
431
+                // Check if public upload is allowed
432
+                if (!$this->shareManager->shareApiLinkAllowPublicUpload()) {
433
+                    throw new OCSForbiddenException($this->l->t('Public upload disabled by the administrator'));
434
+                }
435
+
436
+                // Public upload can only be set for folders
437
+                if ($path instanceof \OCP\Files\File) {
438
+                    throw new OCSNotFoundException($this->l->t('Public upload is only possible for publicly shared folders'));
439
+                }
440
+
441
+                $share->setPermissions(
442
+                    Constants::PERMISSION_READ |
443
+                    Constants::PERMISSION_CREATE |
444
+                    Constants::PERMISSION_UPDATE |
445
+                    Constants::PERMISSION_DELETE
446
+                );
447
+            } else {
448
+                $share->setPermissions(Constants::PERMISSION_READ);
449
+            }
450
+
451
+            // Set password
452
+            if ($password !== '') {
453
+                $share->setPassword($password);
454
+            }
455
+
456
+            //Expire date
457
+            if ($expireDate !== '') {
458
+                try {
459
+                    $expireDate = $this->parseDate($expireDate);
460
+                    $share->setExpirationDate($expireDate);
461
+                } catch (\Exception $e) {
462
+                    throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD'));
463
+                }
464
+            }
465
+
466
+        } else if ($shareType === Share::SHARE_TYPE_REMOTE) {
467
+            if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) {
468
+                throw new OCSForbiddenException($this->l->t('Sharing %s failed because the back end does not allow shares from type %s', [$path->getPath(), $shareType]));
469
+            }
470
+
471
+            $share->setSharedWith($shareWith);
472
+            $share->setPermissions($permissions);
473
+        }  else if ($shareType === Share::SHARE_TYPE_REMOTE_GROUP) {
474
+            if (!$this->shareManager->outgoingServer2ServerGroupSharesAllowed()) {
475
+                throw new OCSForbiddenException($this->l->t('Sharing %s failed because the back end does not allow shares from type %s', [$path->getPath(), $shareType]));
476
+            }
477
+
478
+            $share->setSharedWith($shareWith);
479
+            $share->setPermissions($permissions);
480
+        } else if ($shareType === Share::SHARE_TYPE_EMAIL) {
481
+            if ($share->getNodeType() === 'file') {
482
+                $share->setPermissions(Constants::PERMISSION_READ);
483
+            } else {
484
+                $share->setPermissions($permissions);
485
+            }
486
+            $share->setSharedWith($shareWith);
487
+        } else if ($shareType === Share::SHARE_TYPE_CIRCLE) {
488
+            if (!\OC::$server->getAppManager()->isEnabledForUser('circles') || !class_exists('\OCA\Circles\ShareByCircleProvider')) {
489
+                throw new OCSNotFoundException($this->l->t('You cannot share to a Circle if the app is not enabled'));
490
+            }
491
+
492
+            $circle = \OCA\Circles\Api\v1\Circles::detailsCircle($shareWith);
493
+
494
+            // Valid circle is required to share
495
+            if ($circle === null) {
496
+                throw new OCSNotFoundException($this->l->t('Please specify a valid circle'));
497
+            }
498
+            $share->setSharedWith($shareWith);
499
+            $share->setPermissions($permissions);
500
+        } else {
501
+            throw new OCSBadRequestException($this->l->t('Unknown share type'));
502
+        }
503
+
504
+        $share->setShareType($shareType);
505
+        $share->setSharedBy($this->currentUser);
506
+
507
+        try {
508
+            $share = $this->shareManager->createShare($share);
509
+        } catch (GenericShareException $e) {
510
+            $code = $e->getCode() === 0 ? 403 : $e->getCode();
511
+            throw new OCSException($e->getHint(), $code);
512
+        } catch (\Exception $e) {
513
+            throw new OCSForbiddenException($e->getMessage(), $e);
514
+        }
515
+
516
+        $output = $this->formatShare($share);
517
+
518
+        return new DataResponse($output);
519
+    }
520
+
521
+    /**
522
+     * @param \OCP\Files\File|\OCP\Files\Folder $node
523
+     * @param boolean $includeTags
524
+     * @return DataResponse
525
+     */
526
+    private function getSharedWithMe($node = null, bool $includeTags): DataResponse {
527
+
528
+        $userShares = $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_USER, $node, -1, 0);
529
+        $groupShares = $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_GROUP, $node, -1, 0);
530
+        $circleShares = $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_CIRCLE, $node, -1, 0);
531
+
532
+        $shares = array_merge($userShares, $groupShares, $circleShares);
533
+
534
+        $shares = array_filter($shares, function (IShare $share) {
535
+            return $share->getShareOwner() !== $this->currentUser;
536
+        });
537
+
538
+        $formatted = [];
539
+        foreach ($shares as $share) {
540
+            if ($this->canAccessShare($share)) {
541
+                try {
542
+                    $formatted[] = $this->formatShare($share);
543
+                } catch (NotFoundException $e) {
544
+                    // Ignore this share
545
+                }
546
+            }
547
+        }
548
+
549
+        if ($includeTags) {
550
+            $formatted = Helper::populateTags($formatted, 'file_source', \OC::$server->getTagManager());
551
+        }
552
+
553
+        return new DataResponse($formatted);
554
+    }
555
+
556
+    /**
557
+     * @param \OCP\Files\Folder $folder
558
+     * @return DataResponse
559
+     * @throws OCSBadRequestException
560
+     */
561
+    private function getSharesInDir(Node $folder): DataResponse {
562
+        if (!($folder instanceof \OCP\Files\Folder)) {
563
+            throw new OCSBadRequestException($this->l->t('Not a directory'));
564
+        }
565
+
566
+        $nodes = $folder->getDirectoryListing();
567
+        /** @var \OCP\Share\IShare[] $shares */
568
+        $shares = [];
569
+        foreach ($nodes as $node) {
570
+            $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_USER, $node, false, -1, 0));
571
+            $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_GROUP, $node, false, -1, 0));
572
+            $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_LINK, $node, false, -1, 0));
573
+            if($this->shareManager->shareProviderExists(Share::SHARE_TYPE_EMAIL)) {
574
+                $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_EMAIL, $node, false, -1, 0));
575
+            }
576
+            if ($this->shareManager->outgoingServer2ServerSharesAllowed()) {
577
+                $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_REMOTE, $node, false, -1, 0));
578
+            }
579
+        }
580
+
581
+        $formatted = [];
582
+        foreach ($shares as $share) {
583
+            try {
584
+                $formatted[] = $this->formatShare($share);
585
+            } catch (NotFoundException $e) {
586
+                //Ignore this share
587
+            }
588
+        }
589
+
590
+        return new DataResponse($formatted);
591
+    }
592
+
593
+    /**
594
+     * The getShares function.
595
+     *
596
+     * @NoAdminRequired
597
+     *
598
+     * @param string $shared_with_me
599
+     * @param string $reshares
600
+     * @param string $subfiles
601
+     * @param string $path
602
+     *
603
+     * - Get shares by the current user
604
+     * - Get shares by the current user and reshares (?reshares=true)
605
+     * - Get shares with the current user (?shared_with_me=true)
606
+     * - Get shares for a specific path (?path=...)
607
+     * - Get all shares in a folder (?subfiles=true&path=..)
608
+     *
609
+     * @return DataResponse
610
+     * @throws OCSNotFoundException
611
+     */
612
+    public function getShares(
613
+        string $shared_with_me = 'false',
614
+        string $reshares = 'false',
615
+        string $subfiles = 'false',
616
+        string $path = null,
617
+        string $include_tags = 'false'
618
+    ): DataResponse {
619
+
620
+        if ($path !== null) {
621
+            $userFolder = $this->rootFolder->getUserFolder($this->currentUser);
622
+            try {
623
+                $path = $userFolder->get($path);
624
+                $this->lock($path);
625
+            } catch (\OCP\Files\NotFoundException $e) {
626
+                throw new OCSNotFoundException($this->l->t('Wrong path, file/folder doesn\'t exist'));
627
+            } catch (LockedException $e) {
628
+                throw new OCSNotFoundException($this->l->t('Could not lock path'));
629
+            }
630
+        }
631
+
632
+        $include_tags = $include_tags === 'true';
633
+
634
+        if ($shared_with_me === 'true') {
635
+            $result = $this->getSharedWithMe($path, $include_tags);
636
+            return $result;
637
+        }
638
+
639
+        if ($subfiles === 'true') {
640
+            $result = $this->getSharesInDir($path);
641
+            return $result;
642
+        }
643
+
644
+        if ($reshares === 'true') {
645
+            $reshares = true;
646
+        } else {
647
+            $reshares = false;
648
+        }
649
+
650
+        // Get all shares
651
+        $userShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_USER, $path, $reshares, -1, 0);
652
+        $groupShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_GROUP, $path, $reshares, -1, 0);
653
+        $linkShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_LINK, $path, $reshares, -1, 0);
654
+        if ($this->shareManager->shareProviderExists(Share::SHARE_TYPE_EMAIL)) {
655
+            $mailShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_EMAIL, $path, $reshares, -1, 0);
656
+        } else {
657
+            $mailShares = [];
658
+        }
659
+        if ($this->shareManager->shareProviderExists(Share::SHARE_TYPE_CIRCLE)) {
660
+            $circleShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_CIRCLE, $path, $reshares, -1, 0);
661
+        } else {
662
+            $circleShares = [];
663
+        }
664
+
665
+        $shares = array_merge($userShares, $groupShares, $linkShares, $mailShares, $circleShares);
666
+
667
+        if ($this->shareManager->outgoingServer2ServerSharesAllowed()) {
668
+            $federatedShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_REMOTE, $path, $reshares, -1, 0);
669
+            $shares = array_merge($shares, $federatedShares);
670
+        }
671
+
672
+        if ($this->shareManager->outgoingServer2ServerGroupSharesAllowed()) {
673
+            $federatedShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_REMOTE_GROUP, $path, $reshares, -1, 0);
674
+            $shares = array_merge($shares, $federatedShares);
675
+        }
676
+
677
+        $formatted = [];
678
+        foreach ($shares as $share) {
679
+            try {
680
+                $formatted[] = $this->formatShare($share, $path);
681
+            } catch (NotFoundException $e) {
682
+                //Ignore share
683
+            }
684
+        }
685
+
686
+        if ($include_tags) {
687
+            $formatted = Helper::populateTags($formatted, 'file_source', \OC::$server->getTagManager());
688
+        }
689
+
690
+        return new DataResponse($formatted);
691
+    }
692
+
693
+    /**
694
+     * @NoAdminRequired
695
+     *
696
+     * @param string $id
697
+     * @param int $permissions
698
+     * @param string $password
699
+     * @param string $publicUpload
700
+     * @param string $expireDate
701
+     * @return DataResponse
702
+     * @throws OCSNotFoundException
703
+     * @throws OCSBadRequestException
704
+     * @throws OCSForbiddenException
705
+     */
706
+    public function updateShare(
707
+        string $id,
708
+        int $permissions = null,
709
+        string $password = null,
710
+        string $publicUpload = null,
711
+        string $expireDate = null
712
+    ): DataResponse {
713
+        try {
714
+            $share = $this->getShareById($id);
715
+        } catch (ShareNotFound $e) {
716
+            throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
717
+        }
718
+
719
+        $this->lock($share->getNode());
720
+
721
+        if (!$this->canAccessShare($share, false)) {
722
+            throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
723
+        }
724
+
725
+        if ($permissions === null && $password === null && $publicUpload === null && $expireDate === null) {
726
+            throw new OCSBadRequestException($this->l->t('Wrong or no update parameter given'));
727
+        }
728
+
729
+        /*
730 730
 		 * expirationdate, password and publicUpload only make sense for link shares
731 731
 		 */
732
-		if ($share->getShareType() === Share::SHARE_TYPE_LINK) {
733
-
734
-			$newPermissions = null;
735
-			if ($publicUpload === 'true') {
736
-				$newPermissions = Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE;
737
-			} else if ($publicUpload === 'false') {
738
-				$newPermissions = Constants::PERMISSION_READ;
739
-			}
740
-
741
-			if ($permissions !== null) {
742
-				$newPermissions = (int)$permissions;
743
-				$newPermissions = $newPermissions & ~Constants::PERMISSION_SHARE;
744
-			}
745
-
746
-			if ($newPermissions !== null &&
747
-				!in_array($newPermissions, [
748
-					Constants::PERMISSION_READ,
749
-					Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE, // legacy
750
-					Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE, // correct
751
-					Constants::PERMISSION_CREATE, // hidden file list
752
-					Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE, // allow to edit single files
753
-				], true)
754
-			) {
755
-				throw new OCSBadRequestException($this->l->t('Can\'t change permissions for public share links'));
756
-			}
757
-
758
-			if (
759
-				// legacy
760
-				$newPermissions === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE) ||
761
-				// correct
762
-				$newPermissions === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE)
763
-			) {
764
-				if (!$this->shareManager->shareApiLinkAllowPublicUpload()) {
765
-					throw new OCSForbiddenException($this->l->t('Public upload disabled by the administrator'));
766
-				}
767
-
768
-				if (!($share->getNode() instanceof \OCP\Files\Folder)) {
769
-					throw new OCSBadRequestException($this->l->t('Public upload is only possible for publicly shared folders'));
770
-				}
771
-
772
-				// normalize to correct public upload permissions
773
-				$newPermissions = Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE;
774
-			}
775
-
776
-			if ($newPermissions !== null) {
777
-				$share->setPermissions($newPermissions);
778
-				$permissions = $newPermissions;
779
-			}
780
-
781
-			if ($expireDate === '') {
782
-				$share->setExpirationDate(null);
783
-			} else if ($expireDate !== null) {
784
-				try {
785
-					$expireDate = $this->parseDate($expireDate);
786
-				} catch (\Exception $e) {
787
-					throw new OCSBadRequestException($e->getMessage(), $e);
788
-				}
789
-				$share->setExpirationDate($expireDate);
790
-			}
791
-
792
-			if ($password === '') {
793
-				$share->setPassword(null);
794
-			} else if ($password !== null) {
795
-				$share->setPassword($password);
796
-			}
797
-
798
-		} else {
799
-			if ($permissions !== null) {
800
-				$permissions = (int)$permissions;
801
-				$share->setPermissions($permissions);
802
-			}
803
-
804
-			if ($share->getShareType() === Share::SHARE_TYPE_EMAIL) {
805
-				if ($password === '') {
806
-					$share->setPassword(null);
807
-				} else if ($password !== null) {
808
-					$share->setPassword($password);
809
-				}
810
-			}
811
-
812
-			if ($expireDate === '') {
813
-				$share->setExpirationDate(null);
814
-			} else if ($expireDate !== null) {
815
-				try {
816
-					$expireDate = $this->parseDate($expireDate);
817
-				} catch (\Exception $e) {
818
-					throw new OCSBadRequestException($e->getMessage(), $e);
819
-				}
820
-				$share->setExpirationDate($expireDate);
821
-			}
822
-
823
-		}
824
-
825
-		if ($permissions !== null && $share->getShareOwner() !== $this->currentUser) {
826
-			/* Check if this is an incomming share */
827
-			$incomingShares = $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_USER, $share->getNode(), -1, 0);
828
-			$incomingShares = array_merge($incomingShares, $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_GROUP, $share->getNode(), -1, 0));
829
-
830
-			/** @var \OCP\Share\IShare[] $incomingShares */
831
-			if (!empty($incomingShares)) {
832
-				$maxPermissions = 0;
833
-				foreach ($incomingShares as $incomingShare) {
834
-					$maxPermissions |= $incomingShare->getPermissions();
835
-				}
836
-
837
-				if ($share->getPermissions() & ~$maxPermissions) {
838
-					throw new OCSNotFoundException($this->l->t('Cannot increase permissions'));
839
-				}
840
-			}
841
-		}
842
-
843
-
844
-		try {
845
-			$share = $this->shareManager->updateShare($share);
846
-		} catch (\Exception $e) {
847
-			throw new OCSBadRequestException($e->getMessage(), $e);
848
-		}
849
-
850
-		return new DataResponse($this->formatShare($share));
851
-	}
852
-
853
-	protected function canAccessShare(\OCP\Share\IShare $share, bool $checkGroups = true): bool {
854
-		// A file with permissions 0 can't be accessed by us. So Don't show it
855
-		if ($share->getPermissions() === 0) {
856
-			return false;
857
-		}
858
-
859
-		// Owner of the file and the sharer of the file can always get share
860
-		if ($share->getShareOwner() === $this->currentUser ||
861
-			$share->getSharedBy() === $this->currentUser
862
-		) {
863
-			return true;
864
-		}
865
-
866
-		// If the share is shared with you (or a group you are a member of)
867
-		if ($share->getShareType() === Share::SHARE_TYPE_USER &&
868
-			$share->getSharedWith() === $this->currentUser
869
-		) {
870
-			return true;
871
-		}
872
-
873
-		if ($checkGroups && $share->getShareType() === Share::SHARE_TYPE_GROUP) {
874
-			$sharedWith = $this->groupManager->get($share->getSharedWith());
875
-			$user = $this->userManager->get($this->currentUser);
876
-			if ($user !== null && $sharedWith !== null && $sharedWith->inGroup($user)) {
877
-				return true;
878
-			}
879
-		}
880
-
881
-		if ($share->getShareType() === Share::SHARE_TYPE_CIRCLE) {
882
-			// TODO: have a sanity check like above?
883
-			return true;
884
-		}
885
-
886
-		return false;
887
-	}
888
-
889
-	/**
890
-	 * Make sure that the passed date is valid ISO 8601
891
-	 * So YYYY-MM-DD
892
-	 * If not throw an exception
893
-	 *
894
-	 * @param string $expireDate
895
-	 *
896
-	 * @throws \Exception
897
-	 * @return \DateTime
898
-	 */
899
-	private function parseDate(string $expireDate): \DateTime {
900
-		try {
901
-			$date = new \DateTime($expireDate);
902
-		} catch (\Exception $e) {
903
-			throw new \Exception('Invalid date. Format must be YYYY-MM-DD');
904
-		}
905
-
906
-		if ($date === false) {
907
-			throw new \Exception('Invalid date. Format must be YYYY-MM-DD');
908
-		}
909
-
910
-		$date->setTime(0, 0, 0);
911
-
912
-		return $date;
913
-	}
914
-
915
-	/**
916
-	 * Since we have multiple providers but the OCS Share API v1 does
917
-	 * not support this we need to check all backends.
918
-	 *
919
-	 * @param string $id
920
-	 * @return \OCP\Share\IShare
921
-	 * @throws ShareNotFound
922
-	 */
923
-	private function getShareById(string $id): IShare {
924
-		$share = null;
925
-
926
-		// First check if it is an internal share.
927
-		try {
928
-			$share = $this->shareManager->getShareById('ocinternal:' . $id, $this->currentUser);
929
-			return $share;
930
-		} catch (ShareNotFound $e) {
931
-			// Do nothing, just try the other share type
932
-		}
933
-
934
-
935
-		try {
936
-			if ($this->shareManager->shareProviderExists(Share::SHARE_TYPE_CIRCLE)) {
937
-				$share = $this->shareManager->getShareById('ocCircleShare:' . $id, $this->currentUser);
938
-				return $share;
939
-			}
940
-		} catch (ShareNotFound $e) {
941
-			// Do nothing, just try the other share type
942
-		}
943
-
944
-		try {
945
-			if ($this->shareManager->shareProviderExists(Share::SHARE_TYPE_EMAIL)) {
946
-				$share = $this->shareManager->getShareById('ocMailShare:' . $id, $this->currentUser);
947
-				return $share;
948
-			}
949
-		} catch (ShareNotFound $e) {
950
-			// Do nothing, just try the other share type
951
-		}
952
-
953
-		if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) {
954
-			throw new ShareNotFound();
955
-		}
956
-		$share = $this->shareManager->getShareById('ocFederatedSharing:' . $id, $this->currentUser);
957
-
958
-		return $share;
959
-	}
960
-
961
-	/**
962
-	 * Lock a Node
963
-	 *
964
-	 * @param \OCP\Files\Node $node
965
-	 * @throws LockedException
966
-	 */
967
-	private function lock(\OCP\Files\Node $node) {
968
-		$node->lock(ILockingProvider::LOCK_SHARED);
969
-		$this->lockedNode = $node;
970
-	}
971
-
972
-	/**
973
-	 * Cleanup the remaining locks
974
-	 * @throws @LockedException
975
-	 */
976
-	public function cleanup() {
977
-		if ($this->lockedNode !== null) {
978
-			$this->lockedNode->unlock(ILockingProvider::LOCK_SHARED);
979
-		}
980
-	}
732
+        if ($share->getShareType() === Share::SHARE_TYPE_LINK) {
733
+
734
+            $newPermissions = null;
735
+            if ($publicUpload === 'true') {
736
+                $newPermissions = Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE;
737
+            } else if ($publicUpload === 'false') {
738
+                $newPermissions = Constants::PERMISSION_READ;
739
+            }
740
+
741
+            if ($permissions !== null) {
742
+                $newPermissions = (int)$permissions;
743
+                $newPermissions = $newPermissions & ~Constants::PERMISSION_SHARE;
744
+            }
745
+
746
+            if ($newPermissions !== null &&
747
+                !in_array($newPermissions, [
748
+                    Constants::PERMISSION_READ,
749
+                    Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE, // legacy
750
+                    Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE, // correct
751
+                    Constants::PERMISSION_CREATE, // hidden file list
752
+                    Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE, // allow to edit single files
753
+                ], true)
754
+            ) {
755
+                throw new OCSBadRequestException($this->l->t('Can\'t change permissions for public share links'));
756
+            }
757
+
758
+            if (
759
+                // legacy
760
+                $newPermissions === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE) ||
761
+                // correct
762
+                $newPermissions === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE)
763
+            ) {
764
+                if (!$this->shareManager->shareApiLinkAllowPublicUpload()) {
765
+                    throw new OCSForbiddenException($this->l->t('Public upload disabled by the administrator'));
766
+                }
767
+
768
+                if (!($share->getNode() instanceof \OCP\Files\Folder)) {
769
+                    throw new OCSBadRequestException($this->l->t('Public upload is only possible for publicly shared folders'));
770
+                }
771
+
772
+                // normalize to correct public upload permissions
773
+                $newPermissions = Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE;
774
+            }
775
+
776
+            if ($newPermissions !== null) {
777
+                $share->setPermissions($newPermissions);
778
+                $permissions = $newPermissions;
779
+            }
780
+
781
+            if ($expireDate === '') {
782
+                $share->setExpirationDate(null);
783
+            } else if ($expireDate !== null) {
784
+                try {
785
+                    $expireDate = $this->parseDate($expireDate);
786
+                } catch (\Exception $e) {
787
+                    throw new OCSBadRequestException($e->getMessage(), $e);
788
+                }
789
+                $share->setExpirationDate($expireDate);
790
+            }
791
+
792
+            if ($password === '') {
793
+                $share->setPassword(null);
794
+            } else if ($password !== null) {
795
+                $share->setPassword($password);
796
+            }
797
+
798
+        } else {
799
+            if ($permissions !== null) {
800
+                $permissions = (int)$permissions;
801
+                $share->setPermissions($permissions);
802
+            }
803
+
804
+            if ($share->getShareType() === Share::SHARE_TYPE_EMAIL) {
805
+                if ($password === '') {
806
+                    $share->setPassword(null);
807
+                } else if ($password !== null) {
808
+                    $share->setPassword($password);
809
+                }
810
+            }
811
+
812
+            if ($expireDate === '') {
813
+                $share->setExpirationDate(null);
814
+            } else if ($expireDate !== null) {
815
+                try {
816
+                    $expireDate = $this->parseDate($expireDate);
817
+                } catch (\Exception $e) {
818
+                    throw new OCSBadRequestException($e->getMessage(), $e);
819
+                }
820
+                $share->setExpirationDate($expireDate);
821
+            }
822
+
823
+        }
824
+
825
+        if ($permissions !== null && $share->getShareOwner() !== $this->currentUser) {
826
+            /* Check if this is an incomming share */
827
+            $incomingShares = $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_USER, $share->getNode(), -1, 0);
828
+            $incomingShares = array_merge($incomingShares, $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_GROUP, $share->getNode(), -1, 0));
829
+
830
+            /** @var \OCP\Share\IShare[] $incomingShares */
831
+            if (!empty($incomingShares)) {
832
+                $maxPermissions = 0;
833
+                foreach ($incomingShares as $incomingShare) {
834
+                    $maxPermissions |= $incomingShare->getPermissions();
835
+                }
836
+
837
+                if ($share->getPermissions() & ~$maxPermissions) {
838
+                    throw new OCSNotFoundException($this->l->t('Cannot increase permissions'));
839
+                }
840
+            }
841
+        }
842
+
843
+
844
+        try {
845
+            $share = $this->shareManager->updateShare($share);
846
+        } catch (\Exception $e) {
847
+            throw new OCSBadRequestException($e->getMessage(), $e);
848
+        }
849
+
850
+        return new DataResponse($this->formatShare($share));
851
+    }
852
+
853
+    protected function canAccessShare(\OCP\Share\IShare $share, bool $checkGroups = true): bool {
854
+        // A file with permissions 0 can't be accessed by us. So Don't show it
855
+        if ($share->getPermissions() === 0) {
856
+            return false;
857
+        }
858
+
859
+        // Owner of the file and the sharer of the file can always get share
860
+        if ($share->getShareOwner() === $this->currentUser ||
861
+            $share->getSharedBy() === $this->currentUser
862
+        ) {
863
+            return true;
864
+        }
865
+
866
+        // If the share is shared with you (or a group you are a member of)
867
+        if ($share->getShareType() === Share::SHARE_TYPE_USER &&
868
+            $share->getSharedWith() === $this->currentUser
869
+        ) {
870
+            return true;
871
+        }
872
+
873
+        if ($checkGroups && $share->getShareType() === Share::SHARE_TYPE_GROUP) {
874
+            $sharedWith = $this->groupManager->get($share->getSharedWith());
875
+            $user = $this->userManager->get($this->currentUser);
876
+            if ($user !== null && $sharedWith !== null && $sharedWith->inGroup($user)) {
877
+                return true;
878
+            }
879
+        }
880
+
881
+        if ($share->getShareType() === Share::SHARE_TYPE_CIRCLE) {
882
+            // TODO: have a sanity check like above?
883
+            return true;
884
+        }
885
+
886
+        return false;
887
+    }
888
+
889
+    /**
890
+     * Make sure that the passed date is valid ISO 8601
891
+     * So YYYY-MM-DD
892
+     * If not throw an exception
893
+     *
894
+     * @param string $expireDate
895
+     *
896
+     * @throws \Exception
897
+     * @return \DateTime
898
+     */
899
+    private function parseDate(string $expireDate): \DateTime {
900
+        try {
901
+            $date = new \DateTime($expireDate);
902
+        } catch (\Exception $e) {
903
+            throw new \Exception('Invalid date. Format must be YYYY-MM-DD');
904
+        }
905
+
906
+        if ($date === false) {
907
+            throw new \Exception('Invalid date. Format must be YYYY-MM-DD');
908
+        }
909
+
910
+        $date->setTime(0, 0, 0);
911
+
912
+        return $date;
913
+    }
914
+
915
+    /**
916
+     * Since we have multiple providers but the OCS Share API v1 does
917
+     * not support this we need to check all backends.
918
+     *
919
+     * @param string $id
920
+     * @return \OCP\Share\IShare
921
+     * @throws ShareNotFound
922
+     */
923
+    private function getShareById(string $id): IShare {
924
+        $share = null;
925
+
926
+        // First check if it is an internal share.
927
+        try {
928
+            $share = $this->shareManager->getShareById('ocinternal:' . $id, $this->currentUser);
929
+            return $share;
930
+        } catch (ShareNotFound $e) {
931
+            // Do nothing, just try the other share type
932
+        }
933
+
934
+
935
+        try {
936
+            if ($this->shareManager->shareProviderExists(Share::SHARE_TYPE_CIRCLE)) {
937
+                $share = $this->shareManager->getShareById('ocCircleShare:' . $id, $this->currentUser);
938
+                return $share;
939
+            }
940
+        } catch (ShareNotFound $e) {
941
+            // Do nothing, just try the other share type
942
+        }
943
+
944
+        try {
945
+            if ($this->shareManager->shareProviderExists(Share::SHARE_TYPE_EMAIL)) {
946
+                $share = $this->shareManager->getShareById('ocMailShare:' . $id, $this->currentUser);
947
+                return $share;
948
+            }
949
+        } catch (ShareNotFound $e) {
950
+            // Do nothing, just try the other share type
951
+        }
952
+
953
+        if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) {
954
+            throw new ShareNotFound();
955
+        }
956
+        $share = $this->shareManager->getShareById('ocFederatedSharing:' . $id, $this->currentUser);
957
+
958
+        return $share;
959
+    }
960
+
961
+    /**
962
+     * Lock a Node
963
+     *
964
+     * @param \OCP\Files\Node $node
965
+     * @throws LockedException
966
+     */
967
+    private function lock(\OCP\Files\Node $node) {
968
+        $node->lock(ILockingProvider::LOCK_SHARED);
969
+        $this->lockedNode = $node;
970
+    }
971
+
972
+    /**
973
+     * Cleanup the remaining locks
974
+     * @throws @LockedException
975
+     */
976
+    public function cleanup() {
977
+        if ($this->lockedNode !== null) {
978
+            $this->lockedNode->unlock(ILockingProvider::LOCK_SHARED);
979
+        }
980
+    }
981 981
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -214,14 +214,14 @@  discard block
 block discarded – undo
214 214
 
215 215
 			$result['share_with_displayname'] = $share->getSharedWithDisplayName();
216 216
 			if (empty($result['share_with_displayname'])) {
217
-				$displayNameLength = ($hasCircleId? strrpos($share->getSharedWith(), ' '): strlen($share->getSharedWith()));
217
+				$displayNameLength = ($hasCircleId ? strrpos($share->getSharedWith(), ' ') : strlen($share->getSharedWith()));
218 218
 				$result['share_with_displayname'] = substr($share->getSharedWith(), 0, $displayNameLength);
219 219
 			}
220 220
 
221 221
 			$result['share_with_avatar'] = $share->getSharedWithAvatar();
222 222
 
223
-			$shareWithStart = ($hasCircleId? strrpos($share->getSharedWith(), '[') + 1: 0);
224
-			$shareWithLength = ($hasCircleId? -1: strpos($share->getSharedWith(), ' '));
223
+			$shareWithStart = ($hasCircleId ? strrpos($share->getSharedWith(), '[') + 1 : 0);
224
+			$shareWithLength = ($hasCircleId ? -1 : strpos($share->getSharedWith(), ' '));
225 225
 			$result['share_with'] = substr($share->getSharedWith(), $shareWithStart, $shareWithLength);
226 226
 		}
227 227
 
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
 		// FIXME: If we inject the contacts manager it gets initialized bofore any address books are registered
244 244
 		$result = \OC::$server->getContactsManager()->search($query, [$property]);
245 245
 		foreach ($result as $r) {
246
-			foreach($r[$property] as $value) {
246
+			foreach ($r[$property] as $value) {
247 247
 				if ($value === $query) {
248 248
 					return $r['FN'];
249 249
 				}
@@ -470,7 +470,7 @@  discard block
 block discarded – undo
470 470
 
471 471
 			$share->setSharedWith($shareWith);
472 472
 			$share->setPermissions($permissions);
473
-		}  else if ($shareType === Share::SHARE_TYPE_REMOTE_GROUP) {
473
+		} else if ($shareType === Share::SHARE_TYPE_REMOTE_GROUP) {
474 474
 			if (!$this->shareManager->outgoingServer2ServerGroupSharesAllowed()) {
475 475
 				throw new OCSForbiddenException($this->l->t('Sharing %s failed because the back end does not allow shares from type %s', [$path->getPath(), $shareType]));
476 476
 			}
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
 
532 532
 		$shares = array_merge($userShares, $groupShares, $circleShares);
533 533
 
534
-		$shares = array_filter($shares, function (IShare $share) {
534
+		$shares = array_filter($shares, function(IShare $share) {
535 535
 			return $share->getShareOwner() !== $this->currentUser;
536 536
 		});
537 537
 
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
 			$shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_USER, $node, false, -1, 0));
571 571
 			$shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_GROUP, $node, false, -1, 0));
572 572
 			$shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_LINK, $node, false, -1, 0));
573
-			if($this->shareManager->shareProviderExists(Share::SHARE_TYPE_EMAIL)) {
573
+			if ($this->shareManager->shareProviderExists(Share::SHARE_TYPE_EMAIL)) {
574 574
 				$shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_EMAIL, $node, false, -1, 0));
575 575
 			}
576 576
 			if ($this->shareManager->outgoingServer2ServerSharesAllowed()) {
@@ -739,7 +739,7 @@  discard block
 block discarded – undo
739 739
 			}
740 740
 
741 741
 			if ($permissions !== null) {
742
-				$newPermissions = (int)$permissions;
742
+				$newPermissions = (int) $permissions;
743 743
 				$newPermissions = $newPermissions & ~Constants::PERMISSION_SHARE;
744 744
 			}
745 745
 
@@ -797,7 +797,7 @@  discard block
 block discarded – undo
797 797
 
798 798
 		} else {
799 799
 			if ($permissions !== null) {
800
-				$permissions = (int)$permissions;
800
+				$permissions = (int) $permissions;
801 801
 				$share->setPermissions($permissions);
802 802
 			}
803 803
 
@@ -925,7 +925,7 @@  discard block
 block discarded – undo
925 925
 
926 926
 		// First check if it is an internal share.
927 927
 		try {
928
-			$share = $this->shareManager->getShareById('ocinternal:' . $id, $this->currentUser);
928
+			$share = $this->shareManager->getShareById('ocinternal:'.$id, $this->currentUser);
929 929
 			return $share;
930 930
 		} catch (ShareNotFound $e) {
931 931
 			// Do nothing, just try the other share type
@@ -934,7 +934,7 @@  discard block
 block discarded – undo
934 934
 
935 935
 		try {
936 936
 			if ($this->shareManager->shareProviderExists(Share::SHARE_TYPE_CIRCLE)) {
937
-				$share = $this->shareManager->getShareById('ocCircleShare:' . $id, $this->currentUser);
937
+				$share = $this->shareManager->getShareById('ocCircleShare:'.$id, $this->currentUser);
938 938
 				return $share;
939 939
 			}
940 940
 		} catch (ShareNotFound $e) {
@@ -943,7 +943,7 @@  discard block
 block discarded – undo
943 943
 
944 944
 		try {
945 945
 			if ($this->shareManager->shareProviderExists(Share::SHARE_TYPE_EMAIL)) {
946
-				$share = $this->shareManager->getShareById('ocMailShare:' . $id, $this->currentUser);
946
+				$share = $this->shareManager->getShareById('ocMailShare:'.$id, $this->currentUser);
947 947
 				return $share;
948 948
 			}
949 949
 		} catch (ShareNotFound $e) {
@@ -953,7 +953,7 @@  discard block
 block discarded – undo
953 953
 		if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) {
954 954
 			throw new ShareNotFound();
955 955
 		}
956
-		$share = $this->shareManager->getShareById('ocFederatedSharing:' . $id, $this->currentUser);
956
+		$share = $this->shareManager->getShareById('ocFederatedSharing:'.$id, $this->currentUser);
957 957
 
958 958
 		return $share;
959 959
 	}
Please login to merge, or discard this patch.