Completed
Push — master ( a75f47...f4841e )
by John
24:57 queued 14s
created
lib/public/Share/IShare.php 1 patch
Indentation   +611 added lines, -611 removed lines patch added patch discarded remove patch
@@ -22,615 +22,615 @@
 block discarded – undo
22 22
  * @since 9.0.0
23 23
  */
24 24
 interface IShare {
25
-	/**
26
-	 * @since 17.0.0
27
-	 */
28
-	public const TYPE_USER = 0;
29
-
30
-	/**
31
-	 * @since 17.0.0
32
-	 */
33
-	public const TYPE_GROUP = 1;
34
-
35
-	/**
36
-	 * @internal
37
-	 * @since 18.0.0
38
-	 */
39
-	public const TYPE_USERGROUP = 2;
40
-
41
-	/**
42
-	 * @since 17.0.0
43
-	 */
44
-	public const TYPE_LINK = 3;
45
-
46
-	/**
47
-	 * @since 17.0.0
48
-	 */
49
-	public const TYPE_EMAIL = 4;
50
-
51
-	/**
52
-	 * ToDo Check if it is still in use otherwise remove it
53
-	 * @since 17.0.0
54
-	 */
55
-	// public const TYPE_CONTACT = 5;
56
-
57
-	/**
58
-	 * @since 17.0.0
59
-	 */
60
-	public const TYPE_REMOTE = 6;
61
-
62
-	/**
63
-	 * @since 17.0.0
64
-	 */
65
-	public const TYPE_CIRCLE = 7;
66
-
67
-	/**
68
-	 * @since 17.0.0
69
-	 */
70
-	public const TYPE_GUEST = 8;
71
-
72
-	/**
73
-	 * @since 17.0.0
74
-	 */
75
-	public const TYPE_REMOTE_GROUP = 9;
76
-
77
-	/**
78
-	 * @since 17.0.0
79
-	 */
80
-	public const TYPE_ROOM = 10;
81
-
82
-	/**
83
-	 * Internal type used by RoomShareProvider
84
-	 * @since 17.0.0
85
-	 */
86
-	// const TYPE_USERROOM = 11;
87
-
88
-	/**
89
-	 * @since 21.0.0
90
-	 */
91
-	public const TYPE_DECK = 12;
92
-
93
-	/**
94
-	 * @internal
95
-	 * @since 21.0.0
96
-	 */
97
-	public const TYPE_DECK_USER = 13;
98
-
99
-	/**
100
-	 * @since 26.0.0
101
-	 */
102
-	public const TYPE_SCIENCEMESH = 15;
103
-
104
-	/**
105
-	 * @since 18.0.0
106
-	 */
107
-	public const STATUS_PENDING = 0;
108
-
109
-	/**
110
-	 * @since 18.0.0
111
-	 */
112
-	public const STATUS_ACCEPTED = 1;
113
-
114
-	/**
115
-	 * @since 18.0.0
116
-	 */
117
-	public const STATUS_REJECTED = 2;
118
-
119
-	/**
120
-	 * Set the internal id of the share
121
-	 * It is only allowed to set the internal id of a share once.
122
-	 * Attempts to override the internal id will result in an IllegalIDChangeException
123
-	 *
124
-	 * @param string $id
125
-	 * @return \OCP\Share\IShare
126
-	 * @throws IllegalIDChangeException
127
-	 * @throws \InvalidArgumentException
128
-	 * @since 9.1.0
129
-	 */
130
-	public function setId($id);
131
-
132
-	/**
133
-	 * Get the internal id of the share.
134
-	 *
135
-	 * @return string
136
-	 * @since 9.0.0
137
-	 */
138
-	public function getId();
139
-
140
-	/**
141
-	 * Get the full share id. This is the <providerid>:<internalid>.
142
-	 * The full id is unique in the system.
143
-	 *
144
-	 * @return string
145
-	 * @since 9.0.0
146
-	 * @throws \UnexpectedValueException If the fullId could not be constructed
147
-	 */
148
-	public function getFullId();
149
-
150
-	/**
151
-	 * Set the provider id of the share
152
-	 * It is only allowed to set the provider id of a share once.
153
-	 * Attempts to override the provider id will result in an IllegalIDChangeException
154
-	 *
155
-	 * @param string $id
156
-	 * @return \OCP\Share\IShare
157
-	 * @throws IllegalIDChangeException
158
-	 * @throws \InvalidArgumentException
159
-	 * @since 9.1.0
160
-	 */
161
-	public function setProviderId($id);
162
-
163
-	/**
164
-	 * Set the node of the file/folder that is shared
165
-	 *
166
-	 * @param Node $node
167
-	 * @return \OCP\Share\IShare The modified object
168
-	 * @since 9.0.0
169
-	 */
170
-	public function setNode(Node $node);
171
-
172
-	/**
173
-	 * Get the node of the file/folder that is shared
174
-	 *
175
-	 * @return File|Folder
176
-	 * @since 9.0.0
177
-	 * @throws NotFoundException
178
-	 */
179
-	public function getNode();
180
-
181
-	/**
182
-	 * Set file id for lazy evaluation of the node
183
-	 * @param int $fileId
184
-	 * @return \OCP\Share\IShare The modified object
185
-	 * @since 9.0.0
186
-	 */
187
-	public function setNodeId($fileId);
188
-
189
-	/**
190
-	 * Get the fileid of the node of this share
191
-	 * @return int
192
-	 * @since 9.0.0
193
-	 * @throws NotFoundException
194
-	 */
195
-	public function getNodeId(): int;
196
-
197
-	/**
198
-	 * Set the type of node (file/folder)
199
-	 *
200
-	 * @param string $type
201
-	 * @return \OCP\Share\IShare The modified object
202
-	 * @since 9.0.0
203
-	 */
204
-	public function setNodeType($type);
205
-
206
-	/**
207
-	 * Get the type of node (file/folder)
208
-	 *
209
-	 * @return string
210
-	 * @since 9.0.0
211
-	 * @throws NotFoundException
212
-	 */
213
-	public function getNodeType();
214
-
215
-	/**
216
-	 * Set the shareType
217
-	 *
218
-	 * @param int $shareType
219
-	 * @return \OCP\Share\IShare The modified object
220
-	 * @since 9.0.0
221
-	 */
222
-	public function setShareType($shareType);
223
-
224
-	/**
225
-	 * Get the shareType
226
-	 *
227
-	 * @return int
228
-	 * @since 9.0.0
229
-	 */
230
-	public function getShareType();
231
-
232
-	/**
233
-	 * Set the receiver of this share.
234
-	 *
235
-	 * @param string $sharedWith
236
-	 * @return \OCP\Share\IShare The modified object
237
-	 * @since 9.0.0
238
-	 */
239
-	public function setSharedWith($sharedWith);
240
-
241
-	/**
242
-	 * Get the receiver of this share.
243
-	 *
244
-	 * @return string
245
-	 * @since 9.0.0
246
-	 */
247
-	public function getSharedWith();
248
-
249
-	/**
250
-	 * Set the display name of the receiver of this share.
251
-	 *
252
-	 * @param string $displayName
253
-	 * @return \OCP\Share\IShare The modified object
254
-	 * @since 14.0.0
255
-	 */
256
-	public function setSharedWithDisplayName($displayName);
257
-
258
-	/**
259
-	 * Get the display name of the receiver of this share.
260
-	 *
261
-	 * @return string
262
-	 * @since 14.0.0
263
-	 */
264
-	public function getSharedWithDisplayName();
265
-
266
-	/**
267
-	 * Set the avatar of the receiver of this share.
268
-	 *
269
-	 * @param string $src
270
-	 * @return \OCP\Share\IShare The modified object
271
-	 * @since 14.0.0
272
-	 */
273
-	public function setSharedWithAvatar($src);
274
-
275
-	/**
276
-	 * Get the avatar of the receiver of this share.
277
-	 *
278
-	 * @return string
279
-	 * @since 14.0.0
280
-	 */
281
-	public function getSharedWithAvatar();
282
-
283
-	/**
284
-	 * Set the permissions.
285
-	 * See \OCP\Constants::PERMISSION_*
286
-	 *
287
-	 * @param int $permissions
288
-	 * @return IShare The modified object
289
-	 * @since 9.0.0
290
-	 */
291
-	public function setPermissions($permissions);
292
-
293
-	/**
294
-	 * Get the share permissions
295
-	 * See \OCP\Constants::PERMISSION_*
296
-	 *
297
-	 * @return int
298
-	 * @since 9.0.0
299
-	 */
300
-	public function getPermissions();
301
-
302
-	/**
303
-	 * Create share attributes object
304
-	 *
305
-	 * @since 25.0.0
306
-	 * @return IAttributes
307
-	 */
308
-	public function newAttributes(): IAttributes;
309
-
310
-	/**
311
-	 * Set share attributes
312
-	 *
313
-	 * @param ?IAttributes $attributes
314
-	 * @since 25.0.0
315
-	 * @return IShare The modified object
316
-	 */
317
-	public function setAttributes(?IAttributes $attributes);
318
-
319
-	/**
320
-	 * Get share attributes
321
-	 *
322
-	 * @since 25.0.0
323
-	 * @return ?IAttributes
324
-	 */
325
-	public function getAttributes(): ?IAttributes;
326
-
327
-	/**
328
-	 * Set the accepted status
329
-	 * See self::STATUS_*
330
-	 *
331
-	 * @param int $status
332
-	 * @return IShare The modified object
333
-	 * @since 18.0.0
334
-	 */
335
-	public function setStatus(int $status): IShare;
336
-
337
-	/**
338
-	 * Get the accepted status
339
-	 * See self::STATUS_*
340
-	 *
341
-	 * @return int
342
-	 * @since 18.0.0
343
-	 */
344
-	public function getStatus(): int;
345
-
346
-	/**
347
-	 * Attach a note to a share
348
-	 *
349
-	 * @param string $note
350
-	 * @return \OCP\Share\IShare The modified object
351
-	 * @since 14.0.0
352
-	 */
353
-	public function setNote($note);
354
-
355
-	/**
356
-	 * Get note attached to a share
357
-	 *
358
-	 * @return string
359
-	 * @since 14.0.0
360
-	 */
361
-	public function getNote();
362
-
363
-
364
-	/**
365
-	 * Set the expiration date
366
-	 *
367
-	 * @param \DateTime|null $expireDate
368
-	 * @return \OCP\Share\IShare The modified object
369
-	 * @since 9.0.0
370
-	 */
371
-	public function setExpirationDate(?\DateTime $expireDate);
372
-
373
-	/**
374
-	 * Get the expiration date
375
-	 *
376
-	 * @return \DateTime|null
377
-	 * @since 9.0.0
378
-	 */
379
-	public function getExpirationDate();
380
-
381
-	/**
382
-	 * Set overwrite flag for falsy expiry date values
383
-	 *
384
-	 * @param bool $noExpirationDate
385
-	 * @return \OCP\Share\IShare The modified object
386
-	 * @since 30.0.0
387
-	 */
388
-	public function setNoExpirationDate(bool $noExpirationDate);
389
-
390
-
391
-	/**
392
-	 * Get value of overwrite falsy expiry date flag
393
-	 *
394
-	 * @return bool
395
-	 * @since 30.0.0
396
-	 */
397
-	public function getNoExpirationDate();
398
-
399
-	/**
400
-	 * Is the share expired ?
401
-	 *
402
-	 * @return boolean
403
-	 * @since 18.0.0
404
-	 */
405
-	public function isExpired();
406
-
407
-	/**
408
-	 * set a label for a share, some shares, e.g. public links can have a label
409
-	 *
410
-	 * @param string $label
411
-	 * @return \OCP\Share\IShare The modified object
412
-	 * @since 15.0.0
413
-	 */
414
-	public function setLabel($label);
415
-
416
-	/**
417
-	 * get label for the share, some shares, e.g. public links can have a label
418
-	 *
419
-	 * @return string
420
-	 * @since 15.0.0
421
-	 */
422
-	public function getLabel();
423
-
424
-	/**
425
-	 * Set the sharer of the path.
426
-	 *
427
-	 * @param string $sharedBy
428
-	 * @return \OCP\Share\IShare The modified object
429
-	 * @since 9.0.0
430
-	 */
431
-	public function setSharedBy($sharedBy);
432
-
433
-	/**
434
-	 * Get share sharer
435
-	 *
436
-	 * @return string
437
-	 * @since 9.0.0
438
-	 */
439
-	public function getSharedBy();
440
-
441
-	/**
442
-	 * Set the original share owner (who owns the path that is shared)
443
-	 *
444
-	 * @param string $shareOwner
445
-	 * @return \OCP\Share\IShare The modified object
446
-	 * @since 9.0.0
447
-	 */
448
-	public function setShareOwner($shareOwner);
449
-
450
-	/**
451
-	 * Get the original share owner (who owns the path that is shared)
452
-	 *
453
-	 * @return string
454
-	 * @since 9.0.0
455
-	 */
456
-	public function getShareOwner();
457
-
458
-	/**
459
-	 * Set the password for this share.
460
-	 * When the share is passed to the share manager to be created
461
-	 * or updated the password will be hashed.
462
-	 *
463
-	 * @param string|null $password
464
-	 * @return \OCP\Share\IShare The modified object
465
-	 * @since 9.0.0
466
-	 */
467
-	public function setPassword($password);
468
-
469
-	/**
470
-	 * Get the password of this share.
471
-	 * If this share is obtained via a shareprovider the password is
472
-	 * hashed.
473
-	 *
474
-	 * @return string|null
475
-	 * @since 9.0.0
476
-	 */
477
-	public function getPassword();
478
-
479
-	/**
480
-	 * Set the password's expiration time of this share.
481
-	 *
482
-	 * @return self The modified object
483
-	 * @since 24.0.0
484
-	 */
485
-	public function setPasswordExpirationTime(?\DateTimeInterface $passwordExpirationTime = null): IShare;
486
-
487
-	/**
488
-	 * Get the password's expiration time of this share.
489
-	 * @since 24.0.0
490
-	 */
491
-	public function getPasswordExpirationTime(): ?\DateTimeInterface;
492
-
493
-	/**
494
-	 * Set if the recipient can start a conversation with the owner to get the
495
-	 * password using Nextcloud Talk.
496
-	 *
497
-	 * @param bool $sendPasswordByTalk
498
-	 * @return \OCP\Share\IShare The modified object
499
-	 * @since 14.0.0
500
-	 */
501
-	public function setSendPasswordByTalk(bool $sendPasswordByTalk);
502
-
503
-	/**
504
-	 * Get if the recipient can start a conversation with the owner to get the
505
-	 * password using Nextcloud Talk.
506
-	 * The returned value does not take into account other factors, like Talk
507
-	 * being enabled for the owner of the share or not; it just cover whether
508
-	 * the option is enabled for the share itself or not.
509
-	 *
510
-	 * @return bool
511
-	 * @since 14.0.0
512
-	 */
513
-	public function getSendPasswordByTalk(): bool;
514
-
515
-	/**
516
-	 * Set the public link token.
517
-	 *
518
-	 * @param string $token
519
-	 * @return \OCP\Share\IShare The modified object
520
-	 * @since 9.0.0
521
-	 */
522
-	public function setToken($token);
523
-
524
-	/**
525
-	 * Get the public link token.
526
-	 *
527
-	 * @return string
528
-	 * @since 9.0.0
529
-	 */
530
-	public function getToken();
531
-
532
-	/**
533
-	 * Set the target path of this share relative to the recipients user folder.
534
-	 *
535
-	 * @param string $target
536
-	 * @return \OCP\Share\IShare The modified object
537
-	 * @since 9.0.0
538
-	 */
539
-	public function setTarget($target);
540
-
541
-	/**
542
-	 * Get the target path of this share relative to the recipients user folder.
543
-	 *
544
-	 * @return string
545
-	 * @since 9.0.0
546
-	 */
547
-	public function getTarget();
548
-
549
-	/**
550
-	 * Set the time this share was created
551
-	 *
552
-	 * @param \DateTime $shareTime
553
-	 * @return \OCP\Share\IShare The modified object
554
-	 * @since 9.0.0
555
-	 */
556
-	public function setShareTime(\DateTime $shareTime);
557
-
558
-	/**
559
-	 * Get the timestamp this share was created
560
-	 *
561
-	 * @return \DateTime
562
-	 * @since 9.0.0
563
-	 */
564
-	public function getShareTime();
565
-
566
-	/**
567
-	 * Set if the recipient should be informed by mail about the share.
568
-	 *
569
-	 * @param bool $mailSend
570
-	 * @return \OCP\Share\IShare The modified object
571
-	 * @since 9.0.0
572
-	 */
573
-	public function setMailSend($mailSend);
574
-
575
-	/**
576
-	 * Get if the recipient should be informed by mail about the share.
577
-	 *
578
-	 * @return bool
579
-	 * @since 9.0.0
580
-	 */
581
-	public function getMailSend();
582
-
583
-	/**
584
-	 * Set the cache entry for the shared node
585
-	 *
586
-	 * @param ICacheEntry $entry
587
-	 * @return void
588
-	 * @since 11.0.0
589
-	 */
590
-	public function setNodeCacheEntry(ICacheEntry $entry);
591
-
592
-	/**
593
-	 * Get the cache entry for the shared node
594
-	 *
595
-	 * @return null|ICacheEntry
596
-	 * @since 11.0.0
597
-	 */
598
-	public function getNodeCacheEntry();
599
-
600
-	/**
601
-	 * Sets a shares hide download state
602
-	 * This is mainly for public shares. It will signal that the share page should
603
-	 * hide download buttons etc.
604
-	 *
605
-	 * @param bool $hide
606
-	 * @return IShare
607
-	 * @since 15.0.0
608
-	 */
609
-	public function setHideDownload(bool $hide): IShare;
610
-
611
-	/**
612
-	 * Gets a shares hide download state
613
-	 * This is mainly for public shares. It will signal that the share page should
614
-	 * hide download buttons etc.
615
-	 *
616
-	 * @return bool
617
-	 * @since 15.0.0
618
-	 */
619
-	public function getHideDownload(): bool;
620
-
621
-	/**
622
-	 * Sets a flag that stores whether a reminder via email has been sent
623
-	 *
624
-	 * @return self The modified object
625
-	 * @since 31.0.0
626
-	 */
627
-	public function setReminderSent(bool $reminderSent): IShare;
628
-
629
-	/**
630
-	 * Gets a flag that stores whether a reminder via email has been sent
631
-	 *
632
-	 * @return bool
633
-	 * @since 31.0.0
634
-	 */
635
-	public function getReminderSent(): bool;
25
+    /**
26
+     * @since 17.0.0
27
+     */
28
+    public const TYPE_USER = 0;
29
+
30
+    /**
31
+     * @since 17.0.0
32
+     */
33
+    public const TYPE_GROUP = 1;
34
+
35
+    /**
36
+     * @internal
37
+     * @since 18.0.0
38
+     */
39
+    public const TYPE_USERGROUP = 2;
40
+
41
+    /**
42
+     * @since 17.0.0
43
+     */
44
+    public const TYPE_LINK = 3;
45
+
46
+    /**
47
+     * @since 17.0.0
48
+     */
49
+    public const TYPE_EMAIL = 4;
50
+
51
+    /**
52
+     * ToDo Check if it is still in use otherwise remove it
53
+     * @since 17.0.0
54
+     */
55
+    // public const TYPE_CONTACT = 5;
56
+
57
+    /**
58
+     * @since 17.0.0
59
+     */
60
+    public const TYPE_REMOTE = 6;
61
+
62
+    /**
63
+     * @since 17.0.0
64
+     */
65
+    public const TYPE_CIRCLE = 7;
66
+
67
+    /**
68
+     * @since 17.0.0
69
+     */
70
+    public const TYPE_GUEST = 8;
71
+
72
+    /**
73
+     * @since 17.0.0
74
+     */
75
+    public const TYPE_REMOTE_GROUP = 9;
76
+
77
+    /**
78
+     * @since 17.0.0
79
+     */
80
+    public const TYPE_ROOM = 10;
81
+
82
+    /**
83
+     * Internal type used by RoomShareProvider
84
+     * @since 17.0.0
85
+     */
86
+    // const TYPE_USERROOM = 11;
87
+
88
+    /**
89
+     * @since 21.0.0
90
+     */
91
+    public const TYPE_DECK = 12;
92
+
93
+    /**
94
+     * @internal
95
+     * @since 21.0.0
96
+     */
97
+    public const TYPE_DECK_USER = 13;
98
+
99
+    /**
100
+     * @since 26.0.0
101
+     */
102
+    public const TYPE_SCIENCEMESH = 15;
103
+
104
+    /**
105
+     * @since 18.0.0
106
+     */
107
+    public const STATUS_PENDING = 0;
108
+
109
+    /**
110
+     * @since 18.0.0
111
+     */
112
+    public const STATUS_ACCEPTED = 1;
113
+
114
+    /**
115
+     * @since 18.0.0
116
+     */
117
+    public const STATUS_REJECTED = 2;
118
+
119
+    /**
120
+     * Set the internal id of the share
121
+     * It is only allowed to set the internal id of a share once.
122
+     * Attempts to override the internal id will result in an IllegalIDChangeException
123
+     *
124
+     * @param string $id
125
+     * @return \OCP\Share\IShare
126
+     * @throws IllegalIDChangeException
127
+     * @throws \InvalidArgumentException
128
+     * @since 9.1.0
129
+     */
130
+    public function setId($id);
131
+
132
+    /**
133
+     * Get the internal id of the share.
134
+     *
135
+     * @return string
136
+     * @since 9.0.0
137
+     */
138
+    public function getId();
139
+
140
+    /**
141
+     * Get the full share id. This is the <providerid>:<internalid>.
142
+     * The full id is unique in the system.
143
+     *
144
+     * @return string
145
+     * @since 9.0.0
146
+     * @throws \UnexpectedValueException If the fullId could not be constructed
147
+     */
148
+    public function getFullId();
149
+
150
+    /**
151
+     * Set the provider id of the share
152
+     * It is only allowed to set the provider id of a share once.
153
+     * Attempts to override the provider id will result in an IllegalIDChangeException
154
+     *
155
+     * @param string $id
156
+     * @return \OCP\Share\IShare
157
+     * @throws IllegalIDChangeException
158
+     * @throws \InvalidArgumentException
159
+     * @since 9.1.0
160
+     */
161
+    public function setProviderId($id);
162
+
163
+    /**
164
+     * Set the node of the file/folder that is shared
165
+     *
166
+     * @param Node $node
167
+     * @return \OCP\Share\IShare The modified object
168
+     * @since 9.0.0
169
+     */
170
+    public function setNode(Node $node);
171
+
172
+    /**
173
+     * Get the node of the file/folder that is shared
174
+     *
175
+     * @return File|Folder
176
+     * @since 9.0.0
177
+     * @throws NotFoundException
178
+     */
179
+    public function getNode();
180
+
181
+    /**
182
+     * Set file id for lazy evaluation of the node
183
+     * @param int $fileId
184
+     * @return \OCP\Share\IShare The modified object
185
+     * @since 9.0.0
186
+     */
187
+    public function setNodeId($fileId);
188
+
189
+    /**
190
+     * Get the fileid of the node of this share
191
+     * @return int
192
+     * @since 9.0.0
193
+     * @throws NotFoundException
194
+     */
195
+    public function getNodeId(): int;
196
+
197
+    /**
198
+     * Set the type of node (file/folder)
199
+     *
200
+     * @param string $type
201
+     * @return \OCP\Share\IShare The modified object
202
+     * @since 9.0.0
203
+     */
204
+    public function setNodeType($type);
205
+
206
+    /**
207
+     * Get the type of node (file/folder)
208
+     *
209
+     * @return string
210
+     * @since 9.0.0
211
+     * @throws NotFoundException
212
+     */
213
+    public function getNodeType();
214
+
215
+    /**
216
+     * Set the shareType
217
+     *
218
+     * @param int $shareType
219
+     * @return \OCP\Share\IShare The modified object
220
+     * @since 9.0.0
221
+     */
222
+    public function setShareType($shareType);
223
+
224
+    /**
225
+     * Get the shareType
226
+     *
227
+     * @return int
228
+     * @since 9.0.0
229
+     */
230
+    public function getShareType();
231
+
232
+    /**
233
+     * Set the receiver of this share.
234
+     *
235
+     * @param string $sharedWith
236
+     * @return \OCP\Share\IShare The modified object
237
+     * @since 9.0.0
238
+     */
239
+    public function setSharedWith($sharedWith);
240
+
241
+    /**
242
+     * Get the receiver of this share.
243
+     *
244
+     * @return string
245
+     * @since 9.0.0
246
+     */
247
+    public function getSharedWith();
248
+
249
+    /**
250
+     * Set the display name of the receiver of this share.
251
+     *
252
+     * @param string $displayName
253
+     * @return \OCP\Share\IShare The modified object
254
+     * @since 14.0.0
255
+     */
256
+    public function setSharedWithDisplayName($displayName);
257
+
258
+    /**
259
+     * Get the display name of the receiver of this share.
260
+     *
261
+     * @return string
262
+     * @since 14.0.0
263
+     */
264
+    public function getSharedWithDisplayName();
265
+
266
+    /**
267
+     * Set the avatar of the receiver of this share.
268
+     *
269
+     * @param string $src
270
+     * @return \OCP\Share\IShare The modified object
271
+     * @since 14.0.0
272
+     */
273
+    public function setSharedWithAvatar($src);
274
+
275
+    /**
276
+     * Get the avatar of the receiver of this share.
277
+     *
278
+     * @return string
279
+     * @since 14.0.0
280
+     */
281
+    public function getSharedWithAvatar();
282
+
283
+    /**
284
+     * Set the permissions.
285
+     * See \OCP\Constants::PERMISSION_*
286
+     *
287
+     * @param int $permissions
288
+     * @return IShare The modified object
289
+     * @since 9.0.0
290
+     */
291
+    public function setPermissions($permissions);
292
+
293
+    /**
294
+     * Get the share permissions
295
+     * See \OCP\Constants::PERMISSION_*
296
+     *
297
+     * @return int
298
+     * @since 9.0.0
299
+     */
300
+    public function getPermissions();
301
+
302
+    /**
303
+     * Create share attributes object
304
+     *
305
+     * @since 25.0.0
306
+     * @return IAttributes
307
+     */
308
+    public function newAttributes(): IAttributes;
309
+
310
+    /**
311
+     * Set share attributes
312
+     *
313
+     * @param ?IAttributes $attributes
314
+     * @since 25.0.0
315
+     * @return IShare The modified object
316
+     */
317
+    public function setAttributes(?IAttributes $attributes);
318
+
319
+    /**
320
+     * Get share attributes
321
+     *
322
+     * @since 25.0.0
323
+     * @return ?IAttributes
324
+     */
325
+    public function getAttributes(): ?IAttributes;
326
+
327
+    /**
328
+     * Set the accepted status
329
+     * See self::STATUS_*
330
+     *
331
+     * @param int $status
332
+     * @return IShare The modified object
333
+     * @since 18.0.0
334
+     */
335
+    public function setStatus(int $status): IShare;
336
+
337
+    /**
338
+     * Get the accepted status
339
+     * See self::STATUS_*
340
+     *
341
+     * @return int
342
+     * @since 18.0.0
343
+     */
344
+    public function getStatus(): int;
345
+
346
+    /**
347
+     * Attach a note to a share
348
+     *
349
+     * @param string $note
350
+     * @return \OCP\Share\IShare The modified object
351
+     * @since 14.0.0
352
+     */
353
+    public function setNote($note);
354
+
355
+    /**
356
+     * Get note attached to a share
357
+     *
358
+     * @return string
359
+     * @since 14.0.0
360
+     */
361
+    public function getNote();
362
+
363
+
364
+    /**
365
+     * Set the expiration date
366
+     *
367
+     * @param \DateTime|null $expireDate
368
+     * @return \OCP\Share\IShare The modified object
369
+     * @since 9.0.0
370
+     */
371
+    public function setExpirationDate(?\DateTime $expireDate);
372
+
373
+    /**
374
+     * Get the expiration date
375
+     *
376
+     * @return \DateTime|null
377
+     * @since 9.0.0
378
+     */
379
+    public function getExpirationDate();
380
+
381
+    /**
382
+     * Set overwrite flag for falsy expiry date values
383
+     *
384
+     * @param bool $noExpirationDate
385
+     * @return \OCP\Share\IShare The modified object
386
+     * @since 30.0.0
387
+     */
388
+    public function setNoExpirationDate(bool $noExpirationDate);
389
+
390
+
391
+    /**
392
+     * Get value of overwrite falsy expiry date flag
393
+     *
394
+     * @return bool
395
+     * @since 30.0.0
396
+     */
397
+    public function getNoExpirationDate();
398
+
399
+    /**
400
+     * Is the share expired ?
401
+     *
402
+     * @return boolean
403
+     * @since 18.0.0
404
+     */
405
+    public function isExpired();
406
+
407
+    /**
408
+     * set a label for a share, some shares, e.g. public links can have a label
409
+     *
410
+     * @param string $label
411
+     * @return \OCP\Share\IShare The modified object
412
+     * @since 15.0.0
413
+     */
414
+    public function setLabel($label);
415
+
416
+    /**
417
+     * get label for the share, some shares, e.g. public links can have a label
418
+     *
419
+     * @return string
420
+     * @since 15.0.0
421
+     */
422
+    public function getLabel();
423
+
424
+    /**
425
+     * Set the sharer of the path.
426
+     *
427
+     * @param string $sharedBy
428
+     * @return \OCP\Share\IShare The modified object
429
+     * @since 9.0.0
430
+     */
431
+    public function setSharedBy($sharedBy);
432
+
433
+    /**
434
+     * Get share sharer
435
+     *
436
+     * @return string
437
+     * @since 9.0.0
438
+     */
439
+    public function getSharedBy();
440
+
441
+    /**
442
+     * Set the original share owner (who owns the path that is shared)
443
+     *
444
+     * @param string $shareOwner
445
+     * @return \OCP\Share\IShare The modified object
446
+     * @since 9.0.0
447
+     */
448
+    public function setShareOwner($shareOwner);
449
+
450
+    /**
451
+     * Get the original share owner (who owns the path that is shared)
452
+     *
453
+     * @return string
454
+     * @since 9.0.0
455
+     */
456
+    public function getShareOwner();
457
+
458
+    /**
459
+     * Set the password for this share.
460
+     * When the share is passed to the share manager to be created
461
+     * or updated the password will be hashed.
462
+     *
463
+     * @param string|null $password
464
+     * @return \OCP\Share\IShare The modified object
465
+     * @since 9.0.0
466
+     */
467
+    public function setPassword($password);
468
+
469
+    /**
470
+     * Get the password of this share.
471
+     * If this share is obtained via a shareprovider the password is
472
+     * hashed.
473
+     *
474
+     * @return string|null
475
+     * @since 9.0.0
476
+     */
477
+    public function getPassword();
478
+
479
+    /**
480
+     * Set the password's expiration time of this share.
481
+     *
482
+     * @return self The modified object
483
+     * @since 24.0.0
484
+     */
485
+    public function setPasswordExpirationTime(?\DateTimeInterface $passwordExpirationTime = null): IShare;
486
+
487
+    /**
488
+     * Get the password's expiration time of this share.
489
+     * @since 24.0.0
490
+     */
491
+    public function getPasswordExpirationTime(): ?\DateTimeInterface;
492
+
493
+    /**
494
+     * Set if the recipient can start a conversation with the owner to get the
495
+     * password using Nextcloud Talk.
496
+     *
497
+     * @param bool $sendPasswordByTalk
498
+     * @return \OCP\Share\IShare The modified object
499
+     * @since 14.0.0
500
+     */
501
+    public function setSendPasswordByTalk(bool $sendPasswordByTalk);
502
+
503
+    /**
504
+     * Get if the recipient can start a conversation with the owner to get the
505
+     * password using Nextcloud Talk.
506
+     * The returned value does not take into account other factors, like Talk
507
+     * being enabled for the owner of the share or not; it just cover whether
508
+     * the option is enabled for the share itself or not.
509
+     *
510
+     * @return bool
511
+     * @since 14.0.0
512
+     */
513
+    public function getSendPasswordByTalk(): bool;
514
+
515
+    /**
516
+     * Set the public link token.
517
+     *
518
+     * @param string $token
519
+     * @return \OCP\Share\IShare The modified object
520
+     * @since 9.0.0
521
+     */
522
+    public function setToken($token);
523
+
524
+    /**
525
+     * Get the public link token.
526
+     *
527
+     * @return string
528
+     * @since 9.0.0
529
+     */
530
+    public function getToken();
531
+
532
+    /**
533
+     * Set the target path of this share relative to the recipients user folder.
534
+     *
535
+     * @param string $target
536
+     * @return \OCP\Share\IShare The modified object
537
+     * @since 9.0.0
538
+     */
539
+    public function setTarget($target);
540
+
541
+    /**
542
+     * Get the target path of this share relative to the recipients user folder.
543
+     *
544
+     * @return string
545
+     * @since 9.0.0
546
+     */
547
+    public function getTarget();
548
+
549
+    /**
550
+     * Set the time this share was created
551
+     *
552
+     * @param \DateTime $shareTime
553
+     * @return \OCP\Share\IShare The modified object
554
+     * @since 9.0.0
555
+     */
556
+    public function setShareTime(\DateTime $shareTime);
557
+
558
+    /**
559
+     * Get the timestamp this share was created
560
+     *
561
+     * @return \DateTime
562
+     * @since 9.0.0
563
+     */
564
+    public function getShareTime();
565
+
566
+    /**
567
+     * Set if the recipient should be informed by mail about the share.
568
+     *
569
+     * @param bool $mailSend
570
+     * @return \OCP\Share\IShare The modified object
571
+     * @since 9.0.0
572
+     */
573
+    public function setMailSend($mailSend);
574
+
575
+    /**
576
+     * Get if the recipient should be informed by mail about the share.
577
+     *
578
+     * @return bool
579
+     * @since 9.0.0
580
+     */
581
+    public function getMailSend();
582
+
583
+    /**
584
+     * Set the cache entry for the shared node
585
+     *
586
+     * @param ICacheEntry $entry
587
+     * @return void
588
+     * @since 11.0.0
589
+     */
590
+    public function setNodeCacheEntry(ICacheEntry $entry);
591
+
592
+    /**
593
+     * Get the cache entry for the shared node
594
+     *
595
+     * @return null|ICacheEntry
596
+     * @since 11.0.0
597
+     */
598
+    public function getNodeCacheEntry();
599
+
600
+    /**
601
+     * Sets a shares hide download state
602
+     * This is mainly for public shares. It will signal that the share page should
603
+     * hide download buttons etc.
604
+     *
605
+     * @param bool $hide
606
+     * @return IShare
607
+     * @since 15.0.0
608
+     */
609
+    public function setHideDownload(bool $hide): IShare;
610
+
611
+    /**
612
+     * Gets a shares hide download state
613
+     * This is mainly for public shares. It will signal that the share page should
614
+     * hide download buttons etc.
615
+     *
616
+     * @return bool
617
+     * @since 15.0.0
618
+     */
619
+    public function getHideDownload(): bool;
620
+
621
+    /**
622
+     * Sets a flag that stores whether a reminder via email has been sent
623
+     *
624
+     * @return self The modified object
625
+     * @since 31.0.0
626
+     */
627
+    public function setReminderSent(bool $reminderSent): IShare;
628
+
629
+    /**
630
+     * Gets a flag that stores whether a reminder via email has been sent
631
+     *
632
+     * @return bool
633
+     * @since 31.0.0
634
+     */
635
+    public function getReminderSent(): bool;
636 636
 }
