1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
4
|
|
|
* |
5
|
|
|
* @author Björn Schießle <[email protected]> |
6
|
|
|
* @author Robin Appelman <[email protected]> |
7
|
|
|
* @author Roeland Jago Douma <[email protected]> |
8
|
|
|
* |
9
|
|
|
* @license AGPL-3.0 |
10
|
|
|
* |
11
|
|
|
* This code is free software: you can redistribute it and/or modify |
12
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
13
|
|
|
* as published by the Free Software Foundation. |
14
|
|
|
* |
15
|
|
|
* This program is distributed in the hope that it will be useful, |
16
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18
|
|
|
* GNU Affero General Public License for more details. |
19
|
|
|
* |
20
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
21
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
22
|
|
|
* |
23
|
|
|
*/ |
24
|
|
|
namespace OC\Share20; |
25
|
|
|
|
26
|
|
|
use OCP\Files\Cache\ICacheEntry; |
27
|
|
|
use OCP\Files\File; |
28
|
|
|
use OCP\Files\IRootFolder; |
29
|
|
|
use OCP\Files\Node; |
30
|
|
|
use OCP\Files\NotFoundException; |
31
|
|
|
use OCP\IUserManager; |
32
|
|
|
use OCP\Share\Exceptions\IllegalIDChangeException; |
33
|
|
|
|
34
|
|
|
class Share implements \OCP\Share\IShare { |
35
|
|
|
|
36
|
|
|
/** @var string */ |
37
|
|
|
private $id; |
38
|
|
|
/** @var string */ |
39
|
|
|
private $providerId; |
40
|
|
|
/** @var Node */ |
41
|
|
|
private $node; |
42
|
|
|
/** @var int */ |
43
|
|
|
private $fileId; |
44
|
|
|
/** @var string */ |
45
|
|
|
private $nodeType; |
46
|
|
|
/** @var int */ |
47
|
|
|
private $shareType; |
48
|
|
|
/** @var string */ |
49
|
|
|
private $sharedWith; |
50
|
|
|
/** @var string */ |
51
|
|
|
private $sharedWithDisplayName; |
52
|
|
|
/** @var string */ |
53
|
|
|
private $sharedWithAvatar; |
54
|
|
|
/** @var string */ |
55
|
|
|
private $sharedBy; |
56
|
|
|
/** @var string */ |
57
|
|
|
private $shareOwner; |
58
|
|
|
/** @var int */ |
59
|
|
|
private $permissions; |
60
|
|
|
/** @var string */ |
61
|
|
|
private $note = ''; |
62
|
|
|
/** @var \DateTime */ |
63
|
|
|
private $expireDate; |
64
|
|
|
/** @var string */ |
65
|
|
|
private $password; |
66
|
|
|
/** @var bool */ |
67
|
|
|
private $sendPasswordByTalk = false; |
68
|
|
|
/** @var string */ |
69
|
|
|
private $token; |
70
|
|
|
/** @var int */ |
71
|
|
|
private $parent; |
72
|
|
|
/** @var string */ |
73
|
|
|
private $target; |
74
|
|
|
/** @var \DateTime */ |
75
|
|
|
private $shareTime; |
76
|
|
|
/** @var bool */ |
77
|
|
|
private $mailSend; |
78
|
|
|
|
79
|
|
|
/** @var IRootFolder */ |
80
|
|
|
private $rootFolder; |
81
|
|
|
|
82
|
|
|
/** @var IUserManager */ |
83
|
|
|
private $userManager; |
84
|
|
|
|
85
|
|
|
/** @var ICacheEntry|null */ |
86
|
|
|
private $nodeCacheEntry; |
87
|
|
|
|
88
|
|
|
public function __construct(IRootFolder $rootFolder, IUserManager $userManager) { |
89
|
|
|
$this->rootFolder = $rootFolder; |
90
|
|
|
$this->userManager = $userManager; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @inheritdoc |
95
|
|
|
*/ |
96
|
|
|
public function setId($id) { |
97
|
|
|
if (is_int($id)) { |
98
|
|
|
$id = (string)$id; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
if(!is_string($id)) { |
102
|
|
|
throw new \InvalidArgumentException('String expected.'); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
if ($this->id !== null) { |
106
|
|
|
throw new IllegalIDChangeException('Not allowed to assign a new internal id to a share'); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
$this->id = trim($id); |
110
|
|
|
return $this; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @inheritdoc |
115
|
|
|
*/ |
116
|
|
|
public function getId() { |
117
|
|
|
return $this->id; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @inheritdoc |
122
|
|
|
*/ |
123
|
|
|
public function getFullId() { |
124
|
|
|
if ($this->providerId === null || $this->id === null) { |
125
|
|
|
throw new \UnexpectedValueException; |
126
|
|
|
} |
127
|
|
|
return $this->providerId . ':' . $this->id; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @inheritdoc |
132
|
|
|
*/ |
133
|
|
|
public function setProviderId($id) { |
134
|
|
|
if(!is_string($id)) { |
135
|
|
|
throw new \InvalidArgumentException('String expected.'); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
if ($this->providerId !== null) { |
139
|
|
|
throw new IllegalIDChangeException('Not allowed to assign a new provider id to a share'); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
$this->providerId = trim($id); |
143
|
|
|
return $this; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @inheritdoc |
148
|
|
|
*/ |
149
|
|
|
public function setNode(Node $node) { |
150
|
|
|
$this->fileId = null; |
151
|
|
|
$this->nodeType = null; |
152
|
|
|
$this->node = $node; |
153
|
|
|
return $this; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* @inheritdoc |
158
|
|
|
*/ |
159
|
|
|
public function getNode() { |
160
|
|
|
if ($this->node === null) { |
161
|
|
|
|
162
|
|
|
if ($this->shareOwner === null || $this->fileId === null) { |
163
|
|
|
throw new NotFoundException(); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
// for federated shares the owner can be a remote user, in this |
167
|
|
|
// case we use the initiator |
168
|
|
|
if($this->userManager->userExists($this->shareOwner)) { |
169
|
|
|
$userFolder = $this->rootFolder->getUserFolder($this->shareOwner); |
170
|
|
|
} else { |
171
|
|
|
$userFolder = $this->rootFolder->getUserFolder($this->sharedBy); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
$nodes = $userFolder->getById($this->fileId); |
175
|
|
|
if (empty($nodes)) { |
176
|
|
|
throw new NotFoundException('Node for share not found, fileid: ' . $this->fileId); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
$this->node = $nodes[0]; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
return $this->node; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @inheritdoc |
187
|
|
|
*/ |
188
|
|
|
public function setNodeId($fileId) { |
189
|
|
|
$this->node = null; |
190
|
|
|
$this->fileId = $fileId; |
191
|
|
|
return $this; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* @inheritdoc |
196
|
|
|
*/ |
197
|
|
|
public function getNodeId() { |
198
|
|
|
if ($this->fileId === null) { |
199
|
|
|
$this->fileId = $this->getNode()->getId(); |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
return $this->fileId; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* @inheritdoc |
207
|
|
|
*/ |
208
|
|
|
public function setNodeType($type) { |
209
|
|
|
if ($type !== 'file' && $type !== 'folder') { |
210
|
|
|
throw new \InvalidArgumentException(); |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
$this->nodeType = $type; |
214
|
|
|
return $this; |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* @inheritdoc |
219
|
|
|
*/ |
220
|
|
|
public function getNodeType() { |
221
|
|
|
if ($this->nodeType === null) { |
222
|
|
|
$node = $this->getNode(); |
223
|
|
|
$this->nodeType = $node instanceof File ? 'file' : 'folder'; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
return $this->nodeType; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* @inheritdoc |
231
|
|
|
*/ |
232
|
|
|
public function setShareType($shareType) { |
233
|
|
|
$this->shareType = $shareType; |
234
|
|
|
return $this; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* @inheritdoc |
239
|
|
|
*/ |
240
|
|
|
public function getShareType() { |
241
|
|
|
return $this->shareType; |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
/** |
245
|
|
|
* @inheritdoc |
246
|
|
|
*/ |
247
|
|
|
public function setSharedWith($sharedWith) { |
248
|
|
|
if (!is_string($sharedWith)) { |
249
|
|
|
throw new \InvalidArgumentException(); |
250
|
|
|
} |
251
|
|
|
$this->sharedWith = $sharedWith; |
252
|
|
|
return $this; |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
/** |
256
|
|
|
* @inheritdoc |
257
|
|
|
*/ |
258
|
|
|
public function getSharedWith() { |
259
|
|
|
return $this->sharedWith; |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* @inheritdoc |
264
|
|
|
*/ |
265
|
|
|
public function setSharedWithDisplayName($displayName) { |
266
|
|
|
if (!is_string($displayName)) { |
267
|
|
|
throw new \InvalidArgumentException(); |
268
|
|
|
} |
269
|
|
|
$this->sharedWithDisplayName = $displayName; |
270
|
|
|
return $this; |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
/** |
274
|
|
|
* @inheritdoc |
275
|
|
|
*/ |
276
|
|
|
public function getSharedWithDisplayName() { |
277
|
|
|
return $this->sharedWithDisplayName; |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
/** |
281
|
|
|
* @inheritdoc |
282
|
|
|
*/ |
283
|
|
|
public function setSharedWithAvatar($src) { |
284
|
|
|
if (!is_string($src)) { |
285
|
|
|
throw new \InvalidArgumentException(); |
286
|
|
|
} |
287
|
|
|
$this->sharedWithAvatar = $src; |
288
|
|
|
return $this; |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
/** |
292
|
|
|
* @inheritdoc |
293
|
|
|
*/ |
294
|
|
|
public function getSharedWithAvatar() { |
295
|
|
|
return $this->sharedWithAvatar; |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
/** |
299
|
|
|
* @inheritdoc |
300
|
|
|
*/ |
301
|
|
|
public function setPermissions($permissions) { |
302
|
|
|
//TODO checkes |
303
|
|
|
|
304
|
|
|
$this->permissions = $permissions; |
305
|
|
|
return $this; |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
/** |
309
|
|
|
* @inheritdoc |
310
|
|
|
*/ |
311
|
|
|
public function getPermissions() { |
312
|
|
|
return $this->permissions; |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
/** |
316
|
|
|
* @inheritdoc |
317
|
|
|
*/ |
318
|
|
|
public function setNote($note) { |
319
|
|
|
$this->note = $note; |
320
|
|
|
return $this; |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
/** |
324
|
|
|
* @inheritdoc |
325
|
|
|
*/ |
326
|
|
|
public function getNote() { |
327
|
|
|
if (is_string($this->note)) { |
328
|
|
|
return $this->note; |
329
|
|
|
} |
330
|
|
|
return ''; |
331
|
|
|
} |
332
|
|
|
|
333
|
|
|
/** |
334
|
|
|
* @inheritdoc |
335
|
|
|
*/ |
336
|
|
|
public function setExpirationDate($expireDate) { |
337
|
|
|
//TODO checks |
338
|
|
|
|
339
|
|
|
$this->expireDate = $expireDate; |
340
|
|
|
return $this; |
341
|
|
|
} |
342
|
|
|
|
343
|
|
|
/** |
344
|
|
|
* @inheritdoc |
345
|
|
|
*/ |
346
|
|
|
public function getExpirationDate() { |
347
|
|
|
return $this->expireDate; |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
/** |
351
|
|
|
* @inheritdoc |
352
|
|
|
*/ |
353
|
|
|
public function setSharedBy($sharedBy) { |
354
|
|
|
if (!is_string($sharedBy)) { |
355
|
|
|
throw new \InvalidArgumentException(); |
356
|
|
|
} |
357
|
|
|
//TODO checks |
358
|
|
|
$this->sharedBy = $sharedBy; |
359
|
|
|
|
360
|
|
|
return $this; |
361
|
|
|
} |
362
|
|
|
|
363
|
|
|
/** |
364
|
|
|
* @inheritdoc |
365
|
|
|
*/ |
366
|
|
|
public function getSharedBy() { |
367
|
|
|
//TODO check if set |
368
|
|
|
return $this->sharedBy; |
369
|
|
|
} |
370
|
|
|
|
371
|
|
|
/** |
372
|
|
|
* @inheritdoc |
373
|
|
|
*/ |
374
|
|
|
public function setShareOwner($shareOwner) { |
375
|
|
|
if (!is_string($shareOwner)) { |
376
|
|
|
throw new \InvalidArgumentException(); |
377
|
|
|
} |
378
|
|
|
//TODO checks |
379
|
|
|
|
380
|
|
|
$this->shareOwner = $shareOwner; |
381
|
|
|
return $this; |
382
|
|
|
} |
383
|
|
|
|
384
|
|
|
/** |
385
|
|
|
* @inheritdoc |
386
|
|
|
*/ |
387
|
|
|
public function getShareOwner() { |
388
|
|
|
//TODO check if set |
389
|
|
|
return $this->shareOwner; |
390
|
|
|
} |
391
|
|
|
|
392
|
|
|
/** |
393
|
|
|
* @inheritdoc |
394
|
|
|
*/ |
395
|
|
|
public function setPassword($password) { |
396
|
|
|
$this->password = $password; |
397
|
|
|
return $this; |
398
|
|
|
} |
399
|
|
|
|
400
|
|
|
/** |
401
|
|
|
* @inheritdoc |
402
|
|
|
*/ |
403
|
|
|
public function getPassword() { |
404
|
|
|
return $this->password; |
405
|
|
|
} |
406
|
|
|
|
407
|
|
|
/** |
408
|
|
|
* @inheritdoc |
409
|
|
|
*/ |
410
|
|
|
public function setSendPasswordByTalk(bool $sendPasswordByTalk) { |
411
|
|
|
$this->sendPasswordByTalk = $sendPasswordByTalk; |
412
|
|
|
return $this; |
413
|
|
|
} |
414
|
|
|
|
415
|
|
|
/** |
416
|
|
|
* @inheritdoc |
417
|
|
|
*/ |
418
|
|
|
public function getSendPasswordByTalk(): bool { |
419
|
|
|
return $this->sendPasswordByTalk; |
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
/** |
423
|
|
|
* @inheritdoc |
424
|
|
|
*/ |
425
|
|
|
public function setToken($token) { |
426
|
|
|
$this->token = $token; |
427
|
|
|
return $this; |
428
|
|
|
} |
429
|
|
|
|
430
|
|
|
/** |
431
|
|
|
* @inheritdoc |
432
|
|
|
*/ |
433
|
|
|
public function getToken() { |
434
|
|
|
return $this->token; |
435
|
|
|
} |
436
|
|
|
|
437
|
|
|
/** |
438
|
|
|
* Set the parent of this share |
439
|
|
|
* |
440
|
|
|
* @param int parent |
441
|
|
|
* @return \OCP\Share\IShare |
442
|
|
|
* @deprecated The new shares do not have parents. This is just here for legacy reasons. |
443
|
|
|
*/ |
444
|
|
|
public function setParent($parent) { |
445
|
|
|
$this->parent = $parent; |
446
|
|
|
return $this; |
447
|
|
|
} |
448
|
|
|
|
449
|
|
|
/** |
450
|
|
|
* Get the parent of this share. |
451
|
|
|
* |
452
|
|
|
* @return int |
453
|
|
|
* @deprecated The new shares do not have parents. This is just here for legacy reasons. |
454
|
|
|
*/ |
455
|
|
|
public function getParent() { |
456
|
|
|
return $this->parent; |
457
|
|
|
} |
458
|
|
|
|
459
|
|
|
/** |
460
|
|
|
* @inheritdoc |
461
|
|
|
*/ |
462
|
|
|
public function setTarget($target) { |
463
|
|
|
$this->target = $target; |
464
|
|
|
return $this; |
465
|
|
|
} |
466
|
|
|
|
467
|
|
|
/** |
468
|
|
|
* @inheritdoc |
469
|
|
|
*/ |
470
|
|
|
public function getTarget() { |
471
|
|
|
return $this->target; |
472
|
|
|
} |
473
|
|
|
|
474
|
|
|
/** |
475
|
|
|
* @inheritdoc |
476
|
|
|
*/ |
477
|
|
|
public function setShareTime(\DateTime $shareTime) { |
478
|
|
|
$this->shareTime = $shareTime; |
479
|
|
|
return $this; |
480
|
|
|
} |
481
|
|
|
|
482
|
|
|
/** |
483
|
|
|
* @inheritdoc |
484
|
|
|
*/ |
485
|
|
|
public function getShareTime() { |
486
|
|
|
return $this->shareTime; |
487
|
|
|
} |
488
|
|
|
|
489
|
|
|
/** |
490
|
|
|
* @inheritdoc |
491
|
|
|
*/ |
492
|
|
|
public function setMailSend($mailSend) { |
493
|
|
|
$this->mailSend = $mailSend; |
494
|
|
|
return $this; |
495
|
|
|
} |
496
|
|
|
|
497
|
|
|
/** |
498
|
|
|
* @inheritdoc |
499
|
|
|
*/ |
500
|
|
|
public function getMailSend() { |
501
|
|
|
return $this->mailSend; |
502
|
|
|
} |
503
|
|
|
|
504
|
|
|
/** |
505
|
|
|
* @inheritdoc |
506
|
|
|
*/ |
507
|
|
|
public function setNodeCacheEntry(ICacheEntry $entry) { |
508
|
|
|
$this->nodeCacheEntry = $entry; |
509
|
|
|
} |
510
|
|
|
|
511
|
|
|
/** |
512
|
|
|
* @inheritdoc |
513
|
|
|
*/ |
514
|
|
|
public function getNodeCacheEntry() { |
515
|
|
|
return $this->nodeCacheEntry; |
516
|
|
|
} |
517
|
|
|
} |
518
|
|
|
|