Share::setShouldHashPassword()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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 = true;
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
	}
86
87
	/**
88
	 * @inheritdoc
89
	 */
90
	public function setId($id) {
91
		if (\is_int($id)) {
92
			$id = (string)$id;
93
		}
94
95
		if (!\is_string($id)) {
96
			throw new \InvalidArgumentException('String expected.');
97
		}
98
99
		if ($this->id !== null) {
100
			throw new IllegalIDChangeException('Not allowed to assign a new internal id to a share');
101
		}
102
103
		$this->id = \trim($id);
104
		return $this;
105
	}
106
107
	/**
108
	 * @inheritdoc
109
	 */
110
	public function getId() {
111
		return $this->id;
112
	}
113
114
	/**
115
	 * @inheritdoc
116
	 */
117
	public function getFullId() {
118
		if ($this->providerId === null || $this->id === null) {
119
			throw new \UnexpectedValueException;
120
		}
121
		return $this->providerId . ':' . $this->id;
122
	}
123
124
	/**
125
	 * @inheritdoc
126
	 */
127
	public function setProviderId($id) {
128
		if (!\is_string($id)) {
129
			throw new \InvalidArgumentException('String expected.');
130
		}
131
132
		if ($this->providerId !== null) {
133
			throw new IllegalIDChangeException('Not allowed to assign a new provider id to a share');
134
		}
135
136
		$this->providerId = \trim($id);
137
		return $this;
138
	}
139
140
	/**
141
	 * @inheritdoc
142
	 */
143
	public function setNode(Node $node) {
144
		$this->fileId = null;
145
		$this->nodeType = null;
146
		$this->node = $node;
147
		return $this;
148
	}
149
150
	/**
151
	 * @inheritdoc
152
	 */
153
	public function getNode() {
154
		if ($this->node === null) {
155
			if ($this->shareOwner === null || $this->fileId === null) {
156
				throw new NotFoundException();
157
			}
158
159
			// for federated shares the owner can be a remote user, in this
160
			// case we use the initiator
161
			if ($this->userManager->userExists($this->shareOwner)) {
162
				$userFolder = $this->rootFolder->getUserFolder($this->shareOwner);
163
			} else {
164
				$userFolder = $this->rootFolder->getUserFolder($this->sharedBy);
165
			}
166
167
			$nodes = $userFolder->getById($this->fileId);
168
			if (empty($nodes)) {
169
				throw new NotFoundException();
170
			}
171
172
			$this->node = $nodes[0];
173
		}
174
175
		return $this->node;
176
	}
177
178
	/**
179
	 * @inheritdoc
180
	 */
181
	public function setNodeId($fileId) {
182
		$this->node = null;
183
		$this->fileId = $fileId;
184
		return $this;
185
	}
186
187
	/**
188
	 * @inheritdoc
189
	 */
190
	public function getNodeId() {
191
		if ($this->fileId === null) {
192
			$this->fileId = $this->getNode()->getId();
193
		}
194
195
		return $this->fileId;
196
	}
197
198
	/**
199
	 * @inheritdoc
200
	 */
201
	public function setNodeType($type) {
202
		if ($type !== 'file' && $type !== 'folder') {
203
			throw new \InvalidArgumentException();
204
		}
205
206
		$this->nodeType = $type;
207
		return $this;
208
	}
209
210
	/**
211
	 * @inheritdoc
212
	 */
213
	public function getNodeType() {
214
		if ($this->nodeType === null) {
215
			$node = $this->getNode();
216
			$this->nodeType = $node instanceof File ? 'file' : 'folder';
217
		}
218
219
		return $this->nodeType;
220
	}
221
222
	/**
223
	 * @inheritdoc
224
	 */
225
	public function setShareType($shareType) {
226
		$this->shareType = $shareType;
227
		return $this;
228
	}
229
230
	/**
231
	 * @inheritdoc
232
	 */
233
	public function getShareType() {
234
		return $this->shareType;
235
	}
236
237
	/**
238
	 * @inheritdoc
239
	 */
240
	public function setSharedWith($sharedWith) {
241
		if (!\is_string($sharedWith)) {
242
			throw new \InvalidArgumentException();
243
		}
244
		$this->sharedWith = $sharedWith;
245
		return $this;
246
	}
247
248
	/**
249
	 * @inheritdoc
250
	 */
251
	public function getSharedWith() {
252
		return $this->sharedWith;
253
	}
254
255
	/**
256
	 * @inheritdoc
257
	 */
258
	public function setPermissions($permissions) {
259
		//TODO checkes
260
261
		$this->permissions = $permissions;
262
		return $this;
263
	}
264
265
	/**
266
	 * @inheritdoc
267
	 */
