1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Björn Schießle <[email protected]> |
4
|
|
|
* @author Roeland Jago Douma <[email protected]> |
5
|
|
|
* |
6
|
|
|
* @copyright Copyright (c) 2018, ownCloud GmbH |
7
|
|
|
* @license AGPL-3.0 |
8
|
|
|
* |
9
|
|
|
* This code is free software: you can redistribute it and/or modify |
10
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
11
|
|
|
* as published by the Free Software Foundation. |
12
|
|
|
* |
13
|
|
|
* This program is distributed in the hope that it will be useful, |
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16
|
|
|
* GNU Affero General Public License for more details. |
17
|
|
|
* |
18
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
19
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
20
|
|
|
* |
21
|
|
|
*/ |
22
|
|
|
namespace OC\Share20; |
23
|
|
|
|
24
|
|
|
use OCP\Files\File; |
25
|
|
|
use OCP\Files\IRootFolder; |
26
|
|
|
use OCP\Files\Node; |
27
|
|
|
use OCP\Files\NotFoundException; |
28
|
|
|
use OCP\IUserManager; |
29
|
|
|
use OCP\Share\Exceptions\IllegalIDChangeException; |
30
|
|
|
use OC\Share\Constants; |
31
|
|
|
|
32
|
|
|
class Share implements \OCP\Share\IShare { |
33
|
|
|
|
34
|
|
|
/** @var string */ |
35
|
|
|
private $id; |
36
|
|
|
/** @var string */ |
37
|
|
|
private $providerId; |
38
|
|
|
/** @var Node */ |
39
|
|
|
private $node; |
40
|
|
|
/** @var int */ |
41
|
|
|
private $fileId; |
42
|
|
|
/** @var string */ |
43
|
|
|
private $nodeType; |
44
|
|
|
/** @var int */ |
45
|
|
|
private $shareType; |
46
|
|
|
/** @var string */ |
47
|
|
|
private $sharedWith; |
48
|
|
|
/** @var string */ |
49
|
|
|
private $sharedBy; |
50
|
|
|
/** @var string */ |
51
|
|
|
private $shareOwner; |
52
|
|
|
/** @var int */ |
53
|
|
|
private $permissions; |
54
|
|
|
/** @var \DateTime */ |
55
|
|
|
private $expireDate; |
56
|
|
|
/** @var string */ |
57
|
|
|
private $password; |
58
|
|
|
/** @var string */ |
59
|
|
|
private $token; |
60
|
|
|
/** @var int */ |
61
|
|
|
private $parent; |
62
|
|
|
/** @var string */ |
63
|
|
|
private $target; |
64
|
|
|
/** @var \DateTime */ |
65
|
|
|
private $shareTime; |
66
|
|
|
/** @var bool */ |
67
|
|
|
private $mailSend; |
68
|
|
|
/** @var string */ |
69
|
|
|
private $name; |
70
|
|
|
/** @var int */ |
71
|
|
|
private $state; |
72
|
|
|
/** @var bool */ |
73
|
|
|
private $shouldHashPassword; |
74
|
|
|
|
75
|
|
|
/** @var IRootFolder */ |
76
|
|
|
private $rootFolder; |
77
|
|
|
|
78
|
|
|
/** @var IUserManager */ |
79
|
|
|
private $userManager; |
80
|
|
|
|
81
|
|
|
public function __construct(IRootFolder $rootFolder, IUserManager $userManager) { |
82
|
|
|
$this->rootFolder = $rootFolder; |
83
|
|
|
$this->userManager = $userManager; |
84
|
|
|
$this->state = Constants::STATE_ACCEPTED; |
85
|
|
|
$this->shouldHashPassword = true; |
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
|
|
|
if ($this->shareOwner === null || $this->fileId === null) { |
157
|
|
|
throw new NotFoundException(); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
// for federated shares the owner can be a remote user, in this |
161
|
|
|
// case we use the initiator |
162
|
|
|
if ($this->userManager->userExists($this->shareOwner)) { |
163
|
|
|
$userFolder = $this->rootFolder->getUserFolder($this->shareOwner); |
164
|
|
|
} else { |
165
|
|
|
$userFolder = $this->rootFolder->getUserFolder($this->sharedBy); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
$nodes = $userFolder->getById($this->fileId); |
169
|
|
|
if (empty($nodes)) { |
170
|
|
|
throw new NotFoundException(); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
$this->node = $nodes[0]; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
return $this->node; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @inheritdoc |
181
|
|
|
*/ |
182
|
|
|
public function setNodeId($fileId) { |
183
|
|
|
$this->node = null; |
184
|
|
|
$this->fileId = $fileId; |
185
|
|
|
return $this; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @inheritdoc |
190
|
|
|
*/ |
191
|
|
|
public function getNodeId() { |
192
|
|
|
if ($this->fileId === null) { |
193
|
|
|
$this->fileId = $this->getNode()->getId(); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
return $this->fileId; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @inheritdoc |
201
|
|
|
*/ |
202
|
|
|
public function setNodeType($type) { |
203
|
|
|
if ($type !== 'file' && $type !== 'folder') { |
204
|
|
|
throw new \InvalidArgumentException(); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
$this->nodeType = $type; |
208
|
|
|
return $this; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* @inheritdoc |
213
|
|
|
*/ |
214
|
|
|
public function getNodeType() { |
215
|
|
|
if ($this->nodeType === null) { |
216
|
|
|
$node = $this->getNode(); |
217
|
|
|
$this->nodeType = $node instanceof File ? 'file' : 'folder'; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
return $this->nodeType; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* @inheritdoc |
225
|
|
|
*/ |
226
|
|
|
public function setShareType($shareType) { |
227
|
|
|
$this->shareType = $shareType; |
228
|
|
|
return $this; |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* @inheritdoc |
233
|
|
|
*/ |
234
|
|
|
public function getShareType() { |
235
|
|
|
return $this->shareType; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* @inheritdoc |
240
|
|
|
*/ |
241
|
|
|
public function setSharedWith($sharedWith) { |
242
|
|
|
if (!\is_string($sharedWith)) { |
243
|
|
|
throw new \InvalidArgumentException(); |
244
|
|
|
} |
245
|
|
|
$this->sharedWith = $sharedWith; |
246
|
|
|
return $this; |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
/** |
250
|
|
|
* @inheritdoc |
251
|
|
|
*/ |
252
|
|
|
public function getSharedWith() { |
253
|
|
|
return $this->sharedWith; |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
/** |
257
|
|
|
* @inheritdoc |
258
|
|
|
*/ |
259
|
|
|
public function setPermissions($permissions) { |
260
|
|
|
//TODO checkes |
261
|
|
|
|
262
|
|
|
$this->permissions = $permissions; |
263
|
|
|
return $this; |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* @inheritdoc |
268
|
|
|
*/ |
269
|
|
|
public function getPermissions() { |
270
|
|
|
return $this->permissions; |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
/** |
274
|
|
|
* @inheritdoc |
275
|
|
|
*/ |
276
|
|
|
public function setExpirationDate($expireDate) { |
277
|
|
|
//TODO checks |
278
|
|
|
|
279
|
|
|
$this->expireDate = $expireDate; |
280
|
|
|
return $this; |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
/** |
284
|
|
|
* @inheritdoc |
285
|
|
|
*/ |
286
|
|
|
public function getExpirationDate() { |
287
|
|
|
return $this->expireDate; |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* @inheritdoc |
292
|
|
|
*/ |
293
|
|
|
public function setSharedBy($sharedBy) { |
294
|
|
|
if (!\is_string($sharedBy)) { |
295
|
|
|
throw new \InvalidArgumentException(); |
296
|
|
|
} |
297
|
|
|
//TODO checks |
298
|
|
|
$this->sharedBy = $sharedBy; |
299
|
|
|
|
300
|
|
|
return $this; |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
/** |
304
|
|
|
* @inheritdoc |
305
|
|
|
*/ |
306
|
|
|
public function getSharedBy() { |
307
|
|
|
//TODO check if set |
308
|
|
|
return $this->sharedBy; |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
/** |
312
|
|
|
* @inheritdoc |
313
|
|
|
*/ |
314
|
|
|
public function setShareOwner($shareOwner) { |
315
|
|
|
if (!\is_string($shareOwner)) { |
316
|
|
|
throw new \InvalidArgumentException(); |
317
|
|
|
} |
318
|
|
|
//TODO checks |
319
|
|
|
|
320
|
|
|
$this->shareOwner = $shareOwner; |
321
|
|
|
return $this; |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
/** |
325
|
|
|
* @inheritdoc |
326
|
|
|
*/ |
327
|
|
|
public function getShareOwner() { |
328
|
|
|
//TODO check if set |
329
|
|
|
return $this->shareOwner; |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
/** |
333
|
|
|
* @inheritdoc |
334
|
|
|
*/ |
335
|
|
|
public function setPassword($password) { |
336
|
|
|
$this->password = $password; |
337
|
|
|
return $this; |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
/** |
341
|
|
|
* @inheritdoc |
342
|
|
|
*/ |
343
|
|
|
public function getPassword() { |
344
|
|
|
return $this->password; |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
/** |
348
|
|
|
* @inheritdoc |
349
|
|
|
*/ |
350
|
|
|
public function setToken($token) { |
351
|
|
|
$this->token = $token; |
352
|
|
|
return $this; |
353
|
|
|
} |
354
|
|
|
|
355
|
|
|
/** |
356
|
|
|
* @inheritdoc |
357
|
|
|
*/ |
358
|
|
|
public function getToken() { |
359
|
|
|
return $this->token; |
360
|
|
|
} |
361
|
|
|
|
362
|
|
|
/** |
363
|
|
|
* Set the parent of this share |
364
|
|
|
* |
365
|
|
|
* @param int parent |
366
|
|
|
* @return \OCP\Share\IShare |
367
|
|
|
* @deprecated The new shares do not have parents. This is just here for legacy reasons. |
368
|
|
|
*/ |
369
|
|
|
public function setParent($parent) { |
370
|
|
|
$this->parent = $parent; |
371
|
|
|
return $this; |
372
|
|
|
} |
373
|
|
|
|
374
|
|
|
/** |
375
|
|
|
* Get the parent of this share. |
376
|
|
|
* |
377
|
|
|
* @return int |
378
|
|
|
* @deprecated The new shares do not have parents. This is just here for legacy reasons. |
379
|
|
|
*/ |
380
|
|
|
public function getParent() { |
381
|
|
|
return $this->parent; |
382
|
|
|
} |
383
|
|
|
|
384
|
|
|
/** |
385
|
|
|
* @inheritdoc |
386
|
|
|
*/ |
387
|
|
|
public function setTarget($target) { |
388
|
|
|
$this->target = $target; |
389
|
|
|
return $this; |
390
|
|
|
} |
391
|
|
|
|
392
|
|
|
/** |
393
|
|
|
* @inheritdoc |
394
|
|
|
*/ |
395
|
|
|
public function getTarget() { |
396
|
|
|
return $this->target; |
397
|
|
|
} |
398
|
|
|
|
399
|
|
|
/** |
400
|
|
|
* @inheritdoc |
401
|
|
|
*/ |
402
|
|
|
public function setShareTime(\DateTime $shareTime) { |
403
|
|
|
$this->shareTime = $shareTime; |
404
|
|
|
return $this; |
405
|
|
|
} |
406
|
|
|
|
407
|
|
|
/** |
408
|
|
|
* @inheritdoc |
409
|
|
|
*/ |
410
|
|
|
public function getShareTime() { |
411
|
|
|
return $this->shareTime; |
412
|
|
|
} |
413
|
|
|
|
414
|
|
|
/** |
415
|
|
|
* @inheritdoc |
416
|
|
|
*/ |
417
|
|
|
public function setMailSend($mailSend) { |
418
|
|
|
$this->mailSend = $mailSend; |
419
|
|
|
return $this; |
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
/** |
423
|
|
|
* @inheritdoc |
424
|
|
|
*/ |
425
|
|
|
public function getMailSend() { |
426
|
|
|
return $this->mailSend; |
427
|
|
|
} |
428
|
|
|
|
429
|
|
|
/** |
430
|
|
|
* @inheritdoc |
431
|
|
|
*/ |
432
|
|
|
public function setName($name) { |
433
|
|
|
$this->name = $name; |
434
|
|
|
return $this; |
435
|
|
|
} |
436
|
|
|
|
437
|
|
|
/** |
438
|
|
|
* @inheritdoc |
439
|
|
|
*/ |
440
|
|
|
public function getName() { |
441
|
|
|
return $this->name; |
442
|
|
|
} |
443
|
|
|
|
444
|
|
|
/** |
445
|
|
|
* @inheritdoc |
446
|
|
|
*/ |
447
|
|
|
public function setState($state) { |
448
|
|
|
$this->state = $state; |
449
|
|
|
return $this; |
450
|
|
|
} |
451
|
|
|
|
452
|
|
|
/** |
453
|
|
|
* @inheritdoc |
454
|
|
|
*/ |
455
|
|
|
public function getState() { |
456
|
|
|
return $this->state; |
457
|
|
|
} |
458
|
|
|
|
459
|
|
|
/** |
460
|
|
|
* @inheritdoc |
461
|
|
|
*/ |
462
|
|
|
public function getShouldHashPassword() { |
463
|
|
|
return $this->shouldHashPassword; |
464
|
|
|
} |
465
|
|
|
|
466
|
|
|
/** |
467
|
|
|
* @inheritdoc |
468
|
|
|
*/ |
469
|
|
|
public function setShouldHashPassword($status) { |
470
|
|
|
$this->shouldHashPassword = $status; |
471
|
|
|
} |
472
|
|
|
} |
473
|
|
|
|