Passed
Push — master ( 3eb5ac...514185 )
by Roeland
15:00
created

Share::getPassword()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
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
use OCP\Share\IShare;
34
35
class Share implements \OCP\Share\IShare {
36
37
	/** @var string */
38
	private $id;
39
	/** @var string */
40
	private $providerId;
41
	/** @var Node */
42
	private $node;
43
	/** @var int */
44
	private $fileId;
45
	/** @var string */
46
	private $nodeType;
47
	/** @var int */
48
	private $shareType;
49
	/** @var string */
50
	private $sharedWith;
51
	/** @var string */
52
	private $sharedWithDisplayName;
53
	/** @var string */
54
	private $sharedWithAvatar;
55
	/** @var string */
56
	private $sharedBy;
57
	/** @var string */
58
	private $shareOwner;
59
	/** @var int */
60
	private $permissions;
61
	/** @var string */
62
	private $note = '';
63
	/** @var \DateTime */
64
	private $expireDate;
65
	/** @var string */
66
	private $password;
67
	/** @var bool */
68
	private $sendPasswordByTalk = false;
69
	/** @var string */
70
	private $token;
71
	/** @var int */
72
	private $parent;
73
	/** @var string */
74
	private $target;
75
	/** @var \DateTime */
76
	private $shareTime;
77
	/** @var bool */
78
	private $mailSend;
79
80
	/** @var IRootFolder */
81
	private $rootFolder;
82
83
	/** @var IUserManager */
84
	private $userManager;
85
86
	/** @var ICacheEntry|null */
87
	private $nodeCacheEntry;
88
89
	/** @var bool */
90
	private $hideDownload = false;
91
92
	public function __construct(IRootFolder $rootFolder, IUserManager $userManager) {
93
		$this->rootFolder = $rootFolder;
94
		$this->userManager = $userManager;
95
	}
96
97
	/**
98
	 * @inheritdoc
99
	 */
100
	public function setId($id) {
101
		if (is_int($id)) {
102
			$id = (string)$id;
103
		}
104
105
		if(!is_string($id)) {
106
			throw new \InvalidArgumentException('String expected.');
107
		}
108
109
		if ($this->id !== null) {
110
			throw new IllegalIDChangeException('Not allowed to assign a new internal id to a share');
111
		}
112
113
		$this->id = trim($id);
114
		return $this;
115
	}
116
117
	/**
118
	 * @inheritdoc
119
	 */
120
	public function getId() {
121
		return $this->id;
122
	}
123
124
	/**
125
	 * @inheritdoc
126
	 */
127
	public function getFullId() {
128
		if ($this->providerId === null || $this->id === null) {
129
			throw new \UnexpectedValueException;
130
		}
131
		return $this->providerId . ':' . $this->id;
132
	}
133
134
	/**
135
	 * @inheritdoc
136
	 */
137
	public function setProviderId($id) {
138
		if(!is_string($id)) {
139
			throw new \InvalidArgumentException('String expected.');
140
		}
141
142
		if ($this->providerId !== null) {
143
			throw new IllegalIDChangeException('Not allowed to assign a new provider id to a share');
144
		}
145
146
		$this->providerId = trim($id);
147
		return $this;
148
	}
149
150
	/**
151
	 * @inheritdoc
152
	 */
153
	public function setNode(Node $node) {
154
		$this->fileId = null;
155
		$this->nodeType = null;
156
		$this->node = $node;
157
		return $this;
158
	}
159
160
	/**
161
	 * @inheritdoc
162
	 */
163
	public function getNode() {
164
		if ($this->node === null) {
165
166
			if ($this->shareOwner === null || $this->fileId === null) {
167
				throw new NotFoundException();
168
			}
169
170
			// for federated shares the owner can be a remote user, in this
171
			// case we use the initiator
172
			if($this->userManager->userExists($this->shareOwner)) {
173
				$userFolder = $this->rootFolder->getUserFolder($this->shareOwner);
174
			} else {
175
				$userFolder = $this->rootFolder->getUserFolder($this->sharedBy);
176
			}
177
178
			$nodes = $userFolder->getById($this->fileId);
179
			if (empty($nodes)) {
180
				throw new NotFoundException('Node for share not found, fileid: ' . $this->fileId);
181
			}
182
183
			$this->node = $nodes[0];
184
		}
185
186
		return $this->node;
187
	}
188
189
	/**
190
	 * @inheritdoc
191
	 */
192
	public function setNodeId($fileId) {
193
		$this->node = null;
194
		$this->fileId = $fileId;
195
		return $this;
196
	}
197
198
	/**
199
	 * @inheritdoc
200
	 */
201
	public function getNodeId() {
202
		if ($this->fileId === null) {
203
			$this->fileId = $this->getNode()->getId();
204
		}
205
206
		return $this->fileId;
207
	}
208
209
	/**
210
	 * @inheritdoc
211
	 */
212
	public function setNodeType($type) {
213
		if ($type !== 'file' && $type !== 'folder') {
214
			throw new \InvalidArgumentException();
215
		}
216
217
		$this->nodeType = $type;
218
		return $this;
219
	}
220
221
	/**
222
	 * @inheritdoc
223
	 */
224
	public function getNodeType() {
225
		if ($this->nodeType === null) {
226
			$node = $this->getNode();
227
			$this->nodeType = $node instanceof File ? 'file' : 'folder';
228
		}
229
230
		return $this->nodeType;
231
	}
232
233
	/**
234
	 * @inheritdoc
235
	 */
236
	public function setShareType($shareType) {
237
		$this->shareType = $shareType;
238
		return $this;
239
	}
240
241
	/**
242
	 * @inheritdoc
243
	 */
244
	public function getShareType() {
245
		return $this->shareType;
246
	}
247
248
	/**
249
	 * @inheritdoc
250
	 */
251
	public function setSharedWith($sharedWith) {
252
		if (!is_string($sharedWith)) {
253
			throw new \InvalidArgumentException();
254
		}
255
		$this->sharedWith = $sharedWith;
256
		return $this;
257
	}
258
259
	/**
260
	 * @inheritdoc
261
	 */
262
	public function getSharedWith() {
263
		return $this->sharedWith;
264
	}
265
266
	/**
267
	 * @inheritdoc
268
	 */
269
	public function setSharedWithDisplayName($displayName) {
270
		if (!is_string($displayName)) {
271
			throw new \InvalidArgumentException();
272
		}
273
		$this->sharedWithDisplayName = $displayName;
274
		return $this;
275
	}
276
277
	/**
278
	 * @inheritdoc
279
	 */
280
	public function getSharedWithDisplayName() {
281
		return $this->sharedWithDisplayName;
282
	}
283
284
	/**
285
	 * @inheritdoc
286
	 */
287
	public function setSharedWithAvatar($src) {
288
		if (!is_string($src)) {
289
			throw new \InvalidArgumentException();
290
		}
291
		$this->sharedWithAvatar = $src;
292
		return $this;
293
	}
294
295
	/**
296
	 * @inheritdoc
297
	 */
298
	public function getSharedWithAvatar() {
299
		return $this->sharedWithAvatar;
300
	}
301
302
	/**
303
	 * @inheritdoc
304
	 */
305
	public function setPermissions($permissions) {
306
		//TODO checkes
307
308
		$this->permissions = $permissions;
309
		return $this;
310
	}
311
312
	/**
313
	 * @inheritdoc
314
	 */
315
	public function getPermissions() {
316
		return $this->permissions;
317
	}
318
319
	/**
320
	 * @inheritdoc
321
	 */
322
	public function setNote($note) {
323
		$this->note = $note;
324
		return $this;
325
	}
326
327
	/**
328
	 * @inheritdoc
329
	 */
330
	public function getNote() {
331
		if (is_string($this->note)) {
0 ignored issues
show
introduced by
The condition is_string($this->note) is always true.
Loading history...
332
			return $this->note;
333
		}
334
		return '';
335
	}
336
337
	/**
338
	 * @inheritdoc
339
	 */
340
	public function setExpirationDate($expireDate) {
341
		//TODO checks
342
343
		$this->expireDate = $expireDate;
344
		return $this;
345
	}
346
347
	/**
348
	 * @inheritdoc
349
	 */
350
	public function getExpirationDate() {
351
		return $this->expireDate;
352
	}
353
354
	/**
355
	 * @inheritdoc
356
	 */
357
	public function setSharedBy($sharedBy) {
358
		if (!is_string($sharedBy)) {
359
			throw new \InvalidArgumentException();
360
		}
361
		//TODO checks
362
		$this->sharedBy = $sharedBy;
363
364
		return $this;
365
	}
366
367
	/**
368
	 * @inheritdoc
369
	 */
370
	public function getSharedBy() {
371
		//TODO check if set
372
		return $this->sharedBy;
373
	}
374
375
	/**
376
	 * @inheritdoc
377
	 */
378
	public function setShareOwner($shareOwner) {
379
		if (!is_string($shareOwner)) {
380
			throw new \InvalidArgumentException();
381
		}
382
		//TODO checks
383
384
		$this->shareOwner = $shareOwner;
385
		return $this;
386
	}
387
388
	/**
389
	 * @inheritdoc
390
	 */
391
	public function getShareOwner() {
392
		//TODO check if set
393
		return $this->shareOwner;
394
	}
395
396
	/**
397
	 * @inheritdoc
398
	 */
399
	public function setPassword($password) {
400
		$this->password = $password;
401
		return $this;
402
	}
403
404
	/**
405
	 * @inheritdoc
406
	 */
407
	public function getPassword() {
408
		return $this->password;
409
	}
410
411
	/**
412
	 * @inheritdoc
413
	 */
414
	public function setSendPasswordByTalk(bool $sendPasswordByTalk) {
415
		$this->sendPasswordByTalk = $sendPasswordByTalk;
416
		return $this;
417
	}
418
419
	/**
420
	 * @inheritdoc
421
	 */
422
	public function getSendPasswordByTalk(): bool {
423
		return $this->sendPasswordByTalk;
424
	}
425
426
	/**
427
	 * @inheritdoc
428
	 */
429
	public function setToken($token) {
430
		$this->token = $token;
431
		return $this;
432
	}
433
434
	/**
435
	 * @inheritdoc
436
	 */
437
	public function getToken() {
438
		return $this->token;
439
	}
440
441
	/**
442
	 * Set the parent of this share
443
	 *
444
	 * @param int parent
0 ignored issues
show
Bug introduced by
The type OC\Share20\parent was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
445
	 * @return \OCP\Share\IShare
446
	 * @deprecated The new shares do not have parents. This is just here for legacy reasons.
447
	 */
448
	public function setParent($parent) {
449
		$this->parent = $parent;
450
		return $this;
451
	}
452
453
	/**
454
	 * Get the parent of this share.
455
	 *
456
	 * @return int
457
	 * @deprecated The new shares do not have parents. This is just here for legacy reasons.
458
	 */
459
	public function getParent() {
460
		return $this->parent;
461
	}
462
463
	/**
464
	 * @inheritdoc
465
	 */
466
	public function setTarget($target) {
467
		$this->target = $target;
468
		return $this;
469
	}
470
471
	/**
472
	 * @inheritdoc
473
	 */
474
	public function getTarget() {
475
		return $this->target;
476
	}
477
478
	/**
479
	 * @inheritdoc
480
	 */
481
	public function setShareTime(\DateTime $shareTime) {
482
		$this->shareTime = $shareTime;
483
		return $this;
484
	}
485
486
	/**
487
	 * @inheritdoc
488
	 */
489
	public function getShareTime() {
490
		return $this->shareTime;
491
	}
492
493
	/**
494
	 * @inheritdoc
495
	 */
496
	public function setMailSend($mailSend) {
497
		$this->mailSend = $mailSend;
498
		return $this;
499
	}
500
501
	/**
502
	 * @inheritdoc
503
	 */
504
	public function getMailSend() {
505
		return $this->mailSend;
506
	}
507
508
	/**
509
	 * @inheritdoc
510
	 */
511
	public function setNodeCacheEntry(ICacheEntry $entry) {
512
		$this->nodeCacheEntry = $entry;
513
	}
514
515
	/**
516
	 * @inheritdoc
517
	 */
518
	public function getNodeCacheEntry() {
519
		return $this->nodeCacheEntry;
520
	}
521
522
	public function setHideDownload(bool $hide): IShare {
523
		$this->hideDownload = $hide;
524
		return $this;
525
	}
526
527
	public function getHideDownload(): bool {
528
		return $this->hideDownload;
529
	}
530
}
531