268
	public function getPermissions() {
269
		return $this->permissions;
270
	}
271
272
	/**
273
	 * @inheritdoc
274
	 */
275
	public function setExpirationDate($expireDate) {
276
		//TODO checks
277
278
		$this->expireDate = $expireDate;
279
		return $this;
280
	}
281
282
	/**
283
	 * @inheritdoc
284
	 */
285
	public function getExpirationDate() {
286
		return $this->expireDate;
287
	}
288
289
	/**
290
	 * @inheritdoc
291
	 */
292
	public function setSharedBy($sharedBy) {
293
		if (!\is_string($sharedBy)) {
294
			throw new \InvalidArgumentException();
295
		}
296
		//TODO checks
297
		$this->sharedBy = $sharedBy;
298
299
		return $this;
300
	}
301
302
	/**
303
	 * @inheritdoc
304
	 */
305
	public function getSharedBy() {
306
		//TODO check if set
307
		return $this->sharedBy;
308
	}
309
310
	/**
311
	 * @inheritdoc
312
	 */
313
	public function setShareOwner($shareOwner) {
314
		if (!\is_string($shareOwner)) {
315
			throw new \InvalidArgumentException();
316
		}
317
		//TODO checks
318
319
		$this->shareOwner = $shareOwner;
320
		return $this;
321
	}
322
323
	/**
324
	 * @inheritdoc
325
	 */
326
	public function getShareOwner() {
327
		//TODO check if set
328
		return $this->shareOwner;
329
	}
330
331
	/**
332
	 * @inheritdoc
333
	 */
334
	public function setPassword($password) {
335
		$this->password = $password;
336
		return $this;
337
	}
338
339
	/**
340
	 * @inheritdoc
341
	 */
342
	public function getPassword() {
343
		return $this->password;
344
	}
345
346
	/**
347
	 * @inheritdoc
348
	 */
349
	public function setToken($token) {
350
		$this->token = $token;
351
		return $this;
352
	}
353
354
	/**
355
	 * @inheritdoc
356
	 */
357
	public function getToken() {
358
		return $this->token;
359
	}
360
361
	/**
362
	 * Set the parent of this share
363
	 *
364
	 * @param int parent
365
	 * @return \OCP\Share\IShare
366
	 * @deprecated The new shares do not have parents. This is just here for legacy reasons.
367
	 */
368
	public function setParent($parent) {
369
		$this->parent = $parent;
370
		return $this;
371
	}
372
373
	/**
374
	 * Get the parent of this share.
375
	 *
376
	 * @return int
377
	 * @deprecated The new shares do not have parents. This is just here for legacy reasons.
378
	 */
379
	public function getParent() {
380
		return $this->parent;
381
	}
382
383
	/**
384
	 * @inheritdoc
385
	 */
386
	public function setTarget($target) {
387
		$this->target = $target;
388
		return $this;
389
	}
390
391
	/**
392
	 * @inheritdoc
393
	 */
394
	public function getTarget() {
395
		return $this->target;
396
	}
397
398
	/**
399
	 * @inheritdoc
400
	 */
401
	public function setShareTime(\DateTime $shareTime) {
402
		$this->shareTime = $shareTime;
403
		return $this;
404
	}
405
406
	/**
407
	 * @inheritdoc
408
	 */
409
	public function getShareTime() {
410
		return $this->shareTime;
411
	}
412
413
	/**
414
	 * @inheritdoc
415
	 */
416
	public function setMailSend($mailSend) {
417
		$this->mailSend = $mailSend;
418
		return $this;
419
	}
420
421
	/**
422
	 * @inheritdoc
423
	 */
424
	public function getMailSend() {
425
		return $this->mailSend;
426
	}
427
428
	/**
429
	 * @inheritdoc
430
	 */
431
	public function setName($name) {
432
		$this->name = $name;
433
		return $this;
434
	}
435
436
	/**
437
	 * @inheritdoc
438
	 */
439
	public function getName() {
440
		return $this->name;
441
	}
442
443
	/**
444
	 * @inheritdoc
445
	 */
446
	public function setState($state) {
447
		$this->state = $state;
448
		return $this;
449
	}
450
451
	/**
452
	 * @inheritdoc
453
	 */
454
	public function getState() {
455
		return $this->state;
456
	}
457
458
	/**
459
	 * @inheritdoc
460
	 */
461
	public function getShouldHashPassword() {
462
		return $this->shouldHashPassword;
463
	}
464
465
	/**
466
	 * @inheritdoc
467
	 */
468
	public function setShouldHashPassword($status) {
469
		$this->shouldHashPassword = $status;
470
	}
471
}
472