Please login to merge, or discard this patch.
build/integration/features/bootstrap/Sharing.php 1 patch
Indentation   +721 added lines, -721 removed lines patch added patch discarded remove patch
@@ -14,725 +14,725 @@
 block discarded – undo
14 14
 
15 15
 
16 16
 trait Sharing {
17
-	use Provisioning;
18
-
19
-	/** @var int */
20
-	private $sharingApiVersion = 1;
21
-
22
-	/** @var SimpleXMLElement */
23
-	private $lastShareData = null;
24
-
25
-	/** @var SimpleXMLElement[] */
26
-	private $storedShareData = [];
27
-
28
-	/** @var int */
29
-	private $savedShareId = null;
30
-
31
-	/** @var ResponseInterface */
32
-	private $response;
33
-
34
-	/**
35
-	 * @Given /^as "([^"]*)" creating a share with$/
36
-	 * @param string $user
37
-	 * @param TableNode|null $body
38
-	 */
39
-	public function asCreatingAShareWith($user, $body) {
40
-		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares";
41
-		$client = new Client();
42
-		$options = [
43
-			'headers' => [
44
-				'OCS-APIREQUEST' => 'true',
45
-			],
46
-		];
47
-		if ($user === 'admin') {
48
-			$options['auth'] = $this->adminUser;
49
-		} else {
50
-			$options['auth'] = [$user, $this->regularUser];
51
-		}
52
-
53
-		if ($body instanceof TableNode) {
54
-			$fd = $body->getRowsHash();
55
-			if (array_key_exists('expireDate', $fd)) {
56
-				$dateModification = $fd['expireDate'];
57
-				if ($dateModification === 'null') {
58
-					$fd['expireDate'] = null;
59
-				} elseif (!empty($dateModification)) {
60
-					$fd['expireDate'] = date('Y-m-d', strtotime($dateModification));
61
-				} else {
62
-					$fd['expireDate'] = '';
63
-				}
64
-			}
65
-			$options['form_params'] = $fd;
66
-		}
67
-
68
-		try {
69
-			$this->response = $client->request('POST', $fullUrl, $options);
70
-		} catch (\GuzzleHttp\Exception\ClientException $ex) {
71
-			$this->response = $ex->getResponse();
72
-		}
73
-
74
-		$this->lastShareData = simplexml_load_string($this->response->getBody());
75
-	}
76
-
77
-	/**
78
-	 * @When /^save the last share data as "([^"]*)"$/
79
-	 */
80
-	public function saveLastShareData($name) {
81
-		$this->storedShareData[$name] = $this->lastShareData;
82
-	}
83
-
84
-	/**
85
-	 * @When /^restore the last share data from "([^"]*)"$/
86
-	 */
87
-	public function restoreLastShareData($name) {
88
-		$this->lastShareData = $this->storedShareData[$name];
89
-	}
90
-
91
-	/**
92
-	 * @When /^creating a share with$/
93
-	 * @param TableNode|null $body
94
-	 */
95
-	public function creatingShare($body) {
96
-		$this->asCreatingAShareWith($this->currentUser, $body);
97
-	}
98
-
99
-	/**
100
-	 * @When /^accepting last share$/
101
-	 */
102
-	public function acceptingLastShare() {
103
-		$share_id = $this->lastShareData->data[0]->id;
104
-		$url = "/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/pending/$share_id";
105
-		$this->sendingToWith('POST', $url, null);
106
-
107
-		$this->theHTTPStatusCodeShouldBe('200');
108
-	}
109
-
110
-	/**
111
-	 * @When /^user "([^"]*)" accepts last share$/
112
-	 *
113
-	 * @param string $user
114
-	 */
115
-	public function userAcceptsLastShare(string $user) {
116
-		// "As userXXX" and "user userXXX accepts last share" steps are not
117
-		// expected to be used in the same scenario, but restore the user just
118
-		// in case.
119
-		$previousUser = $this->currentUser;
120
-
121
-		$this->currentUser = $user;
122
-
123
-		$share_id = $this->lastShareData->data[0]->id;
124
-		$url = "/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/pending/$share_id";
125
-		$this->sendingToWith('POST', $url, null);
126
-
127
-		$this->currentUser = $previousUser;
128
-
129
-		$this->theHTTPStatusCodeShouldBe('200');
130
-	}
131
-
132
-	/**
133
-	 * @Then /^last link share can be downloaded$/
134
-	 */
135
-	public function lastLinkShareCanBeDownloaded() {
136
-		if (count($this->lastShareData->data->element) > 0) {
137
-			$url = $this->lastShareData->data[0]->url;
138
-		} else {
139
-			$url = $this->lastShareData->data->url;
140
-		}
141
-		$fullUrl = $url . '/download';
142
-		$this->checkDownload($fullUrl, null, 'text/plain');
143
-	}
144
-
145
-	/**
146
-	 * @Then /^last share can be downloaded$/
147
-	 */
148
-	public function lastShareCanBeDownloaded() {
149
-		if (count($this->lastShareData->data->element) > 0) {
150
-			$token = $this->lastShareData->data[0]->token;
151
-		} else {
152
-			$token = $this->lastShareData->data->token;
153
-		}
154
-
155
-		$fullUrl = substr($this->baseUrl, 0, -4) . 'index.php/s/' . $token . '/download';
156
-		$this->checkDownload($fullUrl, null, 'text/plain');
157
-	}
158
-
159
-	/**
160
-	 * @Then /^last share with password "([^"]*)" can be downloaded$/
161
-	 */
162
-	public function lastShareWithPasswordCanBeDownloaded($password) {
163
-		if (count($this->lastShareData->data->element) > 0) {
164
-			$token = $this->lastShareData->data[0]->token;
165
-		} else {
166
-			$token = $this->lastShareData->data->token;
167
-		}
168
-
169
-		$fullUrl = substr($this->baseUrl, 0, -4) . "public.php/dav/files/$token/";
170
-		$this->checkDownload($fullUrl, ['', $password], 'text/plain');
171
-	}
172
-
173
-	private function checkDownload($url, $auth = null, $mimeType = null) {
174
-		if ($auth !== null) {
175
-			$options['auth'] = $auth;
176
-		}
177
-		$options['stream'] = true;
178
-
179
-		$client = new Client();
180
-		$this->response = $client->get($url, $options);
181
-		Assert::assertEquals(200, $this->response->getStatusCode());
182
-
183
-		$buf = '';
184
-		$body = $this->response->getBody();
185
-		while (!$body->eof()) {
186
-			// read everything
187
-			$buf .= $body->read(8192);
188
-		}
189
-		$body->close();
190
-
191
-		if ($mimeType !== null) {
192
-			$finfo = new finfo;
193
-			Assert::assertEquals($mimeType, $finfo->buffer($buf, FILEINFO_MIME_TYPE));
194
-		}
195
-	}
196
-
197
-	/**
198
-	 * @When /^Adding expiration date to last share$/
199
-	 */
200
-	public function addingExpirationDate() {
201
-		$share_id = (string)$this->lastShareData->data[0]->id;
202
-		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/$share_id";
203
-		$client = new Client();
204
-		$options = [];
205
-		if ($this->currentUser === 'admin') {
206
-			$options['auth'] = $this->adminUser;
207
-		} else {
208
-			$options['auth'] = [$this->currentUser, $this->regularUser];
209
-		}
210
-		$date = date('Y-m-d', strtotime('+3 days'));
211
-		$options['form_params'] = ['expireDate' => $date];
212
-		$this->response = $this->response = $client->request('PUT', $fullUrl, $options);
213
-		Assert::assertEquals(200, $this->response->getStatusCode());
214
-	}
215
-
216
-	/**
217
-	 * @When /^Updating last share with$/
218
-	 * @param TableNode|null $body
219
-	 */
220
-	public function updatingLastShare($body) {
221
-		$share_id = (string)$this->lastShareData->data[0]->id;
222
-		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/$share_id";
223
-		$client = new Client();
224
-		$options = [
225
-			'headers' => [
226
-				'OCS-APIREQUEST' => 'true',
227
-			],
228
-		];
229
-		if ($this->currentUser === 'admin') {
230
-			$options['auth'] = $this->adminUser;
231
-		} else {
232
-			$options['auth'] = [$this->currentUser, $this->regularUser];
233
-		}
234
-
235
-		if ($body instanceof TableNode) {
236
-			$fd = $body->getRowsHash();
237
-			if (array_key_exists('expireDate', $fd)) {
238
-				$dateModification = $fd['expireDate'];
239
-				$fd['expireDate'] = date('Y-m-d', strtotime($dateModification));
240
-			}
241
-			$options['form_params'] = $fd;
242
-		}
243
-
244
-		try {
245
-			$this->response = $client->request('PUT', $fullUrl, $options);
246
-		} catch (\GuzzleHttp\Exception\ClientException $ex) {
247
-			$this->response = $ex->getResponse();
248
-		}
249
-	}
250
-
251
-	public function createShare($user,
252
-		$path = null,
253
-		$shareType = null,
254
-		$shareWith = null,
255
-		$publicUpload = null,
256
-		$password = null,
257
-		$permissions = null,
258
-		$viewOnly = false) {
259
-		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares";
260
-		$client = new Client();
261
-		$options = [
262
-			'headers' => [
263
-				'OCS-APIREQUEST' => 'true',
264
-			],
265
-		];
266
-
267
-		if ($user === 'admin') {
268
-			$options['auth'] = $this->adminUser;
269
-		} else {
270
-			$options['auth'] = [$user, $this->regularUser];
271
-		}
272
-		$body = [];
273
-		if (!is_null($path)) {
274
-			$body['path'] = $path;
275
-		}
276
-		if (!is_null($shareType)) {
277
-			$body['shareType'] = $shareType;
278
-		}
279
-		if (!is_null($shareWith)) {
280
-			$body['shareWith'] = $shareWith;
281
-		}
282
-		if (!is_null($publicUpload)) {
283
-			$body['publicUpload'] = $publicUpload;
284
-		}
285
-		if (!is_null($password)) {
286
-			$body['password'] = $password;
287
-		}
288
-		if (!is_null($permissions)) {
289
-			$body['permissions'] = $permissions;
290
-		}
291
-
292
-		if ($viewOnly === true) {
293
-			$body['attributes'] = json_encode([['scope' => 'permissions', 'key' => 'download', 'value' => false]]);
294
-		}
295
-
296
-		$options['form_params'] = $body;
297
-
298
-		try {
299
-			$this->response = $client->request('POST', $fullUrl, $options);
300
-			$this->lastShareData = simplexml_load_string($this->response->getBody());
301
-		} catch (\GuzzleHttp\Exception\ClientException $ex) {
302
-			$this->response = $ex->getResponse();
303
-			throw new \Exception($this->response->getBody());
304
-		}
305
-	}
306
-
307
-	public function isFieldInResponse($field, $contentExpected) {
308
-		$data = simplexml_load_string($this->response->getBody())->data[0];
309
-		if ((string)$field == 'expiration') {
310
-			if (!empty($contentExpected)) {
311
-				$contentExpected = date('Y-m-d', strtotime($contentExpected)) . ' 00:00:00';
312
-			}
313
-		}
314
-		if (count($data->element) > 0) {
315
-			foreach ($data as $element) {
316
-				if ($contentExpected == 'A_TOKEN') {
317
-					return (strlen((string)$element->$field) == 15);
318
-				} elseif ($contentExpected == 'A_NUMBER') {
319
-					return is_numeric((string)$element->$field);
320
-				} elseif ($contentExpected == 'AN_URL') {
321
-					return $this->isExpectedUrl((string)$element->$field, 'index.php/s/');
322
-				} elseif ((string)$element->$field == $contentExpected) {
323
-					return true;
324
-				} else {
325
-					print($element->$field);
326
-				}
327
-			}
328
-
329
-			return false;
330
-		} else {
331
-			if ($contentExpected == 'A_TOKEN') {
332
-				return (strlen((string)$data->$field) == 15);
333
-			} elseif ($contentExpected == 'A_NUMBER') {
334
-				return is_numeric((string)$data->$field);
335
-			} elseif ($contentExpected == 'AN_URL') {
336
-				return $this->isExpectedUrl((string)$data->$field, 'index.php/s/');
337
-			} elseif ($contentExpected == $data->$field) {
338
-				return true;
339
-			}
340
-			return false;
341
-		}
342
-	}
343
-
344
-	/**
345
-	 * @Then /^File "([^"]*)" should be included in the response$/
346
-	 *
347
-	 * @param string $filename
348
-	 */
349
-	public function checkSharedFileInResponse($filename) {
350
-		Assert::assertEquals(true, $this->isFieldInResponse('file_target', "/$filename"));
351
-	}
352
-
353
-	/**
354
-	 * @Then /^File "([^"]*)" should not be included in the response$/
355
-	 *
356
-	 * @param string $filename
357
-	 */
358
-	public function checkSharedFileNotInResponse($filename) {
359
-		Assert::assertEquals(false, $this->isFieldInResponse('file_target', "/$filename"));
360
-	}
361
-
362
-	/**
363
-	 * @Then /^User "([^"]*)" should be included in the response$/
364
-	 *
365
-	 * @param string $user
366
-	 */
367
-	public function checkSharedUserInResponse($user) {
368
-		Assert::assertEquals(true, $this->isFieldInResponse('share_with', "$user"));
369
-	}
370
-
371
-	/**
372
-	 * @Then /^User "([^"]*)" should not be included in the response$/
373
-	 *
374
-	 * @param string $user
375
-	 */
376
-	public function checkSharedUserNotInResponse($user) {
377
-		Assert::assertEquals(false, $this->isFieldInResponse('share_with', "$user"));
378
-	}
379
-
380
-	public function isUserOrGroupInSharedData($userOrGroup, $permissions = null) {
381
-		$data = simplexml_load_string($this->response->getBody())->data[0];
382
-		foreach ($data as $element) {
383
-			if ($element->share_with == $userOrGroup && ($permissions === null || $permissions == $element->permissions)) {
384
-				return true;
385
-			}
386
-		}
387
-		return false;
388
-	}
389
-
390
-	/**
391
-	 * @Given /^(file|folder|entry) "([^"]*)" of user "([^"]*)" is shared with user "([^"]*)"( with permissions ([\d]*))?( view-only)?$/
392
-	 *
393
-	 * @param string $filepath
394
-	 * @param string $user1
395
-	 * @param string $user2
396
-	 */
397
-	public function assureFileIsShared($entry, $filepath, $user1, $user2, $withPerms = null, $permissions = null, $viewOnly = null) {
398
-		// when view-only is set, permissions is empty string instead of null...
399
-		if ($permissions === '') {
400
-			$permissions = null;
401
-		}
402
-		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares" . "?path=$filepath";
403
-		$client = new Client();
404
-		$options = [];
405
-		if ($user1 === 'admin') {
406
-			$options['auth'] = $this->adminUser;
407
-		} else {
408
-			$options['auth'] = [$user1, $this->regularUser];
409
-		}
410
-		$options['headers'] = [
411
-			'OCS-APIREQUEST' => 'true',
412
-		];
413
-		$this->response = $client->get($fullUrl, $options);
414
-		if ($this->isUserOrGroupInSharedData($user2, $permissions)) {
415
-			return;
416
-		} else {
417
-			$this->createShare($user1, $filepath, 0, $user2, null, null, $permissions, $viewOnly !== null);
418
-		}
419
-		$this->response = $client->get($fullUrl, $options);
420
-		Assert::assertEquals(true, $this->isUserOrGroupInSharedData($user2, $permissions));
421
-	}
422
-
423
-	/**
424
-	 * @Given /^(file|folder|entry) "([^"]*)" of user "([^"]*)" is shared with group "([^"]*)"( with permissions ([\d]*))?( view-only)?$/
425
-	 *
426
-	 * @param string $filepath
427
-	 * @param string $user
428
-	 * @param string $group
429
-	 */
430
-	public function assureFileIsSharedWithGroup($entry, $filepath, $user, $group, $withPerms = null, $permissions = null, $viewOnly = null) {
431
-		// when view-only is set, permissions is empty string instead of null...
432
-		if ($permissions === '') {
433
-			$permissions = null;
434
-		}
435
-		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares" . "?path=$filepath";
436
-		$client = new Client();
437
-		$options = [];
438
-		if ($user === 'admin') {
439
-			$options['auth'] = $this->adminUser;
440
-		} else {
441
-			$options['auth'] = [$user, $this->regularUser];
442
-		}
443
-		$options['headers'] = [
444
-			'OCS-APIREQUEST' => 'true',
445
-		];
446
-		$this->response = $client->get($fullUrl, $options);
447
-		if ($this->isUserOrGroupInSharedData($group, $permissions)) {
448
-			return;
449
-		} else {
450
-			$this->createShare($user, $filepath, 1, $group, null, null, $permissions, $viewOnly !== null);
451
-		}
452
-		$this->response = $client->get($fullUrl, $options);
453
-		Assert::assertEquals(true, $this->isUserOrGroupInSharedData($group, $permissions));
454
-	}
455
-
456
-	/**
457
-	 * @When /^Deleting last share$/
458
-	 */
459
-	public function deletingLastShare() {
460
-		$share_id = $this->lastShareData->data[0]->id;
461
-		$url = "/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/$share_id";
462
-		$this->sendingToWith('DELETE', $url, null);
463
-	}
464
-
465
-	/**
466
-	 * @When /^Getting info of last share$/
467
-	 */
468
-	public function gettingInfoOfLastShare() {
469
-		$share_id = $this->lastShareData->data[0]->id;
470
-		$url = "/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/$share_id";
471
-		$this->sendingToWith('GET', $url, null);
472
-	}
473
-
474
-	/**
475
-	 * @Then /^last share_id is included in the answer$/
476
-	 */
477
-	public function checkingLastShareIDIsIncluded() {
478
-		$share_id = $this->lastShareData->data[0]->id;
479
-		if (!$this->isFieldInResponse('id', $share_id)) {
480
-			Assert::fail("Share id $share_id not found in response");
481
-		}
482
-	}
483
-
484
-	/**
485
-	 * @Then /^last share_id is not included in the answer$/
486
-	 */
487
-	public function checkingLastShareIDIsNotIncluded() {
488
-		$share_id = $this->lastShareData->data[0]->id;
489
-		if ($this->isFieldInResponse('id', $share_id)) {
490
-			Assert::fail("Share id $share_id has been found in response");
491
-		}
492
-	}
493
-
494
-	/**
495
-	 * @Then /^Share fields of last share match with$/
496
-	 * @param TableNode|null $body
497
-	 */
498
-	public function checkShareFields($body) {
499
-		if ($body instanceof TableNode) {
500
-			$fd = $body->getRowsHash();
501
-
502
-			foreach ($fd as $field => $value) {
503
-				if (substr($field, 0, 10) === 'share_with') {
504
-					$value = str_replace('REMOTE', substr($this->remoteBaseUrl, 0, -5), $value);
505
-					$value = str_replace('LOCAL', substr($this->localBaseUrl, 0, -5), $value);
506
-				}
507
-				if (substr($field, 0, 6) === 'remote') {
508
-					$value = str_replace('REMOTE', substr($this->remoteBaseUrl, 0, -4), $value);
509
-					$value = str_replace('LOCAL', substr($this->localBaseUrl, 0, -4), $value);
510
-				}
511
-				if (!$this->isFieldInResponse($field, $value)) {
512
-					Assert::fail("$field" . " doesn't have value " . "$value");
513
-				}
514
-			}
515
-		}
516
-	}
517
-
518
-	/**
519
-	 * @Then the list of returned shares has :count shares
520
-	 */
521
-	public function theListOfReturnedSharesHasShares(int $count) {
522
-		$this->theHTTPStatusCodeShouldBe('200');
523
-		$this->theOCSStatusCodeShouldBe('100');
524
-
525
-		$returnedShares = $this->getXmlResponse()->data[0];
526
-
527
-		Assert::assertEquals($count, count($returnedShares->element));
528
-	}
529
-
530
-	/**
531
-	 * @Then share :count is returned with
532
-	 *
533
-	 * @param int $number
534
-	 * @param TableNode $body
535
-	 */
536
-	public function shareXIsReturnedWith(int $number, TableNode $body) {
537
-		$this->theHTTPStatusCodeShouldBe('200');
538
-		$this->theOCSStatusCodeShouldBe('100');
539
-
540
-		if (!($body instanceof TableNode)) {
541
-			return;
542
-		}
543
-
544
-		$returnedShare = $this->getXmlResponse()->data[0];
545
-		if ($returnedShare->element) {
546
-			$returnedShare = $returnedShare->element[$number];
547
-		}
548
-
549
-		$defaultExpectedFields = [
550
-			'id' => 'A_NUMBER',
551
-			'permissions' => '19',
552
-			'stime' => 'A_NUMBER',
553
-			'parent' => '',
554
-			'expiration' => '',
555
-			'token' => '',
556
-			'storage' => 'A_NUMBER',
557
-			'item_source' => 'A_NUMBER',
558
-			'file_source' => 'A_NUMBER',
559
-			'file_parent' => 'A_NUMBER',
560
-			'mail_send' => '0'
561
-		];
562
-		$expectedFields = array_merge($defaultExpectedFields, $body->getRowsHash());
563
-
564
-		if (!array_key_exists('uid_file_owner', $expectedFields) &&
565
-				array_key_exists('uid_owner', $expectedFields)) {
566
-			$expectedFields['uid_file_owner'] = $expectedFields['uid_owner'];
567
-		}
568
-		if (!array_key_exists('displayname_file_owner', $expectedFields) &&
569
-				array_key_exists('displayname_owner', $expectedFields)) {
570
-			$expectedFields['displayname_file_owner'] = $expectedFields['displayname_owner'];
571
-		}
572
-
573
-		if (array_key_exists('share_type', $expectedFields) &&
574
-				$expectedFields['share_type'] == 10 /* IShare::TYPE_ROOM */ &&
575
-				array_key_exists('share_with', $expectedFields)) {
576
-			if ($expectedFields['share_with'] === 'private_conversation') {
577
-				$expectedFields['share_with'] = 'REGEXP /^private_conversation_[0-9a-f]{6}$/';
578
-			} else {
579
-				$expectedFields['share_with'] = FeatureContext::getTokenForIdentifier($expectedFields['share_with']);
580
-			}
581
-		}
582
-
583
-		foreach ($expectedFields as $field => $value) {
584
-			$this->assertFieldIsInReturnedShare($field, $value, $returnedShare);
585
-		}
586
-	}
587
-
588
-	/**
589
-	 * @return SimpleXMLElement
590
-	 */
591
-	private function getXmlResponse(): \SimpleXMLElement {
592
-		return simplexml_load_string($this->response->getBody());
593
-	}
594
-
595
-	/**
596
-	 * @param string $field
597
-	 * @param string $contentExpected
598
-	 * @param \SimpleXMLElement $returnedShare
599
-	 */
600
-	private function assertFieldIsInReturnedShare(string $field, string $contentExpected, \SimpleXMLElement $returnedShare) {
601
-		if ($contentExpected === 'IGNORE') {
602
-			return;
603
-		}
604
-
605
-		if (!property_exists($returnedShare, $field)) {
606
-			Assert::fail("$field was not found in response");
607
-		}
608
-
609
-		if ($field === 'expiration' && !empty($contentExpected)) {
610
-			$contentExpected = date('Y-m-d', strtotime($contentExpected)) . ' 00:00:00';
611
-		}
612
-
613
-		if ($contentExpected === 'A_NUMBER') {
614
-			Assert::assertTrue(is_numeric((string)$returnedShare->$field), "Field '$field' is not a number: " . $returnedShare->$field);
615
-		} elseif ($contentExpected === 'A_TOKEN') {
616
-			// A token is composed by 15 characters from
617
-			// ISecureRandom::CHAR_HUMAN_READABLE.
618
-			Assert::assertRegExp('/^[abcdefgijkmnopqrstwxyzABCDEFGHJKLMNPQRSTWXYZ23456789]{15}$/', (string)$returnedShare->$field, "Field '$field' is not a token");
619
-		} elseif (strpos($contentExpected, 'REGEXP ') === 0) {
620
-			Assert::assertRegExp(substr($contentExpected, strlen('REGEXP ')), (string)$returnedShare->$field, "Field '$field' does not match");
621
-		} else {
622
-			Assert::assertEquals($contentExpected, (string)$returnedShare->$field, "Field '$field' does not match");
623
-		}
624
-	}
625
-
626
-	/**
627
-	 * @Then As :user remove all shares from the file named :fileName
628
-	 */
629
-	public function asRemoveAllSharesFromTheFileNamed($user, $fileName) {
630
-		$url = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares?format=json";
631
-		$client = new \GuzzleHttp\Client();
632
-		$res = $client->get(
633
-			$url,
634
-			[
635
-				'auth' => [
636
-					$user,
637
-					'123456',
638
-				],
639
-				'headers' => [
640
-					'Content-Type' => 'application/json',
641
-					'OCS-APIREQUEST' => 'true',
642
-				],
643
-			]
644
-		);
645
-		$json = json_decode($res->getBody()->getContents(), true);
646
-		$deleted = false;
647
-		foreach ($json['ocs']['data'] as $data) {
648
-			if (stripslashes($data['path']) === $fileName) {
649
-				$id = $data['id'];
650
-				$client->delete(
651
-					$this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/{$id}",
652
-					[
653
-						'auth' => [
654
-							$user,
655
-							'123456',
656
-						],
657
-						'headers' => [
658
-							'Content-Type' => 'application/json',
659
-							'OCS-APIREQUEST' => 'true',
660
-						],
661
-					]
662
-				);
663
-				$deleted = true;
664
-			}
665
-		}
666
-
667
-		if ($deleted === false) {
668
-			throw new \Exception("Could not delete file $fileName");
669
-		}
670
-	}
671
-
672
-	/**
673
-	 * @When save last share id
674
-	 */
675
-	public function saveLastShareId() {
676
-		$this->savedShareId = ($this->lastShareData['data']['id'] ?? null);
677
-	}
678
-
679
-	/**
680
-	 * @Then share ids should match
681
-	 */
682
-	public function shareIdsShouldMatch() {
683
-		if ($this->savedShareId !== ($this->lastShareData['data']['id'] ?? null)) {
684
-			throw new \Exception('Expected the same link share to be returned');
685
-		}
686
-	}
687
-
688
-	/**
689
-	 * @When /^getting sharees for$/
690
-	 * @param TableNode $body
691
-	 */
692
-	public function whenGettingShareesFor($body) {
693
-		$url = '/apps/files_sharing/api/v1/sharees';
694
-		if ($body instanceof TableNode) {
695
-			$parameters = [];
696
-			foreach ($body->getRowsHash() as $key => $value) {
697
-				$parameters[] = $key . '=' . $value;
698
-			}
699
-			if (!empty($parameters)) {
700
-				$url .= '?' . implode('&', $parameters);
701
-			}
702
-		}
703
-
704
-		$this->sendingTo('GET', $url);
705
-	}
706
-
707
-	/**
708
-	 * @Then /^"([^"]*)" sharees returned (are|is empty)$/
709
-	 * @param string $shareeType
710
-	 * @param string $isEmpty
711
-	 * @param TableNode|null $shareesList
712
-	 */
713
-	public function thenListOfSharees($shareeType, $isEmpty, $shareesList = null) {
714
-		if ($isEmpty !== 'is empty') {
715
-			$sharees = $shareesList->getRows();
716
-			$respondedArray = $this->getArrayOfShareesResponded($this->response, $shareeType);
717
-			Assert::assertEquals($sharees, $respondedArray);
718
-		} else {
719
-			$respondedArray = $this->getArrayOfShareesResponded($this->response, $shareeType);
720
-			Assert::assertEmpty($respondedArray);
721
-		}
722
-	}
723
-
724
-	public function getArrayOfShareesResponded(ResponseInterface $response, $shareeType) {
725
-		$elements = simplexml_load_string($response->getBody())->data;
726
-		$elements = json_decode(json_encode($elements), 1);
727
-		if (strpos($shareeType, 'exact ') === 0) {
728
-			$elements = $elements['exact'];
729
-			$shareeType = substr($shareeType, 6);
730
-		}
731
-
732
-		$sharees = [];
733
-		foreach ($elements[$shareeType] as $element) {
734
-			$sharees[] = [$element['label'], $element['value']['shareType'], $element['value']['shareWith']];
735
-		}
736
-		return $sharees;
737
-	}
17
+    use Provisioning;
18
+
19
+    /** @var int */
20
+    private $sharingApiVersion = 1;
21
+
22
+    /** @var SimpleXMLElement */
23
+    private $lastShareData = null;
24
+
25
+    /** @var SimpleXMLElement[] */
26
+    private $storedShareData = [];
27
+
28
+    /** @var int */
29
+    private $savedShareId = null;
30
+
31
+    /** @var ResponseInterface */
32
+    private $response;
33
+
34
+    /**
35
+     * @Given /^as "([^"]*)" creating a share with$/
36
+     * @param string $user
37
+     * @param TableNode|null $body
38
+     */
39
+    public function asCreatingAShareWith($user, $body) {
40
+        $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares";
41
+        $client = new Client();
42
+        $options = [
43
+            'headers' => [
44
+                'OCS-APIREQUEST' => 'true',
45
+            ],
46
+        ];
47
+        if ($user === 'admin') {
48
+            $options['auth'] = $this->adminUser;
49
+        } else {
50
+            $options['auth'] = [$user, $this->regularUser];
51
+        }
52
+
53
+        if ($body instanceof TableNode) {
54
+            $fd = $body->getRowsHash();
55
+            if (array_key_exists('expireDate', $fd)) {
56
+                $dateModification = $fd['expireDate'];
57
+                if ($dateModification === 'null') {
58
+                    $fd['expireDate'] = null;
59
+                } elseif (!empty($dateModification)) {
60
+                    $fd['expireDate'] = date('Y-m-d', strtotime($dateModification));
61
+                } else {
62
+                    $fd['expireDate'] = '';
63
+                }
64
+            }
65
+            $options['form_params'] = $fd;
66
+        }
67
+
68
+        try {
69
+            $this->response = $client->request('POST', $fullUrl, $options);
70
+        } catch (\GuzzleHttp\Exception\ClientException $ex) {
71
+            $this->response = $ex->getResponse();
72
+        }
73
+
74
+        $this->lastShareData = simplexml_load_string($this->response->getBody());
75
+    }
76
+
77
+    /**
78
+     * @When /^save the last share data as "([^"]*)"$/
79
+     */
80
+    public function saveLastShareData($name) {
81
+        $this->storedShareData[$name] = $this->lastShareData;
82
+    }
83
+
84
+    /**
85
+     * @When /^restore the last share data from "([^"]*)"$/
86
+     */
87
+    public function restoreLastShareData($name) {
88
+        $this->lastShareData = $this->storedShareData[$name];
89
+    }
90
+
91
+    /**
92
+     * @When /^creating a share with$/
93
+     * @param TableNode|null $body
94
+     */
95
+    public function creatingShare($body) {
96
+        $this->asCreatingAShareWith($this->currentUser, $body);
97
+    }
98
+
99
+    /**
100
+     * @When /^accepting last share$/
101
+     */
102
+    public function acceptingLastShare() {
103
+        $share_id = $this->lastShareData->data[0]->id;
104
+        $url = "/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/pending/$share_id";
105
+        $this->sendingToWith('POST', $url, null);
106
+
107
+        $this->theHTTPStatusCodeShouldBe('200');
108
+    }
109
+
110
+    /**
111
+     * @When /^user "([^"]*)" accepts last share$/
112
+     *
113
+     * @param string $user
114
+     */
115
+    public function userAcceptsLastShare(string $user) {
116
+        // "As userXXX" and "user userXXX accepts last share" steps are not
117
+        // expected to be used in the same scenario, but restore the user just
118
+        // in case.
119
+        $previousUser = $this->currentUser;
120
+
121
+        $this->currentUser = $user;
122
+
123
+        $share_id = $this->lastShareData->data[0]->id;
124
+        $url = "/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/pending/$share_id";
125
+        $this->sendingToWith('POST', $url, null);
126
+
127
+        $this->currentUser = $previousUser;
128
+
129
+        $this->theHTTPStatusCodeShouldBe('200');
130
+    }
131
+
132
+    /**
133
+     * @Then /^last link share can be downloaded$/
134
+     */
135
+    public function lastLinkShareCanBeDownloaded() {
136
+        if (count($this->lastShareData->data->element) > 0) {
137
+            $url = $this->lastShareData->data[0]->url;
138
+        } else {
139
+            $url = $this->lastShareData->data->url;
140
+        }
141
+        $fullUrl = $url . '/download';
142
+        $this->checkDownload($fullUrl, null, 'text/plain');
143
+    }
144
+
145
+    /**
146
+     * @Then /^last share can be downloaded$/
147
+     */
148
+    public function lastShareCanBeDownloaded() {
149
+        if (count($this->lastShareData->data->element) > 0) {
150
+            $token = $this->lastShareData->data[0]->token;
151
+        } else {
152
+            $token = $this->lastShareData->data->token;
153
+        }
154
+
155
+        $fullUrl = substr($this->baseUrl, 0, -4) . 'index.php/s/' . $token . '/download';
156
+        $this->checkDownload($fullUrl, null, 'text/plain');
157
+    }
158
+
159
+    /**
160
+     * @Then /^last share with password "([^"]*)" can be downloaded$/
161
+     */
162
+    public function lastShareWithPasswordCanBeDownloaded($password) {
163
+        if (count($this->lastShareData->data->element) > 0) {
164
+            $token = $this->lastShareData->data[0]->token;
165
+        } else {
166
+            $token = $this->lastShareData->data->token;
167
+        }
168
+
169
+        $fullUrl = substr($this->baseUrl, 0, -4) . "public.php/dav/files/$token/";
170
+        $this->checkDownload($fullUrl, ['', $password], 'text/plain');
171
+    }
172
+
173
+    private function checkDownload($url, $auth = null, $mimeType = null) {
174
+        if ($auth !== null) {
175
+            $options['auth'] = $auth;
176
+        }
177
+        $options['stream'] = true;
178
+
179
+        $client = new Client();
180
+        $this->response = $client->get($url, $options);
181
+        Assert::assertEquals(200, $this->response->getStatusCode());
182
+
183
+        $buf = '';
184
+        $body = $this->response->getBody();
185
+        while (!$body->eof()) {
186
+            // read everything
187
+            $buf .= $body->read(8192);
188
+        }
189
+        $body->close();
190
+
191
+        if ($mimeType !== null) {
192
+            $finfo = new finfo;
193
+            Assert::assertEquals($mimeType, $finfo->buffer($buf, FILEINFO_MIME_TYPE));
194
+        }
195
+    }
196
+
197
+    /**
198
+     * @When /^Adding expiration date to last share$/
199
+     */
200
+    public function addingExpirationDate() {
201
+        $share_id = (string)$this->lastShareData->data[0]->id;
202
+        $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/$share_id";
203
+        $client = new Client();
204
+        $options = [];
205
+        if ($this->currentUser === 'admin') {
206
+            $options['auth'] = $this->adminUser;
207
+        } else {
208
+            $options['auth'] = [$this->currentUser, $this->regularUser];
209
+        }
210
+        $date = date('Y-m-d', strtotime('+3 days'));
211
+        $options['form_params'] = ['expireDate' => $date];
212
+        $this->response = $this->response = $client->request('PUT', $fullUrl, $options);
213
+        Assert::assertEquals(200, $this->response->getStatusCode());
214
+    }
215
+
216
+    /**
217
+     * @When /^Updating last share with$/
218
+     * @param TableNode|null $body
219
+     */
220
+    public function updatingLastShare($body) {
221
+        $share_id = (string)$this->lastShareData->data[0]->id;
222
+        $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/$share_id";
223
+        $client = new Client();
224
+        $options = [
225
+            'headers' => [
226
+                'OCS-APIREQUEST' => 'true',
227
+            ],
228
+        ];
229
+        if ($this->currentUser === 'admin') {
230
+            $options['auth'] = $this->adminUser;
231
+        } else {
232
+            $options['auth'] = [$this->currentUser, $this->regularUser];
233
+        }
234
+
235
+        if ($body instanceof TableNode) {
236
+            $fd = $body->getRowsHash();
237
+            if (array_key_exists('expireDate', $fd)) {
238
+                $dateModification = $fd['expireDate'];
239
+                $fd['expireDate'] = date('Y-m-d', strtotime($dateModification));
240
+            }
241
+            $options['form_params'] = $fd;
242
+        }
243
+
244
+        try {
245
+            $this->response = $client->request('PUT', $fullUrl, $options);
246
+        } catch (\GuzzleHttp\Exception\ClientException $ex) {
247
+            $this->response = $ex->getResponse();
248
+        }
249
+    }
250
+
251
+    public function createShare($user,
252
+        $path = null,
253
+        $shareType = null,
254
+        $shareWith = null,
255
+        $publicUpload = null,
256
+        $password = null,
257
+        $permissions = null,
258
+        $viewOnly = false) {
259
+        $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares";
260
+        $client = new Client();
261
+        $options = [
262
+            'headers' => [
263
+                'OCS-APIREQUEST' => 'true',
264
+            ],
265
+        ];
266
+
267
+        if ($user === 'admin') {
268
+            $options['auth'] = $this->adminUser;
269
+        } else {
270
+            $options['auth'] = [$user, $this->regularUser];
271
+        }
272
+        $body = [];
273
+        if (!is_null($path)) {
274
+            $body['path'] = $path;
275
+        }
276
+        if (!is_null($shareType)) {
277
+            $body['shareType'] = $shareType;
278
+        }
279
+        if (!is_null($shareWith)) {
280
+            $body['shareWith'] = $shareWith;
281
+        }
282
+        if (!is_null($publicUpload)) {
283
+            $body['publicUpload'] = $publicUpload;
284
+        }
285
+        if (!is_null($password)) {
286
+            $body['password'] = $password;
287
+        }
288
+        if (!is_null($permissions)) {
289
+            $body['permissions'] = $permissions;
290
+        }
291
+
292
+        if ($viewOnly === true) {
293
+            $body['attributes'] = json_encode([['scope' => 'permissions', 'key' => 'download', 'value' => false]]);
294
+        }
295
+
296
+        $options['form_params'] = $body;
297
+
298
+        try {
299
+            $this->response = $client->request('POST', $fullUrl, $options);
300
+            $this->lastShareData = simplexml_load_string($this->response->getBody());
301
+        } catch (\GuzzleHttp\Exception\ClientException $ex) {
302
+            $this->response = $ex->getResponse();
303
+            throw new \Exception($this->response->getBody());
304
+        }
305
+    }
306
+
307
+    public function isFieldInResponse($field, $contentExpected) {
308
+        $data = simplexml_load_string($this->response->getBody())->data[0];
309
+        if ((string)$field == 'expiration') {
310
+            if (!empty($contentExpected)) {
311
+                $contentExpected = date('Y-m-d', strtotime($contentExpected)) . ' 00:00:00';
312
+            }
313
+        }
314
+        if (count($data->element) > 0) {
315
+            foreach ($data as $element) {
316
+                if ($contentExpected == 'A_TOKEN') {
317
+                    return (strlen((string)$element->$field) == 15);
318
+                } elseif ($contentExpected == 'A_NUMBER') {
319
+                    return is_numeric((string)$element->$field);
320
+                } elseif ($contentExpected == 'AN_URL') {
321
+                    return $this->isExpectedUrl((string)$element->$field, 'index.php/s/');
322
+                } elseif ((string)$element->$field == $contentExpected) {
323
+                    return true;
324
+                } else {
325
+                    print($element->$field);
326
+                }
327
+            }
328
+
329
+            return false;
330
+        } else {
331
+            if ($contentExpected == 'A_TOKEN') {
332
+                return (strlen((string)$data->$field) == 15);
333
+            } elseif ($contentExpected == 'A_NUMBER') {
334
+                return is_numeric((string)$data->$field);
335
+            } elseif ($contentExpected == 'AN_URL') {
336
+                return $this->isExpectedUrl((string)$data->$field, 'index.php/s/');
337
+            } elseif ($contentExpected == $data->$field) {
338
+                return true;
339
+            }
340
+            return false;
341
+        }
342
+    }
343
+
344
+    /**
345
+     * @Then /^File "([^"]*)" should be included in the response$/
346
+     *
347
+     * @param string $filename
348
+     */
349
+    public function checkSharedFileInResponse($filename) {
350
+        Assert::assertEquals(true, $this->isFieldInResponse('file_target', "/$filename"));
351
+    }
352
+
353
+    /**
354
+     * @Then /^File "([^"]*)" should not be included in the response$/
355
+     *
356
+     * @param string $filename
357
+     */
358
+    public function checkSharedFileNotInResponse($filename) {
359
+        Assert::assertEquals(false, $this->isFieldInResponse('file_target', "/$filename"));
360
+    }
361
+
362
+    /**
363
+     * @Then /^User "([^"]*)" should be included in the response$/
364
+     *
365
+     * @param string $user
366
+     */
367
+    public function checkSharedUserInResponse($user) {
368
+        Assert::assertEquals(true, $this->isFieldInResponse('share_with', "$user"));
369
+    }
370
+
371
+    /**
372
+     * @Then /^User "([^"]*)" should not be included in the response$/
373
+     *
374
+     * @param string $user
375
+     */
376
+    public function checkSharedUserNotInResponse($user) {
377
+        Assert::assertEquals(false, $this->isFieldInResponse('share_with', "$user"));
378
+    }
379
+
380
+    public function isUserOrGroupInSharedData($userOrGroup, $permissions = null) {
381
+        $data = simplexml_load_string($this->response->getBody())->data[0];
382
+        foreach ($data as $element) {
383
+            if ($element->share_with == $userOrGroup && ($permissions === null || $permissions == $element->permissions)) {
384
+                return true;
385
+            }
386
+        }
387
+        return false;
388
+    }
389
+
390
+    /**
391
+     * @Given /^(file|folder|entry) "([^"]*)" of user "([^"]*)" is shared with user "([^"]*)"( with permissions ([\d]*))?( view-only)?$/
392
+     *
393
+     * @param string $filepath
394
+     * @param string $user1
395
+     * @param string $user2
396
+     */
397
+    public function assureFileIsShared($entry, $filepath, $user1, $user2, $withPerms = null, $permissions = null, $viewOnly = null) {
398
+        // when view-only is set, permissions is empty string instead of null...
399
+        if ($permissions === '') {
400
+            $permissions = null;
401
+        }
402
+        $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares" . "?path=$filepath";
403
+        $client = new Client();
404
+        $options = [];
405
+        if ($user1 === 'admin') {
406
+            $options['auth'] = $this->adminUser;
407
+        } else {
408
+            $options['auth'] = [$user1, $this->regularUser];
409
+        }
410
+        $options['headers'] = [
411
+            'OCS-APIREQUEST' => 'true',
412
+        ];
413
+        $this->response = $client->get($fullUrl, $options);
414
+        if ($this->isUserOrGroupInSharedData($user2, $permissions)) {
415
+            return;
416
+        } else {
417
+            $this->createShare($user1, $filepath, 0, $user2, null, null, $permissions, $viewOnly !== null);
418
+        }
419
+        $this->response = $client->get($fullUrl, $options);
420
+        Assert::assertEquals(true, $this->isUserOrGroupInSharedData($user2, $permissions));
421
+    }
422
+
423
+    /**
424
+     * @Given /^(file|folder|entry) "([^"]*)" of user "([^"]*)" is shared with group "([^"]*)"( with permissions ([\d]*))?( view-only)?$/
425
+     *
426
+     * @param string $filepath
427
+     * @param string $user
428
+     * @param string $group
429
+     */
430
+    public function assureFileIsSharedWithGroup($entry, $filepath, $user, $group, $withPerms = null, $permissions = null, $viewOnly = null) {
431
+        // when view-only is set, permissions is empty string instead of null...
432
+        if ($permissions === '') {
433
+            $permissions = null;
434
+        }
435
+        $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares" . "?path=$filepath";
436
+        $client = new Client();
437
+        $options = [];
438
+        if ($user === 'admin') {
439
+            $options['auth'] = $this->adminUser;
440
+        } else {
441
+            $options['auth'] = [$user, $this->regularUser];
442
+        }
443
+        $options['headers'] = [
444
+            'OCS-APIREQUEST' => 'true',
445
+        ];
446
+        $this->response = $client->get($fullUrl, $options);
447
+        if ($this->isUserOrGroupInSharedData($group, $permissions)) {
448
+            return;
449
+        } else {
450
+            $this->createShare($user, $filepath, 1, $group, null, null, $permissions, $viewOnly !== null);
451
+        }
452
+        $this->response = $client->get($fullUrl, $options);
453
+        Assert::assertEquals(true, $this->isUserOrGroupInSharedData($group, $permissions));
454
+    }
455
+
456
+    /**
457
+     * @When /^Deleting last share$/
458
+     */
459
+    public function deletingLastShare() {
460
+        $share_id = $this->lastShareData->data[0]->id;
461
+        $url = "/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/$share_id";
462
+        $this->sendingToWith('DELETE', $url, null);
463
+    }
464
+
465
+    /**
466
+     * @When /^Getting info of last share$/
467
+     */
468
+    public function gettingInfoOfLastShare() {
469
+        $share_id = $this->lastShareData->data[0]->id;
470
+        $url = "/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/$share_id";
471
+        $this->sendingToWith('GET', $url, null);
472
+    }
473
+
474
+    /**
475
+     * @Then /^last share_id is included in the answer$/
476
+     */
477
+    public function checkingLastShareIDIsIncluded() {
478
+        $share_id = $this->lastShareData->data[0]->id;
479
+        if (!$this->isFieldInResponse('id', $share_id)) {
480
+            Assert::fail("Share id $share_id not found in response");
481
+        }
482
+    }
483
+
484
+    /**
485
+     * @Then /^last share_id is not included in the answer$/
486
+     */
487
+    public function checkingLastShareIDIsNotIncluded() {
488
+        $share_id = $this->lastShareData->data[0]->id;
489
+        if ($this->isFieldInResponse('id', $share_id)) {
490
+            Assert::fail("Share id $share_id has been found in response");
491
+        }
492
+    }
493
+
494
+    /**
495
+     * @Then /^Share fields of last share match with$/
496
+     * @param TableNode|null $body
497
+     */
498
+    public function checkShareFields($body) {
499
+        if ($body instanceof TableNode) {
500
+            $fd = $body->getRowsHash();
501
+
502
+            foreach ($fd as $field => $value) {
503
+                if (substr($field, 0, 10) === 'share_with') {
504
+                    $value = str_replace('REMOTE', substr($this->remoteBaseUrl, 0, -5), $value);
505
+                    $value = str_replace('LOCAL', substr($this->localBaseUrl, 0, -5), $value);
506
+                }
507
+                if (substr($field, 0, 6) === 'remote') {
508
+                    $value = str_replace('REMOTE', substr($this->remoteBaseUrl, 0, -4), $value);
509
+                    $value = str_replace('LOCAL', substr($this->localBaseUrl, 0, -4), $value);
510
+                }
511
+                if (!$this->isFieldInResponse($field, $value)) {
512
+                    Assert::fail("$field" . " doesn't have value " . "$value");
513
+                }
514
+            }
515
+        }
516
+    }
517
+
518
+    /**
519
+     * @Then the list of returned shares has :count shares
520
+     */
521
+    public function theListOfReturnedSharesHasShares(int $count) {
522
+        $this->theHTTPStatusCodeShouldBe('200');
523
+        $this->theOCSStatusCodeShouldBe('100');
524
+
525
+        $returnedShares = $this->getXmlResponse()->data[0];
526
+
527
+        Assert::assertEquals($count, count($returnedShares->element));
528
+    }
529
+
530
+    /**
531
+     * @Then share :count is returned with
532
+     *
533
+     * @param int $number
534
+     * @param TableNode $body
535
+     */
536
+    public function shareXIsReturnedWith(int $number, TableNode $body) {
537
+        $this->theHTTPStatusCodeShouldBe('200');
538
+        $this->theOCSStatusCodeShouldBe('100');
539
+
540
+        if (!($body instanceof TableNode)) {
541
+            return;
542
+        }
543
+
544
+        $returnedShare = $this->getXmlResponse()->data[0];
545
+        if ($returnedShare->element) {
546
+            $returnedShare = $returnedShare->element[$number];
547
+        }
548
+
549
+        $defaultExpectedFields = [
550
+            'id' => 'A_NUMBER',
551
+            'permissions' => '19',
552
+            'stime' => 'A_NUMBER',
553
+            'parent' => '',
554
+            'expiration' => '',
555
+            'token' => '',
556
+            'storage' => 'A_NUMBER',
557
+            'item_source' => 'A_NUMBER',
558
+            'file_source' => 'A_NUMBER',
559
+            'file_parent' => 'A_NUMBER',
560
+            'mail_send' => '0'
561
+        ];
562
+        $expectedFields = array_merge($defaultExpectedFields, $body->getRowsHash());
563
+
564
+        if (!array_key_exists('uid_file_owner', $expectedFields) &&
565
+                array_key_exists('uid_owner', $expectedFields)) {
566
+            $expectedFields['uid_file_owner'] = $expectedFields['uid_owner'];
567
+        }
568
+        if (!array_key_exists('displayname_file_owner', $expectedFields) &&
569
+                array_key_exists('displayname_owner', $expectedFields)) {
570
+            $expectedFields['displayname_file_owner'] = $expectedFields['displayname_owner'];
571
+        }
572
+
573
+        if (array_key_exists('share_type', $expectedFields) &&
574
+                $expectedFields['share_type'] == 10 /* IShare::TYPE_ROOM */ &&
575
+                array_key_exists('share_with', $expectedFields)) {
576
+            if ($expectedFields['share_with'] === 'private_conversation') {
577
+                $expectedFields['share_with'] = 'REGEXP /^private_conversation_[0-9a-f]{6}$/';
578
+            } else {
579
+                $expectedFields['share_with'] = FeatureContext::getTokenForIdentifier($expectedFields['share_with']);
580
+            }
581
+        }
582
+
583
+        foreach ($expectedFields as $field => $value) {
584
+            $this->assertFieldIsInReturnedShare($field, $value, $returnedShare);
585
+        }
586
+    }
587
+
588
+    /**
589
+     * @return SimpleXMLElement
590
+     */
591
+    private function getXmlResponse(): \SimpleXMLElement {
592
+        return simplexml_load_string($this->response->getBody());
593
+    }
594
+
595
+    /**
596
+     * @param string $field
597
+     * @param string $contentExpected
598
+     * @param \SimpleXMLElement $returnedShare
599
+     */
600
+    private function assertFieldIsInReturnedShare(string $field, string $contentExpected, \SimpleXMLElement $returnedShare) {
601
+        if ($contentExpected === 'IGNORE') {
602
+            return;
603
+        }
604
+
605
+        if (!property_exists($returnedShare, $field)) {
606
+            Assert::fail("$field was not found in response");
607
+        }
608
+
609
+        if ($field === 'expiration' && !empty($contentExpected)) {
610
+            $contentExpected = date('Y-m-d', strtotime($contentExpected)) . ' 00:00:00';
611
+        }
612
+
613
+        if ($contentExpected === 'A_NUMBER') {
614
+            Assert::assertTrue(is_numeric((string)$returnedShare->$field), "Field '$field' is not a number: " . $returnedShare->$field);
615
+        } elseif ($contentExpected === 'A_TOKEN') {
616
+            // A token is composed by 15 characters from
617
+            // ISecureRandom::CHAR_HUMAN_READABLE.
618
+            Assert::assertRegExp('/^[abcdefgijkmnopqrstwxyzABCDEFGHJKLMNPQRSTWXYZ23456789]{15}$/', (string)$returnedShare->$field, "Field '$field' is not a token");
619
+        } elseif (strpos($contentExpected, 'REGEXP ') === 0) {
620
+            Assert::assertRegExp(substr($contentExpected, strlen('REGEXP ')), (string)$returnedShare->$field, "Field '$field' does not match");
621
+        } else {
622
+            Assert::assertEquals($contentExpected, (string)$returnedShare->$field, "Field '$field' does not match");
623
+        }
624
+    }
625
+
626
+    /**
627
+     * @Then As :user remove all shares from the file named :fileName
628
+     */
629
+    public function asRemoveAllSharesFromTheFileNamed($user, $fileName) {
630
+        $url = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares?format=json";
631
+        $client = new \GuzzleHttp\Client();
632
+        $res = $client->get(
633
+            $url,
634
+            [
635
+                'auth' => [
636
+                    $user,
637
+                    '123456',
638
+                ],
639
+                'headers' => [
640
+                    'Content-Type' => 'application/json',
641
+                    'OCS-APIREQUEST' => 'true',
642
+                ],
643
+            ]
644
+        );
645
+        $json = json_decode($res->getBody()->getContents(), true);
646
+        $deleted = false;
647
+        foreach ($json['ocs']['data'] as $data) {
648
+            if (stripslashes($data['path']) === $fileName) {
649
+                $id = $data['id'];
650
+                $client->delete(
651
+                    $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/{$id}",
652
+                    [
653
+                        'auth' => [
654
+                            $user,
655
+                            '123456',
656
+                        ],
657
+                        'headers' => [
658
+                            'Content-Type' => 'application/json',
659
+                            'OCS-APIREQUEST' => 'true',
660
+                        ],
661
+                    ]
662
+                );
663
+                $deleted = true;
664
+            }
665
+        }
666
+
667
+        if ($deleted === false) {
668
+            throw new \Exception("Could not delete file $fileName");
669
+        }
670
+    }
671
+
672
+    /**
673
+     * @When save last share id
674
+     */
675
+    public function saveLastShareId() {
676
+        $this->savedShareId = ($this->lastShareData['data']['id'] ?? null);
677
+    }
678
+
679
+    /**
680
+     * @Then share ids should match
681
+     */
682
+    public function shareIdsShouldMatch() {
683
+        if ($this->savedShareId !== ($this->lastShareData['data']['id'] ?? null)) {
684
+            throw new \Exception('Expected the same link share to be returned');
685
+        }
686
+    }
687
+
688
+    /**
689
+     * @When /^getting sharees for$/
690
+     * @param TableNode $body
691
+     */
692
+    public function whenGettingShareesFor($body) {
693
+        $url = '/apps/files_sharing/api/v1/sharees';
694
+        if ($body instanceof TableNode) {
695
+            $parameters = [];
696
+            foreach ($body->getRowsHash() as $key => $value) {
697
+                $parameters[] = $key . '=' . $value;
698
+            }
699
+            if (!empty($parameters)) {
700
+                $url .= '?' . implode('&', $parameters);
701
+            }
702
+        }
703
+
704
+        $this->sendingTo('GET', $url);
705
+    }
706
+
707
+    /**
708
+     * @Then /^"([^"]*)" sharees returned (are|is empty)$/
709
+     * @param string $shareeType
710
+     * @param string $isEmpty
711
+     * @param TableNode|null $shareesList
712
+     */
713
+    public function thenListOfSharees($shareeType, $isEmpty, $shareesList = null) {
714
+        if ($isEmpty !== 'is empty') {
715
+            $sharees = $shareesList->getRows();
716
+            $respondedArray = $this->getArrayOfShareesResponded($this->response, $shareeType);
717
+            Assert::assertEquals($sharees, $respondedArray);
718
+        } else {
719
+            $respondedArray = $this->getArrayOfShareesResponded($this->response, $shareeType);
720
+            Assert::assertEmpty($respondedArray);
721
+        }
722
+    }
723
+
724
+    public function getArrayOfShareesResponded(ResponseInterface $response, $shareeType) {
725
+        $elements = simplexml_load_string($response->getBody())->data;
726
+        $elements = json_decode(json_encode($elements), 1);
727
+        if (strpos($shareeType, 'exact ') === 0) {
728
+            $elements = $elements['exact'];
729
+            $shareeType = substr($shareeType, 6);
730
+        }
731
+
732
+        $sharees = [];
733
+        foreach ($elements[$shareeType] as $element) {
734
+            $sharees[] = [$element['label'], $element['value']['shareType'], $element['value']['shareWith']];
735
+        }
736
+        return $sharees;
737
+    }
738 738
 }
Please login to merge, or discard this patch.