Completed
Push — master ( 8029dd...0ce4b4 )
by
unknown
30:45
created
build/integration/features/bootstrap/Provisioning.php 1 patch
Indentation   +1015 added lines, -1015 removed lines patch added patch discarded remove patch
@@ -14,1019 +14,1019 @@
 block discarded – undo
14 14
 require __DIR__ . '/../../vendor/autoload.php';
15 15
 
16 16
 trait Provisioning {
17
-	use BasicStructure;
18
-
19
-	/** @var array */
20
-	private $appsToEnableAfterScenario = [];
21
-
22
-	/** @var array */
23
-	private $appsToDisableAfterScenario = [];
24
-
25
-	/** @var array */
26
-	private $createdUsers = [];
27
-
28
-	/** @var array */
29
-	private $createdRemoteUsers = [];
30
-
31
-	/** @var array */
32
-	private $createdRemoteGroups = [];
33
-
34
-	/** @var array */
35
-	private $createdGroups = [];
36
-
37
-	/** @AfterScenario */
38
-	public function restoreAppsEnabledStateAfterScenario() {
39
-		$this->asAn('admin');
40
-
41
-		foreach ($this->appsToEnableAfterScenario as $app) {
42
-			$this->sendingTo('POST', '/cloud/apps/' . $app);
43
-		}
44
-
45
-		foreach ($this->appsToDisableAfterScenario as $app) {
46
-			$this->sendingTo('DELETE', '/cloud/apps/' . $app);
47
-		}
48
-	}
49
-
50
-	/**
51
-	 * @Given /^user "([^"]*)" exists$/
52
-	 * @param string $user
53
-	 */
54
-	public function assureUserExists($user) {
55
-		try {
56
-			$this->userExists($user);
57
-		} catch (\GuzzleHttp\Exception\ClientException $ex) {
58
-			$previous_user = $this->currentUser;
59
-			$this->currentUser = 'admin';
60
-			$this->creatingTheUser($user);
61
-			$this->currentUser = $previous_user;
62
-		}
63
-		$this->userExists($user);
64
-		Assert::assertEquals(200, $this->response->getStatusCode());
65
-	}
66
-
67
-	/**
68
-	 * @Given /^user "([^"]*)" with displayname "((?:[^"]|\\")*)" exists$/
69
-	 * @param string $user
70
-	 */
71
-	public function assureUserWithDisplaynameExists($user, $displayname) {
72
-		try {
73
-			$this->userExists($user);
74
-		} catch (\GuzzleHttp\Exception\ClientException $ex) {
75
-			$previous_user = $this->currentUser;
76
-			$this->currentUser = 'admin';
77
-			$this->creatingTheUser($user, $displayname);
78
-			$this->currentUser = $previous_user;
79
-		}
80
-		$this->userExists($user);
81
-		Assert::assertEquals(200, $this->response->getStatusCode());
82
-	}
83
-
84
-	/**
85
-	 * @Given /^user "([^"]*)" does not exist$/
86
-	 * @param string $user
87
-	 */
88
-	public function userDoesNotExist($user) {
89
-		try {
90
-			$this->userExists($user);
91
-		} catch (\GuzzleHttp\Exception\ClientException $ex) {
92
-			$this->response = $ex->getResponse();
93
-			Assert::assertEquals(404, $ex->getResponse()->getStatusCode());
94
-			return;
95
-		}
96
-		$previous_user = $this->currentUser;
97
-		$this->currentUser = 'admin';
98
-		$this->deletingTheUser($user);
99
-		$this->currentUser = $previous_user;
100
-		try {
101
-			$this->userExists($user);
102
-		} catch (\GuzzleHttp\Exception\ClientException $ex) {
103
-			$this->response = $ex->getResponse();
104
-			Assert::assertEquals(404, $ex->getResponse()->getStatusCode());
105
-		}
106
-	}
107
-
108
-	public function creatingTheUser($user, $displayname = '') {
109
-		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users";
110
-		$client = new Client();
111
-		$options = [];
112
-		if ($this->currentUser === 'admin') {
113
-			$options['auth'] = $this->adminUser;
114
-		}
115
-
116
-		$options['form_params'] = [
117
-			'userid' => $user,
118
-			'password' => '123456'
119
-		];
120
-		if ($displayname !== '') {
121
-			$options['form_params']['displayName'] = $displayname;
122
-		}
123
-		$options['headers'] = [
124
-			'OCS-APIREQUEST' => 'true',
125
-		];
126
-
127
-		$this->response = $client->post($fullUrl, $options);
128
-		if ($this->currentServer === 'LOCAL') {
129
-			$this->createdUsers[$user] = $user;
130
-		} elseif ($this->currentServer === 'REMOTE') {
131
-			$this->createdRemoteUsers[$user] = $user;
132
-		}
133
-
134
-		//Quick hack to login once with the current user
135
-		$options2 = [
136
-			'auth' => [$user, '123456'],
137
-		];
138
-		$options2['headers'] = [
139
-			'OCS-APIREQUEST' => 'true',
140
-		];
141
-		$url = $fullUrl . '/' . $user;
142
-		$client->get($url, $options2);
143
-	}
144
-
145
-	/**
146
-	 * @Then /^user "([^"]*)" has$/
147
-	 *
148
-	 * @param string $user
149
-	 * @param TableNode|null $settings
150
-	 */
151
-	public function userHasSetting($user, $settings) {
152
-		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user";
153
-		$client = new Client();
154
-		$options = [];
155
-		if ($this->currentUser === 'admin') {
156
-			$options['auth'] = $this->adminUser;
157
-		} else {
158
-			$options['auth'] = [$this->currentUser, $this->regularUser];
159
-		}
160
-		$options['headers'] = [
161
-			'OCS-APIREQUEST' => 'true',
162
-		];
163
-
164
-		$response = $client->get($fullUrl, $options);
165
-		foreach ($settings->getRows() as $setting) {
166
-			$value = json_decode(json_encode(simplexml_load_string($response->getBody())->data->{$setting[0]}), 1);
167
-			if (isset($value['element']) && in_array($setting[0], ['additional_mail', 'additional_mailScope'], true)) {
168
-				$expectedValues = explode(';', $setting[1]);
169
-				foreach ($expectedValues as $expected) {
170
-					Assert::assertTrue(in_array($expected, $value['element'], true), 'Data wrong for field: ' . $setting[0]);
171
-				}
172
-			} elseif (isset($value[0])) {
173
-				Assert::assertEqualsCanonicalizing($setting[1], $value[0], 'Data wrong for field: ' . $setting[0]);
174
-			} else {
175
-				Assert::assertEquals('', $setting[1], 'Data wrong for field: ' . $setting[0]);
176
-			}
177
-		}
178
-	}
179
-
180
-	/**
181
-	 * @Then /^user "([^"]*)" has the following profile data$/
182
-	 */
183
-	public function userHasProfileData(string $user, ?TableNode $settings): void {
184
-		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/profile/$user";
185
-		$client = new Client();
186
-		$options = [];
187
-		if ($this->currentUser === 'admin') {
188
-			$options['auth'] = $this->adminUser;
189
-		} else {
190
-			$options['auth'] = [$this->currentUser, $this->regularUser];
191
-		}
192
-		$options['headers'] = [
193
-			'OCS-APIREQUEST' => 'true',
194
-			'Accept' => 'application/json',
195
-		];
196
-
197
-		$response = $client->get($fullUrl, $options);
198
-		$body = $response->getBody()->getContents();
199
-		$data = json_decode($body, true);
200
-		$data = $data['ocs']['data'];
201
-		foreach ($settings->getRows() as $setting) {
202
-			Assert::assertArrayHasKey($setting[0], $data, 'Profile data field missing: ' . $setting[0]);
203
-			if ($setting[1] === 'NULL') {
204
-				Assert::assertNull($data[$setting[0]], 'Profile data wrong for field: ' . $setting[0]);
205
-			} else {
206
-				Assert::assertEquals($setting[1], $data[$setting[0]], 'Profile data wrong for field: ' . $setting[0]);
207
-			}
208
-		}
209
-	}
210
-
211
-	/**
212
-	 * @Then /^group "([^"]*)" has$/
213
-	 *
214
-	 * @param string $user
215
-	 * @param TableNode|null $settings
216
-	 */
217
-	public function groupHasSetting($group, $settings) {
218
-		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/groups/details?search=$group";
219
-		$client = new Client();
220
-		$options = [];
221
-		if ($this->currentUser === 'admin') {
222
-			$options['auth'] = $this->adminUser;
223
-		} else {
224
-			$options['auth'] = [$this->currentUser, $this->regularUser];
225
-		}
226
-		$options['headers'] = [
227
-			'OCS-APIREQUEST' => 'true',
228
-		];
229
-
230
-		$response = $client->get($fullUrl, $options);
231
-		$groupDetails = simplexml_load_string($response->getBody())->data[0]->groups[0]->element;
232
-		foreach ($settings->getRows() as $setting) {
233
-			$value = json_decode(json_encode($groupDetails->{$setting[0]}), 1);
234
-			if (isset($value[0])) {
235
-				Assert::assertEqualsCanonicalizing($setting[1], $value[0]);
236
-			} else {
237
-				Assert::assertEquals('', $setting[1]);
238
-			}
239
-		}
240
-	}
241
-
242
-
243
-	/**
244
-	 * @Then /^user "([^"]*)" has editable fields$/
245
-	 *
246
-	 * @param string $user
247
-	 * @param TableNode|null $fields
248
-	 */
249
-	public function userHasEditableFields($user, $fields) {
250
-		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/user/fields";
251
-		if ($user !== 'self') {
252
-			$fullUrl .= '/' . $user;
253
-		}
254
-		$client = new Client();
255
-		$options = [];
256
-		if ($this->currentUser === 'admin') {
257
-			$options['auth'] = $this->adminUser;
258
-		} else {
259
-			$options['auth'] = [$this->currentUser, $this->regularUser];
260
-		}
261
-		$options['headers'] = [
262
-			'OCS-APIREQUEST' => 'true',
263
-		];
264
-
265
-		$response = $client->get($fullUrl, $options);
266
-		$fieldsArray = json_decode(json_encode(simplexml_load_string($response->getBody())->data->element), 1);
267
-
268
-		$expectedFields = $fields->getRows();
269
-		$expectedFields = $this->simplifyArray($expectedFields);
270
-		Assert::assertEquals($expectedFields, $fieldsArray);
271
-	}
272
-
273
-	/**
274
-	 * @Then /^search users by phone for region "([^"]*)" with$/
275
-	 *
276
-	 * @param string $user
277
-	 * @param TableNode|null $settings
278
-	 */
279
-	public function searchUserByPhone($region, TableNode $searchTable) {
280
-		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/search/by-phone";
281
-		$client = new Client();
282
-		$options = [];
283
-		$options['auth'] = $this->adminUser;
284
-		$options['headers'] = [
285
-			'OCS-APIREQUEST' => 'true',
286
-		];
287
-
288
-		$search = [];
289
-		foreach ($searchTable->getRows() as $row) {
290
-			if (!isset($search[$row[0]])) {
291
-				$search[$row[0]] = [];
292
-			}
293
-			$search[$row[0]][] = $row[1];
294
-		}
295
-
296
-		$options['form_params'] = [
297
-			'location' => $region,
298
-			'search' => $search,
299
-		];
300
-
301
-		$this->response = $client->post($fullUrl, $options);
302
-	}
303
-
304
-	public function createUser($user) {
305
-		$previous_user = $this->currentUser;
306
-		$this->currentUser = 'admin';
307
-		$this->creatingTheUser($user);
308
-		$this->userExists($user);
309
-		$this->currentUser = $previous_user;
310
-	}
311
-
312
-	public function deleteUser($user) {
313
-		$previous_user = $this->currentUser;
314
-		$this->currentUser = 'admin';
315
-		$this->deletingTheUser($user);
316
-		$this->userDoesNotExist($user);
317
-		$this->currentUser = $previous_user;
318
-	}
319
-
320
-	public function createGroup($group) {
321
-		$previous_user = $this->currentUser;
322
-		$this->currentUser = 'admin';
323
-		$this->creatingTheGroup($group);
324
-		$this->groupExists($group);
325
-		$this->currentUser = $previous_user;
326
-	}
327
-
328
-	public function deleteGroup($group) {
329
-		$previous_user = $this->currentUser;
330
-		$this->currentUser = 'admin';
331
-		$this->deletingTheGroup($group);
332
-		$this->groupDoesNotExist($group);
333
-		$this->currentUser = $previous_user;
334
-	}
335
-
336
-	public function userExists($user) {
337
-		$fullUrl = $this->baseUrl . "v2.php/cloud/users/$user";
338
-		$client = new Client();
339
-		$options = [];
340
-		$options['auth'] = $this->adminUser;
341
-		$options['headers'] = [
342
-			'OCS-APIREQUEST' => 'true'
343
-		];
344
-
345
-		$this->response = $client->get($fullUrl, $options);
346
-	}
347
-
348
-	/**
349
-	 * @Then /^check that user "([^"]*)" belongs to group "([^"]*)"$/
350
-	 * @param string $user
351
-	 * @param string $group
352
-	 */
353
-	public function checkThatUserBelongsToGroup($user, $group) {
354
-		$fullUrl = $this->baseUrl . "v2.php/cloud/users/$user/groups";
355
-		$client = new Client();
356
-		$options = [];
357
-		if ($this->currentUser === 'admin') {
358
-			$options['auth'] = $this->adminUser;
359
-		}
360
-		$options['headers'] = [
361
-			'OCS-APIREQUEST' => 'true',
362
-		];
363
-
364
-		$this->response = $client->get($fullUrl, $options);
365
-		$respondedArray = $this->getArrayOfGroupsResponded($this->response);
366
-		sort($respondedArray);
367
-		Assert::assertContains($group, $respondedArray);
368
-		Assert::assertEquals(200, $this->response->getStatusCode());
369
-	}
370
-
371
-	public function userBelongsToGroup($user, $group) {
372
-		$fullUrl = $this->baseUrl . "v2.php/cloud/users/$user/groups";
373
-		$client = new Client();
374
-		$options = [];
375
-		if ($this->currentUser === 'admin') {
376
-			$options['auth'] = $this->adminUser;
377
-		}
378
-		$options['headers'] = [
379
-			'OCS-APIREQUEST' => 'true',
380
-		];
381
-
382
-		$this->response = $client->get($fullUrl, $options);
383
-		$respondedArray = $this->getArrayOfGroupsResponded($this->response);
384
-
385
-		if (array_key_exists($group, $respondedArray)) {
386
-			return true;
387
-		} else {
388
-			return false;
389
-		}
390
-	}
391
-
392
-	/**
393
-	 * @Given /^user "([^"]*)" belongs to group "([^"]*)"$/
394
-	 * @param string $user
395
-	 * @param string $group
396
-	 */
397
-	public function assureUserBelongsToGroup($user, $group) {
398
-		$previous_user = $this->currentUser;
399
-		$this->currentUser = 'admin';
400
-
401
-		if (!$this->userBelongsToGroup($user, $group)) {
402
-			$this->addingUserToGroup($user, $group);
403
-		}
404
-
405
-		$this->checkThatUserBelongsToGroup($user, $group);
406
-		$this->currentUser = $previous_user;
407
-	}
408
-
409
-	/**
410
-	 * @Given /^user "([^"]*)" does not belong to group "([^"]*)"$/
411
-	 * @param string $user
412
-	 * @param string $group
413
-	 */
414
-	public function userDoesNotBelongToGroup($user, $group) {
415
-		$fullUrl = $this->baseUrl . "v2.php/cloud/users/$user/groups";
416
-		$client = new Client();
417
-		$options = [];
418
-		if ($this->currentUser === 'admin') {
419
-			$options['auth'] = $this->adminUser;
420
-		}
421
-		$options['headers'] = [
422
-			'OCS-APIREQUEST' => 'true',
423
-		];
424
-
425
-		$this->response = $client->get($fullUrl, $options);
426
-		$groups = [$group];
427
-		$respondedArray = $this->getArrayOfGroupsResponded($this->response);
428
-		Assert::assertNotEqualsCanonicalizing($groups, $respondedArray);
429
-		Assert::assertEquals(200, $this->response->getStatusCode());
430
-	}
431
-
432
-	/**
433
-	 * @When /^creating the group "([^"]*)"$/
434
-	 * @param string $group
435
-	 */
436
-	public function creatingTheGroup($group) {
437
-		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/groups";
438
-		$client = new Client();
439
-		$options = [];
440
-		if ($this->currentUser === 'admin') {
441
-			$options['auth'] = $this->adminUser;
442
-		}
443
-
444
-		$options['form_params'] = [
445
-			'groupid' => $group,
446
-		];
447
-		$options['headers'] = [
448
-			'OCS-APIREQUEST' => 'true',
449
-		];
450
-
451
-		$this->response = $client->post($fullUrl, $options);
452
-		if ($this->currentServer === 'LOCAL') {
453
-			$this->createdGroups[$group] = $group;
454
-		} elseif ($this->currentServer === 'REMOTE') {
455
-			$this->createdRemoteGroups[$group] = $group;
456
-		}
457
-	}
458
-
459
-	/**
460
-	 * @When /^assure user "([^"]*)" is disabled$/
461
-	 */
462
-	public function assureUserIsDisabled($user) {
463
-		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user/disable";
464
-		$client = new Client();
465
-		$options = [];
466
-		if ($this->currentUser === 'admin') {
467
-			$options['auth'] = $this->adminUser;
468
-		}
469
-		$options['headers'] = [
470
-			'OCS-APIREQUEST' => 'true',
471
-		];
472
-		// TODO: fix hack
473
-		$options['form_params'] = [
474
-			'foo' => 'bar'
475
-		];
476
-
477
-		$this->response = $client->put($fullUrl, $options);
478
-	}
479
-
480
-	/**
481
-	 * @When /^Deleting the user "([^"]*)"$/
482
-	 * @param string $user
483
-	 */
484
-	public function deletingTheUser($user) {
485
-		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user";
486
-		$client = new Client();
487
-		$options = [];
488
-		if ($this->currentUser === 'admin') {
489
-			$options['auth'] = $this->adminUser;
490
-		}
491
-		$options['headers'] = [
492
-			'OCS-APIREQUEST' => 'true',
493
-		];
494
-
495
-		$this->response = $client->delete($fullUrl, $options);
496
-	}
497
-
498
-	/**
499
-	 * @When /^Deleting the group "([^"]*)"$/
500
-	 * @param string $group
501
-	 */
502
-	public function deletingTheGroup($group) {
503
-		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/groups/$group";
504
-		$client = new Client();
505
-		$options = [];
506
-		if ($this->currentUser === 'admin') {
507
-			$options['auth'] = $this->adminUser;
508
-		}
509
-		$options['headers'] = [
510
-			'OCS-APIREQUEST' => 'true',
511
-		];
512
-
513
-		$this->response = $client->delete($fullUrl, $options);
514
-
515
-		if ($this->currentServer === 'LOCAL') {
516
-			unset($this->createdGroups[$group]);
517
-		} elseif ($this->currentServer === 'REMOTE') {
518
-			unset($this->createdRemoteGroups[$group]);
519
-		}
520
-	}
521
-
522
-	/**
523
-	 * @Given /^Add user "([^"]*)" to the group "([^"]*)"$/
524
-	 * @param string $user
525
-	 * @param string $group
526
-	 */
527
-	public function addUserToGroup($user, $group) {
528
-		$this->userExists($user);
529
-		$this->groupExists($group);
530
-		$this->addingUserToGroup($user, $group);
531
-	}
532
-
533
-	/**
534
-	 * @When /^User "([^"]*)" is added to the group "([^"]*)"$/
535
-	 * @param string $user
536
-	 * @param string $group
537
-	 */
538
-	public function addingUserToGroup($user, $group) {
539
-		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user/groups";
540
-		$client = new Client();
541
-		$options = [];
542
-		if ($this->currentUser === 'admin') {
543
-			$options['auth'] = $this->adminUser;
544
-		}
545
-		$options['headers'] = [
546
-			'OCS-APIREQUEST' => 'true',
547
-		];
548
-
549
-		$options['form_params'] = [
550
-			'groupid' => $group,
551
-		];
552
-
553
-		$this->response = $client->post($fullUrl, $options);
554
-	}
555
-
556
-
557
-	public function groupExists($group) {
558
-		$fullUrl = $this->baseUrl . "v2.php/cloud/groups/$group";
559
-		$client = new Client();
560
-		$options = [];
561
-		$options['auth'] = $this->adminUser;
562
-		$options['headers'] = [
563
-			'OCS-APIREQUEST' => 'true',
564
-		];
565
-
566
-		$this->response = $client->get($fullUrl, $options);
567
-	}
568
-
569
-	/**
570
-	 * @Given /^group "([^"]*)" exists$/
571
-	 * @param string $group
572
-	 */
573
-	public function assureGroupExists($group) {
574
-		try {
575
-			$this->groupExists($group);
576
-		} catch (\GuzzleHttp\Exception\ClientException $ex) {
577
-			$previous_user = $this->currentUser;
578
-			$this->currentUser = 'admin';
579
-			$this->creatingTheGroup($group);
580
-			$this->currentUser = $previous_user;
581
-		}
582
-		$this->groupExists($group);
583
-		Assert::assertEquals(200, $this->response->getStatusCode());
584
-	}
585
-
586
-	/**
587
-	 * @Given /^group "([^"]*)" does not exist$/
588
-	 * @param string $group
589
-	 */
590
-	public function groupDoesNotExist($group) {
591
-		try {
592
-			$this->groupExists($group);
593
-		} catch (\GuzzleHttp\Exception\ClientException $ex) {
594
-			$this->response = $ex->getResponse();
595
-			Assert::assertEquals(404, $ex->getResponse()->getStatusCode());
596
-			return;
597
-		}
598
-		$previous_user = $this->currentUser;
599
-		$this->currentUser = 'admin';
600
-		$this->deletingTheGroup($group);
601
-		$this->currentUser = $previous_user;
602
-		try {
603
-			$this->groupExists($group);
604
-		} catch (\GuzzleHttp\Exception\ClientException $ex) {
605
-			$this->response = $ex->getResponse();
606
-			Assert::assertEquals(404, $ex->getResponse()->getStatusCode());
607
-		}
608
-	}
609
-
610
-	/**
611
-	 * @Given /^user "([^"]*)" is subadmin of group "([^"]*)"$/
612
-	 * @param string $user
613
-	 * @param string $group
614
-	 */
615
-	public function userIsSubadminOfGroup($user, $group) {
616
-		$fullUrl = $this->baseUrl . "v2.php/cloud/groups/$group/subadmins";
617
-		$client = new Client();
618
-		$options = [];
619
-		if ($this->currentUser === 'admin') {
620
-			$options['auth'] = $this->adminUser;
621
-		}
622
-		$options['headers'] = [
623
-			'OCS-APIREQUEST' => 'true',
624
-		];
625
-
626
-		$this->response = $client->get($fullUrl, $options);
627
-		$respondedArray = $this->getArrayOfSubadminsResponded($this->response);
628
-		sort($respondedArray);
629
-		Assert::assertContains($user, $respondedArray);
630
-		Assert::assertEquals(200, $this->response->getStatusCode());
631
-	}
632
-
633
-	/**
634
-	 * @Given /^Assure user "([^"]*)" is subadmin of group "([^"]*)"$/
635
-	 * @param string $user
636
-	 * @param string $group
637
-	 */
638
-	public function assureUserIsSubadminOfGroup($user, $group) {
639
-		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user/subadmins";
640
-		$client = new Client();
641
-		$options = [];
642
-		if ($this->currentUser === 'admin') {
643
-			$options['auth'] = $this->adminUser;
644
-		}
645
-		$options['form_params'] = [
646
-			'groupid' => $group
647
-		];
648
-		$options['headers'] = [
649
-			'OCS-APIREQUEST' => 'true',
650
-		];
651
-		$this->response = $client->post($fullUrl, $options);
652
-		Assert::assertEquals(200, $this->response->getStatusCode());
653
-	}
654
-
655
-	/**
656
-	 * @Given /^user "([^"]*)" is not a subadmin of group "([^"]*)"$/
657
-	 * @param string $user
658
-	 * @param string $group
659
-	 */
660
-	public function userIsNotSubadminOfGroup($user, $group) {
661
-		$fullUrl = $this->baseUrl . "v2.php/cloud/groups/$group/subadmins";
662
-		$client = new Client();
663
-		$options = [];
664
-		if ($this->currentUser === 'admin') {
665
-			$options['auth'] = $this->adminUser;
666
-		}
667
-		$options['headers'] = [
668
-			'OCS-APIREQUEST' => 'true',
669
-		];
670
-
671
-		$this->response = $client->get($fullUrl, $options);
672
-		$respondedArray = $this->getArrayOfSubadminsResponded($this->response);
673
-		sort($respondedArray);
674
-		Assert::assertNotContains($user, $respondedArray);
675
-		Assert::assertEquals(200, $this->response->getStatusCode());
676
-	}
677
-
678
-	/**
679
-	 * @Then /^users returned are$/
680
-	 * @param TableNode|null $usersList
681
-	 */
682
-	public function theUsersShouldBe($usersList) {
683
-		if ($usersList instanceof TableNode) {
684
-			$users = $usersList->getRows();
685
-			$usersSimplified = $this->simplifyArray($users);
686
-			$respondedArray = $this->getArrayOfUsersResponded($this->response);
687
-			Assert::assertEqualsCanonicalizing($usersSimplified, $respondedArray);
688
-		}
689
-	}
690
-
691
-	/**
692
-	 * @Then /^phone matches returned are$/
693
-	 * @param TableNode|null $usersList
694
-	 */
695
-	public function thePhoneUsersShouldBe($usersList) {
696
-		if ($usersList instanceof TableNode) {
697
-			$users = $usersList->getRowsHash();
698
-			$listCheckedElements = simplexml_load_string($this->response->getBody())->data;
699
-			$respondedArray = json_decode(json_encode($listCheckedElements), true);
700
-			Assert::assertEquals($users, $respondedArray);
701
-		}
702
-	}
703
-
704
-	/**
705
-	 * @Then /^detailed users returned are$/
706
-	 * @param TableNode|null $usersList
707
-	 */
708
-	public function theDetailedUsersShouldBe($usersList) {
709
-		if ($usersList instanceof TableNode) {
710
-			$users = $usersList->getRows();
711
-			$usersSimplified = $this->simplifyArray($users);
712
-			$respondedArray = $this->getArrayOfDetailedUsersResponded($this->response);
713
-			$respondedArray = array_keys($respondedArray);
714
-			Assert::assertEquals($usersSimplified, $respondedArray);
715
-		}
716
-	}
717
-
718
-	/**
719
-	 * @Then /^groups returned are$/
720
-	 * @param TableNode|null $groupsList
721
-	 */
722
-	public function theGroupsShouldBe($groupsList) {
723
-		if ($groupsList instanceof TableNode) {
724
-			$groups = $groupsList->getRows();
725
-			$groupsSimplified = $this->simplifyArray($groups);
726
-			$respondedArray = $this->getArrayOfGroupsResponded($this->response);
727
-			Assert::assertEqualsCanonicalizing($groupsSimplified, $respondedArray);
728
-		}
729
-	}
730
-
731
-	/**
732
-	 * @Then /^subadmin groups returned are$/
733
-	 * @param TableNode|null $groupsList
734
-	 */
735
-	public function theSubadminGroupsShouldBe($groupsList) {
736
-		if ($groupsList instanceof TableNode) {
737
-			$groups = $groupsList->getRows();
738
-			$groupsSimplified = $this->simplifyArray($groups);
739
-			$respondedArray = $this->getArrayOfSubadminsResponded($this->response);
740
-			Assert::assertEqualsCanonicalizing($groupsSimplified, $respondedArray);
741
-		}
742
-	}
743
-
744
-	/**
745
-	 * @Then /^apps returned are$/
746
-	 * @param TableNode|null $appList
747
-	 */
748
-	public function theAppsShouldBe($appList) {
749
-		if ($appList instanceof TableNode) {
750
-			$apps = $appList->getRows();
751
-			$appsSimplified = $this->simplifyArray($apps);
752
-			$respondedArray = $this->getArrayOfAppsResponded($this->response);
753
-			Assert::assertEqualsCanonicalizing($appsSimplified, $respondedArray);
754
-		}
755
-	}
756
-
757
-	/**
758
-	 * @Then /^subadmin users returned are$/
759
-	 * @param TableNode|null $groupsList
760
-	 */
761
-	public function theSubadminUsersShouldBe($groupsList) {
762
-		$this->theSubadminGroupsShouldBe($groupsList);
763
-	}
764
-
765
-	/**
766
-	 * Parses the xml answer to get the array of users returned.
767
-	 *
768
-	 * @param ResponseInterface $resp
769
-	 * @return array
770
-	 */
771
-	public function getArrayOfUsersResponded($resp) {
772
-		$listCheckedElements = simplexml_load_string($resp->getBody())->data[0]->users[0]->element;
773
-		$extractedElementsArray = json_decode(json_encode($listCheckedElements), 1);
774
-		return $extractedElementsArray;
775
-	}
776
-
777
-	/**
778
-	 * Parses the xml answer to get the array of detailed users returned.
779
-	 *
780
-	 * @param ResponseInterface $resp
781
-	 * @return array
782
-	 */
783
-	public function getArrayOfDetailedUsersResponded($resp) {
784
-		$listCheckedElements = simplexml_load_string($resp->getBody())->data[0]->users;
785
-		$extractedElementsArray = json_decode(json_encode($listCheckedElements), 1);
786
-		return $extractedElementsArray;
787
-	}
788
-
789
-	/**
790
-	 * Parses the xml answer to get the array of groups returned.
791
-	 *
792
-	 * @param ResponseInterface $resp
793
-	 * @return array
794
-	 */
795
-	public function getArrayOfGroupsResponded($resp) {
796
-		$listCheckedElements = simplexml_load_string($resp->getBody())->data[0]->groups[0]->element;
797
-		$extractedElementsArray = json_decode(json_encode($listCheckedElements), 1);
798
-		return $extractedElementsArray;
799
-	}
800
-
801
-	/**
802
-	 * Parses the xml answer to get the array of apps returned.
803
-	 *
804
-	 * @param ResponseInterface $resp
805
-	 * @return array
806
-	 */
807
-	public function getArrayOfAppsResponded($resp) {
808
-		$listCheckedElements = simplexml_load_string($resp->getBody())->data[0]->apps[0]->element;
809
-		$extractedElementsArray = json_decode(json_encode($listCheckedElements), 1);
810
-		return $extractedElementsArray;
811
-	}
812
-
813
-	/**
814
-	 * Parses the xml answer to get the array of subadmins returned.
815
-	 *
816
-	 * @param ResponseInterface $resp
817
-	 * @return array
818
-	 */
819
-	public function getArrayOfSubadminsResponded($resp) {
820
-		$listCheckedElements = simplexml_load_string($resp->getBody())->data[0]->element;
821
-		$extractedElementsArray = json_decode(json_encode($listCheckedElements), 1);
822
-		return $extractedElementsArray;
823
-	}
824
-
825
-	/**
826
-	 * @Given /^app "([^"]*)" enabled state will be restored once the scenario finishes$/
827
-	 * @param string $app
828
-	 */
829
-	public function appEnabledStateWillBeRestoredOnceTheScenarioFinishes($app) {
830
-		if (in_array($app, $this->getAppsWithFilter('enabled'))) {
831
-			$this->appsToEnableAfterScenario[] = $app;
832
-		} elseif (in_array($app, $this->getAppsWithFilter('disabled'))) {
833
-			$this->appsToDisableAfterScenario[] = $app;
834
-		}
835
-
836
-		// Apps that were not installed before the scenario will not be
837
-		// disabled nor uninstalled after the scenario.
838
-	}
839
-
840
-	private function getAppsWithFilter($filter) {
841
-		$fullUrl = $this->baseUrl . 'v2.php/cloud/apps?filter=' . $filter;
842
-		$client = new Client();
843
-		$options = [];
844
-		if ($this->currentUser === 'admin') {
845
-			$options['auth'] = $this->adminUser;
846
-		}
847
-		$options['headers'] = [
848
-			'OCS-APIREQUEST' => 'true',
849
-		];
850
-
851
-		$this->response = $client->get($fullUrl, $options);
852
-		return $this->getArrayOfAppsResponded($this->response);
853
-	}
854
-
855
-	/**
856
-	 * @Given /^app "([^"]*)" is disabled$/
857
-	 * @param string $app
858
-	 */
859
-	public function appIsDisabled($app) {
860
-		$respondedArray = $this->getAppsWithFilter('disabled');
861
-		Assert::assertContains($app, $respondedArray);
862
-		Assert::assertEquals(200, $this->response->getStatusCode());
863
-	}
864
-
865
-	/**
866
-	 * @Given /^app "([^"]*)" is enabled$/
867
-	 * @param string $app
868
-	 */
869
-	public function appIsEnabled($app) {
870
-		$respondedArray = $this->getAppsWithFilter('enabled');
871
-		Assert::assertContains($app, $respondedArray);
872
-		Assert::assertEquals(200, $this->response->getStatusCode());
873
-	}
874
-
875
-	/**
876
-	 * @Given /^app "([^"]*)" is not enabled$/
877
-	 *
878
-	 * Checks that the app is disabled or not installed.
879
-	 *
880
-	 * @param string $app
881
-	 */
882
-	public function appIsNotEnabled($app) {
883
-		$respondedArray = $this->getAppsWithFilter('enabled');
884
-		Assert::assertNotContains($app, $respondedArray);
885
-		Assert::assertEquals(200, $this->response->getStatusCode());
886
-	}
887
-
888
-	/**
889
-	 * @Then /^user "([^"]*)" is disabled$/
890
-	 * @param string $user
891
-	 */
892
-	public function userIsDisabled($user) {
893
-		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user";
894
-		$client = new Client();
895
-		$options = [];
896
-		if ($this->currentUser === 'admin') {
897
-			$options['auth'] = $this->adminUser;
898
-		}
899
-		$options['headers'] = [
900
-			'OCS-APIREQUEST' => 'true',
901
-		];
902
-
903
-		$this->response = $client->get($fullUrl, $options);
904
-		// false in xml is empty
905
-		Assert::assertTrue(empty(simplexml_load_string($this->response->getBody())->data[0]->enabled));
906
-	}
907
-
908
-	/**
909
-	 * @Then /^user "([^"]*)" is enabled$/
910
-	 * @param string $user
911
-	 */
912
-	public function userIsEnabled($user) {
913
-		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user";
914
-		$client = new Client();
915
-		$options = [];
916
-		if ($this->currentUser === 'admin') {
917
-			$options['auth'] = $this->adminUser;
918
-		}
919
-		$options['headers'] = [
920
-			'OCS-APIREQUEST' => 'true',
921
-		];
922
-
923
-		$this->response = $client->get($fullUrl, $options);
924
-		// boolean to string is integer
925
-		Assert::assertEquals('1', simplexml_load_string($this->response->getBody())->data[0]->enabled);
926
-	}
927
-
928
-	/**
929
-	 * @Given user :user has a quota of :quota
930
-	 * @param string $user
931
-	 * @param string $quota
932
-	 */
933
-	public function userHasAQuotaOf($user, $quota) {
934
-		$body = new TableNode([
935
-			0 => ['key', 'quota'],
936
-			1 => ['value', $quota],
937
-		]);
938
-
939
-		// method used from BasicStructure trait
940
-		$this->sendingToWith('PUT', '/cloud/users/' . $user, $body);
941
-	}
942
-
943
-	/**
944
-	 * @Given user :user has unlimited quota
945
-	 * @param string $user
946
-	 */
947
-	public function userHasUnlimitedQuota($user) {
948
-		$this->userHasAQuotaOf($user, 'none');
949
-	}
950
-
951
-	/**
952
-	 * Returns home path of the given user
953
-	 *
954
-	 * @param string $user
955
-	 */
956
-	public function getUserHome($user) {
957
-		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user";
958
-		$client = new Client();
959
-		$options = [];
960
-		$options['auth'] = $this->adminUser;
961
-		$this->response = $client->get($fullUrl, $options);
962
-		return simplexml_load_string($this->response->getBody())->data[0]->home;
963
-	}
964
-
965
-	/**
966
-	 * @BeforeScenario
967
-	 * @AfterScenario
968
-	 */
969
-	public function cleanupUsers() {
970
-		$previousServer = $this->currentServer;
971
-		$this->usingServer('LOCAL');
972
-		foreach ($this->createdUsers as $user) {
973
-			$this->deleteUser($user);
974
-		}
975
-		$this->usingServer('REMOTE');
976
-		foreach ($this->createdRemoteUsers as $remoteUser) {
977
-			$this->deleteUser($remoteUser);
978
-		}
979
-		$this->usingServer($previousServer);
980
-	}
981
-
982
-	/**
983
-	 * @BeforeScenario
984
-	 * @AfterScenario
985
-	 */
986
-	public function cleanupGroups() {
987
-		$previousServer = $this->currentServer;
988
-		$this->usingServer('LOCAL');
989
-		foreach ($this->createdGroups as $group) {
990
-			$this->deleteGroup($group);
991
-		}
992
-		$this->usingServer('REMOTE');
993
-		foreach ($this->createdRemoteGroups as $remoteGroup) {
994
-			$this->deleteGroup($remoteGroup);
995
-		}
996
-		$this->usingServer($previousServer);
997
-	}
998
-
999
-	/**
1000
-	 * @Then /^user "([^"]*)" has not$/
1001
-	 */
1002
-	public function userHasNotSetting($user, TableNode $settings) {
1003
-		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user";
1004
-		$client = new Client();
1005
-		$options = [];
1006
-		if ($this->currentUser === 'admin') {
1007
-			$options['auth'] = $this->adminUser;
1008
-		} else {
1009
-			$options['auth'] = [$this->currentUser, $this->regularUser];
1010
-		}
1011
-		$options['headers'] = [
1012
-			'OCS-APIREQUEST' => 'true',
1013
-		];
1014
-
1015
-		$response = $client->get($fullUrl, $options);
1016
-		foreach ($settings->getRows() as $setting) {
1017
-			$value = json_decode(json_encode(simplexml_load_string($response->getBody())->data->{$setting[0]}), 1);
1018
-			if (isset($value[0])) {
1019
-				if (in_array($setting[0], ['additional_mail', 'additional_mailScope'], true)) {
1020
-					$expectedValues = explode(';', $setting[1]);
1021
-					foreach ($expectedValues as $expected) {
1022
-						Assert::assertFalse(in_array($expected, $value, true));
1023
-					}
1024
-				} else {
1025
-					Assert::assertNotEqualsCanonicalizing($setting[1], $value[0]);
1026
-				}
1027
-			} else {
1028
-				Assert::assertNotEquals('', $setting[1]);
1029
-			}
1030
-		}
1031
-	}
17
+    use BasicStructure;
18
+
19
+    /** @var array */
20
+    private $appsToEnableAfterScenario = [];
21
+
22
+    /** @var array */
23
+    private $appsToDisableAfterScenario = [];
24
+
25
+    /** @var array */
26
+    private $createdUsers = [];
27
+
28
+    /** @var array */
29
+    private $createdRemoteUsers = [];
30
+
31
+    /** @var array */
32
+    private $createdRemoteGroups = [];
33
+
34
+    /** @var array */
35
+    private $createdGroups = [];
36
+
37
+    /** @AfterScenario */
38
+    public function restoreAppsEnabledStateAfterScenario() {
39
+        $this->asAn('admin');
40
+
41
+        foreach ($this->appsToEnableAfterScenario as $app) {
42
+            $this->sendingTo('POST', '/cloud/apps/' . $app);
43
+        }
44
+
45
+        foreach ($this->appsToDisableAfterScenario as $app) {
46
+            $this->sendingTo('DELETE', '/cloud/apps/' . $app);
47
+        }
48
+    }
49
+
50
+    /**
51
+     * @Given /^user "([^"]*)" exists$/
52
+     * @param string $user
53
+     */
54
+    public function assureUserExists($user) {
55
+        try {
56
+            $this->userExists($user);
57
+        } catch (\GuzzleHttp\Exception\ClientException $ex) {
58
+            $previous_user = $this->currentUser;
59
+            $this->currentUser = 'admin';
60
+            $this->creatingTheUser($user);
61
+            $this->currentUser = $previous_user;
62
+        }
63
+        $this->userExists($user);
64
+        Assert::assertEquals(200, $this->response->getStatusCode());
65
+    }
66
+
67
+    /**
68
+     * @Given /^user "([^"]*)" with displayname "((?:[^"]|\\")*)" exists$/
69
+     * @param string $user
70
+     */
71
+    public function assureUserWithDisplaynameExists($user, $displayname) {
72
+        try {
73
+            $this->userExists($user);
74
+        } catch (\GuzzleHttp\Exception\ClientException $ex) {
75
+            $previous_user = $this->currentUser;
76
+            $this->currentUser = 'admin';
77
+            $this->creatingTheUser($user, $displayname);
78
+            $this->currentUser = $previous_user;
79
+        }
80
+        $this->userExists($user);
81
+        Assert::assertEquals(200, $this->response->getStatusCode());
82
+    }
83
+
84
+    /**
85
+     * @Given /^user "([^"]*)" does not exist$/
86
+     * @param string $user
87
+     */
88
+    public function userDoesNotExist($user) {
89
+        try {
90
+            $this->userExists($user);
91
+        } catch (\GuzzleHttp\Exception\ClientException $ex) {
92
+            $this->response = $ex->getResponse();
93
+            Assert::assertEquals(404, $ex->getResponse()->getStatusCode());
94
+            return;
95
+        }
96
+        $previous_user = $this->currentUser;
97
+        $this->currentUser = 'admin';
98
+        $this->deletingTheUser($user);
99
+        $this->currentUser = $previous_user;
100
+        try {
101
+            $this->userExists($user);
102
+        } catch (\GuzzleHttp\Exception\ClientException $ex) {
103
+            $this->response = $ex->getResponse();
104
+            Assert::assertEquals(404, $ex->getResponse()->getStatusCode());
105
+        }
106
+    }
107
+
108
+    public function creatingTheUser($user, $displayname = '') {
109
+        $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users";
110
+        $client = new Client();
111
+        $options = [];
112
+        if ($this->currentUser === 'admin') {
113
+            $options['auth'] = $this->adminUser;
114
+        }
115
+
116
+        $options['form_params'] = [
117
+            'userid' => $user,
118
+            'password' => '123456'
119
+        ];
120
+        if ($displayname !== '') {
121
+            $options['form_params']['displayName'] = $displayname;
122
+        }
123
+        $options['headers'] = [
124
+            'OCS-APIREQUEST' => 'true',
125
+        ];
126
+
127
+        $this->response = $client->post($fullUrl, $options);
128
+        if ($this->currentServer === 'LOCAL') {
129
+            $this->createdUsers[$user] = $user;
130
+        } elseif ($this->currentServer === 'REMOTE') {
131
+            $this->createdRemoteUsers[$user] = $user;
132
+        }
133
+
134
+        //Quick hack to login once with the current user
135
+        $options2 = [
136
+            'auth' => [$user, '123456'],
137
+        ];
138
+        $options2['headers'] = [
139
+            'OCS-APIREQUEST' => 'true',
140
+        ];
141
+        $url = $fullUrl . '/' . $user;
142
+        $client->get($url, $options2);
143
+    }
144
+
145
+    /**
146
+     * @Then /^user "([^"]*)" has$/
147
+     *
148
+     * @param string $user
149
+     * @param TableNode|null $settings
150
+     */
151
+    public function userHasSetting($user, $settings) {
152
+        $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user";
153
+        $client = new Client();
154
+        $options = [];
155
+        if ($this->currentUser === 'admin') {
156
+            $options['auth'] = $this->adminUser;
157
+        } else {
158
+            $options['auth'] = [$this->currentUser, $this->regularUser];
159
+        }
160
+        $options['headers'] = [
161
+            'OCS-APIREQUEST' => 'true',
162
+        ];
163
+
164
+        $response = $client->get($fullUrl, $options);
165
+        foreach ($settings->getRows() as $setting) {
166
+            $value = json_decode(json_encode(simplexml_load_string($response->getBody())->data->{$setting[0]}), 1);
167
+            if (isset($value['element']) && in_array($setting[0], ['additional_mail', 'additional_mailScope'], true)) {
168
+                $expectedValues = explode(';', $setting[1]);
169
+                foreach ($expectedValues as $expected) {
170
+                    Assert::assertTrue(in_array($expected, $value['element'], true), 'Data wrong for field: ' . $setting[0]);
171
+                }
172
+            } elseif (isset($value[0])) {
173
+                Assert::assertEqualsCanonicalizing($setting[1], $value[0], 'Data wrong for field: ' . $setting[0]);
174
+            } else {
175
+                Assert::assertEquals('', $setting[1], 'Data wrong for field: ' . $setting[0]);
176
+            }
177
+        }
178
+    }
179
+
180
+    /**
181
+     * @Then /^user "([^"]*)" has the following profile data$/
182
+     */
183
+    public function userHasProfileData(string $user, ?TableNode $settings): void {
184
+        $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/profile/$user";
185
+        $client = new Client();
186
+        $options = [];
187
+        if ($this->currentUser === 'admin') {
188
+            $options['auth'] = $this->adminUser;
189
+        } else {
190
+            $options['auth'] = [$this->currentUser, $this->regularUser];
191
+        }
192
+        $options['headers'] = [
193
+            'OCS-APIREQUEST' => 'true',
194
+            'Accept' => 'application/json',
195
+        ];
196
+
197
+        $response = $client->get($fullUrl, $options);
198
+        $body = $response->getBody()->getContents();
199
+        $data = json_decode($body, true);
200
+        $data = $data['ocs']['data'];
201
+        foreach ($settings->getRows() as $setting) {
202
+            Assert::assertArrayHasKey($setting[0], $data, 'Profile data field missing: ' . $setting[0]);
203
+            if ($setting[1] === 'NULL') {
204
+                Assert::assertNull($data[$setting[0]], 'Profile data wrong for field: ' . $setting[0]);
205
+            } else {
206
+                Assert::assertEquals($setting[1], $data[$setting[0]], 'Profile data wrong for field: ' . $setting[0]);
207
+            }
208
+        }
209
+    }
210
+
211
+    /**
212
+     * @Then /^group "([^"]*)" has$/
213
+     *
214
+     * @param string $user
215
+     * @param TableNode|null $settings
216
+     */
217
+    public function groupHasSetting($group, $settings) {
218
+        $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/groups/details?search=$group";
219
+        $client = new Client();
220
+        $options = [];
221
+        if ($this->currentUser === 'admin') {
222
+            $options['auth'] = $this->adminUser;
223
+        } else {
224
+            $options['auth'] = [$this->currentUser, $this->regularUser];
225
+        }
226
+        $options['headers'] = [
227
+            'OCS-APIREQUEST' => 'true',
228
+        ];
229
+
230
+        $response = $client->get($fullUrl, $options);
231
+        $groupDetails = simplexml_load_string($response->getBody())->data[0]->groups[0]->element;
232
+        foreach ($settings->getRows() as $setting) {
233
+            $value = json_decode(json_encode($groupDetails->{$setting[0]}), 1);
234
+            if (isset($value[0])) {
235
+                Assert::assertEqualsCanonicalizing($setting[1], $value[0]);
236
+            } else {
237
+                Assert::assertEquals('', $setting[1]);
238
+            }
239
+        }
240
+    }
241
+
242
+
243
+    /**
244
+     * @Then /^user "([^"]*)" has editable fields$/
245
+     *
246
+     * @param string $user
247
+     * @param TableNode|null $fields
248
+     */
249
+    public function userHasEditableFields($user, $fields) {
250
+        $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/user/fields";
251
+        if ($user !== 'self') {
252
+            $fullUrl .= '/' . $user;
253
+        }
254
+        $client = new Client();
255
+        $options = [];
256
+        if ($this->currentUser === 'admin') {
257
+            $options['auth'] = $this->adminUser;
258
+        } else {
259
+            $options['auth'] = [$this->currentUser, $this->regularUser];
260
+        }
261
+        $options['headers'] = [
262
+            'OCS-APIREQUEST' => 'true',
263
+        ];
264
+
265
+        $response = $client->get($fullUrl, $options);
266
+        $fieldsArray = json_decode(json_encode(simplexml_load_string($response->getBody())->data->element), 1);
267
+
268
+        $expectedFields = $fields->getRows();
269
+        $expectedFields = $this->simplifyArray($expectedFields);
270
+        Assert::assertEquals($expectedFields, $fieldsArray);
271
+    }
272
+
273
+    /**
274
+     * @Then /^search users by phone for region "([^"]*)" with$/
275
+     *
276
+     * @param string $user
277
+     * @param TableNode|null $settings
278
+     */
279
+    public function searchUserByPhone($region, TableNode $searchTable) {
280
+        $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/search/by-phone";
281
+        $client = new Client();
282
+        $options = [];
283
+        $options['auth'] = $this->adminUser;
284
+        $options['headers'] = [
285
+            'OCS-APIREQUEST' => 'true',
286
+        ];
287
+
288
+        $search = [];
289
+        foreach ($searchTable->getRows() as $row) {
290
+            if (!isset($search[$row[0]])) {
291
+                $search[$row[0]] = [];
292
+            }
293
+            $search[$row[0]][] = $row[1];
294
+        }
295
+
296
+        $options['form_params'] = [
297
+            'location' => $region,
298
+            'search' => $search,
299
+        ];
300
+
301
+        $this->response = $client->post($fullUrl, $options);
302
+    }
303
+
304
+    public function createUser($user) {
305
+        $previous_user = $this->currentUser;
306
+        $this->currentUser = 'admin';
307
+        $this->creatingTheUser($user);
308
+        $this->userExists($user);
309
+        $this->currentUser = $previous_user;
310
+    }
311
+
312
+    public function deleteUser($user) {
313
+        $previous_user = $this->currentUser;
314
+        $this->currentUser = 'admin';
315
+        $this->deletingTheUser($user);
316
+        $this->userDoesNotExist($user);
317
+        $this->currentUser = $previous_user;
318
+    }
319
+
320
+    public function createGroup($group) {
321
+        $previous_user = $this->currentUser;
322
+        $this->currentUser = 'admin';
323
+        $this->creatingTheGroup($group);
324
+        $this->groupExists($group);
325
+        $this->currentUser = $previous_user;
326
+    }
327
+
328
+    public function deleteGroup($group) {
329
+        $previous_user = $this->currentUser;
330
+        $this->currentUser = 'admin';
331
+        $this->deletingTheGroup($group);
332
+        $this->groupDoesNotExist($group);
333
+        $this->currentUser = $previous_user;
334
+    }
335
+
336
+    public function userExists($user) {
337
+        $fullUrl = $this->baseUrl . "v2.php/cloud/users/$user";
338
+        $client = new Client();
339
+        $options = [];
340
+        $options['auth'] = $this->adminUser;
341
+        $options['headers'] = [
342
+            'OCS-APIREQUEST' => 'true'
343
+        ];
344
+
345
+        $this->response = $client->get($fullUrl, $options);
346
+    }
347
+
348
+    /**
349
+     * @Then /^check that user "([^"]*)" belongs to group "([^"]*)"$/
350
+     * @param string $user
351
+     * @param string $group
352
+     */
353
+    public function checkThatUserBelongsToGroup($user, $group) {
354
+        $fullUrl = $this->baseUrl . "v2.php/cloud/users/$user/groups";
355
+        $client = new Client();
356
+        $options = [];
357
+        if ($this->currentUser === 'admin') {
358
+            $options['auth'] = $this->adminUser;
359
+        }
360
+        $options['headers'] = [
361
+            'OCS-APIREQUEST' => 'true',
362
+        ];
363
+
364
+        $this->response = $client->get($fullUrl, $options);
365
+        $respondedArray = $this->getArrayOfGroupsResponded($this->response);
366
+        sort($respondedArray);
367
+        Assert::assertContains($group, $respondedArray);
368
+        Assert::assertEquals(200, $this->response->getStatusCode());
369
+    }
370
+
371
+    public function userBelongsToGroup($user, $group) {
372
+        $fullUrl = $this->baseUrl . "v2.php/cloud/users/$user/groups";
373
+        $client = new Client();
374
+        $options = [];
375
+        if ($this->currentUser === 'admin') {
376
+            $options['auth'] = $this->adminUser;
377
+        }
378
+        $options['headers'] = [
379
+            'OCS-APIREQUEST' => 'true',
380
+        ];
381
+
382
+        $this->response = $client->get($fullUrl, $options);
383
+        $respondedArray = $this->getArrayOfGroupsResponded($this->response);
384
+
385
+        if (array_key_exists($group, $respondedArray)) {
386
+            return true;
387
+        } else {
388
+            return false;
389
+        }
390
+    }
391
+
392
+    /**
393
+     * @Given /^user "([^"]*)" belongs to group "([^"]*)"$/
394
+     * @param string $user
395
+     * @param string $group
396
+     */
397
+    public function assureUserBelongsToGroup($user, $group) {
398
+        $previous_user = $this->currentUser;
399
+        $this->currentUser = 'admin';
400
+
401
+        if (!$this->userBelongsToGroup($user, $group)) {
402
+            $this->addingUserToGroup($user, $group);
403
+        }
404
+
405
+        $this->checkThatUserBelongsToGroup($user, $group);
406
+        $this->currentUser = $previous_user;
407
+    }
408
+
409
+    /**
410
+     * @Given /^user "([^"]*)" does not belong to group "([^"]*)"$/
411
+     * @param string $user
412
+     * @param string $group
413
+     */
414
+    public function userDoesNotBelongToGroup($user, $group) {
415
+        $fullUrl = $this->baseUrl . "v2.php/cloud/users/$user/groups";
416
+        $client = new Client();
417
+        $options = [];
418
+        if ($this->currentUser === 'admin') {
419
+            $options['auth'] = $this->adminUser;
420
+        }
421
+        $options['headers'] = [
422
+            'OCS-APIREQUEST' => 'true',
423
+        ];
424
+
425
+        $this->response = $client->get($fullUrl, $options);
426
+        $groups = [$group];
427
+        $respondedArray = $this->getArrayOfGroupsResponded($this->response);
428
+        Assert::assertNotEqualsCanonicalizing($groups, $respondedArray);
429
+        Assert::assertEquals(200, $this->response->getStatusCode());
430
+    }
431
+
432
+    /**
433
+     * @When /^creating the group "([^"]*)"$/
434
+     * @param string $group
435
+     */
436
+    public function creatingTheGroup($group) {
437
+        $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/groups";
438
+        $client = new Client();
439
+        $options = [];
440
+        if ($this->currentUser === 'admin') {
441
+            $options['auth'] = $this->adminUser;
442
+        }
443
+
444
+        $options['form_params'] = [
445
+            'groupid' => $group,
446
+        ];
447
+        $options['headers'] = [
448
+            'OCS-APIREQUEST' => 'true',
449
+        ];
450
+
451
+        $this->response = $client->post($fullUrl, $options);
452
+        if ($this->currentServer === 'LOCAL') {
453
+            $this->createdGroups[$group] = $group;
454
+        } elseif ($this->currentServer === 'REMOTE') {
455
+            $this->createdRemoteGroups[$group] = $group;
456
+        }
457
+    }
458
+
459
+    /**
460
+     * @When /^assure user "([^"]*)" is disabled$/
461
+     */
462
+    public function assureUserIsDisabled($user) {
463
+        $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user/disable";
464
+        $client = new Client();
465
+        $options = [];
466
+        if ($this->currentUser === 'admin') {
467
+            $options['auth'] = $this->adminUser;
468
+        }
469
+        $options['headers'] = [
470
+            'OCS-APIREQUEST' => 'true',
471
+        ];
472
+        // TODO: fix hack
473
+        $options['form_params'] = [
474
+            'foo' => 'bar'
475
+        ];
476
+
477
+        $this->response = $client->put($fullUrl, $options);
478
+    }
479
+
480
+    /**
481
+     * @When /^Deleting the user "([^"]*)"$/
482
+     * @param string $user
483
+     */
484
+    public function deletingTheUser($user) {
485
+        $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user";
486
+        $client = new Client();
487
+        $options = [];
488
+        if ($this->currentUser === 'admin') {
489
+            $options['auth'] = $this->adminUser;
490
+        }
491
+        $options['headers'] = [
492
+            'OCS-APIREQUEST' => 'true',
493
+        ];
494
+
495
+        $this->response = $client->delete($fullUrl, $options);
496
+    }
497
+
498
+    /**
499
+     * @When /^Deleting the group "([^"]*)"$/
500
+     * @param string $group
501
+     */
502
+    public function deletingTheGroup($group) {
503
+        $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/groups/$group";
504
+        $client = new Client();
505
+        $options = [];
506
+        if ($this->currentUser === 'admin') {
507
+            $options['auth'] = $this->adminUser;
508
+        }
509
+        $options['headers'] = [
510
+            'OCS-APIREQUEST' => 'true',
511
+        ];
512
+
513
+        $this->response = $client->delete($fullUrl, $options);
514
+
515
+        if ($this->currentServer === 'LOCAL') {
516
+            unset($this->createdGroups[$group]);
517
+        } elseif ($this->currentServer === 'REMOTE') {
518
+            unset($this->createdRemoteGroups[$group]);
519
+        }
520
+    }
521
+
522
+    /**
523
+     * @Given /^Add user "([^"]*)" to the group "([^"]*)"$/
524
+     * @param string $user
525
+     * @param string $group
526
+     */
527
+    public function addUserToGroup($user, $group) {
528
+        $this->userExists($user);
529
+        $this->groupExists($group);
530
+        $this->addingUserToGroup($user, $group);
531
+    }
532
+
533
+    /**
534
+     * @When /^User "([^"]*)" is added to the group "([^"]*)"$/
535
+     * @param string $user
536
+     * @param string $group
537
+     */
538
+    public function addingUserToGroup($user, $group) {
539
+        $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user/groups";
540
+        $client = new Client();
541
+        $options = [];
542
+        if ($this->currentUser === 'admin') {
543
+            $options['auth'] = $this->adminUser;
544
+        }
545
+        $options['headers'] = [
546
+            'OCS-APIREQUEST' => 'true',
547
+        ];
548
+
549
+        $options['form_params'] = [
550
+            'groupid' => $group,
551
+        ];
552
+
553
+        $this->response = $client->post($fullUrl, $options);
554
+    }
555
+
556
+
557
+    public function groupExists($group) {
558
+        $fullUrl = $this->baseUrl . "v2.php/cloud/groups/$group";
559
+        $client = new Client();
560
+        $options = [];
561
+        $options['auth'] = $this->adminUser;
562
+        $options['headers'] = [
563
+            'OCS-APIREQUEST' => 'true',
564
+        ];
565
+
566
+        $this->response = $client->get($fullUrl, $options);
567
+    }
568
+
569
+    /**
570
+     * @Given /^group "([^"]*)" exists$/
571
+     * @param string $group
572
+     */
573
+    public function assureGroupExists($group) {
574
+        try {
575
+            $this->groupExists($group);
576
+        } catch (\GuzzleHttp\Exception\ClientException $ex) {
577
+            $previous_user = $this->currentUser;
578
+            $this->currentUser = 'admin';
579
+            $this->creatingTheGroup($group);
580
+            $this->currentUser = $previous_user;
581
+        }
582
+        $this->groupExists($group);
583
+        Assert::assertEquals(200, $this->response->getStatusCode());
584
+    }
585
+
586
+    /**
587
+     * @Given /^group "([^"]*)" does not exist$/
588
+     * @param string $group
589
+     */
590
+    public function groupDoesNotExist($group) {
591
+        try {
592
+            $this->groupExists($group);
593
+        } catch (\GuzzleHttp\Exception\ClientException $ex) {
594
+            $this->response = $ex->getResponse();
595
+            Assert::assertEquals(404, $ex->getResponse()->getStatusCode());
596
+            return;
597
+        }
598
+        $previous_user = $this->currentUser;
599
+        $this->currentUser = 'admin';
600
+        $this->deletingTheGroup($group);
601
+        $this->currentUser = $previous_user;
602
+        try {
603
+            $this->groupExists($group);
604
+        } catch (\GuzzleHttp\Exception\ClientException $ex) {
605
+            $this->response = $ex->getResponse();
606
+            Assert::assertEquals(404, $ex->getResponse()->getStatusCode());
607
+        }
608
+    }
609
+
610
+    /**
611
+     * @Given /^user "([^"]*)" is subadmin of group "([^"]*)"$/
612
+     * @param string $user
613
+     * @param string $group
614
+     */
615
+    public function userIsSubadminOfGroup($user, $group) {
616
+        $fullUrl = $this->baseUrl . "v2.php/cloud/groups/$group/subadmins";
617
+        $client = new Client();
618
+        $options = [];
619
+        if ($this->currentUser === 'admin') {
620
+            $options['auth'] = $this->adminUser;
621
+        }
622
+        $options['headers'] = [
623
+            'OCS-APIREQUEST' => 'true',
624
+        ];
625
+
626
+        $this->response = $client->get($fullUrl, $options);
627
+        $respondedArray = $this->getArrayOfSubadminsResponded($this->response);
628
+        sort($respondedArray);
629
+        Assert::assertContains($user, $respondedArray);
630
+        Assert::assertEquals(200, $this->response->getStatusCode());
631
+    }
632
+
633
+    /**
634
+     * @Given /^Assure user "([^"]*)" is subadmin of group "([^"]*)"$/
635
+     * @param string $user
636
+     * @param string $group
637
+     */
638
+    public function assureUserIsSubadminOfGroup($user, $group) {
639
+        $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user/subadmins";
640
+        $client = new Client();
641
+        $options = [];
642
+        if ($this->currentUser === 'admin') {
643
+            $options['auth'] = $this->adminUser;
644
+        }
645
+        $options['form_params'] = [
646
+            'groupid' => $group
647
+        ];
648
+        $options['headers'] = [
649
+            'OCS-APIREQUEST' => 'true',
650
+        ];
651
+        $this->response = $client->post($fullUrl, $options);
652
+        Assert::assertEquals(200, $this->response->getStatusCode());
653
+    }
654
+
655
+    /**
656
+     * @Given /^user "([^"]*)" is not a subadmin of group "([^"]*)"$/
657
+     * @param string $user
658
+     * @param string $group
659
+     */
660
+    public function userIsNotSubadminOfGroup($user, $group) {
661
+        $fullUrl = $this->baseUrl . "v2.php/cloud/groups/$group/subadmins";
662
+        $client = new Client();
663
+        $options = [];
664
+        if ($this->currentUser === 'admin') {
665
+            $options['auth'] = $this->adminUser;
666
+        }
667
+        $options['headers'] = [
668
+            'OCS-APIREQUEST' => 'true',
669
+        ];
670
+
671
+        $this->response = $client->get($fullUrl, $options);
672
+        $respondedArray = $this->getArrayOfSubadminsResponded($this->response);
673
+        sort($respondedArray);
674
+        Assert::assertNotContains($user, $respondedArray);
675
+        Assert::assertEquals(200, $this->response->getStatusCode());
676
+    }
677
+
678
+    /**
679
+     * @Then /^users returned are$/
680
+     * @param TableNode|null $usersList
681
+     */
682
+    public function theUsersShouldBe($usersList) {
683
+        if ($usersList instanceof TableNode) {
684
+            $users = $usersList->getRows();
685
+            $usersSimplified = $this->simplifyArray($users);
686
+            $respondedArray = $this->getArrayOfUsersResponded($this->response);
687
+            Assert::assertEqualsCanonicalizing($usersSimplified, $respondedArray);
688
+        }
689
+    }
690
+
691
+    /**
692
+     * @Then /^phone matches returned are$/
693
+     * @param TableNode|null $usersList
694
+     */
695
+    public function thePhoneUsersShouldBe($usersList) {
696
+        if ($usersList instanceof TableNode) {
697
+            $users = $usersList->getRowsHash();
698
+            $listCheckedElements = simplexml_load_string($this->response->getBody())->data;
699
+            $respondedArray = json_decode(json_encode($listCheckedElements), true);
700
+            Assert::assertEquals($users, $respondedArray);
701
+        }
702
+    }
703
+
704
+    /**
705
+     * @Then /^detailed users returned are$/
706
+     * @param TableNode|null $usersList
707
+     */
708
+    public function theDetailedUsersShouldBe($usersList) {
709
+        if ($usersList instanceof TableNode) {
710
+            $users = $usersList->getRows();
711
+            $usersSimplified = $this->simplifyArray($users);
712
+            $respondedArray = $this->getArrayOfDetailedUsersResponded($this->response);
713
+            $respondedArray = array_keys($respondedArray);
714
+            Assert::assertEquals($usersSimplified, $respondedArray);
715
+        }
716
+    }
717
+
718
+    /**
719
+     * @Then /^groups returned are$/
720
+     * @param TableNode|null $groupsList
721
+     */
722
+    public function theGroupsShouldBe($groupsList) {
723
+        if ($groupsList instanceof TableNode) {
724
+            $groups = $groupsList->getRows();
725
+            $groupsSimplified = $this->simplifyArray($groups);
726
+            $respondedArray = $this->getArrayOfGroupsResponded($this->response);
727
+            Assert::assertEqualsCanonicalizing($groupsSimplified, $respondedArray);
728
+        }
729
+    }
730
+
731
+    /**
732
+     * @Then /^subadmin groups returned are$/
733
+     * @param TableNode|null $groupsList
734
+     */
735
+    public function theSubadminGroupsShouldBe($groupsList) {
736
+        if ($groupsList instanceof TableNode) {
737
+            $groups = $groupsList->getRows();
738
+            $groupsSimplified = $this->simplifyArray($groups);
739
+            $respondedArray = $this->getArrayOfSubadminsResponded($this->response);
740
+            Assert::assertEqualsCanonicalizing($groupsSimplified, $respondedArray);
741
+        }
742
+    }
743
+
744
+    /**
745
+     * @Then /^apps returned are$/
746
+     * @param TableNode|null $appList
747
+     */
748
+    public function theAppsShouldBe($appList) {
749
+        if ($appList instanceof TableNode) {
750
+            $apps = $appList->getRows();
751
+            $appsSimplified = $this->simplifyArray($apps);
752
+            $respondedArray = $this->getArrayOfAppsResponded($this->response);
753
+            Assert::assertEqualsCanonicalizing($appsSimplified, $respondedArray);
754
+        }
755
+    }
756
+
757
+    /**
758
+     * @Then /^subadmin users returned are$/
759
+     * @param TableNode|null $groupsList
760
+     */
761
+    public function theSubadminUsersShouldBe($groupsList) {
762
+        $this->theSubadminGroupsShouldBe($groupsList);
763
+    }
764
+
765
+    /**
766
+     * Parses the xml answer to get the array of users returned.
767
+     *
768
+     * @param ResponseInterface $resp
769
+     * @return array
770
+     */
771
+    public function getArrayOfUsersResponded($resp) {
772
+        $listCheckedElements = simplexml_load_string($resp->getBody())->data[0]->users[0]->element;
773
+        $extractedElementsArray = json_decode(json_encode($listCheckedElements), 1);
774
+        return $extractedElementsArray;
775
+    }
776
+
777
+    /**
778
+     * Parses the xml answer to get the array of detailed users returned.
779
+     *
780
+     * @param ResponseInterface $resp
781
+     * @return array
782
+     */
783
+    public function getArrayOfDetailedUsersResponded($resp) {
784
+        $listCheckedElements = simplexml_load_string($resp->getBody())->data[0]->users;
785
+        $extractedElementsArray = json_decode(json_encode($listCheckedElements), 1);
786
+        return $extractedElementsArray;
787
+    }
788
+
789
+    /**
790
+     * Parses the xml answer to get the array of groups returned.
791
+     *
792
+     * @param ResponseInterface $resp
793
+     * @return array
794
+     */
795
+    public function getArrayOfGroupsResponded($resp) {
796
+        $listCheckedElements = simplexml_load_string($resp->getBody())->data[0]->groups[0]->element;
797
+        $extractedElementsArray = json_decode(json_encode($listCheckedElements), 1);
798
+        return $extractedElementsArray;
799
+    }
800
+
801
+    /**
802
+     * Parses the xml answer to get the array of apps returned.
803
+     *
804
+     * @param ResponseInterface $resp
805
+     * @return array
806
+     */
807
+    public function getArrayOfAppsResponded($resp) {
808
+        $listCheckedElements = simplexml_load_string($resp->getBody())->data[0]->apps[0]->element;
809
+        $extractedElementsArray = json_decode(json_encode($listCheckedElements), 1);
810
+        return $extractedElementsArray;
811
+    }
812
+
813
+    /**
814
+     * Parses the xml answer to get the array of subadmins returned.
815
+     *
816
+     * @param ResponseInterface $resp
817
+     * @return array
818
+     */
819
+    public function getArrayOfSubadminsResponded($resp) {
820
+        $listCheckedElements = simplexml_load_string($resp->getBody())->data[0]->element;
821
+        $extractedElementsArray = json_decode(json_encode($listCheckedElements), 1);
822
+        return $extractedElementsArray;
823
+    }
824
+
825
+    /**
826
+     * @Given /^app "([^"]*)" enabled state will be restored once the scenario finishes$/
827
+     * @param string $app
828
+     */
829
+    public function appEnabledStateWillBeRestoredOnceTheScenarioFinishes($app) {
830
+        if (in_array($app, $this->getAppsWithFilter('enabled'))) {
831
+            $this->appsToEnableAfterScenario[] = $app;
832
+        } elseif (in_array($app, $this->getAppsWithFilter('disabled'))) {
833
+            $this->appsToDisableAfterScenario[] = $app;
834
+        }
835
+
836
+        // Apps that were not installed before the scenario will not be
837
+        // disabled nor uninstalled after the scenario.
838
+    }
839
+
840
+    private function getAppsWithFilter($filter) {
841
+        $fullUrl = $this->baseUrl . 'v2.php/cloud/apps?filter=' . $filter;
842
+        $client = new Client();
843
+        $options = [];
844
+        if ($this->currentUser === 'admin') {
845
+            $options['auth'] = $this->adminUser;
846
+        }
847
+        $options['headers'] = [
848
+            'OCS-APIREQUEST' => 'true',
849
+        ];
850
+
851
+        $this->response = $client->get($fullUrl, $options);
852
+        return $this->getArrayOfAppsResponded($this->response);
853
+    }
854
+
855
+    /**
856
+     * @Given /^app "([^"]*)" is disabled$/
857
+     * @param string $app
858
+     */
859
+    public function appIsDisabled($app) {
860
+        $respondedArray = $this->getAppsWithFilter('disabled');
861
+        Assert::assertContains($app, $respondedArray);
862
+        Assert::assertEquals(200, $this->response->getStatusCode());
863
+    }
864
+
865
+    /**
866
+     * @Given /^app "([^"]*)" is enabled$/
867
+     * @param string $app
868
+     */
869
+    public function appIsEnabled($app) {
870
+        $respondedArray = $this->getAppsWithFilter('enabled');
871
+        Assert::assertContains($app, $respondedArray);
872
+        Assert::assertEquals(200, $this->response->getStatusCode());
873
+    }
874
+
875
+    /**
876
+     * @Given /^app "([^"]*)" is not enabled$/
877
+     *
878
+     * Checks that the app is disabled or not installed.
879
+     *
880
+     * @param string $app
881
+     */
882
+    public function appIsNotEnabled($app) {
883
+        $respondedArray = $this->getAppsWithFilter('enabled');
884
+        Assert::assertNotContains($app, $respondedArray);
885
+        Assert::assertEquals(200, $this->response->getStatusCode());
886
+    }
887
+
888
+    /**
889
+     * @Then /^user "([^"]*)" is disabled$/
890
+     * @param string $user
891
+     */
892
+    public function userIsDisabled($user) {
893
+        $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user";
894
+        $client = new Client();
895
+        $options = [];
896
+        if ($this->currentUser === 'admin') {
897
+            $options['auth'] = $this->adminUser;
898
+        }
899
+        $options['headers'] = [
900
+            'OCS-APIREQUEST' => 'true',
901
+        ];
902
+
903
+        $this->response = $client->get($fullUrl, $options);
904
+        // false in xml is empty
905
+        Assert::assertTrue(empty(simplexml_load_string($this->response->getBody())->data[0]->enabled));
906
+    }
907
+
908
+    /**
909
+     * @Then /^user "([^"]*)" is enabled$/
910
+     * @param string $user
911
+     */
912
+    public function userIsEnabled($user) {
913
+        $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user";
914
+        $client = new Client();
915
+        $options = [];
916
+        if ($this->currentUser === 'admin') {
917
+            $options['auth'] = $this->adminUser;
918
+        }
919
+        $options['headers'] = [
920
+            'OCS-APIREQUEST' => 'true',
921
+        ];
922
+
923
+        $this->response = $client->get($fullUrl, $options);
924
+        // boolean to string is integer
925
+        Assert::assertEquals('1', simplexml_load_string($this->response->getBody())->data[0]->enabled);
926
+    }
927
+
928
+    /**
929
+     * @Given user :user has a quota of :quota
930
+     * @param string $user
931
+     * @param string $quota
932
+     */
933
+    public function userHasAQuotaOf($user, $quota) {
934
+        $body = new TableNode([
935
+            0 => ['key', 'quota'],
936
+            1 => ['value', $quota],
937
+        ]);
938
+
939
+        // method used from BasicStructure trait
940
+        $this->sendingToWith('PUT', '/cloud/users/' . $user, $body);
941
+    }
942
+
943
+    /**
944
+     * @Given user :user has unlimited quota
945
+     * @param string $user
946
+     */
947
+    public function userHasUnlimitedQuota($user) {
948
+        $this->userHasAQuotaOf($user, 'none');
949
+    }
950
+
951
+    /**
952
+     * Returns home path of the given user
953
+     *
954
+     * @param string $user
955
+     */
956
+    public function getUserHome($user) {
957
+        $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user";
958
+        $client = new Client();
959
+        $options = [];
960
+        $options['auth'] = $this->adminUser;
961
+        $this->response = $client->get($fullUrl, $options);
962
+        return simplexml_load_string($this->response->getBody())->data[0]->home;
963
+    }
964
+
965
+    /**
966
+     * @BeforeScenario
967
+     * @AfterScenario
968
+     */
969
+    public function cleanupUsers() {
970
+        $previousServer = $this->currentServer;
971
+        $this->usingServer('LOCAL');
972
+        foreach ($this->createdUsers as $user) {
973
+            $this->deleteUser($user);
974
+        }
975
+        $this->usingServer('REMOTE');
976
+        foreach ($this->createdRemoteUsers as $remoteUser) {
977
+            $this->deleteUser($remoteUser);
978
+        }
979
+        $this->usingServer($previousServer);
980
+    }
981
+
982
+    /**
983
+     * @BeforeScenario
984
+     * @AfterScenario
985
+     */
986
+    public function cleanupGroups() {
987
+        $previousServer = $this->currentServer;
988
+        $this->usingServer('LOCAL');
989
+        foreach ($this->createdGroups as $group) {
990
+            $this->deleteGroup($group);
991
+        }
992
+        $this->usingServer('REMOTE');
993
+        foreach ($this->createdRemoteGroups as $remoteGroup) {
994
+            $this->deleteGroup($remoteGroup);
995
+        }
996
+        $this->usingServer($previousServer);
997
+    }
998
+
999
+    /**
1000
+     * @Then /^user "([^"]*)" has not$/
1001
+     */
1002
+    public function userHasNotSetting($user, TableNode $settings) {
1003
+        $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user";
1004
+        $client = new Client();
1005
+        $options = [];
1006
+        if ($this->currentUser === 'admin') {
1007
+            $options['auth'] = $this->adminUser;
1008
+        } else {
1009
+            $options['auth'] = [$this->currentUser, $this->regularUser];
1010
+        }
1011
+        $options['headers'] = [
1012
+            'OCS-APIREQUEST' => 'true',
1013
+        ];
1014
+
1015
+        $response = $client->get($fullUrl, $options);
1016
+        foreach ($settings->getRows() as $setting) {
1017
+            $value = json_decode(json_encode(simplexml_load_string($response->getBody())->data->{$setting[0]}), 1);
1018
+            if (isset($value[0])) {
1019
+                if (in_array($setting[0], ['additional_mail', 'additional_mailScope'], true)) {
1020
+                    $expectedValues = explode(';', $setting[1]);
1021
+                    foreach ($expectedValues as $expected) {
1022
+                        Assert::assertFalse(in_array($expected, $value, true));
1023
+                    }
1024
+                } else {
1025
+                    Assert::assertNotEqualsCanonicalizing($setting[1], $value[0]);
1026
+                }
1027
+            } else {
1028
+                Assert::assertNotEquals('', $setting[1]);
1029
+            }
1030
+        }
1031
+    }
1032 1032
 }
Please login to merge, or discard this patch.
build/integration/features/bootstrap/Sharing.php 1 patch
Indentation   +766 added lines, -766 removed lines patch added patch discarded remove patch
@@ -15,770 +15,770 @@
 block discarded – undo
15 15
 
16 16
 
17 17
 trait Sharing {
18
-	use Provisioning;
19
-
20
-	/** @var int */
21
-	private $sharingApiVersion = 1;
22
-
23
-	/** @var SimpleXMLElement */
24
-	private $lastShareData = null;
25
-
26
-	/** @var SimpleXMLElement[] */
27
-	private $storedShareData = [];
28
-
29
-	/** @var int */
30
-	private $savedShareId = null;
31
-
32
-	/** @var ResponseInterface */
33
-	private $response;
34
-
35
-	/**
36
-	 * @Given /^as "([^"]*)" creating a share with$/
37
-	 * @param string $user
38
-	 * @param TableNode|null $body
39
-	 */
40
-	public function asCreatingAShareWith($user, $body) {
41
-		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares";
42
-		$client = new Client();
43
-		$options = [
44
-			'headers' => [
45
-				'OCS-APIREQUEST' => 'true',
46
-			],
47
-		];
48
-		if ($user === 'admin') {
49
-			$options['auth'] = $this->adminUser;
50
-		} else {
51
-			$options['auth'] = [$user, $this->regularUser];
52
-		}
53
-
54
-		if ($body instanceof TableNode) {
55
-			$fd = $body->getRowsHash();
56
-			if (array_key_exists('expireDate', $fd)) {
57
-				$dateModification = $fd['expireDate'];
58
-				if ($dateModification === 'null') {
59
-					$fd['expireDate'] = null;
60
-				} elseif (!empty($dateModification)) {
61
-					$fd['expireDate'] = date('Y-m-d', strtotime($dateModification));
62
-				} else {
63
-					$fd['expireDate'] = '';
64
-				}
65
-			}
66
-			$options['form_params'] = $fd;
67
-		}
68
-
69
-		try {
70
-			$this->response = $client->request('POST', $fullUrl, $options);
71
-		} catch (\GuzzleHttp\Exception\ClientException $ex) {
72
-			$this->response = $ex->getResponse();
73
-		}
74
-
75
-		$this->lastShareData = simplexml_load_string($this->response->getBody());
76
-	}
77
-
78
-	/**
79
-	 * @When /^save the last share data as "([^"]*)"$/
80
-	 */
81
-	public function saveLastShareData($name) {
82
-		$this->storedShareData[$name] = $this->lastShareData;
83
-	}
84
-
85
-	/**
86
-	 * @When /^restore the last share data from "([^"]*)"$/
87
-	 */
88
-	public function restoreLastShareData($name) {
89
-		$this->lastShareData = $this->storedShareData[$name];
90
-	}
91
-
92
-	/**
93
-	 * @When /^creating a share with$/
94
-	 * @param TableNode|null $body
95
-	 */
96
-	public function creatingShare($body) {
97
-		$this->asCreatingAShareWith($this->currentUser, $body);
98
-	}
99
-
100
-	/**
101
-	 * @When /^accepting last share$/
102
-	 */
103
-	public function acceptingLastShare() {
104
-		$share_id = $this->lastShareData->data[0]->id;
105
-		$url = "/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/pending/$share_id";
106
-		$this->sendingToWith('POST', $url, null);
107
-
108
-		$this->theHTTPStatusCodeShouldBe('200');
109
-	}
110
-
111
-	/**
112
-	 * @When /^user "([^"]*)" accepts last share$/
113
-	 *
114
-	 * @param string $user
115
-	 */
116
-	public function userAcceptsLastShare(string $user) {
117
-		// "As userXXX" and "user userXXX accepts last share" steps are not
118
-		// expected to be used in the same scenario, but restore the user just
119
-		// in case.
120
-		$previousUser = $this->currentUser;
121
-
122
-		$this->currentUser = $user;
123
-
124
-		$share_id = $this->lastShareData->data[0]->id;
125
-		$url = "/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/pending/$share_id";
126
-		$this->sendingToWith('POST', $url, null);
127
-
128
-		$this->currentUser = $previousUser;
129
-
130
-		$this->theHTTPStatusCodeShouldBe('200');
131
-	}
132
-
133
-	/**
134
-	 * @Then /^last link share can be downloaded$/
135
-	 */
136
-	public function lastLinkShareCanBeDownloaded() {
137
-		if (count($this->lastShareData->data->element) > 0) {
138
-			$url = $this->lastShareData->data[0]->url;
139
-		} else {
140
-			$url = $this->lastShareData->data->url;
141
-		}
142
-		$fullUrl = $url . '/download';
143
-		$this->checkDownload($fullUrl, null, 'text/plain');
144
-	}
145
-
146
-	/**
147
-	 * @Then /^last share can be downloaded$/
148
-	 */
149
-	public function lastShareCanBeDownloaded() {
150
-		if (count($this->lastShareData->data->element) > 0) {
151
-			$token = $this->lastShareData->data[0]->token;
152
-		} else {
153
-			$token = $this->lastShareData->data->token;
154
-		}
155
-
156
-		$fullUrl = substr($this->baseUrl, 0, -4) . 'index.php/s/' . $token . '/download';
157
-		$this->checkDownload($fullUrl, null, 'text/plain');
158
-	}
159
-
160
-	/**
161
-	 * @Then /^last share with password "([^"]*)" can be downloaded$/
162
-	 */
163
-	public function lastShareWithPasswordCanBeDownloaded($password) {
164
-		if (count($this->lastShareData->data->element) > 0) {
165
-			$token = $this->lastShareData->data[0]->token;
166
-		} else {
167
-			$token = $this->lastShareData->data->token;
168
-		}
169
-
170
-		$fullUrl = substr($this->baseUrl, 0, -4) . "public.php/dav/files/$token/";
171
-		$this->checkDownload($fullUrl, ['', $password], 'text/plain');
172
-	}
173
-
174
-	private function checkDownload($url, $auth = null, $mimeType = null) {
175
-		if ($auth !== null) {
176
-			$options['auth'] = $auth;
177
-		}
178
-		$options['stream'] = true;
179
-
180
-		$client = new Client();
181
-		$this->response = $client->get($url, $options);
182
-		Assert::assertEquals(200, $this->response->getStatusCode());
183
-
184
-		$buf = '';
185
-		$body = $this->response->getBody();
186
-		while (!$body->eof()) {
187
-			// read everything
188
-			$buf .= $body->read(8192);
189
-		}
190
-		$body->close();
191
-
192
-		if ($mimeType !== null) {
193
-			$finfo = new finfo;
194
-			Assert::assertEquals($mimeType, $finfo->buffer($buf, FILEINFO_MIME_TYPE));
195
-		}
196
-	}
197
-
198
-	/**
199
-	 * @When /^Adding expiration date to last share$/
200
-	 */
201
-	public function addingExpirationDate() {
202
-		$share_id = (string)$this->lastShareData->data[0]->id;
203
-		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/$share_id";
204
-		$client = new Client();
205
-		$options = [];
206
-		if ($this->currentUser === 'admin') {
207
-			$options['auth'] = $this->adminUser;
208
-		} else {
209
-			$options['auth'] = [$this->currentUser, $this->regularUser];
210
-		}
211
-		$date = date('Y-m-d', strtotime('+3 days'));
212
-		$options['form_params'] = ['expireDate' => $date];
213
-		$this->response = $this->response = $client->request('PUT', $fullUrl, $options);
214
-		Assert::assertEquals(200, $this->response->getStatusCode());
215
-	}
216
-
217
-	/**
218
-	 * @When /^Updating last share with$/
219
-	 * @param TableNode|null $body
220
-	 */
221
-	public function updatingLastShare($body) {
222
-		$share_id = (string)$this->lastShareData->data[0]->id;
223
-		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/$share_id";
224
-		$client = new Client();
225
-		$options = [
226
-			'headers' => [
227
-				'OCS-APIREQUEST' => 'true',
228
-			],
229
-		];
230
-		if ($this->currentUser === 'admin') {
231
-			$options['auth'] = $this->adminUser;
232
-		} else {
233
-			$options['auth'] = [$this->currentUser, $this->regularUser];
234
-		}
235
-
236
-		if ($body instanceof TableNode) {
237
-			$fd = $body->getRowsHash();
238
-			if (array_key_exists('expireDate', $fd)) {
239
-				$dateModification = $fd['expireDate'];
240
-				$fd['expireDate'] = date('Y-m-d', strtotime($dateModification));
241
-			}
242
-			$options['form_params'] = $fd;
243
-		}
244
-
245
-		try {
246
-			$this->response = $client->request('PUT', $fullUrl, $options);
247
-		} catch (\GuzzleHttp\Exception\ClientException $ex) {
248
-			$this->response = $ex->getResponse();
249
-		}
250
-	}
251
-
252
-	public function createShare($user,
253
-		$path = null,
254
-		$shareType = null,
255
-		$shareWith = null,
256
-		$publicUpload = null,
257
-		$password = null,
258
-		$permissions = null,
259
-		$viewOnly = false) {
260
-		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares";
261
-		$client = new Client();
262
-		$options = [
263
-			'headers' => [
264
-				'OCS-APIREQUEST' => 'true',
265
-			],
266
-		];
267
-
268
-		if ($user === 'admin') {
269
-			$options['auth'] = $this->adminUser;
270
-		} else {
271
-			$options['auth'] = [$user, $this->regularUser];
272
-		}
273
-		$body = [];
274
-		if (!is_null($path)) {
275
-			$body['path'] = $path;
276
-		}
277
-		if (!is_null($shareType)) {
278
-			$body['shareType'] = $shareType;
279
-		}
280
-		if (!is_null($shareWith)) {
281
-			$body['shareWith'] = $shareWith;
282
-		}
283
-		if (!is_null($publicUpload)) {
284
-			$body['publicUpload'] = $publicUpload;
285
-		}
286
-		if (!is_null($password)) {
287
-			$body['password'] = $password;
288
-		}
289
-		if (!is_null($permissions)) {
290
-			$body['permissions'] = $permissions;
291
-		}
292
-
293
-		if ($viewOnly === true) {
294
-			$body['attributes'] = json_encode([['scope' => 'permissions', 'key' => 'download', 'value' => false]]);
295
-		}
296
-
297
-		$options['form_params'] = $body;
298
-
299
-		try {
300
-			$this->response = $client->request('POST', $fullUrl, $options);
301
-			$this->lastShareData = simplexml_load_string($this->response->getBody());
302
-		} catch (\GuzzleHttp\Exception\ClientException $ex) {
303
-			$this->response = $ex->getResponse();
304
-			throw new \Exception($this->response->getBody());
305
-		}
306
-	}
307
-
308
-	public function isFieldInResponse($field, $contentExpected) {
309
-		$data = simplexml_load_string($this->response->getBody())->data[0];
310
-		if ((string)$field == 'expiration') {
311
-			if (!empty($contentExpected)) {
312
-				$contentExpected = date('Y-m-d', strtotime($contentExpected)) . ' 00:00:00';
313
-			}
314
-		}
315
-		if (count($data->element) > 0) {
316
-			foreach ($data as $element) {
317
-				if ($contentExpected == 'A_TOKEN') {
318
-					return (strlen((string)$element->$field) == 15);
319
-				} elseif ($contentExpected == 'A_NUMBER') {
320
-					return is_numeric((string)$element->$field);
321
-				} elseif ($contentExpected == 'AN_URL') {
322
-					return $this->isExpectedUrl((string)$element->$field, 'index.php/s/');
323
-				} elseif ((string)$element->$field == $contentExpected) {
324
-					return true;
325
-				} else {
326
-					print($element->$field);
327
-				}
328
-			}
329
-
330
-			return false;
331
-		} else {
332
-			if ($contentExpected == 'A_TOKEN') {
333
-				return (strlen((string)$data->$field) == 15);
334
-			} elseif ($contentExpected == 'A_NUMBER') {
335
-				return is_numeric((string)$data->$field);
336
-			} elseif ($contentExpected == 'AN_URL') {
337
-				return $this->isExpectedUrl((string)$data->$field, 'index.php/s/');
338
-			} elseif ($contentExpected == $data->$field) {
339
-				return true;
340
-			} else {
341
-				print($data->$field);
342
-			}
343
-			return false;
344
-		}
345
-	}
346
-
347
-	/**
348
-	 * @Then /^File "([^"]*)" should be included in the response$/
349
-	 *
350
-	 * @param string $filename
351
-	 */
352
-	public function checkSharedFileInResponse($filename) {
353
-		Assert::assertEquals(true, $this->isFieldInResponse('file_target', "/$filename"));
354
-	}
355
-
356
-	/**
357
-	 * @Then /^File "([^"]*)" should not be included in the response$/
358
-	 *
359
-	 * @param string $filename
360
-	 */
361
-	public function checkSharedFileNotInResponse($filename) {
362
-		Assert::assertEquals(false, $this->isFieldInResponse('file_target', "/$filename"));
363
-	}
364
-
365
-	/**
366
-	 * @Then /^User "([^"]*)" should be included in the response$/
367
-	 *
368
-	 * @param string $user
369
-	 */
370
-	public function checkSharedUserInResponse($user) {
371
-		Assert::assertEquals(true, $this->isFieldInResponse('share_with', "$user"));
372
-	}
373
-
374
-	/**
375
-	 * @Then /^User "([^"]*)" should not be included in the response$/
376
-	 *
377
-	 * @param string $user
378
-	 */
379
-	public function checkSharedUserNotInResponse($user) {
380
-		Assert::assertEquals(false, $this->isFieldInResponse('share_with', "$user"));
381
-	}
382
-
383
-	public function isUserOrGroupInSharedData($userOrGroup, $permissions = null) {
384
-		$data = simplexml_load_string($this->response->getBody())->data[0];
385
-		foreach ($data as $element) {
386
-			if ($element->share_with == $userOrGroup && ($permissions === null || $permissions == $element->permissions)) {
387
-				return true;
388
-			}
389
-		}
390
-		return false;
391
-	}
392
-
393
-	/**
394
-	 * @Given /^(file|folder|entry) "([^"]*)" of user "([^"]*)" is shared with user "([^"]*)"( with permissions ([\d]*))?( view-only)?$/
395
-	 *
396
-	 * @param string $filepath
397
-	 * @param string $user1
398
-	 * @param string $user2
399
-	 */
400
-	public function assureFileIsShared($entry, $filepath, $user1, $user2, $withPerms = null, $permissions = null, $viewOnly = null) {
401
-		// when view-only is set, permissions is empty string instead of null...
402
-		if ($permissions === '') {
403
-			$permissions = null;
404
-		}
405
-		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares" . "?path=$filepath";
406
-		$client = new Client();
407
-		$options = [];
408
-		if ($user1 === 'admin') {
409
-			$options['auth'] = $this->adminUser;
410
-		} else {
411
-			$options['auth'] = [$user1, $this->regularUser];
412
-		}
413
-		$options['headers'] = [
414
-			'OCS-APIREQUEST' => 'true',
415
-		];
416
-		$this->response = $client->get($fullUrl, $options);
417
-		if ($this->isUserOrGroupInSharedData($user2, $permissions)) {
418
-			return;
419
-		} else {
420
-			$this->createShare($user1, $filepath, 0, $user2, null, null, $permissions, $viewOnly !== null);
421
-		}
422
-		$this->response = $client->get($fullUrl, $options);
423
-		Assert::assertEquals(true, $this->isUserOrGroupInSharedData($user2, $permissions));
424
-	}
425
-
426
-	/**
427
-	 * @Given /^(file|folder|entry) "([^"]*)" of user "([^"]*)" is shared with group "([^"]*)"( with permissions ([\d]*))?( view-only)?$/
428
-	 *
429
-	 * @param string $filepath
430
-	 * @param string $user
431
-	 * @param string $group
432
-	 */
433
-	public function assureFileIsSharedWithGroup($entry, $filepath, $user, $group, $withPerms = null, $permissions = null, $viewOnly = null) {
434
-		// when view-only is set, permissions is empty string instead of null...
435
-		if ($permissions === '') {
436
-			$permissions = null;
437
-		}
438
-		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares" . "?path=$filepath";
439
-		$client = new Client();
440
-		$options = [];
441
-		if ($user === 'admin') {
442
-			$options['auth'] = $this->adminUser;
443
-		} else {
444
-			$options['auth'] = [$user, $this->regularUser];
445
-		}
446
-		$options['headers'] = [
447
-			'OCS-APIREQUEST' => 'true',
448
-		];
449
-		$this->response = $client->get($fullUrl, $options);
450
-		if ($this->isUserOrGroupInSharedData($group, $permissions)) {
451
-			return;
452
-		} else {
453
-			$this->createShare($user, $filepath, 1, $group, null, null, $permissions, $viewOnly !== null);
454
-		}
455
-		$this->response = $client->get($fullUrl, $options);
456
-		Assert::assertEquals(true, $this->isUserOrGroupInSharedData($group, $permissions));
457
-	}
458
-
459
-	/**
460
-	 * @When /^Deleting last share$/
461
-	 */
462
-	public function deletingLastShare() {
463
-		$share_id = $this->lastShareData->data[0]->id;
464
-		$url = "/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/$share_id";
465
-		$this->sendingToWith('DELETE', $url, null);
466
-	}
467
-
468
-	/**
469
-	 * @When /^Getting info of last share$/
470
-	 */
471
-	public function gettingInfoOfLastShare() {
472
-		$share_id = $this->lastShareData->data[0]->id;
473
-		$url = "/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/$share_id";
474
-		$this->sendingToWith('GET', $url, null);
475
-	}
476
-
477
-	/**
478
-	 * @Then /^last share_id is included in the answer$/
479
-	 */
480
-	public function checkingLastShareIDIsIncluded() {
481
-		$share_id = $this->lastShareData->data[0]->id;
482
-		if (!$this->isFieldInResponse('id', $share_id)) {
483
-			Assert::fail("Share id $share_id not found in response");
484
-		}
485
-	}
486
-
487
-	/**
488
-	 * @Then /^last share_id is not included in the answer$/
489
-	 */
490
-	public function checkingLastShareIDIsNotIncluded() {
491
-		$share_id = $this->lastShareData->data[0]->id;
492
-		if ($this->isFieldInResponse('id', $share_id)) {
493
-			Assert::fail("Share id $share_id has been found in response");
494
-		}
495
-	}
496
-
497
-	/**
498
-	 * @Then /^Share fields of last share match with$/
499
-	 * @param TableNode|null $body
500
-	 */
501
-	public function checkShareFields($body) {
502
-		if ($body instanceof TableNode) {
503
-			$fd = $body->getRowsHash();
504
-
505
-			foreach ($fd as $field => $value) {
506
-				if (substr($field, 0, 10) === 'share_with') {
507
-					$value = str_replace('REMOTE', substr($this->remoteBaseUrl, 0, -5), $value);
508
-					$value = str_replace('LOCAL', substr($this->localBaseUrl, 0, -5), $value);
509
-				}
510
-				if (substr($field, 0, 6) === 'remote') {
511
-					$value = str_replace('REMOTE', substr($this->remoteBaseUrl, 0, -4), $value);
512
-					$value = str_replace('LOCAL', substr($this->localBaseUrl, 0, -4), $value);
513
-				}
514
-				if (!$this->isFieldInResponse($field, $value)) {
515
-					Assert::fail("$field" . " doesn't have value " . "$value");
516
-				}
517
-			}
518
-		}
519
-	}
520
-
521
-	/**
522
-	 * @Then the list of returned shares has :count shares
523
-	 */
524
-	public function theListOfReturnedSharesHasShares(int $count) {
525
-		$this->theHTTPStatusCodeShouldBe('200');
526
-		$this->theOCSStatusCodeShouldBe('100');
527
-
528
-		$returnedShares = $this->getXmlResponse()->data[0];
529
-
530
-		Assert::assertEquals($count, count($returnedShares->element));
531
-	}
532
-
533
-	/**
534
-	 * @Then share :count is returned with
535
-	 *
536
-	 * @param int $number
537
-	 * @param TableNode $body
538
-	 */
539
-	public function shareXIsReturnedWith(int $number, TableNode $body) {
540
-		$this->theHTTPStatusCodeShouldBe('200');
541
-		$this->theOCSStatusCodeShouldBe('100');
542
-
543
-		if (!($body instanceof TableNode)) {
544
-			return;
545
-		}
546
-
547
-		$returnedShare = $this->getXmlResponse()->data[0];
548
-		if ($returnedShare->element) {
549
-			$returnedShare = $returnedShare->element[$number];
550
-		}
551
-
552
-		$defaultExpectedFields = [
553
-			'id' => 'A_NUMBER',
554
-			'permissions' => '19',
555
-			'stime' => 'A_NUMBER',
556
-			'parent' => '',
557
-			'expiration' => '',
558
-			'token' => '',
559
-			'storage' => 'A_NUMBER',
560
-			'item_source' => 'A_NUMBER',
561
-			'file_source' => 'A_NUMBER',
562
-			'file_parent' => 'A_NUMBER',
563
-			'mail_send' => '0'
564
-		];
565
-		$expectedFields = array_merge($defaultExpectedFields, $body->getRowsHash());
566
-
567
-		if (!array_key_exists('uid_file_owner', $expectedFields)
568
-				&& array_key_exists('uid_owner', $expectedFields)) {
569
-			$expectedFields['uid_file_owner'] = $expectedFields['uid_owner'];
570
-		}
571
-		if (!array_key_exists('displayname_file_owner', $expectedFields)
572
-				&& array_key_exists('displayname_owner', $expectedFields)) {
573
-			$expectedFields['displayname_file_owner'] = $expectedFields['displayname_owner'];
574
-		}
575
-
576
-		if (array_key_exists('share_type', $expectedFields)
577
-				&& $expectedFields['share_type'] == 10 /* IShare::TYPE_ROOM */
578
-				&& array_key_exists('share_with', $expectedFields)) {
579
-			if ($expectedFields['share_with'] === 'private_conversation') {
580
-				$expectedFields['share_with'] = 'REGEXP /^private_conversation_[0-9a-f]{6}$/';
581
-			} else {
582
-				$expectedFields['share_with'] = FeatureContext::getTokenForIdentifier($expectedFields['share_with']);
583
-			}
584
-		}
585
-
586
-		foreach ($expectedFields as $field => $value) {
587
-			$this->assertFieldIsInReturnedShare($field, $value, $returnedShare);
588
-		}
589
-	}
590
-
591
-	/**
592
-	 * @return SimpleXMLElement
593
-	 */
594
-	private function getXmlResponse(): \SimpleXMLElement {
595
-		return simplexml_load_string($this->response->getBody());
596
-	}
597
-
598
-	/**
599
-	 * @param string $field
600
-	 * @param string $contentExpected
601
-	 * @param \SimpleXMLElement $returnedShare
602
-	 */
603
-	private function assertFieldIsInReturnedShare(string $field, string $contentExpected, \SimpleXMLElement $returnedShare) {
604
-		if ($contentExpected === 'IGNORE') {
605
-			return;
606
-		}
607
-
608
-		if (!property_exists($returnedShare, $field)) {
609
-			Assert::fail("$field was not found in response");
610
-		}
611
-
612
-		if ($field === 'expiration' && !empty($contentExpected)) {
613
-			$contentExpected = date('Y-m-d', strtotime($contentExpected)) . ' 00:00:00';
614
-		}
615
-
616
-		if ($contentExpected === 'A_NUMBER') {
617
-			Assert::assertTrue(is_numeric((string)$returnedShare->$field), "Field '$field' is not a number: " . $returnedShare->$field);
618
-		} elseif ($contentExpected === 'A_TOKEN') {
619
-			// A token is composed by 15 characters from
620
-			// ISecureRandom::CHAR_HUMAN_READABLE.
621
-			Assert::assertRegExp('/^[abcdefgijkmnopqrstwxyzABCDEFGHJKLMNPQRSTWXYZ23456789]{15}$/', (string)$returnedShare->$field, "Field '$field' is not a token");
622
-		} elseif (strpos($contentExpected, 'REGEXP ') === 0) {
623
-			Assert::assertRegExp(substr($contentExpected, strlen('REGEXP ')), (string)$returnedShare->$field, "Field '$field' does not match");
624
-		} else {
625
-			Assert::assertEquals($contentExpected, (string)$returnedShare->$field, "Field '$field' does not match");
626
-		}
627
-	}
628
-
629
-	/**
630
-	 * @Then As :user remove all shares from the file named :fileName
631
-	 */
632
-	public function asRemoveAllSharesFromTheFileNamed($user, $fileName) {
633
-		$url = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares?format=json";
634
-		$client = new \GuzzleHttp\Client();
635
-		$res = $client->get(
636
-			$url,
637
-			[
638
-				'auth' => [
639
-					$user,
640
-					'123456',
641
-				],
642
-				'headers' => [
643
-					'Content-Type' => 'application/json',
644
-					'OCS-APIREQUEST' => 'true',
645
-				],
646
-			]
647
-		);
648
-		$json = json_decode($res->getBody()->getContents(), true);
649
-		$deleted = false;
650
-		foreach ($json['ocs']['data'] as $data) {
651
-			if (stripslashes($data['path']) === $fileName) {
652
-				$id = $data['id'];
653
-				$client->delete(
654
-					$this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/{$id}",
655
-					[
656
-						'auth' => [
657
-							$user,
658
-							'123456',
659
-						],
660
-						'headers' => [
661
-							'Content-Type' => 'application/json',
662
-							'OCS-APIREQUEST' => 'true',
663
-						],
664
-					]
665
-				);
666
-				$deleted = true;
667
-			}
668
-		}
669
-
670
-		if ($deleted === false) {
671
-			throw new \Exception("Could not delete file $fileName");
672
-		}
673
-	}
674
-
675
-	/**
676
-	 * @When save last share id
677
-	 */
678
-	public function saveLastShareId() {
679
-		$this->savedShareId = ($this->lastShareData['data']['id'] ?? null);
680
-	}
681
-
682
-	/**
683
-	 * @Then share ids should match
684
-	 */
685
-	public function shareIdsShouldMatch() {
686
-		if ($this->savedShareId !== ($this->lastShareData['data']['id'] ?? null)) {
687
-			throw new \Exception('Expected the same link share to be returned');
688
-		}
689
-	}
690
-
691
-	/**
692
-	 * @When /^getting sharees for$/
693
-	 * @param TableNode $body
694
-	 */
695
-	public function whenGettingShareesFor($body) {
696
-		$url = '/apps/files_sharing/api/v1/sharees';
697
-		if ($body instanceof TableNode) {
698
-			$parameters = [];
699
-			foreach ($body->getRowsHash() as $key => $value) {
700
-				if ($key === 'shareTypes') {
701
-					foreach (explode(' ', $value) as $shareType) {
702
-						$parameters[] = 'shareType[]=' . $shareType;
703
-					}
704
-				} else {
705
-					$parameters[] = $key . '=' . $value;
706
-				}
707
-			}
708
-			if (!empty($parameters)) {
709
-				$url .= '?' . implode('&', $parameters);
710
-			}
711
-		}
712
-
713
-		$this->sendingTo('GET', $url);
714
-	}
715
-
716
-	/**
717
-	 * @Then /^"([^"]*)" sharees returned (are|is empty)$/
718
-	 * @param string $shareeType
719
-	 * @param string $isEmpty
720
-	 * @param TableNode|null $shareesList
721
-	 */
722
-	public function thenListOfSharees($shareeType, $isEmpty, $shareesList = null) {
723
-		if ($isEmpty !== 'is empty') {
724
-			$sharees = $shareesList->getRows();
725
-			$respondedArray = $this->getArrayOfShareesResponded($this->response, $shareeType);
726
-			Assert::assertEquals($sharees, $respondedArray);
727
-		} else {
728
-			$respondedArray = $this->getArrayOfShareesResponded($this->response, $shareeType);
729
-			Assert::assertEmpty($respondedArray);
730
-		}
731
-	}
732
-
733
-	public function getArrayOfShareesResponded(ResponseInterface $response, $shareeType) {
734
-		$elements = simplexml_load_string($response->getBody())->data;
735
-		$elements = json_decode(json_encode($elements), 1);
736
-		if (strpos($shareeType, 'exact ') === 0) {
737
-			$elements = $elements['exact'];
738
-			$shareeType = substr($shareeType, 6);
739
-		}
740
-
741
-		// "simplexml_load_string" creates a SimpleXMLElement object for each
742
-		// XML element with child elements. In turn, each child is indexed by
743
-		// its tag in the SimpleXMLElement object. However, when there are
744
-		// several child XML elements with the same tag, an array with all the
745
-		// children with the same tag is indexed instead. Therefore, when the
746
-		// XML contains
747
-		// <XXX>
748
-		//   <element>
749
-		//     <label>...</label>
750
-		//     <value>...</value>
751
-		//   </element>
752
-		// </XXX>
753
-		// the "$elements[$shareeType]" variable contains an "element" key which
754
-		// in turn contains "label" and "value" keys, but when the XML contains
755
-		// <XXX>
756
-		//   <element>
757
-		//     <label>...</label>
758
-		//     <value>...</value>
759
-		//   </element>
760
-		//   <element>
761
-		//     <label>...</label>
762
-		//     <value>...</value>
763
-		//   </element>
764
-		// </XXX>
765
-		// the "$elements[$shareeType]" variable contains an "element" key which
766
-		// in turn contains "0" and "1" keys, and in turn each one contains
767
-		// "label" and "value" keys.
768
-		if (array_key_exists('element', $elements[$shareeType]) && is_int(array_keys($elements[$shareeType]['element'])[0])) {
769
-			$elements[$shareeType] = $elements[$shareeType]['element'];
770
-		}
771
-
772
-		$sharees = [];
773
-		foreach ($elements[$shareeType] as $element) {
774
-			$sharee = [$element['label'], $element['value']['shareType'], $element['value']['shareWith']];
775
-
776
-			if (array_key_exists('shareWithDisplayNameUnique', $element)) {
777
-				$sharee[] = $element['shareWithDisplayNameUnique'];
778
-			}
779
-
780
-			$sharees[] = $sharee;
781
-		}
782
-		return $sharees;
783
-	}
18
+    use Provisioning;
19
+
20
+    /** @var int */
21
+    private $sharingApiVersion = 1;
22
+
23
+    /** @var SimpleXMLElement */
24
+    private $lastShareData = null;
25
+
26
+    /** @var SimpleXMLElement[] */
27
+    private $storedShareData = [];
28
+
29
+    /** @var int */
30
+    private $savedShareId = null;
31
+
32
+    /** @var ResponseInterface */
33
+    private $response;
34
+
35
+    /**
36
+     * @Given /^as "([^"]*)" creating a share with$/
37
+     * @param string $user
38
+     * @param TableNode|null $body
39
+     */
40
+    public function asCreatingAShareWith($user, $body) {
41
+        $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares";
42
+        $client = new Client();
43
+        $options = [
44
+            'headers' => [
45
+                'OCS-APIREQUEST' => 'true',
46
+            ],
47
+        ];
48
+        if ($user === 'admin') {
49
+            $options['auth'] = $this->adminUser;
50
+        } else {
51
+            $options['auth'] = [$user, $this->regularUser];
52
+        }
53
+
54
+        if ($body instanceof TableNode) {
55
+            $fd = $body->getRowsHash();
56
+            if (array_key_exists('expireDate', $fd)) {
57
+                $dateModification = $fd['expireDate'];
58
+                if ($dateModification === 'null') {
59
+                    $fd['expireDate'] = null;
60
+                } elseif (!empty($dateModification)) {
61
+                    $fd['expireDate'] = date('Y-m-d', strtotime($dateModification));
62
+                } else {
63
+                    $fd['expireDate'] = '';
64
+                }
65
+            }
66
+            $options['form_params'] = $fd;
67
+        }
68
+
69
+        try {
70
+            $this->response = $client->request('POST', $fullUrl, $options);
71
+        } catch (\GuzzleHttp\Exception\ClientException $ex) {
72
+            $this->response = $ex->getResponse();
73
+        }
74
+
75
+        $this->lastShareData = simplexml_load_string($this->response->getBody());
76
+    }
77
+
78
+    /**
79
+     * @When /^save the last share data as "([^"]*)"$/
80
+     */
81
+    public function saveLastShareData($name) {
82
+        $this->storedShareData[$name] = $this->lastShareData;
83
+    }
84
+
85
+    /**
86
+     * @When /^restore the last share data from "([^"]*)"$/
87
+     */
88
+    public function restoreLastShareData($name) {
89
+        $this->lastShareData = $this->storedShareData[$name];
90
+    }
91
+
92
+    /**
93
+     * @When /^creating a share with$/
94
+     * @param TableNode|null $body
95
+     */
96
+    public function creatingShare($body) {
97
+        $this->asCreatingAShareWith($this->currentUser, $body);
98
+    }
99
+
100
+    /**
101
+     * @When /^accepting last share$/
102
+     */
103
+    public function acceptingLastShare() {
104
+        $share_id = $this->lastShareData->data[0]->id;
105
+        $url = "/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/pending/$share_id";
106
+        $this->sendingToWith('POST', $url, null);
107
+
108
+        $this->theHTTPStatusCodeShouldBe('200');
109
+    }
110
+
111
+    /**
112
+     * @When /^user "([^"]*)" accepts last share$/
113
+     *
114
+     * @param string $user
115
+     */
116
+    public function userAcceptsLastShare(string $user) {
117
+        // "As userXXX" and "user userXXX accepts last share" steps are not
118
+        // expected to be used in the same scenario, but restore the user just
119
+        // in case.
120
+        $previousUser = $this->currentUser;
121
+
122
+        $this->currentUser = $user;
123
+
124
+        $share_id = $this->lastShareData->data[0]->id;
125
+        $url = "/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/pending/$share_id";
126
+        $this->sendingToWith('POST', $url, null);
127
+
128
+        $this->currentUser = $previousUser;
129
+
130
+        $this->theHTTPStatusCodeShouldBe('200');
131
+    }
132
+
133
+    /**
134
+     * @Then /^last link share can be downloaded$/
135
+     */
136
+    public function lastLinkShareCanBeDownloaded() {
137
+        if (count($this->lastShareData->data->element) > 0) {
138
+            $url = $this->lastShareData->data[0]->url;
139
+        } else {
140
+            $url = $this->lastShareData->data->url;
141
+        }
142
+        $fullUrl = $url . '/download';
143
+        $this->checkDownload($fullUrl, null, 'text/plain');
144
+    }
145
+
146
+    /**
147
+     * @Then /^last share can be downloaded$/
148
+     */
149
+    public function lastShareCanBeDownloaded() {
150
+        if (count($this->lastShareData->data->element) > 0) {
151
+            $token = $this->lastShareData->data[0]->token;
152
+        } else {
153
+            $token = $this->lastShareData->data->token;
154
+        }
155
+
156
+        $fullUrl = substr($this->baseUrl, 0, -4) . 'index.php/s/' . $token . '/download';
157
+        $this->checkDownload($fullUrl, null, 'text/plain');
158
+    }
159
+
160
+    /**
161
+     * @Then /^last share with password "([^"]*)" can be downloaded$/
162
+     */
163
+    public function lastShareWithPasswordCanBeDownloaded($password) {
164
+        if (count($this->lastShareData->data->element) > 0) {
165
+            $token = $this->lastShareData->data[0]->token;
166
+        } else {
167
+            $token = $this->lastShareData->data->token;
168
+        }
169
+
170
+        $fullUrl = substr($this->baseUrl, 0, -4) . "public.php/dav/files/$token/";
171
+        $this->checkDownload($fullUrl, ['', $password], 'text/plain');
172
+    }
173
+
174
+    private function checkDownload($url, $auth = null, $mimeType = null) {
175
+        if ($auth !== null) {
176
+            $options['auth'] = $auth;
177
+        }
178
+        $options['stream'] = true;
179
+
180
+        $client = new Client();
181
+        $this->response = $client->get($url, $options);
182
+        Assert::assertEquals(200, $this->response->getStatusCode());
183
+
184
+        $buf = '';
185
+        $body = $this->response->getBody();
186
+        while (!$body->eof()) {
187
+            // read everything
188
+            $buf .= $body->read(8192);
189
+        }
190
+        $body->close();
191
+
192
+        if ($mimeType !== null) {
193
+            $finfo = new finfo;
194
+            Assert::assertEquals($mimeType, $finfo->buffer($buf, FILEINFO_MIME_TYPE));
195
+        }
196
+    }
197
+
198
+    /**
199
+     * @When /^Adding expiration date to last share$/
200
+     */
201
+    public function addingExpirationDate() {
202
+        $share_id = (string)$this->lastShareData->data[0]->id;
203
+        $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/$share_id";
204
+        $client = new Client();
205
+        $options = [];
206
+        if ($this->currentUser === 'admin') {
207
+            $options['auth'] = $this->adminUser;
208
+        } else {
209
+            $options['auth'] = [$this->currentUser, $this->regularUser];
210
+        }
211
+        $date = date('Y-m-d', strtotime('+3 days'));
212
+        $options['form_params'] = ['expireDate' => $date];
213
+        $this->response = $this->response = $client->request('PUT', $fullUrl, $options);
214
+        Assert::assertEquals(200, $this->response->getStatusCode());
215
+    }
216
+
217
+    /**
218
+     * @When /^Updating last share with$/
219
+     * @param TableNode|null $body
220
+     */
221
+    public function updatingLastShare($body) {
222
+        $share_id = (string)$this->lastShareData->data[0]->id;
223
+        $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/$share_id";
224
+        $client = new Client();
225
+        $options = [
226
+            'headers' => [
227
+                'OCS-APIREQUEST' => 'true',
228
+            ],
229
+        ];
230
+        if ($this->currentUser === 'admin') {
231
+            $options['auth'] = $this->adminUser;
232
+        } else {
233
+            $options['auth'] = [$this->currentUser, $this->regularUser];
234
+        }
235
+
236
+        if ($body instanceof TableNode) {
237
+            $fd = $body->getRowsHash();
238
+            if (array_key_exists('expireDate', $fd)) {
239
+                $dateModification = $fd['expireDate'];
240
+                $fd['expireDate'] = date('Y-m-d', strtotime($dateModification));
241
+            }
242
+            $options['form_params'] = $fd;
243
+        }
244
+
245
+        try {
246
+            $this->response = $client->request('PUT', $fullUrl, $options);
247
+        } catch (\GuzzleHttp\Exception\ClientException $ex) {
248
+            $this->response = $ex->getResponse();
249
+        }
250
+    }
251
+
252
+    public function createShare($user,
253
+        $path = null,
254
+        $shareType = null,
255
+        $shareWith = null,
256
+        $publicUpload = null,
257
+        $password = null,
258
+        $permissions = null,
259
+        $viewOnly = false) {
260
+        $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares";
261
+        $client = new Client();
262
+        $options = [
263
+            'headers' => [
264
+                'OCS-APIREQUEST' => 'true',
265
+            ],
266
+        ];
267
+
268
+        if ($user === 'admin') {
269
+            $options['auth'] = $this->adminUser;
270
+        } else {
271
+            $options['auth'] = [$user, $this->regularUser];
272
+        }
273
+        $body = [];
274
+        if (!is_null($path)) {
275
+            $body['path'] = $path;
276
+        }
277
+        if (!is_null($shareType)) {
278
+            $body['shareType'] = $shareType;
279
+        }
280
+        if (!is_null($shareWith)) {
281
+            $body['shareWith'] = $shareWith;
282
+        }
283
+        if (!is_null($publicUpload)) {
284
+            $body['publicUpload'] = $publicUpload;
285
+        }
286
+        if (!is_null($password)) {
287
+            $body['password'] = $password;
288
+        }
289
+        if (!is_null($permissions)) {
290
+            $body['permissions'] = $permissions;
291
+        }
292
+
293
+        if ($viewOnly === true) {
294
+            $body['attributes'] = json_encode([['scope' => 'permissions', 'key' => 'download', 'value' => false]]);
295
+        }
296
+
297
+        $options['form_params'] = $body;
298
+
299
+        try {
300
+            $this->response = $client->request('POST', $fullUrl, $options);
301
+            $this->lastShareData = simplexml_load_string($this->response->getBody());
302
+        } catch (\GuzzleHttp\Exception\ClientException $ex) {
303
+            $this->response = $ex->getResponse();
304
+            throw new \Exception($this->response->getBody());
305
+        }
306
+    }
307
+
308
+    public function isFieldInResponse($field, $contentExpected) {
309
+        $data = simplexml_load_string($this->response->getBody())->data[0];
310
+        if ((string)$field == 'expiration') {
311
+            if (!empty($contentExpected)) {
312
+                $contentExpected = date('Y-m-d', strtotime($contentExpected)) . ' 00:00:00';
313
+            }
314
+        }
315
+        if (count($data->element) > 0) {
316
+            foreach ($data as $element) {
317
+                if ($contentExpected == 'A_TOKEN') {
318
+                    return (strlen((string)$element->$field) == 15);
319
+                } elseif ($contentExpected == 'A_NUMBER') {
320
+                    return is_numeric((string)$element->$field);
321
+                } elseif ($contentExpected == 'AN_URL') {
322
+                    return $this->isExpectedUrl((string)$element->$field, 'index.php/s/');
323
+                } elseif ((string)$element->$field == $contentExpected) {
324
+                    return true;
325
+                } else {
326
+                    print($element->$field);
327
+                }
328
+            }
329
+
330
+            return false;
331
+        } else {
332
+            if ($contentExpected == 'A_TOKEN') {
333
+                return (strlen((string)$data->$field) == 15);
334
+            } elseif ($contentExpected == 'A_NUMBER') {
335
+                return is_numeric((string)$data->$field);
336
+            } elseif ($contentExpected == 'AN_URL') {
337
+                return $this->isExpectedUrl((string)$data->$field, 'index.php/s/');
338
+            } elseif ($contentExpected == $data->$field) {
339
+                return true;
340
+            } else {
341
+                print($data->$field);
342
+            }
343
+            return false;
344
+        }
345
+    }
346
+
347
+    /**
348
+     * @Then /^File "([^"]*)" should be included in the response$/
349
+     *
350
+     * @param string $filename
351
+     */
352
+    public function checkSharedFileInResponse($filename) {
353
+        Assert::assertEquals(true, $this->isFieldInResponse('file_target', "/$filename"));
354
+    }
355
+
356
+    /**
357
+     * @Then /^File "([^"]*)" should not be included in the response$/
358
+     *
359
+     * @param string $filename
360
+     */
361
+    public function checkSharedFileNotInResponse($filename) {
362
+        Assert::assertEquals(false, $this->isFieldInResponse('file_target', "/$filename"));
363
+    }
364
+
365
+    /**
366
+     * @Then /^User "([^"]*)" should be included in the response$/
367
+     *
368
+     * @param string $user
369
+     */
370
+    public function checkSharedUserInResponse($user) {
371
+        Assert::assertEquals(true, $this->isFieldInResponse('share_with', "$user"));
372
+    }
373
+
374
+    /**
375
+     * @Then /^User "([^"]*)" should not be included in the response$/
376
+     *
377
+     * @param string $user
378
+     */
379
+    public function checkSharedUserNotInResponse($user) {
380
+        Assert::assertEquals(false, $this->isFieldInResponse('share_with', "$user"));
381
+    }
382
+
383
+    public function isUserOrGroupInSharedData($userOrGroup, $permissions = null) {
384
+        $data = simplexml_load_string($this->response->getBody())->data[0];
385
+        foreach ($data as $element) {
386
+            if ($element->share_with == $userOrGroup && ($permissions === null || $permissions == $element->permissions)) {
387
+                return true;
388
+            }
389
+        }
390
+        return false;
391
+    }
392
+
393
+    /**
394
+     * @Given /^(file|folder|entry) "([^"]*)" of user "([^"]*)" is shared with user "([^"]*)"( with permissions ([\d]*))?( view-only)?$/
395
+     *
396
+     * @param string $filepath
397
+     * @param string $user1
398
+     * @param string $user2
399
+     */
400
+    public function assureFileIsShared($entry, $filepath, $user1, $user2, $withPerms = null, $permissions = null, $viewOnly = null) {
401
+        // when view-only is set, permissions is empty string instead of null...
402
+        if ($permissions === '') {
403
+            $permissions = null;
404
+        }
405
+        $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares" . "?path=$filepath";
406
+        $client = new Client();
407
+        $options = [];
408
+        if ($user1 === 'admin') {
409
+            $options['auth'] = $this->adminUser;
410
+        } else {
411
+            $options['auth'] = [$user1, $this->regularUser];
412
+        }
413
+        $options['headers'] = [
414
+            'OCS-APIREQUEST' => 'true',
415
+        ];
416
+        $this->response = $client->get($fullUrl, $options);
417
+        if ($this->isUserOrGroupInSharedData($user2, $permissions)) {
418
+            return;
419
+        } else {
420
+            $this->createShare($user1, $filepath, 0, $user2, null, null, $permissions, $viewOnly !== null);
421
+        }
422
+        $this->response = $client->get($fullUrl, $options);
423
+        Assert::assertEquals(true, $this->isUserOrGroupInSharedData($user2, $permissions));
424
+    }
425
+
426
+    /**
427
+     * @Given /^(file|folder|entry) "([^"]*)" of user "([^"]*)" is shared with group "([^"]*)"( with permissions ([\d]*))?( view-only)?$/
428
+     *
429
+     * @param string $filepath
430
+     * @param string $user
431
+     * @param string $group
432
+     */
433
+    public function assureFileIsSharedWithGroup($entry, $filepath, $user, $group, $withPerms = null, $permissions = null, $viewOnly = null) {
434
+        // when view-only is set, permissions is empty string instead of null...
435
+        if ($permissions === '') {
436
+            $permissions = null;
437
+        }
438
+        $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares" . "?path=$filepath";
439
+        $client = new Client();
440
+        $options = [];
441
+        if ($user === 'admin') {
442
+            $options['auth'] = $this->adminUser;
443
+        } else {
444
+            $options['auth'] = [$user, $this->regularUser];
445
+        }
446
+        $options['headers'] = [
447
+            'OCS-APIREQUEST' => 'true',
448
+        ];
449
+        $this->response = $client->get($fullUrl, $options);
450
+        if ($this->isUserOrGroupInSharedData($group, $permissions)) {
451
+            return;
452
+        } else {
453
+            $this->createShare($user, $filepath, 1, $group, null, null, $permissions, $viewOnly !== null);
454
+        }
455
+        $this->response = $client->get($fullUrl, $options);
456
+        Assert::assertEquals(true, $this->isUserOrGroupInSharedData($group, $permissions));
457
+    }
458
+
459
+    /**
460
+     * @When /^Deleting last share$/
461
+     */
462
+    public function deletingLastShare() {
463
+        $share_id = $this->lastShareData->data[0]->id;
464
+        $url = "/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/$share_id";
465
+        $this->sendingToWith('DELETE', $url, null);
466
+    }
467
+
468
+    /**
469
+     * @When /^Getting info of last share$/
470
+     */
471
+    public function gettingInfoOfLastShare() {
472
+        $share_id = $this->lastShareData->data[0]->id;
473
+        $url = "/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/$share_id";
474
+        $this->sendingToWith('GET', $url, null);
475
+    }
476
+
477
+    /**
478
+     * @Then /^last share_id is included in the answer$/
479
+     */
480
+    public function checkingLastShareIDIsIncluded() {
481
+        $share_id = $this->lastShareData->data[0]->id;
482
+        if (!$this->isFieldInResponse('id', $share_id)) {
483
+            Assert::fail("Share id $share_id not found in response");
484
+        }
485
+    }
486
+
487
+    /**
488
+     * @Then /^last share_id is not included in the answer$/
489
+     */
490
+    public function checkingLastShareIDIsNotIncluded() {
491
+        $share_id = $this->lastShareData->data[0]->id;
492
+        if ($this->isFieldInResponse('id', $share_id)) {
493
+            Assert::fail("Share id $share_id has been found in response");
494
+        }
495
+    }
496
+
497
+    /**
498
+     * @Then /^Share fields of last share match with$/
499
+     * @param TableNode|null $body
500
+     */
501
+    public function checkShareFields($body) {
502
+        if ($body instanceof TableNode) {
503
+            $fd = $body->getRowsHash();
504
+
505
+            foreach ($fd as $field => $value) {
506
+                if (substr($field, 0, 10) === 'share_with') {
507
+                    $value = str_replace('REMOTE', substr($this->remoteBaseUrl, 0, -5), $value);
508
+                    $value = str_replace('LOCAL', substr($this->localBaseUrl, 0, -5), $value);
509
+                }
510
+                if (substr($field, 0, 6) === 'remote') {
511
+                    $value = str_replace('REMOTE', substr($this->remoteBaseUrl, 0, -4), $value);
512
+                    $value = str_replace('LOCAL', substr($this->localBaseUrl, 0, -4), $value);
513
+                }
514
+                if (!$this->isFieldInResponse($field, $value)) {
515
+                    Assert::fail("$field" . " doesn't have value " . "$value");
516
+                }
517
+            }
518
+        }
519
+    }
520
+
521
+    /**
522
+     * @Then the list of returned shares has :count shares
523
+     */
524
+    public function theListOfReturnedSharesHasShares(int $count) {
525
+        $this->theHTTPStatusCodeShouldBe('200');
526
+        $this->theOCSStatusCodeShouldBe('100');
527
+
528
+        $returnedShares = $this->getXmlResponse()->data[0];
529
+
530
+        Assert::assertEquals($count, count($returnedShares->element));
531
+    }
532
+
533
+    /**
534
+     * @Then share :count is returned with
535
+     *
536
+     * @param int $number
537
+     * @param TableNode $body
538
+     */
539
+    public function shareXIsReturnedWith(int $number, TableNode $body) {
540
+        $this->theHTTPStatusCodeShouldBe('200');
541
+        $this->theOCSStatusCodeShouldBe('100');
542
+
543
+        if (!($body instanceof TableNode)) {
544
+            return;
545
+        }
546
+
547
+        $returnedShare = $this->getXmlResponse()->data[0];
548
+        if ($returnedShare->element) {
549
+            $returnedShare = $returnedShare->element[$number];
550
+        }
551
+
552
+        $defaultExpectedFields = [
553
+            'id' => 'A_NUMBER',
554
+            'permissions' => '19',
555
+            'stime' => 'A_NUMBER',
556
+            'parent' => '',
557
+            'expiration' => '',
558
+            'token' => '',
559
+            'storage' => 'A_NUMBER',
560
+            'item_source' => 'A_NUMBER',
561
+            'file_source' => 'A_NUMBER',
562
+            'file_parent' => 'A_NUMBER',
563
+            'mail_send' => '0'
564
+        ];
565
+        $expectedFields = array_merge($defaultExpectedFields, $body->getRowsHash());
566
+
567
+        if (!array_key_exists('uid_file_owner', $expectedFields)
568
+                && array_key_exists('uid_owner', $expectedFields)) {
569
+            $expectedFields['uid_file_owner'] = $expectedFields['uid_owner'];
570
+        }
571
+        if (!array_key_exists('displayname_file_owner', $expectedFields)
572
+                && array_key_exists('displayname_owner', $expectedFields)) {
573
+            $expectedFields['displayname_file_owner'] = $expectedFields['displayname_owner'];
574
+        }
575
+
576
+        if (array_key_exists('share_type', $expectedFields)
577
+                && $expectedFields['share_type'] == 10 /* IShare::TYPE_ROOM */
578
+                && array_key_exists('share_with', $expectedFields)) {
579
+            if ($expectedFields['share_with'] === 'private_conversation') {
580
+                $expectedFields['share_with'] = 'REGEXP /^private_conversation_[0-9a-f]{6}$/';
581
+            } else {
582
+                $expectedFields['share_with'] = FeatureContext::getTokenForIdentifier($expectedFields['share_with']);
583
+            }
584
+        }
585
+
586
+        foreach ($expectedFields as $field => $value) {
587
+            $this->assertFieldIsInReturnedShare($field, $value, $returnedShare);
588
+        }
589
+    }
590
+
591
+    /**
592
+     * @return SimpleXMLElement
593
+     */
594
+    private function getXmlResponse(): \SimpleXMLElement {
595
+        return simplexml_load_string($this->response->getBody());
596
+    }
597
+
598
+    /**
599
+     * @param string $field
600
+     * @param string $contentExpected
601
+     * @param \SimpleXMLElement $returnedShare
602
+     */
603
+    private function assertFieldIsInReturnedShare(string $field, string $contentExpected, \SimpleXMLElement $returnedShare) {
604
+        if ($contentExpected === 'IGNORE') {
605
+            return;
606
+        }
607
+
608
+        if (!property_exists($returnedShare, $field)) {
609
+            Assert::fail("$field was not found in response");
610
+        }
611
+
612
+        if ($field === 'expiration' && !empty($contentExpected)) {
613
+            $contentExpected = date('Y-m-d', strtotime($contentExpected)) . ' 00:00:00';
614
+        }
615
+
616
+        if ($contentExpected === 'A_NUMBER') {
617
+            Assert::assertTrue(is_numeric((string)$returnedShare->$field), "Field '$field' is not a number: " . $returnedShare->$field);
618
+        } elseif ($contentExpected === 'A_TOKEN') {
619
+            // A token is composed by 15 characters from
620
+            // ISecureRandom::CHAR_HUMAN_READABLE.
621
+            Assert::assertRegExp('/^[abcdefgijkmnopqrstwxyzABCDEFGHJKLMNPQRSTWXYZ23456789]{15}$/', (string)$returnedShare->$field, "Field '$field' is not a token");
622
+        } elseif (strpos($contentExpected, 'REGEXP ') === 0) {
623
+            Assert::assertRegExp(substr($contentExpected, strlen('REGEXP ')), (string)$returnedShare->$field, "Field '$field' does not match");
624
+        } else {
625
+            Assert::assertEquals($contentExpected, (string)$returnedShare->$field, "Field '$field' does not match");
626
+        }
627
+    }
628
+
629
+    /**
630
+     * @Then As :user remove all shares from the file named :fileName
631
+     */
632
+    public function asRemoveAllSharesFromTheFileNamed($user, $fileName) {
633
+        $url = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares?format=json";
634
+        $client = new \GuzzleHttp\Client();
635
+        $res = $client->get(
636
+            $url,
637
+            [
638
+                'auth' => [
639
+                    $user,
640
+                    '123456',
641
+                ],
642
+                'headers' => [
643
+                    'Content-Type' => 'application/json',
644
+                    'OCS-APIREQUEST' => 'true',
645
+                ],
646
+            ]
647
+        );
648
+        $json = json_decode($res->getBody()->getContents(), true);
649
+        $deleted = false;
650
+        foreach ($json['ocs']['data'] as $data) {
651
+            if (stripslashes($data['path']) === $fileName) {
652
+                $id = $data['id'];
653
+                $client->delete(
654
+                    $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/{$id}",
655
+                    [
656
+                        'auth' => [
657
+                            $user,
658
+                            '123456',
659
+                        ],
660
+                        'headers' => [
661
+                            'Content-Type' => 'application/json',
662
+                            'OCS-APIREQUEST' => 'true',
663
+                        ],
664
+                    ]
665
+                );
666
+                $deleted = true;
667
+            }
668
+        }
669
+
670
+        if ($deleted === false) {
671
+            throw new \Exception("Could not delete file $fileName");
672
+        }
673
+    }
674
+
675
+    /**
676
+     * @When save last share id
677
+     */
678
+    public function saveLastShareId() {
679
+        $this->savedShareId = ($this->lastShareData['data']['id'] ?? null);
680
+    }
681
+
682
+    /**
683
+     * @Then share ids should match
684
+     */
685
+    public function shareIdsShouldMatch() {
686
+        if ($this->savedShareId !== ($this->lastShareData['data']['id'] ?? null)) {
687
+            throw new \Exception('Expected the same link share to be returned');
688
+        }
689
+    }
690
+
691
+    /**
692
+     * @When /^getting sharees for$/
693
+     * @param TableNode $body
694
+     */
695
+    public function whenGettingShareesFor($body) {
696
+        $url = '/apps/files_sharing/api/v1/sharees';
697
+        if ($body instanceof TableNode) {
698
+            $parameters = [];
699
+            foreach ($body->getRowsHash() as $key => $value) {
700
+                if ($key === 'shareTypes') {
701
+                    foreach (explode(' ', $value) as $shareType) {
702
+                        $parameters[] = 'shareType[]=' . $shareType;
703
+                    }
704
+                } else {
705
+                    $parameters[] = $key . '=' . $value;
706
+                }
707
+            }
708
+            if (!empty($parameters)) {
709
+                $url .= '?' . implode('&', $parameters);
710
+            }
711
+        }
712
+
713
+        $this->sendingTo('GET', $url);
714
+    }
715
+
716
+    /**
717
+     * @Then /^"([^"]*)" sharees returned (are|is empty)$/
718
+     * @param string $shareeType
719
+     * @param string $isEmpty
720
+     * @param TableNode|null $shareesList
721
+     */
722
+    public function thenListOfSharees($shareeType, $isEmpty, $shareesList = null) {
723
+        if ($isEmpty !== 'is empty') {
724
+            $sharees = $shareesList->getRows();
725
+            $respondedArray = $this->getArrayOfShareesResponded($this->response, $shareeType);
726
+            Assert::assertEquals($sharees, $respondedArray);
727
+        } else {
728
+            $respondedArray = $this->getArrayOfShareesResponded($this->response, $shareeType);
729
+            Assert::assertEmpty($respondedArray);
730
+        }
731
+    }
732
+
733
+    public function getArrayOfShareesResponded(ResponseInterface $response, $shareeType) {
734
+        $elements = simplexml_load_string($response->getBody())->data;
735
+        $elements = json_decode(json_encode($elements), 1);
736
+        if (strpos($shareeType, 'exact ') === 0) {
737
+            $elements = $elements['exact'];
738
+            $shareeType = substr($shareeType, 6);
739
+        }
740
+
741
+        // "simplexml_load_string" creates a SimpleXMLElement object for each
742
+        // XML element with child elements. In turn, each child is indexed by
743
+        // its tag in the SimpleXMLElement object. However, when there are
744
+        // several child XML elements with the same tag, an array with all the
745
+        // children with the same tag is indexed instead. Therefore, when the
746
+        // XML contains
747
+        // <XXX>
748
+        //   <element>
749
+        //     <label>...</label>
750
+        //     <value>...</value>
751
+        //   </element>
752
+        // </XXX>
753
+        // the "$elements[$shareeType]" variable contains an "element" key which
754
+        // in turn contains "label" and "value" keys, but when the XML contains
755
+        // <XXX>
756
+        //   <element>
757
+        //     <label>...</label>
758
+        //     <value>...</value>
759
+        //   </element>
760
+        //   <element>
761
+        //     <label>...</label>
762
+        //     <value>...</value>
763
+        //   </element>
764
+        // </XXX>
765
+        // the "$elements[$shareeType]" variable contains an "element" key which
766
+        // in turn contains "0" and "1" keys, and in turn each one contains
767
+        // "label" and "value" keys.
768
+        if (array_key_exists('element', $elements[$shareeType]) && is_int(array_keys($elements[$shareeType]['element'])[0])) {
769
+            $elements[$shareeType] = $elements[$shareeType]['element'];
770
+        }
771
+
772
+        $sharees = [];
773
+        foreach ($elements[$shareeType] as $element) {
774
+            $sharee = [$element['label'], $element['value']['shareType'], $element['value']['shareWith']];
775
+
776
+            if (array_key_exists('shareWithDisplayNameUnique', $element)) {
777
+                $sharee[] = $element['shareWithDisplayNameUnique'];
778
+            }
779
+
780
+            $sharees[] = $sharee;
781
+        }
782
+        return $sharees;
783
+    }
784 784
 }
Please login to merge, or discard this patch.
lib/private/Server.php 1 patch
Indentation   +1392 added lines, -1392 removed lines patch added patch discarded remove patch
@@ -259,1436 +259,1436 @@
 block discarded – undo
259 259
  * TODO: hookup all manager classes
260 260
  */
261 261
 class Server extends ServerContainer implements IServerContainer {
262
-	/** @var string */
263
-	private $webRoot;
264
-
265
-	/**
266
-	 * @param string $webRoot
267
-	 * @param \OC\Config $config
268
-	 */
269
-	public function __construct($webRoot, \OC\Config $config) {
270
-		parent::__construct();
271
-		$this->webRoot = $webRoot;
272
-
273
-		// To find out if we are running from CLI or not
274
-		$this->registerParameter('isCLI', \OC::$CLI);
275
-		$this->registerParameter('serverRoot', \OC::$SERVERROOT);
276
-
277
-		$this->registerService(ContainerInterface::class, function (ContainerInterface $c) {
278
-			return $c;
279
-		});
280
-		$this->registerDeprecatedAlias(\OCP\IServerContainer::class, ContainerInterface::class);
281
-
282
-		$this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class);
283
-
284
-		$this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class);
285
-
286
-		$this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class);
287
-
288
-		$this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
289
-
290
-		$this->registerAlias(\OCP\ContextChat\IContentManager::class, \OC\ContextChat\ContentManager::class);
291
-
292
-		$this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class);
293
-		$this->registerAlias(ITemplateManager::class, TemplateManager::class);
294
-		$this->registerAlias(\OCP\Template\ITemplateManager::class, \OC\Template\TemplateManager::class);
295
-
296
-		$this->registerAlias(IActionFactory::class, ActionFactory::class);
297
-
298
-		$this->registerService(View::class, function (Server $c) {
299
-			return new View();
300
-		}, false);
301
-
302
-		$this->registerService(IPreview::class, function (ContainerInterface $c) {
303
-			return new PreviewManager(
304
-				$c->get(\OCP\IConfig::class),
305
-				$c->get(IRootFolder::class),
306
-				$c->get(IEventDispatcher::class),
307
-				$c->get(GeneratorHelper::class),
308
-				$c->get(ISession::class)->get('user_id'),
309
-				$c->get(Coordinator::class),
310
-				$c->get(IServerContainer::class),
311
-				$c->get(IBinaryFinder::class),
312
-				$c->get(IMagickSupport::class)
313
-			);
314
-		});
315
-		$this->registerAlias(IMimeIconProvider::class, MimeIconProvider::class);
316
-
317
-		$this->registerService(Watcher::class, function (ContainerInterface $c): Watcher {
318
-			return new Watcher(
319
-				$c->get(\OC\Preview\Storage\StorageFactory::class),
320
-				$c->get(PreviewMapper::class),
321
-				$c->get(IDBConnection::class),
322
-			);
323
-		});
324
-
325
-		$this->registerService(IProfiler::class, function (Server $c) {
326
-			return new Profiler($c->get(SystemConfig::class));
327
-		});
328
-
329
-		$this->registerService(Encryption\Manager::class, function (Server $c): Encryption\Manager {
330
-			$view = new View();
331
-			$util = new Encryption\Util(
332
-				$view,
333
-				$c->get(IUserManager::class),
334
-				$c->get(IGroupManager::class),
335
-				$c->get(\OCP\IConfig::class)
336
-			);
337
-			return new Encryption\Manager(
338
-				$c->get(\OCP\IConfig::class),
339
-				$c->get(LoggerInterface::class),
340
-				$c->getL10N('core'),
341
-				new View(),
342
-				$util,
343
-				new ArrayCache()
344
-			);
345
-		});
346
-		$this->registerAlias(\OCP\Encryption\IManager::class, Encryption\Manager::class);
347
-
348
-		$this->registerService(IFile::class, function (ContainerInterface $c) {
349
-			$util = new Encryption\Util(
350
-				new View(),
351
-				$c->get(IUserManager::class),
352
-				$c->get(IGroupManager::class),
353
-				$c->get(\OCP\IConfig::class)
354
-			);
355
-			return new Encryption\File(
356
-				$util,
357
-				$c->get(IRootFolder::class),
358
-				$c->get(\OCP\Share\IManager::class)
359
-			);
360
-		});
361
-
362
-		$this->registerService(IStorage::class, function (ContainerInterface $c) {
363
-			$view = new View();
364
-			$util = new Encryption\Util(
365
-				$view,
366
-				$c->get(IUserManager::class),
367
-				$c->get(IGroupManager::class),
368
-				$c->get(\OCP\IConfig::class)
369
-			);
370
-
371
-			return new Encryption\Keys\Storage(
372
-				$view,
373
-				$util,
374
-				$c->get(ICrypto::class),
375
-				$c->get(\OCP\IConfig::class)
376
-			);
377
-		});
378
-
379
-		$this->registerAlias(\OCP\ITagManager::class, TagManager::class);
380
-
381
-		$this->registerService('SystemTagManagerFactory', function (ContainerInterface $c) {
382
-			/** @var \OCP\IConfig $config */
383
-			$config = $c->get(\OCP\IConfig::class);
384
-			$factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class);
385
-			return new $factoryClass($this);
386
-		});
387
-		$this->registerService(ISystemTagManager::class, function (ContainerInterface $c) {
388
-			return $c->get('SystemTagManagerFactory')->getManager();
389
-		});
390
-		/** @deprecated 19.0.0 */
391
-		$this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class);
392
-
393
-		$this->registerService(ISystemTagObjectMapper::class, function (ContainerInterface $c) {
394
-			return $c->get('SystemTagManagerFactory')->getObjectMapper();
395
-		});
396
-		$this->registerAlias(IFileAccess::class, FileAccess::class);
397
-		$this->registerService('RootFolder', function (ContainerInterface $c) {
398
-			$manager = \OC\Files\Filesystem::getMountManager();
399
-			$view = new View();
400
-			/** @var IUserSession $userSession */
401
-			$userSession = $c->get(IUserSession::class);
402
-			$root = new Root(
403
-				$manager,
404
-				$view,
405
-				$userSession->getUser(),
406
-				$c->get(IUserMountCache::class),
407
-				$this->get(LoggerInterface::class),
408
-				$this->get(IUserManager::class),
409
-				$this->get(IEventDispatcher::class),
410
-				$this->get(ICacheFactory::class),
411
-				$this->get(IAppConfig::class),
412
-			);
413
-
414
-			$previewConnector = new \OC\Preview\WatcherConnector(
415
-				$root,
416
-				$c->get(SystemConfig::class),
417
-				$this->get(IEventDispatcher::class)
418
-			);
419
-			$previewConnector->connectWatcher();
420
-
421
-			return $root;
422
-		});
423
-		$this->registerService(HookConnector::class, function (ContainerInterface $c) {
424
-			return new HookConnector(
425
-				$c->get(IRootFolder::class),
426
-				new View(),
427
-				$c->get(IEventDispatcher::class),
428
-				$c->get(LoggerInterface::class)
429
-			);
430
-		});
431
-
432
-		$this->registerService(IRootFolder::class, function (ContainerInterface $c) {
433
-			return new LazyRoot(function () use ($c) {
434
-				return $c->get('RootFolder');
435
-			});
436
-		});
437
-
438
-		$this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class);
439
-
440
-		$this->registerService(DisplayNameCache::class, function (ContainerInterface $c) {
441
-			return $c->get(\OC\User\Manager::class)->getDisplayNameCache();
442
-		});
443
-
444
-		$this->registerService(\OCP\IGroupManager::class, function (ContainerInterface $c) {
445
-			$groupManager = new \OC\Group\Manager(
446
-				$this->get(IUserManager::class),
447
-				$this->get(IEventDispatcher::class),
448
-				$this->get(LoggerInterface::class),
449
-				$this->get(ICacheFactory::class),
450
-				$this->get(IRemoteAddress::class),
451
-			);
452
-			return $groupManager;
453
-		});
454
-
455
-		$this->registerService(Store::class, function (ContainerInterface $c) {
456
-			$session = $c->get(ISession::class);
457
-			if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) {
458
-				$tokenProvider = $c->get(IProvider::class);
459
-			} else {
460
-				$tokenProvider = null;
461
-			}
462
-			$logger = $c->get(LoggerInterface::class);
463
-			$crypto = $c->get(ICrypto::class);
464
-			return new Store($session, $logger, $crypto, $tokenProvider);
465
-		});
466
-		$this->registerAlias(IStore::class, Store::class);
467
-		$this->registerAlias(IProvider::class, Authentication\Token\Manager::class);
468
-		$this->registerAlias(OCPIProvider::class, Authentication\Token\Manager::class);
469
-
470
-		$this->registerService(\OC\User\Session::class, function (Server $c) {
471
-			$manager = $c->get(IUserManager::class);
472
-			$session = new \OC\Session\Memory();
473
-			$timeFactory = new TimeFactory();
474
-			// Token providers might require a working database. This code
475
-			// might however be called when Nextcloud is not yet setup.
476
-			if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) {
477
-				$provider = $c->get(IProvider::class);
478
-			} else {
479
-				$provider = null;
480
-			}
481
-
482
-			$userSession = new \OC\User\Session(
483
-				$manager,
484
-				$session,
485
-				$timeFactory,
486
-				$provider,
487
-				$c->get(\OCP\IConfig::class),
488
-				$c->get(ISecureRandom::class),
489
-				$c->get('LockdownManager'),
490
-				$c->get(LoggerInterface::class),
491
-				$c->get(IEventDispatcher::class),
492
-			);
493
-			/** @deprecated 21.0.0 use BeforeUserCreatedEvent event with the IEventDispatcher instead */
494
-			$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
495
-				\OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]);
496
-			});
497
-			/** @deprecated 21.0.0 use UserCreatedEvent event with the IEventDispatcher instead */
498
-			$userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
499
-				/** @var \OC\User\User $user */
500
-				\OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]);
501
-			});
502
-			/** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */
503
-			$userSession->listen('\OC\User', 'preDelete', function ($user) {
504
-				/** @var \OC\User\User $user */
505
-				\OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]);
506
-			});
507
-			/** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */
508
-			$userSession->listen('\OC\User', 'postDelete', function ($user) {
509
-				/** @var \OC\User\User $user */
510
-				\OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]);
511
-			});
512
-			$userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
513
-				/** @var \OC\User\User $user */
514
-				\OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]);
515
-			});
516
-			$userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
517
-				/** @var \OC\User\User $user */
518
-				\OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]);
519
-			});
520
-			$userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
521
-				\OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]);
522
-
523
-				/** @var IEventDispatcher $dispatcher */
524
-				$dispatcher = $this->get(IEventDispatcher::class);
525
-				$dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password));
526
-			});
527
-			$userSession->listen('\OC\User', 'postLogin', function ($user, $loginName, $password, $isTokenLogin) {
528
-				/** @var \OC\User\User $user */
529
-				\OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'loginName' => $loginName, 'password' => $password, 'isTokenLogin' => $isTokenLogin]);
530
-
531
-				/** @var IEventDispatcher $dispatcher */
532
-				$dispatcher = $this->get(IEventDispatcher::class);
533
-				$dispatcher->dispatchTyped(new UserLoggedInEvent($user, $loginName, $password, $isTokenLogin));
534
-			});
535
-			$userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) {
536
-				/** @var IEventDispatcher $dispatcher */
537
-				$dispatcher = $this->get(IEventDispatcher::class);
538
-				$dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid));
539
-			});
540
-			$userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) {
541
-				/** @var \OC\User\User $user */
542
-				\OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]);
543
-
544
-				/** @var IEventDispatcher $dispatcher */
545
-				$dispatcher = $this->get(IEventDispatcher::class);
546
-				$dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password));
547
-			});
548
-			$userSession->listen('\OC\User', 'logout', function ($user) {
549
-				\OC_Hook::emit('OC_User', 'logout', []);
550
-
551
-				/** @var IEventDispatcher $dispatcher */
552
-				$dispatcher = $this->get(IEventDispatcher::class);
553
-				$dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user));
554
-			});
555
-			$userSession->listen('\OC\User', 'postLogout', function ($user) {
556
-				/** @var IEventDispatcher $dispatcher */
557
-				$dispatcher = $this->get(IEventDispatcher::class);
558
-				$dispatcher->dispatchTyped(new UserLoggedOutEvent($user));
559
-			});
560
-			$userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) {
561
-				/** @var \OC\User\User $user */
562
-				\OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]);
563
-			});
564
-			return $userSession;
565
-		});
566
-		$this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class);
567
-
568
-		$this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class);
569
-
570
-		$this->registerAlias(INavigationManager::class, \OC\NavigationManager::class);
571
-
572
-		$this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
573
-
574
-		$this->registerService(\OC\SystemConfig::class, function ($c) use ($config) {
575
-			return new \OC\SystemConfig($config);
576
-		});
577
-
578
-		$this->registerAlias(IAppConfig::class, \OC\AppConfig::class);
579
-		$this->registerAlias(IUserConfig::class, \OC\Config\UserConfig::class);
580
-		$this->registerAlias(IAppManager::class, AppManager::class);
581
-
582
-		$this->registerService(IFactory::class, function (Server $c) {
583
-			return new \OC\L10N\Factory(
584
-				$c->get(\OCP\IConfig::class),
585
-				$c->getRequest(),
586
-				$c->get(IUserSession::class),
587
-				$c->get(ICacheFactory::class),
588
-				\OC::$SERVERROOT,
589
-				$c->get(IAppManager::class),
590
-			);
591
-		});
592
-
593
-		$this->registerAlias(IURLGenerator::class, URLGenerator::class);
594
-
595
-		$this->registerAlias(ICache::class, Cache\File::class);
596
-		$this->registerService(Factory::class, function (Server $c) {
597
-			$profiler = $c->get(IProfiler::class);
598
-			$logger = $c->get(LoggerInterface::class);
599
-			$serverVersion = $c->get(ServerVersion::class);
600
-			/** @var SystemConfig $config */
601
-			$config = $c->get(SystemConfig::class);
602
-			if (!$config->getValue('installed', false) || (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
603
-				return new \OC\Memcache\Factory(
604
-					$logger,
605
-					$profiler,
606
-					$serverVersion,
607
-					ArrayCache::class,
608
-					ArrayCache::class,
609
-					ArrayCache::class
610
-				);
611
-			}
612
-
613
-			return new \OC\Memcache\Factory(
614
-				$logger,
615
-				$profiler,
616
-				$serverVersion,
617
-				/** @psalm-taint-escape callable */
618
-				$config->getValue('memcache.local', null),
619
-				/** @psalm-taint-escape callable */
620
-				$config->getValue('memcache.distributed', null),
621
-				/** @psalm-taint-escape callable */
622
-				$config->getValue('memcache.locking', null),
623
-				/** @psalm-taint-escape callable */
624
-				$config->getValue('redis_log_file')
625
-			);
626
-		});
627
-		$this->registerAlias(ICacheFactory::class, Factory::class);
628
-
629
-		$this->registerService('RedisFactory', function (Server $c) {
630
-			$systemConfig = $c->get(SystemConfig::class);
631
-			return new RedisFactory($systemConfig, $c->get(IEventLogger::class));
632
-		});
633
-
634
-		$this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
635
-			$l10n = $this->get(IFactory::class)->get('lib');
636
-			return new \OC\Activity\Manager(
637
-				$c->getRequest(),
638
-				$c->get(IUserSession::class),
639
-				$c->get(\OCP\IConfig::class),
640
-				$c->get(IValidator::class),
641
-				$c->get(IRichTextFormatter::class),
642
-				$l10n,
643
-				$c->get(ITimeFactory::class),
644
-			);
645
-		});
646
-
647
-		$this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
648
-			return new \OC\Activity\EventMerger(
649
-				$c->getL10N('lib')
650
-			);
651
-		});
652
-		$this->registerAlias(IValidator::class, Validator::class);
653
-
654
-		$this->registerService(AvatarManager::class, function (Server $c) {
655
-			return new AvatarManager(
656
-				$c->get(IUserSession::class),
657
-				$c->get(\OC\User\Manager::class),
658
-				$c->getAppDataDir('avatar'),
659
-				$c->getL10N('lib'),
660
-				$c->get(LoggerInterface::class),
661
-				$c->get(\OCP\IConfig::class),
662
-				$c->get(IAccountManager::class),
663
-				$c->get(KnownUserService::class)
664
-			);
665
-		});
666
-
667
-		$this->registerAlias(IAvatarManager::class, AvatarManager::class);
668
-
669
-		$this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class);
670
-		$this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class);
671
-		$this->registerAlias(\OCP\Support\Subscription\IAssertion::class, \OC\Support\Subscription\Assertion::class);
672
-
673
-		/** Only used by the PsrLoggerAdapter should not be used by apps */
674
-		$this->registerService(\OC\Log::class, function (Server $c) {
675
-			$logType = $c->get(AllConfig::class)->getSystemValue('log_type', 'file');
676
-			$factory = new LogFactory($c, $this->get(SystemConfig::class));
677
-			$logger = $factory->get($logType);
678
-			$registry = $c->get(\OCP\Support\CrashReport\IRegistry::class);
679
-
680
-			return new Log($logger, $this->get(SystemConfig::class), crashReporters: $registry);
681
-		});
682
-		// PSR-3 logger
683
-		$this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class);
684
-
685
-		$this->registerService(ILogFactory::class, function (Server $c) {
686
-			return new LogFactory($c, $this->get(SystemConfig::class));
687
-		});
688
-
689
-		$this->registerAlias(IJobList::class, \OC\BackgroundJob\JobList::class);
690
-
691
-		$this->registerService(Router::class, function (Server $c) {
692
-			$cacheFactory = $c->get(ICacheFactory::class);
693
-			if ($cacheFactory->isLocalCacheAvailable()) {
694
-				$router = $c->resolve(CachingRouter::class);
695
-			} else {
696
-				$router = $c->resolve(Router::class);
697
-			}
698
-			return $router;
699
-		});
700
-		$this->registerAlias(IRouter::class, Router::class);
701
-
702
-		$this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) {
703
-			$config = $c->get(\OCP\IConfig::class);
704
-			if (ltrim($config->getSystemValueString('memcache.distributed', ''), '\\') === \OC\Memcache\Redis::class) {
705
-				$backend = new \OC\Security\RateLimiting\Backend\MemoryCacheBackend(
706
-					$c->get(AllConfig::class),
707
-					$this->get(ICacheFactory::class),
708
-					new \OC\AppFramework\Utility\TimeFactory()
709
-				);
710
-			} else {
711
-				$backend = new \OC\Security\RateLimiting\Backend\DatabaseBackend(
712
-					$c->get(AllConfig::class),
713
-					$c->get(IDBConnection::class),
714
-					new \OC\AppFramework\Utility\TimeFactory()
715
-				);
716
-			}
717
-
718
-			return $backend;
719
-		});
720
-
721
-		$this->registerAlias(\OCP\Security\ISecureRandom::class, SecureRandom::class);
722
-		$this->registerAlias(\OCP\Security\IRemoteHostValidator::class, \OC\Security\RemoteHostValidator::class);
723
-		$this->registerAlias(IVerificationToken::class, VerificationToken::class);
724
-
725
-		$this->registerAlias(ICrypto::class, Crypto::class);
726
-
727
-		$this->registerAlias(IHasher::class, Hasher::class);
728
-
729
-		$this->registerAlias(ICredentialsManager::class, CredentialsManager::class);
730
-
731
-		$this->registerAlias(IDBConnection::class, ConnectionAdapter::class);
732
-		$this->registerService(Connection::class, function (Server $c) {
733
-			$systemConfig = $c->get(SystemConfig::class);
734
-			$factory = new \OC\DB\ConnectionFactory($systemConfig, $c->get(ICacheFactory::class));
735
-			$type = $systemConfig->getValue('dbtype', 'sqlite');
736
-			if (!$factory->isValidType($type)) {
737
-				throw new \OC\DatabaseException('Invalid database type');
738
-			}
739
-			$connection = $factory->getConnection($type, []);
740
-			return $connection;
741
-		});
742
-
743
-		$this->registerAlias(ICertificateManager::class, CertificateManager::class);
744
-		$this->registerAlias(IClientService::class, ClientService::class);
745
-		$this->registerService(NegativeDnsCache::class, function (ContainerInterface $c) {
746
-			return new NegativeDnsCache(
747
-				$c->get(ICacheFactory::class),
748
-			);
749
-		});
750
-		$this->registerDeprecatedAlias('HttpClientService', IClientService::class);
751
-		$this->registerService(IEventLogger::class, function (ContainerInterface $c) {
752
-			return new EventLogger($c->get(SystemConfig::class), $c->get(LoggerInterface::class), $c->get(Log::class));
753
-		});
754
-
755
-		$this->registerService(IQueryLogger::class, function (ContainerInterface $c) {
756
-			$queryLogger = new QueryLogger();
757
-			if ($c->get(SystemConfig::class)->getValue('debug', false)) {
758
-				// In debug mode, module is being activated by default
759
-				$queryLogger->activate();
760
-			}
761
-			return $queryLogger;
762
-		});
763
-
764
-		$this->registerAlias(ITempManager::class, TempManager::class);
765
-		$this->registerAlias(IDateTimeZone::class, DateTimeZone::class);
766
-
767
-		$this->registerService(IDateTimeFormatter::class, function (Server $c) {
768
-			$language = $c->get(\OCP\IConfig::class)->getUserValue($c->get(ISession::class)->get('user_id'), 'core', 'lang', null);
769
-
770
-			return new DateTimeFormatter(
771
-				$c->get(IDateTimeZone::class)->getTimeZone(),
772
-				$c->getL10N('lib', $language)
773
-			);
774
-		});
775
-
776
-		$this->registerService(IUserMountCache::class, function (ContainerInterface $c) {
777
-			$mountCache = $c->get(UserMountCache::class);
778
-			$listener = new UserMountCacheListener($mountCache);
779
-			$listener->listen($c->get(IUserManager::class));
780
-			return $mountCache;
781
-		});
782
-
783
-		$this->registerService(IMountProviderCollection::class, function (ContainerInterface $c) {
784
-			$loader = $c->get(IStorageFactory::class);
785
-			$mountCache = $c->get(IUserMountCache::class);
786
-			$eventLogger = $c->get(IEventLogger::class);
787
-			$manager = new MountProviderCollection($loader, $mountCache, $eventLogger);
788
-
789
-			// builtin providers
790
-
791
-			$config = $c->get(\OCP\IConfig::class);
792
-			$logger = $c->get(LoggerInterface::class);
793
-			$objectStoreConfig = $c->get(PrimaryObjectStoreConfig::class);
794
-			$manager->registerProvider(new CacheMountProvider($config));
795
-			$manager->registerHomeProvider(new LocalHomeMountProvider());
796
-			$manager->registerHomeProvider(new ObjectHomeMountProvider($objectStoreConfig));
797
-			$manager->registerRootProvider(new RootMountProvider($objectStoreConfig, $config));
798
-
799
-			return $manager;
800
-		});
801
-
802
-		$this->registerService(IBus::class, function (ContainerInterface $c) {
803
-			$busClass = $c->get(\OCP\IConfig::class)->getSystemValueString('commandbus');
804
-			if ($busClass) {
805
-				[$app, $class] = explode('::', $busClass, 2);
806
-				if ($c->get(IAppManager::class)->isEnabledForUser($app)) {
807
-					$c->get(IAppManager::class)->loadApp($app);
808
-					return $c->get($class);
809
-				} else {
810
-					throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled");
811
-				}
812
-			} else {
813
-				$jobList = $c->get(IJobList::class);
814
-				return new CronBus($jobList);
815
-			}
816
-		});
817
-		$this->registerDeprecatedAlias('AsyncCommandBus', IBus::class);
818
-		$this->registerAlias(ITrustedDomainHelper::class, TrustedDomainHelper::class);
819
-		$this->registerAlias(IThrottler::class, Throttler::class);
820
-
821
-		$this->registerService(\OC\Security\Bruteforce\Backend\IBackend::class, function ($c) {
822
-			$config = $c->get(\OCP\IConfig::class);
823
-			if (!$config->getSystemValueBool('auth.bruteforce.protection.force.database', false)
824
-				&& ltrim($config->getSystemValueString('memcache.distributed', ''), '\\') === \OC\Memcache\Redis::class) {
825
-				$backend = $c->get(\OC\Security\Bruteforce\Backend\MemoryCacheBackend::class);
826
-			} else {
827
-				$backend = $c->get(\OC\Security\Bruteforce\Backend\DatabaseBackend::class);
828
-			}
829
-
830
-			return $backend;
831
-		});
832
-
833
-		$this->registerDeprecatedAlias('IntegrityCodeChecker', Checker::class);
834
-		$this->registerService(Checker::class, function (ContainerInterface $c) {
835
-			// IConfig requires a working database. This code
836
-			// might however be called when Nextcloud is not yet setup.
837
-			if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) {
838
-				$config = $c->get(\OCP\IConfig::class);
839
-				$appConfig = $c->get(\OCP\IAppConfig::class);
840
-			} else {
841
-				$config = null;
842
-				$appConfig = null;
843
-			}
844
-
845
-			return new Checker(
846
-				$c->get(ServerVersion::class),
847
-				$c->get(EnvironmentHelper::class),
848
-				new FileAccessHelper(),
849
-				$config,
850
-				$appConfig,
851
-				$c->get(ICacheFactory::class),
852
-				$c->get(IAppManager::class),
853
-				$c->get(IMimeTypeDetector::class)
854
-			);
855
-		});
856
-		$this->registerService(Request::class, function (ContainerInterface $c) {
857
-			if (isset($this['urlParams'])) {
858
-				$urlParams = $this['urlParams'];
859
-			} else {
860
-				$urlParams = [];
861
-			}
862
-
863
-			if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
864
-				&& in_array('fakeinput', stream_get_wrappers())
865
-			) {
866
-				$stream = 'fakeinput://data';
867
-			} else {
868
-				$stream = 'php://input';
869
-			}
870
-
871
-			return new Request(
872
-				[
873
-					'get' => $_GET,
874
-					'post' => $_POST,
875
-					'files' => $_FILES,
876
-					'server' => $_SERVER,
877
-					'env' => $_ENV,
878
-					'cookies' => $_COOKIE,
879
-					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
880
-						? $_SERVER['REQUEST_METHOD']
881
-						: '',
882
-					'urlParams' => $urlParams,
883
-				],
884
-				$this->get(IRequestId::class),
885
-				$this->get(\OCP\IConfig::class),
886
-				$this->get(CsrfTokenManager::class),
887
-				$stream
888
-			);
889
-		});
890
-		$this->registerAlias(\OCP\IRequest::class, Request::class);
891
-
892
-		$this->registerService(IRequestId::class, function (ContainerInterface $c): IRequestId {
893
-			return new RequestId(
894
-				$_SERVER['UNIQUE_ID'] ?? '',
895
-				$this->get(ISecureRandom::class)
896
-			);
897
-		});
898
-
899
-		/** @since 32.0.0 */
900
-		$this->registerAlias(IEmailValidator::class, EmailValidator::class);
901
-
902
-		$this->registerService(IMailer::class, function (Server $c) {
903
-			return new Mailer(
904
-				$c->get(\OCP\IConfig::class),
905
-				$c->get(LoggerInterface::class),
906
-				$c->get(Defaults::class),
907
-				$c->get(IURLGenerator::class),
908
-				$c->getL10N('lib'),
909
-				$c->get(IEventDispatcher::class),
910
-				$c->get(IFactory::class),
911
-				$c->get(IEmailValidator::class),
912
-			);
913
-		});
914
-
915
-		/** @since 30.0.0 */
916
-		$this->registerAlias(\OCP\Mail\Provider\IManager::class, \OC\Mail\Provider\Manager::class);
917
-
918
-		$this->registerService(ILDAPProviderFactory::class, function (ContainerInterface $c) {
919
-			$config = $c->get(\OCP\IConfig::class);
920
-			$factoryClass = $config->getSystemValue('ldapProviderFactory', null);
921
-			if (is_null($factoryClass) || !class_exists($factoryClass)) {
922
-				return new NullLDAPProviderFactory($this);
923
-			}
924
-			/** @var \OCP\LDAP\ILDAPProviderFactory $factory */
925
-			return new $factoryClass($this);
926
-		});
927
-		$this->registerService(ILDAPProvider::class, function (ContainerInterface $c) {
928
-			$factory = $c->get(ILDAPProviderFactory::class);
929
-			return $factory->getLDAPProvider();
930
-		});
931
-		$this->registerService(ILockingProvider::class, function (ContainerInterface $c) {
932
-			$ini = $c->get(IniGetWrapper::class);
933
-			$config = $c->get(\OCP\IConfig::class);
934
-			$ttl = $config->getSystemValueInt('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
935
-			if ($config->getSystemValueBool('filelocking.enabled', true) || (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
936
-				/** @var \OC\Memcache\Factory $memcacheFactory */
937
-				$memcacheFactory = $c->get(ICacheFactory::class);
938
-				$memcache = $memcacheFactory->createLocking('lock');
939
-				if (!($memcache instanceof \OC\Memcache\NullCache)) {
940
-					$timeFactory = $c->get(ITimeFactory::class);
941
-					return new MemcacheLockingProvider($memcache, $timeFactory, $ttl);
942
-				}
943
-				return new DBLockingProvider(
944
-					$c->get(IDBConnection::class),
945
-					new TimeFactory(),
946
-					$ttl,
947
-					!\OC::$CLI
948
-				);
949
-			}
950
-			return new NoopLockingProvider();
951
-		});
952
-
953
-		$this->registerService(ILockManager::class, function (Server $c): LockManager {
954
-			return new LockManager();
955
-		});
956
-
957
-		$this->registerAlias(ILockdownManager::class, 'LockdownManager');
958
-		$this->registerService(SetupManager::class, function ($c) {
959
-			// create the setupmanager through the mount manager to resolve the cyclic dependency
960
-			return $c->get(\OC\Files\Mount\Manager::class)->getSetupManager();
961
-		});
962
-		$this->registerAlias(IMountManager::class, \OC\Files\Mount\Manager::class);
963
-
964
-		$this->registerService(IMimeTypeDetector::class, function (ContainerInterface $c) {
965
-			return new \OC\Files\Type\Detection(
966
-				$c->get(IURLGenerator::class),
967
-				$c->get(LoggerInterface::class),
968
-				\OC::$configDir,
969
-				\OC::$SERVERROOT . '/resources/config/'
970
-			);
971
-		});
972
-
973
-		$this->registerAlias(IMimeTypeLoader::class, Loader::class);
974
-		$this->registerService(BundleFetcher::class, function () {
975
-			return new BundleFetcher($this->getL10N('lib'));
976
-		});
977
-		$this->registerAlias(\OCP\Notification\IManager::class, Manager::class);
978
-
979
-		$this->registerService(CapabilitiesManager::class, function (ContainerInterface $c) {
980
-			$manager = new CapabilitiesManager($c->get(LoggerInterface::class));
981
-			$manager->registerCapability(function () use ($c) {
982
-				return new \OC\OCS\CoreCapabilities($c->get(\OCP\IConfig::class));
983
-			});
984
-			$manager->registerCapability(function () use ($c) {
985
-				return $c->get(\OC\Security\Bruteforce\Capabilities::class);
986
-			});
987
-			return $manager;
988
-		});
989
-
990
-		$this->registerService(ICommentsManager::class, function (Server $c) {
991
-			$config = $c->get(\OCP\IConfig::class);
992
-			$factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class);
993
-			/** @var \OCP\Comments\ICommentsManagerFactory $factory */
994
-			$factory = new $factoryClass($this);
995
-			$manager = $factory->getManager();
996
-
997
-			$manager->registerDisplayNameResolver('user', function ($id) use ($c) {
998
-				$manager = $c->get(IUserManager::class);
999
-				$userDisplayName = $manager->getDisplayName($id);
1000
-				if ($userDisplayName === null) {
1001
-					$l = $c->get(IFactory::class)->get('core');
1002
-					return $l->t('Unknown account');
1003
-				}
1004
-				return $userDisplayName;
1005
-			});
1006
-
1007
-			return $manager;
1008
-		});
1009
-
1010
-		$this->registerAlias(\OC_Defaults::class, 'ThemingDefaults');
1011
-		$this->registerService('ThemingDefaults', function (Server $c) {
1012
-			try {
1013
-				$classExists = class_exists('OCA\Theming\ThemingDefaults');
1014
-			} catch (\OCP\AutoloadNotAllowedException $e) {
1015
-				// App disabled or in maintenance mode
1016
-				$classExists = false;
1017
-			}
1018
-
1019
-			if ($classExists && $c->get(\OCP\IConfig::class)->getSystemValueBool('installed', false) && $c->get(IAppManager::class)->isEnabledForAnyone('theming') && $c->get(TrustedDomainHelper::class)->isTrustedDomain($c->getRequest()->getInsecureServerHost())) {
1020
-				$backgroundService = new BackgroundService(
1021
-					$c->get(IRootFolder::class),
1022
-					$c->get(IAppDataFactory::class)->get('theming'),
1023
-					$c->get(IAppConfig::class),
1024
-					$c->get(\OCP\IConfig::class),
1025
-					$c->get(ISession::class)->get('user_id'),
1026
-				);
1027
-				$imageManager = new ImageManager(
1028
-					$c->get(\OCP\IConfig::class),
1029
-					$c->get(IAppDataFactory::class)->get('theming'),
1030
-					$c->get(IURLGenerator::class),
1031
-					$c->get(ICacheFactory::class),
1032
-					$c->get(LoggerInterface::class),
1033
-					$c->get(ITempManager::class),
1034
-					$backgroundService,
1035
-				);
1036
-				return new ThemingDefaults(
1037
-					$c->get(\OCP\IConfig::class),
1038
-					new AppConfig(
1039
-						$c->get(\OCP\IConfig::class),
1040
-						$c->get(\OCP\IAppConfig::class),
1041
-						'theming',
1042
-					),
1043
-					$c->get(IFactory::class)->get('theming'),
1044
-					$c->get(IUserSession::class),
1045
-					$c->get(IURLGenerator::class),
1046
-					$c->get(ICacheFactory::class),
1047
-					new Util(
1048
-						$c->get(ServerVersion::class),
1049
-						$c->get(\OCP\IConfig::class),
1050
-						$this->get(IAppManager::class),
1051
-						$c->get(IAppDataFactory::class)->get('theming'),
1052
-						$imageManager,
1053
-					),
1054
-					$imageManager,
1055
-					$c->get(IAppManager::class),
1056
-					$c->get(INavigationManager::class),
1057
-					$backgroundService,
1058
-				);
1059
-			}
1060
-			return new \OC_Defaults();
1061
-		});
1062
-		$this->registerService(JSCombiner::class, function (Server $c) {
1063
-			return new JSCombiner(
1064
-				$c->getAppDataDir('js'),
1065
-				$c->get(IURLGenerator::class),
1066
-				$this->get(ICacheFactory::class),
1067
-				$c->get(\OCP\IConfig::class),
1068
-				$c->get(LoggerInterface::class)
1069
-			);
1070
-		});
1071
-		$this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class);
1072
-
1073
-		$this->registerService('CryptoWrapper', function (ContainerInterface $c) {
1074
-			// FIXME: Instantiated here due to cyclic dependency
1075
-			$request = new Request(
1076
-				[
1077
-					'get' => $_GET,
1078
-					'post' => $_POST,
1079
-					'files' => $_FILES,
1080
-					'server' => $_SERVER,
1081
-					'env' => $_ENV,
1082
-					'cookies' => $_COOKIE,
1083
-					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
1084
-						? $_SERVER['REQUEST_METHOD']
1085
-						: null,
1086
-				],
1087
-				$c->get(IRequestId::class),
1088
-				$c->get(\OCP\IConfig::class)
1089
-			);
1090
-
1091
-			return new CryptoWrapper(
1092
-				$c->get(ICrypto::class),
1093
-				$c->get(ISecureRandom::class),
1094
-				$request
1095
-			);
1096
-		});
1097
-		$this->registerService(SessionStorage::class, function (ContainerInterface $c) {
1098
-			return new SessionStorage($c->get(ISession::class));
1099
-		});
1100
-		$this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class);
1101
-
1102
-		$this->registerService(IProviderFactory::class, function (ContainerInterface $c) {
1103
-			$config = $c->get(\OCP\IConfig::class);
1104
-			$factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class);
1105
-			/** @var \OCP\Share\IProviderFactory $factory */
1106
-			return $c->get($factoryClass);
1107
-		});
1108
-
1109
-		$this->registerAlias(\OCP\Share\IManager::class, \OC\Share20\Manager::class);
1110
-
1111
-		$this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) {
1112
-			$instance = new Collaboration\Collaborators\Search($c);
1113
-
1114
-			// register default plugins
1115
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]);
1116
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserByMailPlugin::class]);
1117
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]);
1118
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailByMailPlugin::class]);
1119
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]);
1120
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]);
1121
-
1122
-			return $instance;
1123
-		});
1124
-		$this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class);
1125
-
1126
-		$this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class);
1127
-
1128
-		$this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class);
1129
-		$this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class);
1130
-
1131
-		$this->registerAlias(IReferenceManager::class, ReferenceManager::class);
1132
-		$this->registerAlias(ITeamManager::class, TeamManager::class);
1133
-
1134
-		$this->registerDeprecatedAlias('SettingsManager', \OC\Settings\Manager::class);
1135
-		$this->registerAlias(\OCP\Settings\IManager::class, \OC\Settings\Manager::class);
1136
-		$this->registerService(\OC\Files\AppData\Factory::class, function (ContainerInterface $c) {
1137
-			return new \OC\Files\AppData\Factory(
1138
-				$c->get(IRootFolder::class),
1139
-				$c->get(SystemConfig::class)
1140
-			);
1141
-		});
1142
-
1143
-		$this->registerService('LockdownManager', function (ContainerInterface $c) {
1144
-			return new LockdownManager(function () use ($c) {
1145
-				return $c->get(ISession::class);
1146
-			});
1147
-		});
1148
-
1149
-		$this->registerService(\OCP\OCS\IDiscoveryService::class, function (ContainerInterface $c) {
1150
-			return new DiscoveryService(
1151
-				$c->get(ICacheFactory::class),
1152
-				$c->get(IClientService::class)
1153
-			);
1154
-		});
1155
-		$this->registerAlias(IOCMDiscoveryService::class, OCMDiscoveryService::class);
1156
-
1157
-		$this->registerService(ICloudIdManager::class, function (ContainerInterface $c) {
1158
-			return new CloudIdManager(
1159
-				$c->get(ICacheFactory::class),
1160
-				$c->get(IEventDispatcher::class),
1161
-				$c->get(\OCP\Contacts\IManager::class),
1162
-				$c->get(IURLGenerator::class),
1163
-				$c->get(IUserManager::class),
1164
-			);
1165
-		});
262
+    /** @var string */
263
+    private $webRoot;
264
+
265
+    /**
266
+     * @param string $webRoot
267
+     * @param \OC\Config $config
268
+     */
269
+    public function __construct($webRoot, \OC\Config $config) {
270
+        parent::__construct();
271
+        $this->webRoot = $webRoot;
272
+
273
+        // To find out if we are running from CLI or not
274
+        $this->registerParameter('isCLI', \OC::$CLI);
275
+        $this->registerParameter('serverRoot', \OC::$SERVERROOT);
276
+
277
+        $this->registerService(ContainerInterface::class, function (ContainerInterface $c) {
278
+            return $c;
279
+        });
280
+        $this->registerDeprecatedAlias(\OCP\IServerContainer::class, ContainerInterface::class);
281
+
282
+        $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class);
283
+
284
+        $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class);
285
+
286
+        $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class);
287
+
288
+        $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
289
+
290
+        $this->registerAlias(\OCP\ContextChat\IContentManager::class, \OC\ContextChat\ContentManager::class);
291
+
292
+        $this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class);
293
+        $this->registerAlias(ITemplateManager::class, TemplateManager::class);
294
+        $this->registerAlias(\OCP\Template\ITemplateManager::class, \OC\Template\TemplateManager::class);
295
+
296
+        $this->registerAlias(IActionFactory::class, ActionFactory::class);
297
+
298
+        $this->registerService(View::class, function (Server $c) {
299
+            return new View();
300
+        }, false);
301
+
302
+        $this->registerService(IPreview::class, function (ContainerInterface $c) {
303
+            return new PreviewManager(
304
+                $c->get(\OCP\IConfig::class),
305
+                $c->get(IRootFolder::class),
306
+                $c->get(IEventDispatcher::class),
307
+                $c->get(GeneratorHelper::class),
308
+                $c->get(ISession::class)->get('user_id'),
309
+                $c->get(Coordinator::class),
310
+                $c->get(IServerContainer::class),
311
+                $c->get(IBinaryFinder::class),
312
+                $c->get(IMagickSupport::class)
313
+            );
314
+        });
315
+        $this->registerAlias(IMimeIconProvider::class, MimeIconProvider::class);
316
+
317
+        $this->registerService(Watcher::class, function (ContainerInterface $c): Watcher {
318
+            return new Watcher(
319
+                $c->get(\OC\Preview\Storage\StorageFactory::class),
320
+                $c->get(PreviewMapper::class),
321
+                $c->get(IDBConnection::class),
322
+            );
323
+        });
324
+
325
+        $this->registerService(IProfiler::class, function (Server $c) {
326
+            return new Profiler($c->get(SystemConfig::class));
327
+        });
328
+
329
+        $this->registerService(Encryption\Manager::class, function (Server $c): Encryption\Manager {
330
+            $view = new View();
331
+            $util = new Encryption\Util(
332
+                $view,
333
+                $c->get(IUserManager::class),
334
+                $c->get(IGroupManager::class),
335
+                $c->get(\OCP\IConfig::class)
336
+            );
337
+            return new Encryption\Manager(
338
+                $c->get(\OCP\IConfig::class),
339
+                $c->get(LoggerInterface::class),
340
+                $c->getL10N('core'),
341
+                new View(),
342
+                $util,
343
+                new ArrayCache()
344
+            );
345
+        });
346
+        $this->registerAlias(\OCP\Encryption\IManager::class, Encryption\Manager::class);
347
+
348
+        $this->registerService(IFile::class, function (ContainerInterface $c) {
349
+            $util = new Encryption\Util(
350
+                new View(),
351
+                $c->get(IUserManager::class),
352
+                $c->get(IGroupManager::class),
353
+                $c->get(\OCP\IConfig::class)
354
+            );
355
+            return new Encryption\File(
356
+                $util,
357
+                $c->get(IRootFolder::class),
358
+                $c->get(\OCP\Share\IManager::class)
359
+            );
360
+        });
361
+
362
+        $this->registerService(IStorage::class, function (ContainerInterface $c) {
363
+            $view = new View();
364
+            $util = new Encryption\Util(
365
+                $view,
366
+                $c->get(IUserManager::class),
367
+                $c->get(IGroupManager::class),
368
+                $c->get(\OCP\IConfig::class)
369
+            );
370
+
371
+            return new Encryption\Keys\Storage(
372
+                $view,
373
+                $util,
374
+                $c->get(ICrypto::class),
375
+                $c->get(\OCP\IConfig::class)
376
+            );
377
+        });
378
+
379
+        $this->registerAlias(\OCP\ITagManager::class, TagManager::class);
380
+
381
+        $this->registerService('SystemTagManagerFactory', function (ContainerInterface $c) {
382
+            /** @var \OCP\IConfig $config */
383
+            $config = $c->get(\OCP\IConfig::class);
384
+            $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class);
385
+            return new $factoryClass($this);
386
+        });
387
+        $this->registerService(ISystemTagManager::class, function (ContainerInterface $c) {
388
+            return $c->get('SystemTagManagerFactory')->getManager();
389
+        });
390
+        /** @deprecated 19.0.0 */
391
+        $this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class);
392
+
393
+        $this->registerService(ISystemTagObjectMapper::class, function (ContainerInterface $c) {
394
+            return $c->get('SystemTagManagerFactory')->getObjectMapper();
395
+        });
396
+        $this->registerAlias(IFileAccess::class, FileAccess::class);
397
+        $this->registerService('RootFolder', function (ContainerInterface $c) {
398
+            $manager = \OC\Files\Filesystem::getMountManager();
399
+            $view = new View();
400
+            /** @var IUserSession $userSession */
401
+            $userSession = $c->get(IUserSession::class);
402
+            $root = new Root(
403
+                $manager,
404
+                $view,
405
+                $userSession->getUser(),
406
+                $c->get(IUserMountCache::class),
407
+                $this->get(LoggerInterface::class),
408
+                $this->get(IUserManager::class),
409
+                $this->get(IEventDispatcher::class),
410
+                $this->get(ICacheFactory::class),
411
+                $this->get(IAppConfig::class),
412
+            );
413
+
414
+            $previewConnector = new \OC\Preview\WatcherConnector(
415
+                $root,
416
+                $c->get(SystemConfig::class),
417
+                $this->get(IEventDispatcher::class)
418
+            );
419
+            $previewConnector->connectWatcher();
420
+
421
+            return $root;
422
+        });
423
+        $this->registerService(HookConnector::class, function (ContainerInterface $c) {
424
+            return new HookConnector(
425
+                $c->get(IRootFolder::class),
426
+                new View(),
427
+                $c->get(IEventDispatcher::class),
428
+                $c->get(LoggerInterface::class)
429
+            );
430
+        });
431
+
432
+        $this->registerService(IRootFolder::class, function (ContainerInterface $c) {
433
+            return new LazyRoot(function () use ($c) {
434
+                return $c->get('RootFolder');
435
+            });
436
+        });
437
+
438
+        $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class);
439
+
440
+        $this->registerService(DisplayNameCache::class, function (ContainerInterface $c) {
441
+            return $c->get(\OC\User\Manager::class)->getDisplayNameCache();
442
+        });
443
+
444
+        $this->registerService(\OCP\IGroupManager::class, function (ContainerInterface $c) {
445
+            $groupManager = new \OC\Group\Manager(
446
+                $this->get(IUserManager::class),
447
+                $this->get(IEventDispatcher::class),
448
+                $this->get(LoggerInterface::class),
449
+                $this->get(ICacheFactory::class),
450
+                $this->get(IRemoteAddress::class),
451
+            );
452
+            return $groupManager;
453
+        });
454
+
455
+        $this->registerService(Store::class, function (ContainerInterface $c) {
456
+            $session = $c->get(ISession::class);
457
+            if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) {
458
+                $tokenProvider = $c->get(IProvider::class);
459
+            } else {
460
+                $tokenProvider = null;
461
+            }
462
+            $logger = $c->get(LoggerInterface::class);
463
+            $crypto = $c->get(ICrypto::class);
464
+            return new Store($session, $logger, $crypto, $tokenProvider);
465
+        });
466
+        $this->registerAlias(IStore::class, Store::class);
467
+        $this->registerAlias(IProvider::class, Authentication\Token\Manager::class);
468
+        $this->registerAlias(OCPIProvider::class, Authentication\Token\Manager::class);
469
+
470
+        $this->registerService(\OC\User\Session::class, function (Server $c) {
471
+            $manager = $c->get(IUserManager::class);
472
+            $session = new \OC\Session\Memory();
473
+            $timeFactory = new TimeFactory();
474
+            // Token providers might require a working database. This code
475
+            // might however be called when Nextcloud is not yet setup.
476
+            if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) {
477
+                $provider = $c->get(IProvider::class);
478
+            } else {
479
+                $provider = null;
480
+            }
481
+
482
+            $userSession = new \OC\User\Session(
483
+                $manager,
484
+                $session,
485
+                $timeFactory,
486
+                $provider,
487
+                $c->get(\OCP\IConfig::class),
488
+                $c->get(ISecureRandom::class),
489
+                $c->get('LockdownManager'),
490
+                $c->get(LoggerInterface::class),
491
+                $c->get(IEventDispatcher::class),
492
+            );
493
+            /** @deprecated 21.0.0 use BeforeUserCreatedEvent event with the IEventDispatcher instead */
494
+            $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
495
+                \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]);
496
+            });
497
+            /** @deprecated 21.0.0 use UserCreatedEvent event with the IEventDispatcher instead */
498
+            $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
499
+                /** @var \OC\User\User $user */
500
+                \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]);
501
+            });
502
+            /** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */
503
+            $userSession->listen('\OC\User', 'preDelete', function ($user) {
504
+                /** @var \OC\User\User $user */
505
+                \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]);
506
+            });
507
+            /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */
508
+            $userSession->listen('\OC\User', 'postDelete', function ($user) {
509
+                /** @var \OC\User\User $user */
510
+                \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]);
511
+            });
512
+            $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
513
+                /** @var \OC\User\User $user */
514
+                \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]);
515
+            });
516
+            $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
517
+                /** @var \OC\User\User $user */
518
+                \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]);
519
+            });
520
+            $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
521
+                \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]);
522
+
523
+                /** @var IEventDispatcher $dispatcher */
524
+                $dispatcher = $this->get(IEventDispatcher::class);
525
+                $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password));
526
+            });
527
+            $userSession->listen('\OC\User', 'postLogin', function ($user, $loginName, $password, $isTokenLogin) {
528
+                /** @var \OC\User\User $user */
529
+                \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'loginName' => $loginName, 'password' => $password, 'isTokenLogin' => $isTokenLogin]);
530
+
531
+                /** @var IEventDispatcher $dispatcher */
532
+                $dispatcher = $this->get(IEventDispatcher::class);
533
+                $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $loginName, $password, $isTokenLogin));
534
+            });
535
+            $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) {
536
+                /** @var IEventDispatcher $dispatcher */
537
+                $dispatcher = $this->get(IEventDispatcher::class);
538
+                $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid));
539
+            });
540
+            $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) {
541
+                /** @var \OC\User\User $user */
542
+                \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]);
543
+
544
+                /** @var IEventDispatcher $dispatcher */
545
+                $dispatcher = $this->get(IEventDispatcher::class);
546
+                $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password));
547
+            });
548
+            $userSession->listen('\OC\User', 'logout', function ($user) {
549
+                \OC_Hook::emit('OC_User', 'logout', []);
550
+
551
+                /** @var IEventDispatcher $dispatcher */
552
+                $dispatcher = $this->get(IEventDispatcher::class);
553
+                $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user));
554
+            });
555
+            $userSession->listen('\OC\User', 'postLogout', function ($user) {
556
+                /** @var IEventDispatcher $dispatcher */
557
+                $dispatcher = $this->get(IEventDispatcher::class);
558
+                $dispatcher->dispatchTyped(new UserLoggedOutEvent($user));
559
+            });
560
+            $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) {
561
+                /** @var \OC\User\User $user */
562
+                \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]);
563
+            });
564
+            return $userSession;
565
+        });
566
+        $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class);
567
+
568
+        $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class);
569
+
570
+        $this->registerAlias(INavigationManager::class, \OC\NavigationManager::class);
571
+
572
+        $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
573
+
574
+        $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) {
575
+            return new \OC\SystemConfig($config);
576
+        });
577
+
578
+        $this->registerAlias(IAppConfig::class, \OC\AppConfig::class);
579
+        $this->registerAlias(IUserConfig::class, \OC\Config\UserConfig::class);
580
+        $this->registerAlias(IAppManager::class, AppManager::class);
581
+
582
+        $this->registerService(IFactory::class, function (Server $c) {
583
+            return new \OC\L10N\Factory(
584
+                $c->get(\OCP\IConfig::class),
585
+                $c->getRequest(),
586
+                $c->get(IUserSession::class),
587
+                $c->get(ICacheFactory::class),
588
+                \OC::$SERVERROOT,
589
+                $c->get(IAppManager::class),
590
+            );
591
+        });
592
+
593
+        $this->registerAlias(IURLGenerator::class, URLGenerator::class);
594
+
595
+        $this->registerAlias(ICache::class, Cache\File::class);
596
+        $this->registerService(Factory::class, function (Server $c) {
597
+            $profiler = $c->get(IProfiler::class);
598
+            $logger = $c->get(LoggerInterface::class);
599
+            $serverVersion = $c->get(ServerVersion::class);
600
+            /** @var SystemConfig $config */
601
+            $config = $c->get(SystemConfig::class);
602
+            if (!$config->getValue('installed', false) || (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
603
+                return new \OC\Memcache\Factory(
604
+                    $logger,
605
+                    $profiler,
606
+                    $serverVersion,
607
+                    ArrayCache::class,
608
+                    ArrayCache::class,
609
+                    ArrayCache::class
610
+                );
611
+            }
612
+
613
+            return new \OC\Memcache\Factory(
614
+                $logger,
615
+                $profiler,
616
+                $serverVersion,
617
+                /** @psalm-taint-escape callable */
618
+                $config->getValue('memcache.local', null),
619
+                /** @psalm-taint-escape callable */
620
+                $config->getValue('memcache.distributed', null),
621
+                /** @psalm-taint-escape callable */
622
+                $config->getValue('memcache.locking', null),
623
+                /** @psalm-taint-escape callable */
624
+                $config->getValue('redis_log_file')
625
+            );
626
+        });
627
+        $this->registerAlias(ICacheFactory::class, Factory::class);
628
+
629
+        $this->registerService('RedisFactory', function (Server $c) {
630
+            $systemConfig = $c->get(SystemConfig::class);
631
+            return new RedisFactory($systemConfig, $c->get(IEventLogger::class));
632
+        });
633
+
634
+        $this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
635
+            $l10n = $this->get(IFactory::class)->get('lib');
636
+            return new \OC\Activity\Manager(
637
+                $c->getRequest(),
638
+                $c->get(IUserSession::class),
639
+                $c->get(\OCP\IConfig::class),
640
+                $c->get(IValidator::class),
641
+                $c->get(IRichTextFormatter::class),
642
+                $l10n,
643
+                $c->get(ITimeFactory::class),
644
+            );
645
+        });
646
+
647
+        $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
648
+            return new \OC\Activity\EventMerger(
649
+                $c->getL10N('lib')
650
+            );
651
+        });
652
+        $this->registerAlias(IValidator::class, Validator::class);
653
+
654
+        $this->registerService(AvatarManager::class, function (Server $c) {
655
+            return new AvatarManager(
656
+                $c->get(IUserSession::class),
657
+                $c->get(\OC\User\Manager::class),
658
+                $c->getAppDataDir('avatar'),
659
+                $c->getL10N('lib'),
660
+                $c->get(LoggerInterface::class),
661
+                $c->get(\OCP\IConfig::class),
662
+                $c->get(IAccountManager::class),
663
+                $c->get(KnownUserService::class)
664
+            );
665
+        });
666
+
667
+        $this->registerAlias(IAvatarManager::class, AvatarManager::class);
668
+
669
+        $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class);
670
+        $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class);
671
+        $this->registerAlias(\OCP\Support\Subscription\IAssertion::class, \OC\Support\Subscription\Assertion::class);
672
+
673
+        /** Only used by the PsrLoggerAdapter should not be used by apps */
674
+        $this->registerService(\OC\Log::class, function (Server $c) {
675
+            $logType = $c->get(AllConfig::class)->getSystemValue('log_type', 'file');
676
+            $factory = new LogFactory($c, $this->get(SystemConfig::class));
677
+            $logger = $factory->get($logType);
678
+            $registry = $c->get(\OCP\Support\CrashReport\IRegistry::class);
679
+
680
+            return new Log($logger, $this->get(SystemConfig::class), crashReporters: $registry);
681
+        });
682
+        // PSR-3 logger
683
+        $this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class);
684
+
685
+        $this->registerService(ILogFactory::class, function (Server $c) {
686
+            return new LogFactory($c, $this->get(SystemConfig::class));
687
+        });
688
+
689
+        $this->registerAlias(IJobList::class, \OC\BackgroundJob\JobList::class);
690
+
691
+        $this->registerService(Router::class, function (Server $c) {
692
+            $cacheFactory = $c->get(ICacheFactory::class);
693
+            if ($cacheFactory->isLocalCacheAvailable()) {
694
+                $router = $c->resolve(CachingRouter::class);
695
+            } else {
696
+                $router = $c->resolve(Router::class);
697
+            }
698
+            return $router;
699
+        });
700
+        $this->registerAlias(IRouter::class, Router::class);
701
+
702
+        $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) {
703
+            $config = $c->get(\OCP\IConfig::class);
704
+            if (ltrim($config->getSystemValueString('memcache.distributed', ''), '\\') === \OC\Memcache\Redis::class) {
705
+                $backend = new \OC\Security\RateLimiting\Backend\MemoryCacheBackend(
706
+                    $c->get(AllConfig::class),
707
+                    $this->get(ICacheFactory::class),
708
+                    new \OC\AppFramework\Utility\TimeFactory()
709
+                );
710
+            } else {
711
+                $backend = new \OC\Security\RateLimiting\Backend\DatabaseBackend(
712
+                    $c->get(AllConfig::class),
713
+                    $c->get(IDBConnection::class),
714
+                    new \OC\AppFramework\Utility\TimeFactory()
715
+                );
716
+            }
717
+
718
+            return $backend;
719
+        });
720
+
721
+        $this->registerAlias(\OCP\Security\ISecureRandom::class, SecureRandom::class);
722
+        $this->registerAlias(\OCP\Security\IRemoteHostValidator::class, \OC\Security\RemoteHostValidator::class);
723
+        $this->registerAlias(IVerificationToken::class, VerificationToken::class);
724
+
725
+        $this->registerAlias(ICrypto::class, Crypto::class);
726
+
727
+        $this->registerAlias(IHasher::class, Hasher::class);
728
+
729
+        $this->registerAlias(ICredentialsManager::class, CredentialsManager::class);
730
+
731
+        $this->registerAlias(IDBConnection::class, ConnectionAdapter::class);
732
+        $this->registerService(Connection::class, function (Server $c) {
733
+            $systemConfig = $c->get(SystemConfig::class);
734
+            $factory = new \OC\DB\ConnectionFactory($systemConfig, $c->get(ICacheFactory::class));
735
+            $type = $systemConfig->getValue('dbtype', 'sqlite');
736
+            if (!$factory->isValidType($type)) {
737
+                throw new \OC\DatabaseException('Invalid database type');
738
+            }
739
+            $connection = $factory->getConnection($type, []);
740
+            return $connection;
741
+        });
742
+
743
+        $this->registerAlias(ICertificateManager::class, CertificateManager::class);
744
+        $this->registerAlias(IClientService::class, ClientService::class);
745
+        $this->registerService(NegativeDnsCache::class, function (ContainerInterface $c) {
746
+            return new NegativeDnsCache(
747
+                $c->get(ICacheFactory::class),
748
+            );
749
+        });
750
+        $this->registerDeprecatedAlias('HttpClientService', IClientService::class);
751
+        $this->registerService(IEventLogger::class, function (ContainerInterface $c) {
752
+            return new EventLogger($c->get(SystemConfig::class), $c->get(LoggerInterface::class), $c->get(Log::class));
753
+        });
754
+
755
+        $this->registerService(IQueryLogger::class, function (ContainerInterface $c) {
756
+            $queryLogger = new QueryLogger();
757
+            if ($c->get(SystemConfig::class)->getValue('debug', false)) {
758
+                // In debug mode, module is being activated by default
759
+                $queryLogger->activate();
760
+            }
761
+            return $queryLogger;
762
+        });
763
+
764
+        $this->registerAlias(ITempManager::class, TempManager::class);
765
+        $this->registerAlias(IDateTimeZone::class, DateTimeZone::class);
766
+
767
+        $this->registerService(IDateTimeFormatter::class, function (Server $c) {
768
+            $language = $c->get(\OCP\IConfig::class)->getUserValue($c->get(ISession::class)->get('user_id'), 'core', 'lang', null);
769
+
770
+            return new DateTimeFormatter(
771
+                $c->get(IDateTimeZone::class)->getTimeZone(),
772
+                $c->getL10N('lib', $language)
773
+            );
774
+        });
775
+
776
+        $this->registerService(IUserMountCache::class, function (ContainerInterface $c) {
777
+            $mountCache = $c->get(UserMountCache::class);
778
+            $listener = new UserMountCacheListener($mountCache);
779
+            $listener->listen($c->get(IUserManager::class));
780
+            return $mountCache;
781
+        });
782
+
783
+        $this->registerService(IMountProviderCollection::class, function (ContainerInterface $c) {
784
+            $loader = $c->get(IStorageFactory::class);
785
+            $mountCache = $c->get(IUserMountCache::class);
786
+            $eventLogger = $c->get(IEventLogger::class);
787
+            $manager = new MountProviderCollection($loader, $mountCache, $eventLogger);
788
+
789
+            // builtin providers
790
+
791
+            $config = $c->get(\OCP\IConfig::class);
792
+            $logger = $c->get(LoggerInterface::class);
793
+            $objectStoreConfig = $c->get(PrimaryObjectStoreConfig::class);
794
+            $manager->registerProvider(new CacheMountProvider($config));
795
+            $manager->registerHomeProvider(new LocalHomeMountProvider());
796
+            $manager->registerHomeProvider(new ObjectHomeMountProvider($objectStoreConfig));
797
+            $manager->registerRootProvider(new RootMountProvider($objectStoreConfig, $config));
798
+
799
+            return $manager;
800
+        });
801
+
802
+        $this->registerService(IBus::class, function (ContainerInterface $c) {
803
+            $busClass = $c->get(\OCP\IConfig::class)->getSystemValueString('commandbus');
804
+            if ($busClass) {
805
+                [$app, $class] = explode('::', $busClass, 2);
806
+                if ($c->get(IAppManager::class)->isEnabledForUser($app)) {
807
+                    $c->get(IAppManager::class)->loadApp($app);
808
+                    return $c->get($class);
809
+                } else {
810
+                    throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled");
811
+                }
812
+            } else {
813
+                $jobList = $c->get(IJobList::class);
814
+                return new CronBus($jobList);
815
+            }
816
+        });
817
+        $this->registerDeprecatedAlias('AsyncCommandBus', IBus::class);
818
+        $this->registerAlias(ITrustedDomainHelper::class, TrustedDomainHelper::class);
819
+        $this->registerAlias(IThrottler::class, Throttler::class);
820
+
821
+        $this->registerService(\OC\Security\Bruteforce\Backend\IBackend::class, function ($c) {
822
+            $config = $c->get(\OCP\IConfig::class);
823
+            if (!$config->getSystemValueBool('auth.bruteforce.protection.force.database', false)
824
+                && ltrim($config->getSystemValueString('memcache.distributed', ''), '\\') === \OC\Memcache\Redis::class) {
825
+                $backend = $c->get(\OC\Security\Bruteforce\Backend\MemoryCacheBackend::class);
826
+            } else {
827
+                $backend = $c->get(\OC\Security\Bruteforce\Backend\DatabaseBackend::class);
828
+            }
829
+
830
+            return $backend;
831
+        });
832
+
833
+        $this->registerDeprecatedAlias('IntegrityCodeChecker', Checker::class);
834
+        $this->registerService(Checker::class, function (ContainerInterface $c) {
835
+            // IConfig requires a working database. This code
836
+            // might however be called when Nextcloud is not yet setup.
837
+            if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) {
838
+                $config = $c->get(\OCP\IConfig::class);
839
+                $appConfig = $c->get(\OCP\IAppConfig::class);
840
+            } else {
841
+                $config = null;
842
+                $appConfig = null;
843
+            }
844
+
845
+            return new Checker(
846
+                $c->get(ServerVersion::class),
847
+                $c->get(EnvironmentHelper::class),
848
+                new FileAccessHelper(),
849
+                $config,
850
+                $appConfig,
851
+                $c->get(ICacheFactory::class),
852
+                $c->get(IAppManager::class),
853
+                $c->get(IMimeTypeDetector::class)
854
+            );
855
+        });
856
+        $this->registerService(Request::class, function (ContainerInterface $c) {
857
+            if (isset($this['urlParams'])) {
858
+                $urlParams = $this['urlParams'];
859
+            } else {
860
+                $urlParams = [];
861
+            }
862
+
863
+            if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
864
+                && in_array('fakeinput', stream_get_wrappers())
865
+            ) {
866
+                $stream = 'fakeinput://data';
867
+            } else {
868
+                $stream = 'php://input';
869
+            }
870
+
871
+            return new Request(
872
+                [
873
+                    'get' => $_GET,
874
+                    'post' => $_POST,
875
+                    'files' => $_FILES,
876
+                    'server' => $_SERVER,
877
+                    'env' => $_ENV,
878
+                    'cookies' => $_COOKIE,
879
+                    'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
880
+                        ? $_SERVER['REQUEST_METHOD']
881
+                        : '',
882
+                    'urlParams' => $urlParams,
883
+                ],
884
+                $this->get(IRequestId::class),
885
+                $this->get(\OCP\IConfig::class),
886
+                $this->get(CsrfTokenManager::class),
887
+                $stream
888
+            );
889
+        });
890
+        $this->registerAlias(\OCP\IRequest::class, Request::class);
891
+
892
+        $this->registerService(IRequestId::class, function (ContainerInterface $c): IRequestId {
893
+            return new RequestId(
894
+                $_SERVER['UNIQUE_ID'] ?? '',
895
+                $this->get(ISecureRandom::class)
896
+            );
897
+        });
898
+
899
+        /** @since 32.0.0 */
900
+        $this->registerAlias(IEmailValidator::class, EmailValidator::class);
901
+
902
+        $this->registerService(IMailer::class, function (Server $c) {
903
+            return new Mailer(
904
+                $c->get(\OCP\IConfig::class),
905
+                $c->get(LoggerInterface::class),
906
+                $c->get(Defaults::class),
907
+                $c->get(IURLGenerator::class),
908
+                $c->getL10N('lib'),
909
+                $c->get(IEventDispatcher::class),
910
+                $c->get(IFactory::class),
911
+                $c->get(IEmailValidator::class),
912
+            );
913
+        });
914
+
915
+        /** @since 30.0.0 */
916
+        $this->registerAlias(\OCP\Mail\Provider\IManager::class, \OC\Mail\Provider\Manager::class);
917
+
918
+        $this->registerService(ILDAPProviderFactory::class, function (ContainerInterface $c) {
919
+            $config = $c->get(\OCP\IConfig::class);
920
+            $factoryClass = $config->getSystemValue('ldapProviderFactory', null);
921
+            if (is_null($factoryClass) || !class_exists($factoryClass)) {
922
+                return new NullLDAPProviderFactory($this);
923
+            }
924
+            /** @var \OCP\LDAP\ILDAPProviderFactory $factory */
925
+            return new $factoryClass($this);
926
+        });
927
+        $this->registerService(ILDAPProvider::class, function (ContainerInterface $c) {
928
+            $factory = $c->get(ILDAPProviderFactory::class);
929
+            return $factory->getLDAPProvider();
930
+        });
931
+        $this->registerService(ILockingProvider::class, function (ContainerInterface $c) {
932
+            $ini = $c->get(IniGetWrapper::class);
933
+            $config = $c->get(\OCP\IConfig::class);
934
+            $ttl = $config->getSystemValueInt('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
935
+            if ($config->getSystemValueBool('filelocking.enabled', true) || (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
936
+                /** @var \OC\Memcache\Factory $memcacheFactory */
937
+                $memcacheFactory = $c->get(ICacheFactory::class);
938
+                $memcache = $memcacheFactory->createLocking('lock');
939
+                if (!($memcache instanceof \OC\Memcache\NullCache)) {
940
+                    $timeFactory = $c->get(ITimeFactory::class);
941
+                    return new MemcacheLockingProvider($memcache, $timeFactory, $ttl);
942
+                }
943
+                return new DBLockingProvider(
944
+                    $c->get(IDBConnection::class),
945
+                    new TimeFactory(),
946
+                    $ttl,
947
+                    !\OC::$CLI
948
+                );
949
+            }
950
+            return new NoopLockingProvider();
951
+        });
952
+
953
+        $this->registerService(ILockManager::class, function (Server $c): LockManager {
954
+            return new LockManager();
955
+        });
956
+
957
+        $this->registerAlias(ILockdownManager::class, 'LockdownManager');
958
+        $this->registerService(SetupManager::class, function ($c) {
959
+            // create the setupmanager through the mount manager to resolve the cyclic dependency
960
+            return $c->get(\OC\Files\Mount\Manager::class)->getSetupManager();
961
+        });
962
+        $this->registerAlias(IMountManager::class, \OC\Files\Mount\Manager::class);
963
+
964
+        $this->registerService(IMimeTypeDetector::class, function (ContainerInterface $c) {
965
+            return new \OC\Files\Type\Detection(
966
+                $c->get(IURLGenerator::class),
967
+                $c->get(LoggerInterface::class),
968
+                \OC::$configDir,
969
+                \OC::$SERVERROOT . '/resources/config/'
970
+            );
971
+        });
972
+
973
+        $this->registerAlias(IMimeTypeLoader::class, Loader::class);
974
+        $this->registerService(BundleFetcher::class, function () {
975
+            return new BundleFetcher($this->getL10N('lib'));
976
+        });
977
+        $this->registerAlias(\OCP\Notification\IManager::class, Manager::class);
978
+
979
+        $this->registerService(CapabilitiesManager::class, function (ContainerInterface $c) {
980
+            $manager = new CapabilitiesManager($c->get(LoggerInterface::class));
981
+            $manager->registerCapability(function () use ($c) {
982
+                return new \OC\OCS\CoreCapabilities($c->get(\OCP\IConfig::class));
983
+            });
984
+            $manager->registerCapability(function () use ($c) {
985
+                return $c->get(\OC\Security\Bruteforce\Capabilities::class);
986
+            });
987
+            return $manager;
988
+        });
989
+
990
+        $this->registerService(ICommentsManager::class, function (Server $c) {
991
+            $config = $c->get(\OCP\IConfig::class);
992
+            $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class);
993
+            /** @var \OCP\Comments\ICommentsManagerFactory $factory */
994
+            $factory = new $factoryClass($this);
995
+            $manager = $factory->getManager();
996
+
997
+            $manager->registerDisplayNameResolver('user', function ($id) use ($c) {
998
+                $manager = $c->get(IUserManager::class);
999
+                $userDisplayName = $manager->getDisplayName($id);
1000
+                if ($userDisplayName === null) {
1001
+                    $l = $c->get(IFactory::class)->get('core');
1002
+                    return $l->t('Unknown account');
1003
+                }
1004
+                return $userDisplayName;
1005
+            });
1006
+
1007
+            return $manager;
1008
+        });
1009
+
1010
+        $this->registerAlias(\OC_Defaults::class, 'ThemingDefaults');
1011
+        $this->registerService('ThemingDefaults', function (Server $c) {
1012
+            try {
1013
+                $classExists = class_exists('OCA\Theming\ThemingDefaults');
1014
+            } catch (\OCP\AutoloadNotAllowedException $e) {
1015
+                // App disabled or in maintenance mode
1016
+                $classExists = false;
1017
+            }
1018
+
1019
+            if ($classExists && $c->get(\OCP\IConfig::class)->getSystemValueBool('installed', false) && $c->get(IAppManager::class)->isEnabledForAnyone('theming') && $c->get(TrustedDomainHelper::class)->isTrustedDomain($c->getRequest()->getInsecureServerHost())) {
1020
+                $backgroundService = new BackgroundService(
1021
+                    $c->get(IRootFolder::class),
1022
+                    $c->get(IAppDataFactory::class)->get('theming'),
1023
+                    $c->get(IAppConfig::class),
1024
+                    $c->get(\OCP\IConfig::class),
1025
+                    $c->get(ISession::class)->get('user_id'),
1026
+                );
1027
+                $imageManager = new ImageManager(
1028
+                    $c->get(\OCP\IConfig::class),
1029
+                    $c->get(IAppDataFactory::class)->get('theming'),
1030
+                    $c->get(IURLGenerator::class),
1031
+                    $c->get(ICacheFactory::class),
1032
+                    $c->get(LoggerInterface::class),
1033
+                    $c->get(ITempManager::class),
1034
+                    $backgroundService,
1035
+                );
1036
+                return new ThemingDefaults(
1037
+                    $c->get(\OCP\IConfig::class),
1038
+                    new AppConfig(
1039
+                        $c->get(\OCP\IConfig::class),
1040
+                        $c->get(\OCP\IAppConfig::class),
1041
+                        'theming',
1042
+                    ),
1043
+                    $c->get(IFactory::class)->get('theming'),
1044
+                    $c->get(IUserSession::class),
1045
+                    $c->get(IURLGenerator::class),
1046
+                    $c->get(ICacheFactory::class),
1047
+                    new Util(
1048
+                        $c->get(ServerVersion::class),
1049
+                        $c->get(\OCP\IConfig::class),
1050
+                        $this->get(IAppManager::class),
1051
+                        $c->get(IAppDataFactory::class)->get('theming'),
1052
+                        $imageManager,
1053
+                    ),
1054
+                    $imageManager,
1055
+                    $c->get(IAppManager::class),
1056
+                    $c->get(INavigationManager::class),
1057
+                    $backgroundService,
1058
+                );
1059
+            }
1060
+            return new \OC_Defaults();
1061
+        });
1062
+        $this->registerService(JSCombiner::class, function (Server $c) {
1063
+            return new JSCombiner(
1064
+                $c->getAppDataDir('js'),
1065
+                $c->get(IURLGenerator::class),
1066
+                $this->get(ICacheFactory::class),
1067
+                $c->get(\OCP\IConfig::class),
1068
+                $c->get(LoggerInterface::class)
1069
+            );
1070
+        });
1071
+        $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class);
1072
+
1073
+        $this->registerService('CryptoWrapper', function (ContainerInterface $c) {
1074
+            // FIXME: Instantiated here due to cyclic dependency
1075
+            $request = new Request(
1076
+                [
1077
+                    'get' => $_GET,
1078
+                    'post' => $_POST,
1079
+                    'files' => $_FILES,
1080
+                    'server' => $_SERVER,
1081
+                    'env' => $_ENV,
1082
+                    'cookies' => $_COOKIE,
1083
+                    'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
1084
+                        ? $_SERVER['REQUEST_METHOD']
1085
+                        : null,
1086
+                ],
1087
+                $c->get(IRequestId::class),
1088
+                $c->get(\OCP\IConfig::class)
1089
+            );
1090
+
1091
+            return new CryptoWrapper(
1092
+                $c->get(ICrypto::class),
1093
+                $c->get(ISecureRandom::class),
1094
+                $request
1095
+            );
1096
+        });
1097
+        $this->registerService(SessionStorage::class, function (ContainerInterface $c) {
1098
+            return new SessionStorage($c->get(ISession::class));
1099
+        });
1100
+        $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class);
1101
+
1102
+        $this->registerService(IProviderFactory::class, function (ContainerInterface $c) {
1103
+            $config = $c->get(\OCP\IConfig::class);
1104
+            $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class);
1105
+            /** @var \OCP\Share\IProviderFactory $factory */
1106
+            return $c->get($factoryClass);
1107
+        });
1108
+
1109
+        $this->registerAlias(\OCP\Share\IManager::class, \OC\Share20\Manager::class);
1110
+
1111
+        $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) {
1112
+            $instance = new Collaboration\Collaborators\Search($c);
1113
+
1114
+            // register default plugins
1115
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]);
1116
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserByMailPlugin::class]);
1117
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]);
1118
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailByMailPlugin::class]);
1119
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]);
1120
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]);
1121
+
1122
+            return $instance;
1123
+        });
1124
+        $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class);
1125
+
1126
+        $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class);
1127
+
1128
+        $this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class);
1129
+        $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class);
1130
+
1131
+        $this->registerAlias(IReferenceManager::class, ReferenceManager::class);
1132
+        $this->registerAlias(ITeamManager::class, TeamManager::class);
1133
+
1134
+        $this->registerDeprecatedAlias('SettingsManager', \OC\Settings\Manager::class);
1135
+        $this->registerAlias(\OCP\Settings\IManager::class, \OC\Settings\Manager::class);
1136
+        $this->registerService(\OC\Files\AppData\Factory::class, function (ContainerInterface $c) {
1137
+            return new \OC\Files\AppData\Factory(
1138
+                $c->get(IRootFolder::class),
1139
+                $c->get(SystemConfig::class)
1140
+            );
1141
+        });
1142
+
1143
+        $this->registerService('LockdownManager', function (ContainerInterface $c) {
1144
+            return new LockdownManager(function () use ($c) {
1145
+                return $c->get(ISession::class);
1146
+            });
1147
+        });
1148
+
1149
+        $this->registerService(\OCP\OCS\IDiscoveryService::class, function (ContainerInterface $c) {
1150
+            return new DiscoveryService(
1151
+                $c->get(ICacheFactory::class),
1152
+                $c->get(IClientService::class)
1153
+            );
1154
+        });
1155
+        $this->registerAlias(IOCMDiscoveryService::class, OCMDiscoveryService::class);
1156
+
1157
+        $this->registerService(ICloudIdManager::class, function (ContainerInterface $c) {
1158
+            return new CloudIdManager(
1159
+                $c->get(ICacheFactory::class),
1160
+                $c->get(IEventDispatcher::class),
1161
+                $c->get(\OCP\Contacts\IManager::class),
1162
+                $c->get(IURLGenerator::class),
1163
+                $c->get(IUserManager::class),
1164
+            );
1165
+        });
1166 1166
 
1167
-		$this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class);
1168
-		$this->registerAlias(ICloudFederationProviderManager::class, CloudFederationProviderManager::class);
1169
-		$this->registerService(ICloudFederationFactory::class, function (Server $c) {
1170
-			return new CloudFederationFactory();
1171
-		});
1167
+        $this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class);
1168
+        $this->registerAlias(ICloudFederationProviderManager::class, CloudFederationProviderManager::class);
1169
+        $this->registerService(ICloudFederationFactory::class, function (Server $c) {
1170
+            return new CloudFederationFactory();
1171
+        });
1172 1172
 
1173
-		$this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
1173
+        $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
1174 1174
 
1175
-		$this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
1176
-		$this->registerAlias(\Psr\Clock\ClockInterface::class, \OCP\AppFramework\Utility\ITimeFactory::class);
1175
+        $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
1176
+        $this->registerAlias(\Psr\Clock\ClockInterface::class, \OCP\AppFramework\Utility\ITimeFactory::class);
1177 1177
 
1178
-		$this->registerService(Defaults::class, function (Server $c) {
1179
-			return new Defaults(
1180
-				$c->get('ThemingDefaults')
1181
-			);
1182
-		});
1178
+        $this->registerService(Defaults::class, function (Server $c) {
1179
+            return new Defaults(
1180
+                $c->get('ThemingDefaults')
1181
+            );
1182
+        });
1183 1183
 
1184
-		$this->registerService(\OCP\ISession::class, function (ContainerInterface $c) {
1185
-			return $c->get(\OCP\IUserSession::class)->getSession();
1186
-		}, false);
1184
+        $this->registerService(\OCP\ISession::class, function (ContainerInterface $c) {
1185
+            return $c->get(\OCP\IUserSession::class)->getSession();
1186
+        }, false);
1187 1187
 
1188
-		$this->registerService(IShareHelper::class, function (ContainerInterface $c) {
1189
-			return new ShareHelper(
1190
-				$c->get(\OCP\Share\IManager::class)
1191
-			);
1192
-		});
1188
+        $this->registerService(IShareHelper::class, function (ContainerInterface $c) {
1189
+            return new ShareHelper(
1190
+                $c->get(\OCP\Share\IManager::class)
1191
+            );
1192
+        });
1193 1193
 
1194
-		$this->registerService(IApiFactory::class, function (ContainerInterface $c) {
1195
-			return new ApiFactory($c->get(IClientService::class));
1196
-		});
1194
+        $this->registerService(IApiFactory::class, function (ContainerInterface $c) {
1195
+            return new ApiFactory($c->get(IClientService::class));
1196
+        });
1197 1197
 
1198
-		$this->registerService(IInstanceFactory::class, function (ContainerInterface $c) {
1199
-			$memcacheFactory = $c->get(ICacheFactory::class);
1200
-			return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->get(IClientService::class));
1201
-		});
1198
+        $this->registerService(IInstanceFactory::class, function (ContainerInterface $c) {
1199
+            $memcacheFactory = $c->get(ICacheFactory::class);
1200
+            return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->get(IClientService::class));
1201
+        });
1202 1202
 
1203
-		$this->registerAlias(IContactsStore::class, ContactsStore::class);
1204
-		$this->registerAlias(IAccountManager::class, AccountManager::class);
1203
+        $this->registerAlias(IContactsStore::class, ContactsStore::class);
1204
+        $this->registerAlias(IAccountManager::class, AccountManager::class);
1205 1205
 
1206
-		$this->registerAlias(IStorageFactory::class, StorageFactory::class);
1206
+        $this->registerAlias(IStorageFactory::class, StorageFactory::class);
1207 1207
 
1208
-		$this->registerAlias(\OCP\Dashboard\IManager::class, \OC\Dashboard\Manager::class);
1208
+        $this->registerAlias(\OCP\Dashboard\IManager::class, \OC\Dashboard\Manager::class);
1209 1209
 
1210
-		$this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class);
1211
-		$this->registerAlias(IFilesMetadataManager::class, FilesMetadataManager::class);
1210
+        $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class);
1211
+        $this->registerAlias(IFilesMetadataManager::class, FilesMetadataManager::class);
1212 1212
 
1213
-		$this->registerAlias(ISubAdmin::class, SubAdmin::class);
1213
+        $this->registerAlias(ISubAdmin::class, SubAdmin::class);
1214 1214
 
1215
-		$this->registerAlias(IInitialStateService::class, InitialStateService::class);
1215
+        $this->registerAlias(IInitialStateService::class, InitialStateService::class);
1216 1216
 
1217
-		$this->registerAlias(\OCP\IEmojiHelper::class, \OC\EmojiHelper::class);
1217
+        $this->registerAlias(\OCP\IEmojiHelper::class, \OC\EmojiHelper::class);
1218 1218
 
1219
-		$this->registerAlias(\OCP\UserStatus\IManager::class, \OC\UserStatus\Manager::class);
1219
+        $this->registerAlias(\OCP\UserStatus\IManager::class, \OC\UserStatus\Manager::class);
1220 1220
 
1221
-		$this->registerAlias(IBroker::class, Broker::class);
1221
+        $this->registerAlias(IBroker::class, Broker::class);
1222 1222
 
1223
-		$this->registerAlias(\OCP\Files\AppData\IAppDataFactory::class, \OC\Files\AppData\Factory::class);
1223
+        $this->registerAlias(\OCP\Files\AppData\IAppDataFactory::class, \OC\Files\AppData\Factory::class);
1224 1224
 
1225
-		$this->registerAlias(\OCP\Files\IFilenameValidator::class, \OC\Files\FilenameValidator::class);
1225
+        $this->registerAlias(\OCP\Files\IFilenameValidator::class, \OC\Files\FilenameValidator::class);
1226 1226
 
1227
-		$this->registerAlias(IBinaryFinder::class, BinaryFinder::class);
1227
+        $this->registerAlias(IBinaryFinder::class, BinaryFinder::class);
1228 1228
 
1229
-		$this->registerAlias(\OCP\Share\IPublicShareTemplateFactory::class, \OC\Share20\PublicShareTemplateFactory::class);
1229
+        $this->registerAlias(\OCP\Share\IPublicShareTemplateFactory::class, \OC\Share20\PublicShareTemplateFactory::class);
1230 1230
 
1231
-		$this->registerAlias(ITranslationManager::class, TranslationManager::class);
1231
+        $this->registerAlias(ITranslationManager::class, TranslationManager::class);
1232 1232
 
1233
-		$this->registerAlias(IConversionManager::class, ConversionManager::class);
1233
+        $this->registerAlias(IConversionManager::class, ConversionManager::class);
1234 1234
 
1235
-		$this->registerAlias(ISpeechToTextManager::class, SpeechToTextManager::class);
1235
+        $this->registerAlias(ISpeechToTextManager::class, SpeechToTextManager::class);
1236 1236
 
1237
-		$this->registerAlias(IEventSourceFactory::class, EventSourceFactory::class);
1237
+        $this->registerAlias(IEventSourceFactory::class, EventSourceFactory::class);
1238 1238
 
1239
-		$this->registerAlias(\OCP\TextProcessing\IManager::class, \OC\TextProcessing\Manager::class);
1239
+        $this->registerAlias(\OCP\TextProcessing\IManager::class, \OC\TextProcessing\Manager::class);
1240 1240
 
1241
-		$this->registerAlias(\OCP\TextToImage\IManager::class, \OC\TextToImage\Manager::class);
1241
+        $this->registerAlias(\OCP\TextToImage\IManager::class, \OC\TextToImage\Manager::class);
1242 1242
 
1243
-		$this->registerAlias(ILimiter::class, Limiter::class);
1243
+        $this->registerAlias(ILimiter::class, Limiter::class);
1244 1244
 
1245
-		$this->registerAlias(IPhoneNumberUtil::class, PhoneNumberUtil::class);
1245
+        $this->registerAlias(IPhoneNumberUtil::class, PhoneNumberUtil::class);
1246 1246
 
1247
-		// there is no reason for having OCMProvider as a Service
1248
-		$this->registerDeprecatedAlias(ICapabilityAwareOCMProvider::class, OCMProvider::class);
1249
-		$this->registerDeprecatedAlias(IOCMProvider::class, OCMProvider::class);
1247
+        // there is no reason for having OCMProvider as a Service
1248
+        $this->registerDeprecatedAlias(ICapabilityAwareOCMProvider::class, OCMProvider::class);
1249
+        $this->registerDeprecatedAlias(IOCMProvider::class, OCMProvider::class);
1250 1250
 
1251
-		$this->registerAlias(ISetupCheckManager::class, SetupCheckManager::class);
1251
+        $this->registerAlias(ISetupCheckManager::class, SetupCheckManager::class);
1252 1252
 
1253
-		$this->registerAlias(IProfileManager::class, ProfileManager::class);
1253
+        $this->registerAlias(IProfileManager::class, ProfileManager::class);
1254 1254
 
1255
-		$this->registerAlias(IAvailabilityCoordinator::class, AvailabilityCoordinator::class);
1255
+        $this->registerAlias(IAvailabilityCoordinator::class, AvailabilityCoordinator::class);
1256 1256
 
1257
-		$this->registerAlias(IDeclarativeManager::class, DeclarativeManager::class);
1257
+        $this->registerAlias(IDeclarativeManager::class, DeclarativeManager::class);
1258 1258
 
1259
-		$this->registerAlias(\OCP\TaskProcessing\IManager::class, \OC\TaskProcessing\Manager::class);
1259
+        $this->registerAlias(\OCP\TaskProcessing\IManager::class, \OC\TaskProcessing\Manager::class);
1260 1260
 
1261
-		$this->registerAlias(IRemoteAddress::class, RemoteAddress::class);
1261
+        $this->registerAlias(IRemoteAddress::class, RemoteAddress::class);
1262 1262
 
1263
-		$this->registerAlias(\OCP\Security\Ip\IFactory::class, \OC\Security\Ip\Factory::class);
1263
+        $this->registerAlias(\OCP\Security\Ip\IFactory::class, \OC\Security\Ip\Factory::class);
1264 1264
 
1265
-		$this->registerAlias(IRichTextFormatter::class, \OC\RichObjectStrings\RichTextFormatter::class);
1265
+        $this->registerAlias(IRichTextFormatter::class, \OC\RichObjectStrings\RichTextFormatter::class);
1266 1266
 
1267
-		$this->registerAlias(ISignatureManager::class, SignatureManager::class);
1267
+        $this->registerAlias(ISignatureManager::class, SignatureManager::class);
1268 1268
 
1269
-		$this->registerAlias(IGenerator::class, Generator::class);
1270
-		$this->registerService(ISequence::class, function (ContainerInterface $c): ISequence {
1271
-			if (PHP_SAPI !== 'cli') {
1272
-				$sequence = $c->get(APCuSequence::class);
1273
-				if ($sequence->isAvailable()) {
1274
-					return $sequence;
1275
-				}
1276
-			}
1277
-
1278
-			return $c->get(FileSequence::class);
1279
-		}, false);
1280
-		$this->registerAlias(IDecoder::class, Decoder::class);
1281
-
1282
-		$this->connectDispatcher();
1283
-	}
1284
-
1285
-	public function boot() {
1286
-		/** @var HookConnector $hookConnector */
1287
-		$hookConnector = $this->get(HookConnector::class);
1288
-		$hookConnector->viewToNode();
1289
-	}
1290
-
1291
-	private function connectDispatcher(): void {
1292
-		/** @var IEventDispatcher $eventDispatcher */
1293
-		$eventDispatcher = $this->get(IEventDispatcher::class);
1294
-		$eventDispatcher->addServiceListener(LoginFailed::class, LoginFailedListener::class);
1295
-		$eventDispatcher->addServiceListener(PostLoginEvent::class, UserLoggedInListener::class);
1296
-		$eventDispatcher->addServiceListener(UserChangedEvent::class, UserChangedListener::class);
1297
-		$eventDispatcher->addServiceListener(BeforeUserDeletedEvent::class, BeforeUserDeletedListener::class);
1298
-
1299
-		FilesMetadataManager::loadListeners($eventDispatcher);
1300
-		GenerateBlurhashMetadata::loadListeners($eventDispatcher);
1301
-	}
1302
-
1303
-	/**
1304
-	 * @return \OCP\Contacts\IManager
1305
-	 * @deprecated 20.0.0
1306
-	 */
1307
-	public function getContactsManager() {
1308
-		return $this->get(\OCP\Contacts\IManager::class);
1309
-	}
1310
-
1311
-	/**
1312
-	 * @return \OC\Encryption\Manager
1313
-	 * @deprecated 20.0.0
1314
-	 */
1315
-	public function getEncryptionManager() {
1316
-		return $this->get(\OCP\Encryption\IManager::class);
1317
-	}
1318
-
1319
-	/**
1320
-	 * @return \OC\Encryption\File
1321
-	 * @deprecated 20.0.0
1322
-	 */
1323
-	public function getEncryptionFilesHelper() {
1324
-		return $this->get(IFile::class);
1325
-	}
1326
-
1327
-	/**
1328
-	 * The current request object holding all information about the request
1329
-	 * currently being processed is returned from this method.
1330
-	 * In case the current execution was not initiated by a web request null is returned
1331
-	 *
1332
-	 * @return \OCP\IRequest
1333
-	 * @deprecated 20.0.0
1334
-	 */
1335
-	public function getRequest() {
1336
-		return $this->get(IRequest::class);
1337
-	}
1338
-
1339
-	/**
1340
-	 * Returns the root folder of ownCloud's data directory
1341
-	 *
1342
-	 * @return IRootFolder
1343
-	 * @deprecated 20.0.0
1344
-	 */
1345
-	public function getRootFolder() {
1346
-		return $this->get(IRootFolder::class);
1347
-	}
1348
-
1349
-	/**
1350
-	 * Returns the root folder of ownCloud's data directory
1351
-	 * This is the lazy variant so this gets only initialized once it
1352
-	 * is actually used.
1353
-	 *
1354
-	 * @return IRootFolder
1355
-	 * @deprecated 20.0.0
1356
-	 */
1357
-	public function getLazyRootFolder() {
1358
-		return $this->get(IRootFolder::class);
1359
-	}
1360
-
1361
-	/**
1362
-	 * Returns a view to ownCloud's files folder
1363
-	 *
1364
-	 * @param string $userId user ID
1365
-	 * @return \OCP\Files\Folder|null
1366
-	 * @deprecated 20.0.0
1367
-	 */
1368
-	public function getUserFolder($userId = null) {
1369
-		if ($userId === null) {
1370
-			$user = $this->get(IUserSession::class)->getUser();
1371
-			if (!$user) {
1372
-				return null;
1373
-			}
1374
-			$userId = $user->getUID();
1375
-		}
1376
-		$root = $this->get(IRootFolder::class);
1377
-		return $root->getUserFolder($userId);
1378
-	}
1379
-
1380
-	/**
1381
-	 * @return \OC\User\Manager
1382
-	 * @deprecated 20.0.0
1383
-	 */
1384
-	public function getUserManager() {
1385
-		return $this->get(IUserManager::class);
1386
-	}
1387
-
1388
-	/**
1389
-	 * @return \OC\Group\Manager
1390
-	 * @deprecated 20.0.0
1391
-	 */
1392
-	public function getGroupManager() {
1393
-		return $this->get(IGroupManager::class);
1394
-	}
1395
-
1396
-	/**
1397
-	 * @return \OC\User\Session
1398
-	 * @deprecated 20.0.0
1399
-	 */
1400
-	public function getUserSession() {
1401
-		return $this->get(IUserSession::class);
1402
-	}
1403
-
1404
-	/**
1405
-	 * @return \OCP\ISession
1406
-	 * @deprecated 20.0.0
1407
-	 */
1408
-	public function getSession() {
1409
-		return $this->get(Session::class)->getSession();
1410
-	}
1411
-
1412
-	/**
1413
-	 * @param \OCP\ISession $session
1414
-	 * @return void
1415
-	 */
1416
-	public function setSession(\OCP\ISession $session) {
1417
-		$this->get(SessionStorage::class)->setSession($session);
1418
-		$this->get(Session::class)->setSession($session);
1419
-		$this->get(Store::class)->setSession($session);
1420
-	}
1421
-
1422
-	/**
1423
-	 * @return \OCP\IConfig
1424
-	 * @deprecated 20.0.0
1425
-	 */
1426
-	public function getConfig() {
1427
-		return $this->get(AllConfig::class);
1428
-	}
1429
-
1430
-	/**
1431
-	 * @return \OC\SystemConfig
1432
-	 * @deprecated 20.0.0
1433
-	 */
1434
-	public function getSystemConfig() {
1435
-		return $this->get(SystemConfig::class);
1436
-	}
1437
-
1438
-	/**
1439
-	 * @return IFactory
1440
-	 * @deprecated 20.0.0
1441
-	 */
1442
-	public function getL10NFactory() {
1443
-		return $this->get(IFactory::class);
1444
-	}
1445
-
1446
-	/**
1447
-	 * get an L10N instance
1448
-	 *
1449
-	 * @param string $app appid
1450
-	 * @param string $lang
1451
-	 * @return IL10N
1452
-	 * @deprecated 20.0.0 use DI of {@see IL10N} or {@see IFactory} instead, or {@see \OCP\Util::getL10N()} as a last resort
1453
-	 */
1454
-	public function getL10N($app, $lang = null) {
1455
-		return $this->get(IFactory::class)->get($app, $lang);
1456
-	}
1457
-
1458
-	/**
1459
-	 * @return IURLGenerator
1460
-	 * @deprecated 20.0.0
1461
-	 */
1462
-	public function getURLGenerator() {
1463
-		return $this->get(IURLGenerator::class);
1464
-	}
1465
-
1466
-	/**
1467
-	 * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1468
-	 * getMemCacheFactory() instead.
1469
-	 *
1470
-	 * @return ICache
1471
-	 * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1472
-	 */
1473
-	public function getCache() {
1474
-		return $this->get(ICache::class);
1475
-	}
1476
-
1477
-	/**
1478
-	 * Returns an \OCP\CacheFactory instance
1479
-	 *
1480
-	 * @return \OCP\ICacheFactory
1481
-	 * @deprecated 20.0.0
1482
-	 */
1483
-	public function getMemCacheFactory() {
1484
-		return $this->get(ICacheFactory::class);
1485
-	}
1486
-
1487
-	/**
1488
-	 * Returns the current session
1489
-	 *
1490
-	 * @return \OCP\IDBConnection
1491
-	 * @deprecated 20.0.0
1492
-	 */
1493
-	public function getDatabaseConnection() {
1494
-		return $this->get(IDBConnection::class);
1495
-	}
1496
-
1497
-	/**
1498
-	 * Returns the activity manager
1499
-	 *
1500
-	 * @return \OCP\Activity\IManager
1501
-	 * @deprecated 20.0.0
1502
-	 */
1503
-	public function getActivityManager() {
1504
-		return $this->get(\OCP\Activity\IManager::class);
1505
-	}
1506
-
1507
-	/**
1508
-	 * Returns an job list for controlling background jobs
1509
-	 *
1510
-	 * @return IJobList
1511
-	 * @deprecated 20.0.0
1512
-	 */
1513
-	public function getJobList() {
1514
-		return $this->get(IJobList::class);
1515
-	}
1516
-
1517
-	/**
1518
-	 * Returns a SecureRandom instance
1519
-	 *
1520
-	 * @return \OCP\Security\ISecureRandom
1521
-	 * @deprecated 20.0.0
1522
-	 */
1523
-	public function getSecureRandom() {
1524
-		return $this->get(ISecureRandom::class);
1525
-	}
1526
-
1527
-	/**
1528
-	 * Returns a Crypto instance
1529
-	 *
1530
-	 * @return ICrypto
1531
-	 * @deprecated 20.0.0
1532
-	 */
1533
-	public function getCrypto() {
1534
-		return $this->get(ICrypto::class);
1535
-	}
1536
-
1537
-	/**
1538
-	 * Returns a Hasher instance
1539
-	 *
1540
-	 * @return IHasher
1541
-	 * @deprecated 20.0.0
1542
-	 */
1543
-	public function getHasher() {
1544
-		return $this->get(IHasher::class);
1545
-	}
1546
-
1547
-	/**
1548
-	 * Get the certificate manager
1549
-	 *
1550
-	 * @return \OCP\ICertificateManager
1551
-	 */
1552
-	public function getCertificateManager() {
1553
-		return $this->get(ICertificateManager::class);
1554
-	}
1555
-
1556
-	/**
1557
-	 * Get the manager for temporary files and folders
1558
-	 *
1559
-	 * @return \OCP\ITempManager
1560
-	 * @deprecated 20.0.0
1561
-	 */
1562
-	public function getTempManager() {
1563
-		return $this->get(ITempManager::class);
1564
-	}
1565
-
1566
-	/**
1567
-	 * Get the app manager
1568
-	 *
1569
-	 * @return \OCP\App\IAppManager
1570
-	 * @deprecated 20.0.0
1571
-	 */
1572
-	public function getAppManager() {
1573
-		return $this->get(IAppManager::class);
1574
-	}
1575
-
1576
-	/**
1577
-	 * Creates a new mailer
1578
-	 *
1579
-	 * @return IMailer
1580
-	 * @deprecated 20.0.0
1581
-	 */
1582
-	public function getMailer() {
1583
-		return $this->get(IMailer::class);
1584
-	}
1585
-
1586
-	/**
1587
-	 * Get the webroot
1588
-	 *
1589
-	 * @return string
1590
-	 * @deprecated 20.0.0
1591
-	 */
1592
-	public function getWebRoot() {
1593
-		return $this->webRoot;
1594
-	}
1595
-
1596
-	/**
1597
-	 * Get the locking provider
1598
-	 *
1599
-	 * @return ILockingProvider
1600
-	 * @since 8.1.0
1601
-	 * @deprecated 20.0.0
1602
-	 */
1603
-	public function getLockingProvider() {
1604
-		return $this->get(ILockingProvider::class);
1605
-	}
1606
-
1607
-	/**
1608
-	 * Get the MimeTypeDetector
1609
-	 *
1610
-	 * @return IMimeTypeDetector
1611
-	 * @deprecated 20.0.0
1612
-	 */
1613
-	public function getMimeTypeDetector() {
1614
-		return $this->get(IMimeTypeDetector::class);
1615
-	}
1616
-
1617
-	/**
1618
-	 * Get the MimeTypeLoader
1619
-	 *
1620
-	 * @return IMimeTypeLoader
1621
-	 * @deprecated 20.0.0
1622
-	 */
1623
-	public function getMimeTypeLoader() {
1624
-		return $this->get(IMimeTypeLoader::class);
1625
-	}
1626
-
1627
-	/**
1628
-	 * Get the Notification Manager
1629
-	 *
1630
-	 * @return \OCP\Notification\IManager
1631
-	 * @since 8.2.0
1632
-	 * @deprecated 20.0.0
1633
-	 */
1634
-	public function getNotificationManager() {
1635
-		return $this->get(\OCP\Notification\IManager::class);
1636
-	}
1637
-
1638
-	/**
1639
-	 * @return \OCA\Theming\ThemingDefaults
1640
-	 * @deprecated 20.0.0
1641
-	 */
1642
-	public function getThemingDefaults() {
1643
-		return $this->get('ThemingDefaults');
1644
-	}
1645
-
1646
-	/**
1647
-	 * @return \OC\IntegrityCheck\Checker
1648
-	 * @deprecated 20.0.0
1649
-	 */
1650
-	public function getIntegrityCodeChecker() {
1651
-		return $this->get('IntegrityCodeChecker');
1652
-	}
1653
-
1654
-	/**
1655
-	 * @return CsrfTokenManager
1656
-	 * @deprecated 20.0.0
1657
-	 */
1658
-	public function getCsrfTokenManager() {
1659
-		return $this->get(CsrfTokenManager::class);
1660
-	}
1661
-
1662
-	/**
1663
-	 * @return ContentSecurityPolicyNonceManager
1664
-	 * @deprecated 20.0.0
1665
-	 */
1666
-	public function getContentSecurityPolicyNonceManager() {
1667
-		return $this->get(ContentSecurityPolicyNonceManager::class);
1668
-	}
1669
-
1670
-	/**
1671
-	 * @return \OCP\Settings\IManager
1672
-	 * @deprecated 20.0.0
1673
-	 */
1674
-	public function getSettingsManager() {
1675
-		return $this->get(\OC\Settings\Manager::class);
1676
-	}
1677
-
1678
-	/**
1679
-	 * @return \OCP\Files\IAppData
1680
-	 * @deprecated 20.0.0 Use get(\OCP\Files\AppData\IAppDataFactory::class)->get($app) instead
1681
-	 */
1682
-	public function getAppDataDir($app) {
1683
-		$factory = $this->get(\OC\Files\AppData\Factory::class);
1684
-		return $factory->get($app);
1685
-	}
1686
-
1687
-	/**
1688
-	 * @return \OCP\Federation\ICloudIdManager
1689
-	 * @deprecated 20.0.0
1690
-	 */
1691
-	public function getCloudIdManager() {
1692
-		return $this->get(ICloudIdManager::class);
1693
-	}
1269
+        $this->registerAlias(IGenerator::class, Generator::class);
1270
+        $this->registerService(ISequence::class, function (ContainerInterface $c): ISequence {
1271
+            if (PHP_SAPI !== 'cli') {
1272
+                $sequence = $c->get(APCuSequence::class);
1273
+                if ($sequence->isAvailable()) {
1274
+                    return $sequence;
1275
+                }
1276
+            }
1277
+
1278
+            return $c->get(FileSequence::class);
1279
+        }, false);
1280
+        $this->registerAlias(IDecoder::class, Decoder::class);
1281
+
1282
+        $this->connectDispatcher();
1283
+    }
1284
+
1285
+    public function boot() {
1286
+        /** @var HookConnector $hookConnector */
1287
+        $hookConnector = $this->get(HookConnector::class);
1288
+        $hookConnector->viewToNode();
1289
+    }
1290
+
1291
+    private function connectDispatcher(): void {
1292
+        /** @var IEventDispatcher $eventDispatcher */
1293
+        $eventDispatcher = $this->get(IEventDispatcher::class);
1294
+        $eventDispatcher->addServiceListener(LoginFailed::class, LoginFailedListener::class);
1295
+        $eventDispatcher->addServiceListener(PostLoginEvent::class, UserLoggedInListener::class);
1296
+        $eventDispatcher->addServiceListener(UserChangedEvent::class, UserChangedListener::class);
1297
+        $eventDispatcher->addServiceListener(BeforeUserDeletedEvent::class, BeforeUserDeletedListener::class);
1298
+
1299
+        FilesMetadataManager::loadListeners($eventDispatcher);
1300
+        GenerateBlurhashMetadata::loadListeners($eventDispatcher);
1301
+    }
1302
+
1303
+    /**
1304
+     * @return \OCP\Contacts\IManager
1305
+     * @deprecated 20.0.0
1306
+     */
1307
+    public function getContactsManager() {
1308
+        return $this->get(\OCP\Contacts\IManager::class);
1309
+    }
1310
+
1311
+    /**
1312
+     * @return \OC\Encryption\Manager
1313
+     * @deprecated 20.0.0
1314
+     */
1315
+    public function getEncryptionManager() {
1316
+        return $this->get(\OCP\Encryption\IManager::class);
1317
+    }
1318
+
1319
+    /**
1320
+     * @return \OC\Encryption\File
1321
+     * @deprecated 20.0.0
1322
+     */
1323
+    public function getEncryptionFilesHelper() {
1324
+        return $this->get(IFile::class);
1325
+    }
1326
+
1327
+    /**
1328
+     * The current request object holding all information about the request
1329
+     * currently being processed is returned from this method.
1330
+     * In case the current execution was not initiated by a web request null is returned
1331
+     *
1332
+     * @return \OCP\IRequest
1333
+     * @deprecated 20.0.0
1334
+     */
1335
+    public function getRequest() {
1336
+        return $this->get(IRequest::class);
1337
+    }
1338
+
1339
+    /**
1340
+     * Returns the root folder of ownCloud's data directory
1341
+     *
1342
+     * @return IRootFolder
1343
+     * @deprecated 20.0.0
1344
+     */
1345
+    public function getRootFolder() {
1346
+        return $this->get(IRootFolder::class);
1347
+    }
1348
+
1349
+    /**
1350
+     * Returns the root folder of ownCloud's data directory
1351
+     * This is the lazy variant so this gets only initialized once it
1352
+     * is actually used.
1353
+     *
1354
+     * @return IRootFolder
1355
+     * @deprecated 20.0.0
1356
+     */
1357
+    public function getLazyRootFolder() {
1358
+        return $this->get(IRootFolder::class);
1359
+    }
1360
+
1361
+    /**
1362
+     * Returns a view to ownCloud's files folder
1363
+     *
1364
+     * @param string $userId user ID
1365
+     * @return \OCP\Files\Folder|null
1366
+     * @deprecated 20.0.0
1367
+     */
1368
+    public function getUserFolder($userId = null) {
1369
+        if ($userId === null) {
1370
+            $user = $this->get(IUserSession::class)->getUser();
1371
+            if (!$user) {
1372
+                return null;
1373
+            }
1374
+            $userId = $user->getUID();
1375
+        }
1376
+        $root = $this->get(IRootFolder::class);
1377
+        return $root->getUserFolder($userId);
1378
+    }
1379
+
1380
+    /**
1381
+     * @return \OC\User\Manager
1382
+     * @deprecated 20.0.0
1383
+     */
1384
+    public function getUserManager() {
1385
+        return $this->get(IUserManager::class);
1386
+    }
1387
+
1388
+    /**
1389
+     * @return \OC\Group\Manager
1390
+     * @deprecated 20.0.0
1391
+     */
1392
+    public function getGroupManager() {
1393
+        return $this->get(IGroupManager::class);
1394
+    }
1395
+
1396
+    /**
1397
+     * @return \OC\User\Session
1398
+     * @deprecated 20.0.0
1399
+     */
1400
+    public function getUserSession() {
1401
+        return $this->get(IUserSession::class);
1402
+    }
1403
+
1404
+    /**
1405
+     * @return \OCP\ISession
1406
+     * @deprecated 20.0.0
1407
+     */
1408
+    public function getSession() {
1409
+        return $this->get(Session::class)->getSession();
1410
+    }
1411
+
1412
+    /**
1413
+     * @param \OCP\ISession $session
1414
+     * @return void
1415
+     */
1416
+    public function setSession(\OCP\ISession $session) {
1417
+        $this->get(SessionStorage::class)->setSession($session);
1418
+        $this->get(Session::class)->setSession($session);
1419
+        $this->get(Store::class)->setSession($session);
1420
+    }
1421
+
1422
+    /**
1423
+     * @return \OCP\IConfig
1424
+     * @deprecated 20.0.0
1425
+     */
1426
+    public function getConfig() {
1427
+        return $this->get(AllConfig::class);
1428
+    }
1429
+
1430
+    /**
1431
+     * @return \OC\SystemConfig
1432
+     * @deprecated 20.0.0
1433
+     */
1434
+    public function getSystemConfig() {
1435
+        return $this->get(SystemConfig::class);
1436
+    }
1437
+
1438
+    /**
1439
+     * @return IFactory
1440
+     * @deprecated 20.0.0
1441
+     */
1442
+    public function getL10NFactory() {
1443
+        return $this->get(IFactory::class);
1444
+    }
1445
+
1446
+    /**
1447
+     * get an L10N instance
1448
+     *
1449
+     * @param string $app appid
1450
+     * @param string $lang
1451
+     * @return IL10N
1452
+     * @deprecated 20.0.0 use DI of {@see IL10N} or {@see IFactory} instead, or {@see \OCP\Util::getL10N()} as a last resort
1453
+     */
1454
+    public function getL10N($app, $lang = null) {
1455
+        return $this->get(IFactory::class)->get($app, $lang);
1456
+    }
1457
+
1458
+    /**
1459
+     * @return IURLGenerator
1460
+     * @deprecated 20.0.0
1461
+     */
1462
+    public function getURLGenerator() {
1463
+        return $this->get(IURLGenerator::class);
1464
+    }
1465
+
1466
+    /**
1467
+     * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1468
+     * getMemCacheFactory() instead.
1469
+     *
1470
+     * @return ICache
1471
+     * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1472
+     */
1473
+    public function getCache() {
1474
+        return $this->get(ICache::class);
1475
+    }
1476
+
1477
+    /**
1478
+     * Returns an \OCP\CacheFactory instance
1479
+     *
1480
+     * @return \OCP\ICacheFactory
1481
+     * @deprecated 20.0.0
1482
+     */
1483
+    public function getMemCacheFactory() {
1484
+        return $this->get(ICacheFactory::class);
1485
+    }
1486
+
1487
+    /**
1488
+     * Returns the current session
1489
+     *
1490
+     * @return \OCP\IDBConnection
1491
+     * @deprecated 20.0.0
1492
+     */
1493
+    public function getDatabaseConnection() {
1494
+        return $this->get(IDBConnection::class);
1495
+    }
1496
+
1497
+    /**
1498
+     * Returns the activity manager
1499
+     *
1500
+     * @return \OCP\Activity\IManager
1501
+     * @deprecated 20.0.0
1502
+     */
1503
+    public function getActivityManager() {
1504
+        return $this->get(\OCP\Activity\IManager::class);
1505
+    }
1506
+
1507
+    /**
1508
+     * Returns an job list for controlling background jobs
1509
+     *
1510
+     * @return IJobList
1511
+     * @deprecated 20.0.0
1512
+     */
1513
+    public function getJobList() {
1514
+        return $this->get(IJobList::class);
1515
+    }
1516
+
1517
+    /**
1518
+     * Returns a SecureRandom instance
1519
+     *
1520
+     * @return \OCP\Security\ISecureRandom
1521
+     * @deprecated 20.0.0
1522
+     */
1523
+    public function getSecureRandom() {
1524
+        return $this->get(ISecureRandom::class);
1525
+    }
1526
+
1527
+    /**
1528
+     * Returns a Crypto instance
1529
+     *
1530
+     * @return ICrypto
1531
+     * @deprecated 20.0.0
1532
+     */
1533
+    public function getCrypto() {
1534
+        return $this->get(ICrypto::class);
1535
+    }
1536
+
1537
+    /**
1538
+     * Returns a Hasher instance
1539
+     *
1540
+     * @return IHasher
1541
+     * @deprecated 20.0.0
1542
+     */
1543
+    public function getHasher() {
1544
+        return $this->get(IHasher::class);
1545
+    }
1546
+
1547
+    /**
1548
+     * Get the certificate manager
1549
+     *
1550
+     * @return \OCP\ICertificateManager
1551
+     */
1552
+    public function getCertificateManager() {
1553
+        return $this->get(ICertificateManager::class);
1554
+    }
1555
+
1556
+    /**
1557
+     * Get the manager for temporary files and folders
1558
+     *
1559
+     * @return \OCP\ITempManager
1560
+     * @deprecated 20.0.0
1561
+     */
1562
+    public function getTempManager() {
1563
+        return $this->get(ITempManager::class);
1564
+    }
1565
+
1566
+    /**
1567
+     * Get the app manager
1568
+     *
1569
+     * @return \OCP\App\IAppManager
1570
+     * @deprecated 20.0.0
1571
+     */
1572
+    public function getAppManager() {
1573
+        return $this->get(IAppManager::class);
1574
+    }
1575
+
1576
+    /**
1577
+     * Creates a new mailer
1578
+     *
1579
+     * @return IMailer
1580
+     * @deprecated 20.0.0
1581
+     */
1582
+    public function getMailer() {
1583
+        return $this->get(IMailer::class);
1584
+    }
1585
+
1586
+    /**
1587
+     * Get the webroot
1588
+     *
1589
+     * @return string
1590
+     * @deprecated 20.0.0
1591
+     */
1592
+    public function getWebRoot() {
1593
+        return $this->webRoot;
1594
+    }
1595
+
1596
+    /**
1597
+     * Get the locking provider
1598
+     *
1599
+     * @return ILockingProvider
1600
+     * @since 8.1.0
1601
+     * @deprecated 20.0.0
1602
+     */
1603
+    public function getLockingProvider() {
1604
+        return $this->get(ILockingProvider::class);
1605
+    }
1606
+
1607
+    /**
1608
+     * Get the MimeTypeDetector
1609
+     *
1610
+     * @return IMimeTypeDetector
1611
+     * @deprecated 20.0.0
1612
+     */
1613
+    public function getMimeTypeDetector() {
1614
+        return $this->get(IMimeTypeDetector::class);
1615
+    }
1616
+
1617
+    /**
1618
+     * Get the MimeTypeLoader
1619
+     *
1620
+     * @return IMimeTypeLoader
1621
+     * @deprecated 20.0.0
1622
+     */
1623
+    public function getMimeTypeLoader() {
1624
+        return $this->get(IMimeTypeLoader::class);
1625
+    }
1626
+
1627
+    /**
1628
+     * Get the Notification Manager
1629
+     *
1630
+     * @return \OCP\Notification\IManager
1631
+     * @since 8.2.0
1632
+     * @deprecated 20.0.0
1633
+     */
1634
+    public function getNotificationManager() {
1635
+        return $this->get(\OCP\Notification\IManager::class);
1636
+    }
1637
+
1638
+    /**
1639
+     * @return \OCA\Theming\ThemingDefaults
1640
+     * @deprecated 20.0.0
1641
+     */
1642
+    public function getThemingDefaults() {
1643
+        return $this->get('ThemingDefaults');
1644
+    }
1645
+
1646
+    /**
1647
+     * @return \OC\IntegrityCheck\Checker
1648
+     * @deprecated 20.0.0
1649
+     */
1650
+    public function getIntegrityCodeChecker() {
1651
+        return $this->get('IntegrityCodeChecker');
1652
+    }
1653
+
1654
+    /**
1655
+     * @return CsrfTokenManager
1656
+     * @deprecated 20.0.0
1657
+     */
1658
+    public function getCsrfTokenManager() {
1659
+        return $this->get(CsrfTokenManager::class);
1660
+    }
1661
+
1662
+    /**
1663
+     * @return ContentSecurityPolicyNonceManager
1664
+     * @deprecated 20.0.0
1665
+     */
1666
+    public function getContentSecurityPolicyNonceManager() {
1667
+        return $this->get(ContentSecurityPolicyNonceManager::class);
1668
+    }
1669
+
1670
+    /**
1671
+     * @return \OCP\Settings\IManager
1672
+     * @deprecated 20.0.0
1673
+     */
1674
+    public function getSettingsManager() {
1675
+        return $this->get(\OC\Settings\Manager::class);
1676
+    }
1677
+
1678
+    /**
1679
+     * @return \OCP\Files\IAppData
1680
+     * @deprecated 20.0.0 Use get(\OCP\Files\AppData\IAppDataFactory::class)->get($app) instead
1681
+     */
1682
+    public function getAppDataDir($app) {
1683
+        $factory = $this->get(\OC\Files\AppData\Factory::class);
1684
+        return $factory->get($app);
1685
+    }
1686
+
1687
+    /**
1688
+     * @return \OCP\Federation\ICloudIdManager
1689
+     * @deprecated 20.0.0
1690
+     */
1691
+    public function getCloudIdManager() {
1692
+        return $this->get(ICloudIdManager::class);
1693
+    }
1694 1694
 }
Please login to merge, or discard this patch.
lib/private/Collaboration/Collaborators/MailByMailPlugin.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -20,26 +20,26 @@
 block discarded – undo
20 20
  */
21 21
 class MailByMailPlugin extends MailPlugin {
22 22
 
23
-	public function __construct(
24
-		IManager $contactsManager,
25
-		ICloudIdManager $cloudIdManager,
26
-		IConfig $config,
27
-		IGroupManager $groupManager,
28
-		KnownUserService $knownUserService,
29
-		IUserSession $userSession,
30
-		IEmailValidator $emailValidator,
31
-		mixed $shareWithGroupOnlyExcludeGroupsList = [],
32
-	) {
33
-		parent::__construct(
34
-			$contactsManager,
35
-			$cloudIdManager,
36
-			$config,
37
-			$groupManager,
38
-			$knownUserService,
39
-			$userSession,
40
-			$emailValidator,
41
-			$shareWithGroupOnlyExcludeGroupsList,
42
-			IShare::TYPE_EMAIL,
43
-		);
44
-	}
23
+    public function __construct(
24
+        IManager $contactsManager,
25
+        ICloudIdManager $cloudIdManager,
26
+        IConfig $config,
27
+        IGroupManager $groupManager,
28
+        KnownUserService $knownUserService,
29
+        IUserSession $userSession,
30
+        IEmailValidator $emailValidator,
31
+        mixed $shareWithGroupOnlyExcludeGroupsList = [],
32
+    ) {
33
+        parent::__construct(
34
+            $contactsManager,
35
+            $cloudIdManager,
36
+            $config,
37
+            $groupManager,
38
+            $knownUserService,
39
+            $userSession,
40
+            $emailValidator,
41
+            $shareWithGroupOnlyExcludeGroupsList,
42
+            IShare::TYPE_EMAIL,
43
+        );
44
+    }
45 45
 }
Please login to merge, or discard this patch.
lib/private/Collaboration/Collaborators/UserByMailPlugin.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -20,26 +20,26 @@
 block discarded – undo
20 20
  */
21 21
 class UserByMailPlugin extends MailPlugin {
22 22
 
23
-	public function __construct(
24
-		IManager $contactsManager,
25
-		ICloudIdManager $cloudIdManager,
26
-		IConfig $config,
27
-		IGroupManager $groupManager,
28
-		KnownUserService $knownUserService,
29
-		IUserSession $userSession,
30
-		IEmailValidator $emailValidator,
31
-		mixed $shareWithGroupOnlyExcludeGroupsList = [],
32
-	) {
33
-		parent::__construct(
34
-			$contactsManager,
35
-			$cloudIdManager,
36
-			$config,
37
-			$groupManager,
38
-			$knownUserService,
39
-			$userSession,
40
-			$emailValidator,
41
-			$shareWithGroupOnlyExcludeGroupsList,
42
-			IShare::TYPE_USER,
43
-		);
44
-	}
23
+    public function __construct(
24
+        IManager $contactsManager,
25
+        ICloudIdManager $cloudIdManager,
26
+        IConfig $config,
27
+        IGroupManager $groupManager,
28
+        KnownUserService $knownUserService,
29
+        IUserSession $userSession,
30
+        IEmailValidator $emailValidator,
31
+        mixed $shareWithGroupOnlyExcludeGroupsList = [],
32
+    ) {
33
+        parent::__construct(
34
+            $contactsManager,
35
+            $cloudIdManager,
36
+            $config,
37
+            $groupManager,
38
+            $knownUserService,
39
+            $userSession,
40
+            $emailValidator,
41
+            $shareWithGroupOnlyExcludeGroupsList,
42
+            IShare::TYPE_USER,
43
+        );
44
+    }
45 45
 }
Please login to merge, or discard this patch.
lib/private/Collaboration/Collaborators/MailPlugin.php 1 patch
Indentation   +249 added lines, -249 removed lines patch added patch discarded remove patch
@@ -21,255 +21,255 @@
 block discarded – undo
21 21
 use OCP\Share\IShare;
22 22
 
23 23
 class MailPlugin implements ISearchPlugin {
24
-	protected bool $shareWithGroupOnly;
25
-
26
-	protected bool $shareeEnumeration;
27
-
28
-	protected bool $shareeEnumerationInGroupOnly;
29
-
30
-	protected bool $shareeEnumerationPhone;
31
-
32
-	protected bool $shareeEnumerationFullMatch;
33
-
34
-	protected bool $shareeEnumerationFullMatchEmail;
35
-
36
-	public function __construct(
37
-		private IManager $contactsManager,
38
-		private ICloudIdManager $cloudIdManager,
39
-		private IConfig $config,
40
-		private IGroupManager $groupManager,
41
-		private KnownUserService $knownUserService,
42
-		private IUserSession $userSession,
43
-		private IEmailValidator $emailValidator,
44
-		private mixed $shareWithGroupOnlyExcludeGroupsList,
45
-		private int $shareType,
46
-	) {
47
-		$this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes';
48
-		$this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes';
49
-		$this->shareeEnumerationInGroupOnly = $this->shareeEnumeration && $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no') === 'yes';
50
-		$this->shareeEnumerationPhone = $this->shareeEnumeration && $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_phone', 'no') === 'yes';
51
-		$this->shareeEnumerationFullMatch = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match', 'yes') === 'yes';
52
-		$this->shareeEnumerationFullMatchEmail = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_email', 'yes') === 'yes';
53
-
54
-		if ($this->shareWithGroupOnly) {
55
-			$this->shareWithGroupOnlyExcludeGroupsList = json_decode($this->config->getAppValue('core', 'shareapi_only_share_with_group_members_exclude_group_list', ''), true) ?? [];
56
-		}
57
-	}
58
-
59
-	/**
60
-	 * {@inheritdoc}
61
-	 */
62
-	public function search($search, $limit, $offset, ISearchResult $searchResult): bool {
63
-		if ($this->shareeEnumerationFullMatch && !$this->shareeEnumerationFullMatchEmail) {
64
-			return false;
65
-		}
66
-
67
-		// Extract the email address from "Foo Bar <[email protected]>" and then search with "[email protected]" instead
68
-		$result = preg_match('/<([^@]+@.+)>$/', $search, $matches);
69
-		if ($result && filter_var($matches[1], FILTER_VALIDATE_EMAIL)) {
70
-			return $this->search($matches[1], $limit, $offset, $searchResult);
71
-		}
72
-
73
-		$currentUserId = $this->userSession->getUser()->getUID();
74
-
75
-		$result = $userResults = ['wide' => [], 'exact' => []];
76
-		$userType = new SearchResultType('users');
77
-		$emailType = new SearchResultType('emails');
78
-
79
-		// Search in contacts
80
-		$addressBookContacts = $this->contactsManager->search(
81
-			$search,
82
-			['EMAIL', 'FN'],
83
-			[
84
-				'limit' => $limit,
85
-				'offset' => $offset,
86
-				'enumeration' => $this->shareeEnumeration,
87
-				'fullmatch' => $this->shareeEnumerationFullMatch,
88
-			]
89
-		);
90
-		$lowerSearch = strtolower($search);
91
-		foreach ($addressBookContacts as $contact) {
92
-			if (isset($contact['EMAIL'])) {
93
-				$emailAddresses = $contact['EMAIL'];
94
-				if (\is_string($emailAddresses)) {
95
-					$emailAddresses = [$emailAddresses];
96
-				}
97
-				foreach ($emailAddresses as $type => $emailAddress) {
98
-					$displayName = $emailAddress;
99
-					$emailAddressType = null;
100
-					if (\is_array($emailAddress)) {
101
-						$emailAddressData = $emailAddress;
102
-						$emailAddress = $emailAddressData['value'];
103
-						$emailAddressType = $emailAddressData['type'];
104
-					}
105
-
106
-					if (!filter_var($emailAddress, FILTER_VALIDATE_EMAIL)) {
107
-						continue;
108
-					}
109
-
110
-					if (isset($contact['FN'])) {
111
-						$displayName = $contact['FN'] . ' (' . $emailAddress . ')';
112
-					}
113
-					$exactEmailMatch = strtolower($emailAddress) === $lowerSearch;
114
-
115
-					if (isset($contact['isLocalSystemBook'])) {
116
-						if ($this->shareWithGroupOnly) {
117
-							/*
24
+    protected bool $shareWithGroupOnly;
25
+
26
+    protected bool $shareeEnumeration;
27
+
28
+    protected bool $shareeEnumerationInGroupOnly;
29
+
30
+    protected bool $shareeEnumerationPhone;
31
+
32
+    protected bool $shareeEnumerationFullMatch;
33
+
34
+    protected bool $shareeEnumerationFullMatchEmail;
35
+
36
+    public function __construct(
37
+        private IManager $contactsManager,
38
+        private ICloudIdManager $cloudIdManager,
39
+        private IConfig $config,
40
+        private IGroupManager $groupManager,
41
+        private KnownUserService $knownUserService,
42
+        private IUserSession $userSession,
43
+        private IEmailValidator $emailValidator,
44
+        private mixed $shareWithGroupOnlyExcludeGroupsList,
45
+        private int $shareType,
46
+    ) {
47
+        $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes';
48
+        $this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes';
49
+        $this->shareeEnumerationInGroupOnly = $this->shareeEnumeration && $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no') === 'yes';
50
+        $this->shareeEnumerationPhone = $this->shareeEnumeration && $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_phone', 'no') === 'yes';
51
+        $this->shareeEnumerationFullMatch = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match', 'yes') === 'yes';
52
+        $this->shareeEnumerationFullMatchEmail = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_email', 'yes') === 'yes';
53
+
54
+        if ($this->shareWithGroupOnly) {
55
+            $this->shareWithGroupOnlyExcludeGroupsList = json_decode($this->config->getAppValue('core', 'shareapi_only_share_with_group_members_exclude_group_list', ''), true) ?? [];
56
+        }
57
+    }
58
+
59
+    /**
60
+     * {@inheritdoc}
61
+     */
62
+    public function search($search, $limit, $offset, ISearchResult $searchResult): bool {
63
+        if ($this->shareeEnumerationFullMatch && !$this->shareeEnumerationFullMatchEmail) {
64
+            return false;
65
+        }
66
+
67
+        // Extract the email address from "Foo Bar <[email protected]>" and then search with "[email protected]" instead
68
+        $result = preg_match('/<([^@]+@.+)>$/', $search, $matches);
69
+        if ($result && filter_var($matches[1], FILTER_VALIDATE_EMAIL)) {
70
+            return $this->search($matches[1], $limit, $offset, $searchResult);
71
+        }
72
+
73
+        $currentUserId = $this->userSession->getUser()->getUID();
74
+
75
+        $result = $userResults = ['wide' => [], 'exact' => []];
76
+        $userType = new SearchResultType('users');
77
+        $emailType = new SearchResultType('emails');
78
+
79
+        // Search in contacts
80
+        $addressBookContacts = $this->contactsManager->search(
81
+            $search,
82
+            ['EMAIL', 'FN'],
83
+            [
84
+                'limit' => $limit,
85
+                'offset' => $offset,
86
+                'enumeration' => $this->shareeEnumeration,
87
+                'fullmatch' => $this->shareeEnumerationFullMatch,
88
+            ]
89
+        );
90
+        $lowerSearch = strtolower($search);
91
+        foreach ($addressBookContacts as $contact) {
92
+            if (isset($contact['EMAIL'])) {
93
+                $emailAddresses = $contact['EMAIL'];
94
+                if (\is_string($emailAddresses)) {
95
+                    $emailAddresses = [$emailAddresses];
96
+                }
97
+                foreach ($emailAddresses as $type => $emailAddress) {
98
+                    $displayName = $emailAddress;
99
+                    $emailAddressType = null;
100
+                    if (\is_array($emailAddress)) {
101
+                        $emailAddressData = $emailAddress;
102
+                        $emailAddress = $emailAddressData['value'];
103
+                        $emailAddressType = $emailAddressData['type'];
104
+                    }
105
+
106
+                    if (!filter_var($emailAddress, FILTER_VALIDATE_EMAIL)) {
107
+                        continue;
108
+                    }
109
+
110
+                    if (isset($contact['FN'])) {
111
+                        $displayName = $contact['FN'] . ' (' . $emailAddress . ')';
112
+                    }
113
+                    $exactEmailMatch = strtolower($emailAddress) === $lowerSearch;
114
+
115
+                    if (isset($contact['isLocalSystemBook'])) {
116
+                        if ($this->shareWithGroupOnly) {
117
+                            /*
118 118
 							 * Check if the user may share with the user associated with the e-mail of the just found contact
119 119
 							 */
120
-							$userGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser());
121
-
122
-							// ShareWithGroupOnly filtering
123
-							$userGroups = array_diff($userGroups, $this->shareWithGroupOnlyExcludeGroupsList);
124
-
125
-							$found = false;
126
-							foreach ($userGroups as $userGroup) {
127
-								if ($this->groupManager->isInGroup($contact['UID'], $userGroup)) {
128
-									$found = true;
129
-									break;
130
-								}
131
-							}
132
-							if (!$found) {
133
-								continue;
134
-							}
135
-						}
136
-						if ($exactEmailMatch && $this->shareeEnumerationFullMatch) {
137
-							try {
138
-								$cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0] ?? '');
139
-							} catch (\InvalidArgumentException $e) {
140
-								continue;
141
-							}
142
-
143
-							if ($this->shareType === IShare::TYPE_USER && !$this->isCurrentUser($cloud) && !$searchResult->hasResult($userType, $cloud->getUser())) {
144
-								$singleResult = [[
145
-									'label' => $displayName,
146
-									'uuid' => $contact['UID'] ?? $emailAddress,
147
-									'name' => $contact['FN'] ?? $displayName,
148
-									'value' => [
149
-										'shareType' => IShare::TYPE_USER,
150
-										'shareWith' => $cloud->getUser(),
151
-									],
152
-									'shareWithDisplayNameUnique' => !empty($emailAddress) ? $emailAddress : $cloud->getUser()
153
-
154
-								]];
155
-								$searchResult->addResultSet($userType, [], $singleResult);
156
-								$searchResult->markExactIdMatch($emailType);
157
-							}
158
-							return false;
159
-						}
160
-
161
-						if ($this->shareeEnumeration) {
162
-							try {
163
-								if (!isset($contact['CLOUD'])) {
164
-									continue;
165
-								}
166
-								$cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0] ?? '');
167
-							} catch (\InvalidArgumentException $e) {
168
-								continue;
169
-							}
170
-
171
-							$addToWide = !($this->shareeEnumerationInGroupOnly || $this->shareeEnumerationPhone);
172
-							if (!$addToWide && $this->shareeEnumerationPhone && $this->knownUserService->isKnownToUser($currentUserId, $contact['UID'])) {
173
-								$addToWide = true;
174
-							}
175
-
176
-							if (!$addToWide && $this->shareeEnumerationInGroupOnly) {
177
-								$addToWide = false;
178
-								$userGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser());
179
-								foreach ($userGroups as $userGroup) {
180
-									if ($this->groupManager->isInGroup($contact['UID'], $userGroup)) {
181
-										$addToWide = true;
182
-										break;
183
-									}
184
-								}
185
-							}
186
-							if ($addToWide && !$this->isCurrentUser($cloud) && !$searchResult->hasResult($userType, $cloud->getUser())) {
187
-								if ($this->shareType === IShare::TYPE_USER) {
188
-									$userResults['wide'][] = [
189
-										'label' => $displayName,
190
-										'uuid' => $contact['UID'] ?? $emailAddress,
191
-										'name' => $contact['FN'] ?? $displayName,
192
-										'value' => [
193
-											'shareType' => IShare::TYPE_USER,
194
-											'shareWith' => $cloud->getUser(),
195
-										],
196
-										'shareWithDisplayNameUnique' => !empty($emailAddress) ? $emailAddress : $cloud->getUser()
197
-									];
198
-								}
199
-								continue;
200
-							}
201
-						}
202
-						continue;
203
-					}
204
-
205
-					if ($this->shareType !== IShare::TYPE_EMAIL) {
206
-						continue;
207
-					}
208
-
209
-					if ($exactEmailMatch
210
-						|| (isset($contact['FN']) && strtolower($contact['FN']) === $lowerSearch)) {
211
-						if ($exactEmailMatch) {
212
-							$searchResult->markExactIdMatch($emailType);
213
-						}
214
-						$result['exact'][] = [
215
-							'label' => $displayName,
216
-							'uuid' => $contact['UID'] ?? $emailAddress,
217
-							'name' => $contact['FN'] ?? $displayName,
218
-							'type' => $emailAddressType ?? '',
219
-							'value' => [
220
-								'shareType' => IShare::TYPE_EMAIL,
221
-								'shareWith' => $emailAddress,
222
-							],
223
-						];
224
-					} else {
225
-						$result['wide'][] = [
226
-							'label' => $displayName,
227
-							'uuid' => $contact['UID'] ?? $emailAddress,
228
-							'name' => $contact['FN'] ?? $displayName,
229
-							'type' => $emailAddressType ?? '',
230
-							'value' => [
231
-								'shareType' => IShare::TYPE_EMAIL,
232
-								'shareWith' => $emailAddress,
233
-							],
234
-						];
235
-					}
236
-				}
237
-			}
238
-		}
239
-
240
-		$reachedEnd = true;
241
-		if ($this->shareeEnumeration) {
242
-			$reachedEnd = (count($result['wide']) < $offset + $limit)
243
-				&& (count($userResults['wide']) < $offset + $limit);
244
-
245
-			$result['wide'] = array_slice($result['wide'], $offset, $limit);
246
-			$userResults['wide'] = array_slice($userResults['wide'], $offset, $limit);
247
-		}
248
-
249
-		if ($this->shareType === IShare::TYPE_EMAIL
250
-				&& !$searchResult->hasExactIdMatch($emailType) && $this->emailValidator->isValid($search)) {
251
-			$result['exact'][] = [
252
-				'label' => $search,
253
-				'uuid' => $search,
254
-				'value' => [
255
-					'shareType' => IShare::TYPE_EMAIL,
256
-					'shareWith' => $search,
257
-				],
258
-			];
259
-		}
260
-
261
-		if ($this->shareType === IShare::TYPE_USER && !empty($userResults['wide'])) {
262
-			$searchResult->addResultSet($userType, $userResults['wide'], []);
263
-		}
264
-		if ($this->shareType === IShare::TYPE_EMAIL) {
265
-			$searchResult->addResultSet($emailType, $result['wide'], $result['exact']);
266
-		}
267
-
268
-		return !$reachedEnd;
269
-	}
270
-
271
-	public function isCurrentUser(ICloudId $cloud): bool {
272
-		$currentUser = $this->userSession->getUser();
273
-		return $currentUser instanceof IUser && $currentUser->getUID() === $cloud->getUser();
274
-	}
120
+                            $userGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser());
121
+
122
+                            // ShareWithGroupOnly filtering
123
+                            $userGroups = array_diff($userGroups, $this->shareWithGroupOnlyExcludeGroupsList);
124
+
125
+                            $found = false;
126
+                            foreach ($userGroups as $userGroup) {
127
+                                if ($this->groupManager->isInGroup($contact['UID'], $userGroup)) {
128
+                                    $found = true;
129
+                                    break;
130
+                                }
131
+                            }
132
+                            if (!$found) {
133
+                                continue;
134
+                            }
135
+                        }
136
+                        if ($exactEmailMatch && $this->shareeEnumerationFullMatch) {
137
+                            try {
138
+                                $cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0] ?? '');
139
+                            } catch (\InvalidArgumentException $e) {
140
+                                continue;
141
+                            }
142
+
143
+                            if ($this->shareType === IShare::TYPE_USER && !$this->isCurrentUser($cloud) && !$searchResult->hasResult($userType, $cloud->getUser())) {
144
+                                $singleResult = [[
145
+                                    'label' => $displayName,
146
+                                    'uuid' => $contact['UID'] ?? $emailAddress,
147
+                                    'name' => $contact['FN'] ?? $displayName,
148
+                                    'value' => [
149
+                                        'shareType' => IShare::TYPE_USER,
150
+                                        'shareWith' => $cloud->getUser(),
151
+                                    ],
152
+                                    'shareWithDisplayNameUnique' => !empty($emailAddress) ? $emailAddress : $cloud->getUser()
153
+
154
+                                ]];
155
+                                $searchResult->addResultSet($userType, [], $singleResult);
156
+                                $searchResult->markExactIdMatch($emailType);
157
+                            }
158
+                            return false;
159
+                        }
160
+
161
+                        if ($this->shareeEnumeration) {
162
+                            try {
163
+                                if (!isset($contact['CLOUD'])) {
164
+                                    continue;
165
+                                }
166
+                                $cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0] ?? '');
167
+                            } catch (\InvalidArgumentException $e) {
168
+                                continue;
169
+                            }
170
+
171
+                            $addToWide = !($this->shareeEnumerationInGroupOnly || $this->shareeEnumerationPhone);
172
+                            if (!$addToWide && $this->shareeEnumerationPhone && $this->knownUserService->isKnownToUser($currentUserId, $contact['UID'])) {
173
+                                $addToWide = true;
174
+                            }
175
+
176
+                            if (!$addToWide && $this->shareeEnumerationInGroupOnly) {
177
+                                $addToWide = false;
178
+                                $userGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser());
179
+                                foreach ($userGroups as $userGroup) {
180
+                                    if ($this->groupManager->isInGroup($contact['UID'], $userGroup)) {
181
+                                        $addToWide = true;
182
+                                        break;
183
+                                    }
184
+                                }
185
+                            }
186
+                            if ($addToWide && !$this->isCurrentUser($cloud) && !$searchResult->hasResult($userType, $cloud->getUser())) {
187
+                                if ($this->shareType === IShare::TYPE_USER) {
188
+                                    $userResults['wide'][] = [
189
+                                        'label' => $displayName,
190
+                                        'uuid' => $contact['UID'] ?? $emailAddress,
191
+                                        'name' => $contact['FN'] ?? $displayName,
192
+                                        'value' => [
193
+                                            'shareType' => IShare::TYPE_USER,
194
+                                            'shareWith' => $cloud->getUser(),
195
+                                        ],
196
+                                        'shareWithDisplayNameUnique' => !empty($emailAddress) ? $emailAddress : $cloud->getUser()
197
+                                    ];
198
+                                }
199
+                                continue;
200
+                            }
201
+                        }
202
+                        continue;
203
+                    }
204
+
205
+                    if ($this->shareType !== IShare::TYPE_EMAIL) {
206
+                        continue;
207
+                    }
208
+
209
+                    if ($exactEmailMatch
210
+                        || (isset($contact['FN']) && strtolower($contact['FN']) === $lowerSearch)) {
211
+                        if ($exactEmailMatch) {
212
+                            $searchResult->markExactIdMatch($emailType);
213
+                        }
214
+                        $result['exact'][] = [
215
+                            'label' => $displayName,
216
+                            'uuid' => $contact['UID'] ?? $emailAddress,
217
+                            'name' => $contact['FN'] ?? $displayName,
218
+                            'type' => $emailAddressType ?? '',
219
+                            'value' => [
220
+                                'shareType' => IShare::TYPE_EMAIL,
221
+                                'shareWith' => $emailAddress,
222
+                            ],
223
+                        ];
224
+                    } else {
225
+                        $result['wide'][] = [
226
+                            'label' => $displayName,
227
+                            'uuid' => $contact['UID'] ?? $emailAddress,
228
+                            'name' => $contact['FN'] ?? $displayName,
229
+                            'type' => $emailAddressType ?? '',
230
+                            'value' => [
231
+                                'shareType' => IShare::TYPE_EMAIL,
232
+                                'shareWith' => $emailAddress,
233
+                            ],
234
+                        ];
235
+                    }
236
+                }
237
+            }
238
+        }
239
+
240
+        $reachedEnd = true;
241
+        if ($this->shareeEnumeration) {
242
+            $reachedEnd = (count($result['wide']) < $offset + $limit)
243
+                && (count($userResults['wide']) < $offset + $limit);
244
+
245
+            $result['wide'] = array_slice($result['wide'], $offset, $limit);
246
+            $userResults['wide'] = array_slice($userResults['wide'], $offset, $limit);
247
+        }
248
+
249
+        if ($this->shareType === IShare::TYPE_EMAIL
250
+                && !$searchResult->hasExactIdMatch($emailType) && $this->emailValidator->isValid($search)) {
251
+            $result['exact'][] = [
252
+                'label' => $search,
253
+                'uuid' => $search,
254
+                'value' => [
255
+                    'shareType' => IShare::TYPE_EMAIL,
256
+                    'shareWith' => $search,
257
+                ],
258
+            ];
259
+        }
260
+
261
+        if ($this->shareType === IShare::TYPE_USER && !empty($userResults['wide'])) {
262
+            $searchResult->addResultSet($userType, $userResults['wide'], []);
263
+        }
264
+        if ($this->shareType === IShare::TYPE_EMAIL) {
265
+            $searchResult->addResultSet($emailType, $result['wide'], $result['exact']);
266
+        }
267
+
268
+        return !$reachedEnd;
269
+    }
270
+
271
+    public function isCurrentUser(ICloudId $cloud): bool {
272
+        $currentUser = $this->userSession->getUser();
273
+        return $currentUser instanceof IUser && $currentUser->getUID() === $cloud->getUser();
274
+    }
275 275
 }
Please login to merge, or discard this patch.
tests/lib/Collaboration/Collaborators/MailPluginTest.php 1 patch
Indentation   +1050 added lines, -1050 removed lines patch added patch discarded remove patch
@@ -27,1102 +27,1102 @@
 block discarded – undo
27 27
 use Test\Traits\EmailValidatorTrait;
28 28
 
29 29
 class MailPluginTest extends TestCase {
30
-	use EmailValidatorTrait;
30
+    use EmailValidatorTrait;
31 31
 
32
-	/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
33
-	protected $config;
32
+    /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
33
+    protected $config;
34 34
 
35
-	/** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
36
-	protected $contactsManager;
35
+    /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
36
+    protected $contactsManager;
37 37
 
38
-	/** @var ICloudIdManager|\PHPUnit\Framework\MockObject\MockObject */
39
-	protected $cloudIdManager;
38
+    /** @var ICloudIdManager|\PHPUnit\Framework\MockObject\MockObject */
39
+    protected $cloudIdManager;
40 40
 
41
-	/** @var MailPlugin */
42
-	protected $plugin;
41
+    /** @var MailPlugin */
42
+    protected $plugin;
43 43
 
44
-	/** @var SearchResult */
45
-	protected $searchResult;
44
+    /** @var SearchResult */
45
+    protected $searchResult;
46 46
 
47
-	/** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */
48
-	protected $groupManager;
47
+    /** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */
48
+    protected $groupManager;
49 49
 
50
-	/** @var KnownUserService|\PHPUnit\Framework\MockObject\MockObject */
51
-	protected $knownUserService;
50
+    /** @var KnownUserService|\PHPUnit\Framework\MockObject\MockObject */
51
+    protected $knownUserService;
52 52
 
53
-	/** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
54
-	protected $userSession;
53
+    /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
54
+    protected $userSession;
55 55
 
56
-	protected function setUp(): void {
57
-		parent::setUp();
56
+    protected function setUp(): void {
57
+        parent::setUp();
58 58
 
59
-		$this->config = $this->createMock(IConfig::class);
60
-		$this->contactsManager = $this->createMock(IManager::class);
61
-		$this->groupManager = $this->createMock(IGroupManager::class);
62
-		$this->knownUserService = $this->createMock(KnownUserService::class);
63
-		$this->userSession = $this->createMock(IUserSession::class);
64
-		$this->cloudIdManager = new CloudIdManager(
65
-			$this->createMock(ICacheFactory::class),
66
-			$this->createMock(IEventDispatcher::class),
67
-			$this->contactsManager,
68
-			$this->createMock(IURLGenerator::class),
69
-			$this->createMock(IUserManager::class),
70
-		);
59
+        $this->config = $this->createMock(IConfig::class);
60
+        $this->contactsManager = $this->createMock(IManager::class);
61
+        $this->groupManager = $this->createMock(IGroupManager::class);
62
+        $this->knownUserService = $this->createMock(KnownUserService::class);
63
+        $this->userSession = $this->createMock(IUserSession::class);
64
+        $this->cloudIdManager = new CloudIdManager(
65
+            $this->createMock(ICacheFactory::class),
66
+            $this->createMock(IEventDispatcher::class),
67
+            $this->contactsManager,
68
+            $this->createMock(IURLGenerator::class),
69
+            $this->createMock(IUserManager::class),
70
+        );
71 71
 
72
-		$this->searchResult = new SearchResult();
73
-	}
72
+        $this->searchResult = new SearchResult();
73
+    }
74 74
 
75
-	public function instantiatePlugin(int $shareType) {
76
-		$this->plugin = new MailPlugin(
77
-			$this->contactsManager,
78
-			$this->cloudIdManager,
79
-			$this->config,
80
-			$this->groupManager,
81
-			$this->knownUserService,
82
-			$this->userSession,
83
-			$this->getEmailValidatorWithStrictEmailCheck(),
84
-			[],
85
-			$shareType,
86
-		);
87
-	}
75
+    public function instantiatePlugin(int $shareType) {
76
+        $this->plugin = new MailPlugin(
77
+            $this->contactsManager,
78
+            $this->cloudIdManager,
79
+            $this->config,
80
+            $this->groupManager,
81
+            $this->knownUserService,
82
+            $this->userSession,
83
+            $this->getEmailValidatorWithStrictEmailCheck(),
84
+            [],
85
+            $shareType,
86
+        );
87
+    }
88 88
 
89
-	/**
90
-	 *
91
-	 * @param string $searchTerm
92
-	 * @param array $contacts
93
-	 * @param bool $shareeEnumeration
94
-	 * @param array $expectedResult
95
-	 * @param bool $expectedExactIdMatch
96
-	 * @param bool $expectedMoreResults
97
-	 * @param bool $validEmail
98
-	 */
99
-	#[\PHPUnit\Framework\Attributes\DataProvider('dataSearchEmail')]
100
-	public function testSearchEmail($searchTerm, $contacts, $shareeEnumeration, $expectedResult, $expectedExactIdMatch, $expectedMoreResults, $validEmail): void {
101
-		$this->config->expects($this->any())
102
-			->method('getAppValue')
103
-			->willReturnCallback(
104
-				function ($appName, $key, $default) use ($shareeEnumeration) {
105
-					if ($appName === 'core' && $key === 'shareapi_allow_share_dialog_user_enumeration') {
106
-						return $shareeEnumeration ? 'yes' : 'no';
107
-					}
108
-					return $default;
109
-				}
110
-			);
89
+    /**
90
+     *
91
+     * @param string $searchTerm
92
+     * @param array $contacts
93
+     * @param bool $shareeEnumeration
94
+     * @param array $expectedResult
95
+     * @param bool $expectedExactIdMatch
96
+     * @param bool $expectedMoreResults
97
+     * @param bool $validEmail
98
+     */
99
+    #[\PHPUnit\Framework\Attributes\DataProvider('dataSearchEmail')]
100
+    public function testSearchEmail($searchTerm, $contacts, $shareeEnumeration, $expectedResult, $expectedExactIdMatch, $expectedMoreResults, $validEmail): void {
101
+        $this->config->expects($this->any())
102
+            ->method('getAppValue')
103
+            ->willReturnCallback(
104
+                function ($appName, $key, $default) use ($shareeEnumeration) {
105
+                    if ($appName === 'core' && $key === 'shareapi_allow_share_dialog_user_enumeration') {
106
+                        return $shareeEnumeration ? 'yes' : 'no';
107
+                    }
108
+                    return $default;
109
+                }
110
+            );
111 111
 
112
-		$this->instantiatePlugin(IShare::TYPE_EMAIL);
112
+        $this->instantiatePlugin(IShare::TYPE_EMAIL);
113 113
 
114
-		$currentUser = $this->createMock(IUser::class);
115
-		$currentUser->method('getUID')
116
-			->willReturn('current');
117
-		$this->userSession->method('getUser')
118
-			->willReturn($currentUser);
114
+        $currentUser = $this->createMock(IUser::class);
115
+        $currentUser->method('getUID')
116
+            ->willReturn('current');
117
+        $this->userSession->method('getUser')
118
+            ->willReturn($currentUser);
119 119
 
120
-		$this->contactsManager->expects($this->any())
121
-			->method('search')
122
-			->willReturnCallback(function ($search, $searchAttributes) use ($searchTerm, $contacts) {
123
-				if ($search === $searchTerm) {
124
-					return $contacts;
125
-				}
126
-				return [];
127
-			});
120
+        $this->contactsManager->expects($this->any())
121
+            ->method('search')
122
+            ->willReturnCallback(function ($search, $searchAttributes) use ($searchTerm, $contacts) {
123
+                if ($search === $searchTerm) {
124
+                    return $contacts;
125
+                }
126
+                return [];
127
+            });
128 128
 
129
-		$moreResults = $this->plugin->search($searchTerm, 2, 0, $this->searchResult);
130
-		$result = $this->searchResult->asArray();
129
+        $moreResults = $this->plugin->search($searchTerm, 2, 0, $this->searchResult);
130
+        $result = $this->searchResult->asArray();
131 131
 
132
-		$this->assertSame($expectedExactIdMatch, $this->searchResult->hasExactIdMatch(new SearchResultType('emails')));
133
-		$this->assertEquals($expectedResult, $result);
134
-		$this->assertSame($expectedMoreResults, $moreResults);
135
-	}
132
+        $this->assertSame($expectedExactIdMatch, $this->searchResult->hasExactIdMatch(new SearchResultType('emails')));
133
+        $this->assertEquals($expectedResult, $result);
134
+        $this->assertSame($expectedMoreResults, $moreResults);
135
+    }
136 136
 
137
-	public static function dataSearchEmail(): array {
138
-		return [
139
-			// data set 0
140
-			['test', [], true, ['emails' => [], 'exact' => ['emails' => []]], false, false, false],
141
-			// data set 1
142
-			['test', [], false, ['emails' => [], 'exact' => ['emails' => []]], false, false, false],
143
-			// data set 2
144
-			[
145
-				'[email protected]',
146
-				[],
147
-				true,
148
-				['emails' => [], 'exact' => ['emails' => [['uuid' => '[email protected]', 'label' => '[email protected]', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => '[email protected]']]]]],
149
-				false,
150
-				false,
151
-				true,
152
-			],
153
-			// data set 3
154
-			[ // no valid email address
155
-				'test@remote',
156
-				[],
157
-				true,
158
-				['emails' => [], 'exact' => ['emails' => []]],
159
-				false,
160
-				false,
161
-				false,
162
-			],
163
-			// data set 4
164
-			[
165
-				'[email protected]',
166
-				[],
167
-				false,
168
-				['emails' => [], 'exact' => ['emails' => [['uuid' => '[email protected]', 'label' => '[email protected]', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => '[email protected]']]]]],
169
-				false,
170
-				false,
171
-				true,
172
-			],
173
-			// data set 5
174
-			[
175
-				'test',
176
-				[
177
-					[
178
-						'UID' => 'uid3',
179
-						'FN' => 'User3 @ Localhost',
180
-					],
181
-					[
182
-						'UID' => 'uid2',
183
-						'FN' => 'User2 @ Localhost',
184
-						'EMAIL' => [
185
-						],
186
-					],
187
-					[
188
-						'UID' => 'uid1',
189
-						'FN' => 'User @ Localhost',
190
-						'EMAIL' => [
191
-							'[email protected]',
192
-						],
193
-					],
194
-				],
195
-				true,
196
-				['emails' => [['uuid' => 'uid1', 'name' => 'User @ Localhost', 'type' => '', 'label' => 'User @ Localhost ([email protected])', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => '[email protected]']]], 'exact' => ['emails' => []]],
197
-				false,
198
-				false,
199
-				false,
200
-			],
201
-			// data set 6
202
-			[
203
-				'test',
204
-				[
205
-					[
206
-						'UID' => 'uid3',
207
-						'FN' => 'User3 @ Localhost',
208
-					],
209
-					[
210
-						'UID' => 'uid2',
211
-						'FN' => 'User2 @ Localhost',
212
-						'EMAIL' => [
213
-						],
214
-					],
215
-					[
216
-						'isLocalSystemBook' => true,
217
-						'UID' => 'uid1',
218
-						'FN' => 'User @ Localhost',
219
-						'EMAIL' => [
220
-							'username@localhost',
221
-						],
222
-					],
223
-				],
224
-				false,
225
-				['emails' => [], 'exact' => ['emails' => []]],
226
-				false,
227
-				false,
228
-				false,
229
-			],
230
-			// data set 7
231
-			[
232
-				'[email protected]',
233
-				[
234
-					[
235
-						'UID' => 'uid3',
236
-						'FN' => 'User3 @ example.com',
237
-					],
238
-					[
239
-						'UID' => 'uid2',
240
-						'FN' => 'User2 @ example.com',
241
-						'EMAIL' => [
242
-						],
243
-					],
244
-					[
245
-						'UID' => 'uid1',
246
-						'FN' => 'User @ example.com',
247
-						'EMAIL' => [
248
-							'[email protected]',
249
-						],
250
-					],
251
-				],
252
-				true,
253
-				['emails' => [['uuid' => 'uid1', 'name' => 'User @ example.com', 'type' => '', 'label' => 'User @ example.com ([email protected])', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => '[email protected]']]], 'exact' => ['emails' => [['label' => '[email protected]', 'uuid' => '[email protected]', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => '[email protected]']]]]],
254
-				false,
255
-				false,
256
-				true,
257
-			],
258
-			// data set 8
259
-			[
260
-				'[email protected]',
261
-				[
262
-					[
263
-						'UID' => 'uid3',
264
-						'FN' => 'User3 @ Localhost',
265
-					],
266
-					[
267
-						'UID' => 'uid2',
268
-						'FN' => 'User2 @ Localhost',
269
-						'EMAIL' => [
270
-						],
271
-					],
272
-					[
273
-						'isLocalSystemBook' => true,
274
-						'UID' => 'uid1',
275
-						'FN' => 'User @ Localhost',
276
-						'EMAIL' => [
277
-							'username@localhost',
278
-						],
279
-					],
280
-				],
281
-				false,
282
-				['emails' => [], 'exact' => ['emails' => [['label' => '[email protected]', 'uuid' => '[email protected]', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => '[email protected]']]]]],
283
-				false,
284
-				false,
285
-				true,
286
-			],
287
-			// data set 9
288
-			[
289
-				'[email protected]',
290
-				[
291
-					[
292
-						'UID' => 'uid3',
293
-						'FN' => 'User3 @ example.com',
294
-					],
295
-					[
296
-						'UID' => 'uid2',
297
-						'FN' => 'User2 @ example.com',
298
-						'EMAIL' => [
299
-						],
300
-					],
301
-					[
302
-						'UID' => 'uid1',
303
-						'FN' => 'User @ example.com',
304
-						'EMAIL' => [
305
-							'[email protected]',
306
-						],
307
-					],
308
-				],
309
-				true,
310
-				['emails' => [], 'exact' => ['emails' => [['name' => 'User @ example.com', 'uuid' => 'uid1', 'type' => '', 'label' => 'User @ example.com ([email protected])', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => '[email protected]']]]]],
311
-				true,
312
-				false,
313
-				false,
314
-			],
315
-			// data set 10
316
-			[
317
-				'[email protected]',
318
-				[
319
-					[
320
-						'UID' => 'uid1',
321
-						'FN' => 'User3 @ example.com',
322
-					],
323
-					[
324
-						'UID' => 'uid2',
325
-						'FN' => 'User2 @ example.com',
326
-						'EMAIL' => [
327
-						],
328
-					],
329
-					[
330
-						'UID' => 'uid1',
331
-						'FN' => 'User @ example.com',
332
-						'EMAIL' => [
333
-							'[email protected]',
334
-						],
335
-					],
336
-				],
337
-				false,
338
-				['emails' => [], 'exact' => ['emails' => [['name' => 'User @ example.com', 'uuid' => 'uid1', 'type' => '', 'label' => 'User @ example.com ([email protected])', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => '[email protected]']]]]],
339
-				true,
340
-				false,
341
-				false,
342
-			],
343
-			// data set 11
344
-			// contact with space
345
-			[
346
-				'user name@localhost',
347
-				[
348
-					[
349
-						'UID' => 'uid3',
350
-						'FN' => 'User3 @ Localhost',
351
-					],
352
-					[
353
-						'UID' => 'uid2',
354
-						'FN' => 'User2 @ Localhost',
355
-						'EMAIL' => [
356
-						],
357
-					],
358
-					[
359
-						'UID' => 'uid1',
360
-						'FN' => 'User Name @ Localhost',
361
-						'EMAIL' => [
362
-							'user name@localhost',
363
-						],
364
-					],
365
-				],
366
-				false,
367
-				['emails' => [], 'exact' => ['emails' => []]],
368
-				false,
369
-				false,
370
-				false,
371
-			],
372
-			// data set 12
373
-			// remote with space, no contact
374
-			[
375
-				'user [email protected]',
376
-				[
377
-					[
378
-						'UID' => 'uid3',
379
-						'FN' => 'User3 @ Localhost',
380
-					],
381
-					[
382
-						'UID' => 'uid2',
383
-						'FN' => 'User2 @ Localhost',
384
-						'EMAIL' => [
385
-						],
386
-					],
387
-					[
388
-						'isLocalSystemBook' => true,
389
-						'UID' => 'uid1',
390
-						'FN' => 'User @ Localhost',
391
-						'EMAIL' => [
392
-							'username@localhost',
393
-						],
394
-					],
395
-				],
396
-				false,
397
-				['emails' => [], 'exact' => ['emails' => []]],
398
-				false,
399
-				false,
400
-				false,
401
-			],
402
-			// data set 13
403
-			// Local user found by email => no result
404
-			[
405
-				'[email protected]',
406
-				[
407
-					[
408
-						'UID' => 'uid1',
409
-						'FN' => 'User',
410
-						'EMAIL' => ['[email protected]'],
411
-						'CLOUD' => ['test@localhost'],
412
-						'isLocalSystemBook' => true,
413
-					]
414
-				],
415
-				false,
416
-				['exact' => []],
417
-				false,
418
-				false,
419
-				true,
420
-			],
421
-			// data set 14
422
-			// Current local user found by email => no result
423
-			[
424
-				'[email protected]',
425
-				[
426
-					[
427
-						'UID' => 'uid1',
428
-						'FN' => 'User',
429
-						'EMAIL' => ['[email protected]'],
430
-						'CLOUD' => ['current@localhost'],
431
-						'isLocalSystemBook' => true,
432
-					]
433
-				],
434
-				true,
435
-				['exact' => []],
436
-				false,
437
-				false,
438
-				true,
439
-			],
440
-			// data set 15
441
-			// Several local users found by email => no result nor pagination
442
-			[
443
-				'test@example',
444
-				[
445
-					[
446
-						'UID' => 'uid1',
447
-						'FN' => 'User1',
448
-						'EMAIL' => ['[email protected]'],
449
-						'CLOUD' => ['test1@localhost'],
450
-						'isLocalSystemBook' => true,
451
-					],
452
-					[
453
-						'UID' => 'uid2',
454
-						'FN' => 'User2',
455
-						'EMAIL' => ['[email protected]'],
456
-						'CLOUD' => ['test2@localhost'],
457
-						'isLocalSystemBook' => true,
458
-					],
459
-					[
460
-						'UID' => 'uid3',
461
-						'FN' => 'User3',
462
-						'EMAIL' => ['[email protected]'],
463
-						'CLOUD' => ['test3@localhost'],
464
-						'isLocalSystemBook' => true,
465
-					],
466
-					[
467
-						'UID' => 'uid4',
468
-						'FN' => 'User4',
469
-						'EMAIL' => ['[email protected]'],
470
-						'CLOUD' => ['test4@localhost'],
471
-						'isLocalSystemBook' => true,
472
-					],
473
-				],
474
-				true,
475
-				['emails' => [], 'exact' => ['emails' => []]],
476
-				false,
477
-				false,
478
-				false,
479
-			],
480
-			// data set 16
481
-			// Pagination and "more results" for normal emails
482
-			[
483
-				'test@example',
484
-				[
485
-					[
486
-						'UID' => 'uid1',
487
-						'FN' => 'User1',
488
-						'EMAIL' => ['[email protected]'],
489
-						'CLOUD' => ['test1@localhost'],
490
-					],
491
-					[
492
-						'UID' => 'uid2',
493
-						'FN' => 'User2',
494
-						'EMAIL' => ['[email protected]'],
495
-						'CLOUD' => ['test2@localhost'],
496
-					],
497
-					[
498
-						'UID' => 'uid3',
499
-						'FN' => 'User3',
500
-						'EMAIL' => ['[email protected]'],
501
-						'CLOUD' => ['test3@localhost'],
502
-					],
503
-					[
504
-						'UID' => 'uid4',
505
-						'FN' => 'User4',
506
-						'EMAIL' => ['[email protected]'],
507
-						'CLOUD' => ['test4@localhost'],
508
-					],
509
-				],
510
-				true,
511
-				['emails' => [
512
-					['uuid' => 'uid1', 'name' => 'User1', 'type' => '', 'label' => 'User1 ([email protected])', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => '[email protected]']],
513
-					['uuid' => 'uid2', 'name' => 'User2', 'type' => '', 'label' => 'User2 ([email protected])', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => '[email protected]']],
514
-				], 'exact' => ['emails' => []]],
515
-				false,
516
-				true,
517
-				false,
518
-			],
519
-			// data set 17
520
-			// multiple email addresses with type
521
-			[
522
-				'User Name',
523
-				[
524
-					[
525
-						'UID' => 'uid3',
526
-						'FN' => 'User3',
527
-					],
528
-					[
529
-						'UID' => 'uid2',
530
-						'FN' => 'User2',
531
-						'EMAIL' => [
532
-						],
533
-					],
534
-					[
535
-						'UID' => 'uid1',
536
-						'FN' => 'User Name',
537
-						'EMAIL' => [
538
-							['type' => 'HOME', 'value' => '[email protected]'],
539
-							['type' => 'WORK', 'value' => '[email protected]'],
540
-						],
541
-					],
542
-				],
543
-				false,
544
-				['emails' => [
545
-				], 'exact' => ['emails' => [
546
-					['name' => 'User Name', 'uuid' => 'uid1', 'type' => 'HOME', 'label' => 'User Name ([email protected])', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => '[email protected]']],
547
-					['name' => 'User Name', 'uuid' => 'uid1', 'type' => 'WORK', 'label' => 'User Name ([email protected])', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => '[email protected]']]
548
-				]]],
549
-				false,
550
-				false,
551
-				false,
552
-			],
553
-			// data set 18
554
-			// idn email
555
-			[
556
-				'test@lölölölölölölöl.com',
557
-				[],
558
-				true,
559
-				['emails' => [], 'exact' => ['emails' => [['uuid' => 'test@lölölölölölölöl.com', 'label' => 'test@lölölölölölölöl.com', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => 'test@lölölölölölölöl.com']]]]],
560
-				false,
561
-				false,
562
-				true,
563
-			],
564
-		];
565
-	}
137
+    public static function dataSearchEmail(): array {
138
+        return [
139
+            // data set 0
140
+            ['test', [], true, ['emails' => [], 'exact' => ['emails' => []]], false, false, false],
141
+            // data set 1
142
+            ['test', [], false, ['emails' => [], 'exact' => ['emails' => []]], false, false, false],
143
+            // data set 2
144
+            [
145
+                '[email protected]',
146
+                [],
147
+                true,
148
+                ['emails' => [], 'exact' => ['emails' => [['uuid' => '[email protected]', 'label' => '[email protected]', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => '[email protected]']]]]],
149
+                false,
150
+                false,
151
+                true,
152
+            ],
153
+            // data set 3
154
+            [ // no valid email address
155
+                'test@remote',
156
+                [],
157
+                true,
158
+                ['emails' => [], 'exact' => ['emails' => []]],
159
+                false,
160
+                false,
161
+                false,
162
+            ],
163
+            // data set 4
164
+            [
165
+                '[email protected]',
166
+                [],
167
+                false,
168
+                ['emails' => [], 'exact' => ['emails' => [['uuid' => '[email protected]', 'label' => '[email protected]', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => '[email protected]']]]]],
169
+                false,
170
+                false,
171
+                true,
172
+            ],
173
+            // data set 5
174
+            [
175
+                'test',
176
+                [
177
+                    [
178
+                        'UID' => 'uid3',
179
+                        'FN' => 'User3 @ Localhost',
180
+                    ],
181
+                    [
182
+                        'UID' => 'uid2',
183
+                        'FN' => 'User2 @ Localhost',
184
+                        'EMAIL' => [
185
+                        ],
186
+                    ],
187
+                    [
188
+                        'UID' => 'uid1',
189
+                        'FN' => 'User @ Localhost',
190
+                        'EMAIL' => [
191
+                            '[email protected]',
192
+                        ],
193
+                    ],
194
+                ],
195
+                true,
196
+                ['emails' => [['uuid' => 'uid1', 'name' => 'User @ Localhost', 'type' => '', 'label' => 'User @ Localhost ([email protected])', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => '[email protected]']]], 'exact' => ['emails' => []]],
197
+                false,
198
+                false,
199
+                false,
200
+            ],
201
+            // data set 6
202
+            [
203
+                'test',
204
+                [
205
+                    [
206
+                        'UID' => 'uid3',
207
+                        'FN' => 'User3 @ Localhost',
208
+                    ],
209
+                    [
210
+                        'UID' => 'uid2',
211
+                        'FN' => 'User2 @ Localhost',
212
+                        'EMAIL' => [
213
+                        ],
214
+                    ],
215
+                    [
216
+                        'isLocalSystemBook' => true,
217
+                        'UID' => 'uid1',
218
+                        'FN' => 'User @ Localhost',
219
+                        'EMAIL' => [
220
+                            'username@localhost',
221
+                        ],
222
+                    ],
223
+                ],
224
+                false,
225
+                ['emails' => [], 'exact' => ['emails' => []]],
226
+                false,
227
+                false,
228
+                false,
229
+            ],
230
+            // data set 7
231
+            [
232
+                '[email protected]',
233
+                [
234
+                    [
235
+                        'UID' => 'uid3',
236
+                        'FN' => 'User3 @ example.com',
237
+                    ],
238
+                    [
239
+                        'UID' => 'uid2',
240
+                        'FN' => 'User2 @ example.com',
241
+                        'EMAIL' => [
242
+                        ],
243
+                    ],
244
+                    [
245
+                        'UID' => 'uid1',
246
+                        'FN' => 'User @ example.com',
247
+                        'EMAIL' => [
248
+                            '[email protected]',
249
+                        ],
250
+                    ],
251
+                ],
252
+                true,
253
+                ['emails' => [['uuid' => 'uid1', 'name' => 'User @ example.com', 'type' => '', 'label' => 'User @ example.com ([email protected])', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => '[email protected]']]], 'exact' => ['emails' => [['label' => '[email protected]', 'uuid' => '[email protected]', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => '[email protected]']]]]],
254
+                false,
255
+                false,
256
+                true,
257
+            ],
258
+            // data set 8
259
+            [
260
+                '[email protected]',
261
+                [
262
+                    [
263
+                        'UID' => 'uid3',
264
+                        'FN' => 'User3 @ Localhost',
265
+                    ],
266
+                    [
267
+                        'UID' => 'uid2',
268
+                        'FN' => 'User2 @ Localhost',
269
+                        'EMAIL' => [
270
+                        ],
271
+                    ],
272
+                    [
273
+                        'isLocalSystemBook' => true,
274
+                        'UID' => 'uid1',
275
+                        'FN' => 'User @ Localhost',
276
+                        'EMAIL' => [
277
+                            'username@localhost',
278
+                        ],
279
+                    ],
280
+                ],
281
+                false,
282
+                ['emails' => [], 'exact' => ['emails' => [['label' => '[email protected]', 'uuid' => '[email protected]', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => '[email protected]']]]]],
283
+                false,
284
+                false,
285
+                true,
286
+            ],
287
+            // data set 9
288
+            [
289
+                '[email protected]',
290
+                [
291
+                    [
292
+                        'UID' => 'uid3',
293
+                        'FN' => 'User3 @ example.com',
294
+                    ],
295
+                    [
296
+                        'UID' => 'uid2',
297
+                        'FN' => 'User2 @ example.com',
298
+                        'EMAIL' => [
299
+                        ],
300
+                    ],
301
+                    [
302
+                        'UID' => 'uid1',
303
+                        'FN' => 'User @ example.com',
304
+                        'EMAIL' => [
305
+                            '[email protected]',
306
+                        ],
307
+                    ],
308
+                ],
309
+                true,
310
+                ['emails' => [], 'exact' => ['emails' => [['name' => 'User @ example.com', 'uuid' => 'uid1', 'type' => '', 'label' => 'User @ example.com ([email protected])', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => '[email protected]']]]]],
311
+                true,
312
+                false,
313
+                false,
314
+            ],
315
+            // data set 10
316
+            [
317
+                '[email protected]',
318
+                [
319
+                    [
320
+                        'UID' => 'uid1',
321
+                        'FN' => 'User3 @ example.com',
322
+                    ],
323
+                    [
324
+                        'UID' => 'uid2',
325
+                        'FN' => 'User2 @ example.com',
326
+                        'EMAIL' => [
327
+                        ],
328
+                    ],
329
+                    [
330
+                        'UID' => 'uid1',
331
+                        'FN' => 'User @ example.com',
332
+                        'EMAIL' => [
333
+                            '[email protected]',
334
+                        ],
335
+                    ],
336
+                ],
337
+                false,
338
+                ['emails' => [], 'exact' => ['emails' => [['name' => 'User @ example.com', 'uuid' => 'uid1', 'type' => '', 'label' => 'User @ example.com ([email protected])', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => '[email protected]']]]]],
339
+                true,
340
+                false,
341
+                false,
342
+            ],
343
+            // data set 11
344
+            // contact with space
345
+            [
346
+                'user name@localhost',
347
+                [
348
+                    [
349
+                        'UID' => 'uid3',
350
+                        'FN' => 'User3 @ Localhost',
351
+                    ],
352
+                    [
353
+                        'UID' => 'uid2',
354
+                        'FN' => 'User2 @ Localhost',
355
+                        'EMAIL' => [
356
+                        ],
357
+                    ],
358
+                    [
359
+                        'UID' => 'uid1',
360
+                        'FN' => 'User Name @ Localhost',
361
+                        'EMAIL' => [
362
+                            'user name@localhost',
363
+                        ],
364
+                    ],
365
+                ],
366
+                false,
367
+                ['emails' => [], 'exact' => ['emails' => []]],
368
+                false,
369
+                false,
370
+                false,
371
+            ],
372
+            // data set 12
373
+            // remote with space, no contact
374
+            [
375
+                'user [email protected]',
376
+                [
377
+                    [
378
+                        'UID' => 'uid3',
379
+                        'FN' => 'User3 @ Localhost',
380
+                    ],
381
+                    [
382
+                        'UID' => 'uid2',
383
+                        'FN' => 'User2 @ Localhost',
384
+                        'EMAIL' => [
385
+                        ],
386
+                    ],
387
+                    [
388
+                        'isLocalSystemBook' => true,
389
+                        'UID' => 'uid1',
390
+                        'FN' => 'User @ Localhost',
391
+                        'EMAIL' => [
392
+                            'username@localhost',
393
+                        ],
394
+                    ],
395
+                ],
396
+                false,
397
+                ['emails' => [], 'exact' => ['emails' => []]],
398
+                false,
399
+                false,
400
+                false,
401
+            ],
402
+            // data set 13
403
+            // Local user found by email => no result
404
+            [
405
+                '[email protected]',
406
+                [
407
+                    [
408
+                        'UID' => 'uid1',
409
+                        'FN' => 'User',
410
+                        'EMAIL' => ['[email protected]'],
411
+                        'CLOUD' => ['test@localhost'],
412
+                        'isLocalSystemBook' => true,
413
+                    ]
414
+                ],
415
+                false,
416
+                ['exact' => []],
417
+                false,
418
+                false,
419
+                true,
420
+            ],
421
+            // data set 14
422
+            // Current local user found by email => no result
423
+            [
424
+                '[email protected]',
425
+                [
426
+                    [
427
+                        'UID' => 'uid1',
428
+                        'FN' => 'User',
429
+                        'EMAIL' => ['[email protected]'],
430
+                        'CLOUD' => ['current@localhost'],
431
+                        'isLocalSystemBook' => true,
432
+                    ]
433
+                ],
434
+                true,
435
+                ['exact' => []],
436
+                false,
437
+                false,
438
+                true,
439
+            ],
440
+            // data set 15
441
+            // Several local users found by email => no result nor pagination
442
+            [
443
+                'test@example',
444
+                [
445
+                    [
446
+                        'UID' => 'uid1',
447
+                        'FN' => 'User1',
448
+                        'EMAIL' => ['[email protected]'],
449
+                        'CLOUD' => ['test1@localhost'],
450
+                        'isLocalSystemBook' => true,
451
+                    ],
452
+                    [
453
+                        'UID' => 'uid2',
454
+                        'FN' => 'User2',
455
+                        'EMAIL' => ['[email protected]'],
456
+                        'CLOUD' => ['test2@localhost'],
457
+                        'isLocalSystemBook' => true,
458
+                    ],
459
+                    [
460
+                        'UID' => 'uid3',
461
+                        'FN' => 'User3',
462
+                        'EMAIL' => ['[email protected]'],
463
+                        'CLOUD' => ['test3@localhost'],
464
+                        'isLocalSystemBook' => true,
465
+                    ],
466
+                    [
467
+                        'UID' => 'uid4',
468
+                        'FN' => 'User4',
469
+                        'EMAIL' => ['[email protected]'],
470
+                        'CLOUD' => ['test4@localhost'],
471
+                        'isLocalSystemBook' => true,
472
+                    ],
473
+                ],
474
+                true,
475
+                ['emails' => [], 'exact' => ['emails' => []]],
476
+                false,
477
+                false,
478
+                false,
479
+            ],
480
+            // data set 16
481
+            // Pagination and "more results" for normal emails
482
+            [
483
+                'test@example',
484
+                [
485
+                    [
486
+                        'UID' => 'uid1',
487
+                        'FN' => 'User1',
488
+                        'EMAIL' => ['[email protected]'],
489
+                        'CLOUD' => ['test1@localhost'],
490
+                    ],
491
+                    [
492
+                        'UID' => 'uid2',
493
+                        'FN' => 'User2',
494
+                        'EMAIL' => ['[email protected]'],
495
+                        'CLOUD' => ['test2@localhost'],
496
+                    ],
497
+                    [
498
+                        'UID' => 'uid3',
499
+                        'FN' => 'User3',
500
+                        'EMAIL' => ['[email protected]'],
501
+                        'CLOUD' => ['test3@localhost'],
502
+                    ],
503
+                    [
504
+                        'UID' => 'uid4',
505
+                        'FN' => 'User4',
506
+                        'EMAIL' => ['[email protected]'],
507
+                        'CLOUD' => ['test4@localhost'],
508
+                    ],
509
+                ],
510
+                true,
511
+                ['emails' => [
512
+                    ['uuid' => 'uid1', 'name' => 'User1', 'type' => '', 'label' => 'User1 ([email protected])', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => '[email protected]']],
513
+                    ['uuid' => 'uid2', 'name' => 'User2', 'type' => '', 'label' => 'User2 ([email protected])', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => '[email protected]']],
514
+                ], 'exact' => ['emails' => []]],
515
+                false,
516
+                true,
517
+                false,
518
+            ],
519
+            // data set 17
520
+            // multiple email addresses with type
521
+            [
522
+                'User Name',
523
+                [
524
+                    [
525
+                        'UID' => 'uid3',
526
+                        'FN' => 'User3',
527
+                    ],
528
+                    [
529
+                        'UID' => 'uid2',
530
+                        'FN' => 'User2',
531
+                        'EMAIL' => [
532
+                        ],
533
+                    ],
534
+                    [
535
+                        'UID' => 'uid1',
536
+                        'FN' => 'User Name',
537
+                        'EMAIL' => [
538
+                            ['type' => 'HOME', 'value' => '[email protected]'],
539
+                            ['type' => 'WORK', 'value' => '[email protected]'],
540
+                        ],
541
+                    ],
542
+                ],
543
+                false,
544
+                ['emails' => [
545
+                ], 'exact' => ['emails' => [
546
+                    ['name' => 'User Name', 'uuid' => 'uid1', 'type' => 'HOME', 'label' => 'User Name ([email protected])', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => '[email protected]']],
547
+                    ['name' => 'User Name', 'uuid' => 'uid1', 'type' => 'WORK', 'label' => 'User Name ([email protected])', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => '[email protected]']]
548
+                ]]],
549
+                false,
550
+                false,
551
+                false,
552
+            ],
553
+            // data set 18
554
+            // idn email
555
+            [
556
+                'test@lölölölölölölöl.com',
557
+                [],
558
+                true,
559
+                ['emails' => [], 'exact' => ['emails' => [['uuid' => 'test@lölölölölölölöl.com', 'label' => 'test@lölölölölölölöl.com', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => 'test@lölölölölölölöl.com']]]]],
560
+                false,
561
+                false,
562
+                true,
563
+            ],
564
+        ];
565
+    }
566 566
 
567
-	/**
568
-	 *
569
-	 * @param string $searchTerm
570
-	 * @param array $contacts
571
-	 * @param bool $shareeEnumeration
572
-	 * @param array $expectedResult
573
-	 * @param bool $expectedExactIdMatch
574
-	 * @param bool $expectedMoreResults
575
-	 */
576
-	#[\PHPUnit\Framework\Attributes\DataProvider('dataSearchUser')]
577
-	public function testSearchUser($searchTerm, $contacts, $shareeEnumeration, $expectedResult, $expectedExactIdMatch, $expectedMoreResults): void {
578
-		$this->config->expects($this->any())
579
-			->method('getAppValue')
580
-			->willReturnCallback(
581
-				function ($appName, $key, $default) use ($shareeEnumeration) {
582
-					if ($appName === 'core' && $key === 'shareapi_allow_share_dialog_user_enumeration') {
583
-						return $shareeEnumeration ? 'yes' : 'no';
584
-					}
585
-					return $default;
586
-				}
587
-			);
567
+    /**
568
+     *
569
+     * @param string $searchTerm
570
+     * @param array $contacts
571
+     * @param bool $shareeEnumeration
572
+     * @param array $expectedResult
573
+     * @param bool $expectedExactIdMatch
574
+     * @param bool $expectedMoreResults
575
+     */
576
+    #[\PHPUnit\Framework\Attributes\DataProvider('dataSearchUser')]
577
+    public function testSearchUser($searchTerm, $contacts, $shareeEnumeration, $expectedResult, $expectedExactIdMatch, $expectedMoreResults): void {
578
+        $this->config->expects($this->any())
579
+            ->method('getAppValue')
580
+            ->willReturnCallback(
581
+                function ($appName, $key, $default) use ($shareeEnumeration) {
582
+                    if ($appName === 'core' && $key === 'shareapi_allow_share_dialog_user_enumeration') {
583
+                        return $shareeEnumeration ? 'yes' : 'no';
584
+                    }
585
+                    return $default;
586
+                }
587
+            );
588 588
 
589
-		$this->instantiatePlugin(IShare::TYPE_USER);
589
+        $this->instantiatePlugin(IShare::TYPE_USER);
590 590
 
591
-		$currentUser = $this->createMock(IUser::class);
592
-		$currentUser->method('getUID')
593
-			->willReturn('current');
594
-		$this->userSession->method('getUser')
595
-			->willReturn($currentUser);
591
+        $currentUser = $this->createMock(IUser::class);
592
+        $currentUser->method('getUID')
593
+            ->willReturn('current');
594
+        $this->userSession->method('getUser')
595
+            ->willReturn($currentUser);
596 596
 
597
-		$this->contactsManager->expects($this->any())
598
-			->method('search')
599
-			->willReturnCallback(function ($search, $searchAttributes) use ($searchTerm, $contacts) {
600
-				if ($search === $searchTerm) {
601
-					return $contacts;
602
-				}
603
-				return [];
604
-			});
597
+        $this->contactsManager->expects($this->any())
598
+            ->method('search')
599
+            ->willReturnCallback(function ($search, $searchAttributes) use ($searchTerm, $contacts) {
600
+                if ($search === $searchTerm) {
601
+                    return $contacts;
602
+                }
603
+                return [];
604
+            });
605 605
 
606
-		$moreResults = $this->plugin->search($searchTerm, 2, 0, $this->searchResult);
607
-		$result = $this->searchResult->asArray();
606
+        $moreResults = $this->plugin->search($searchTerm, 2, 0, $this->searchResult);
607
+        $result = $this->searchResult->asArray();
608 608
 
609
-		$this->assertSame($expectedExactIdMatch, $this->searchResult->hasExactIdMatch(new SearchResultType('emails')));
610
-		$this->assertEquals($expectedResult, $result);
611
-		$this->assertSame($expectedMoreResults, $moreResults);
612
-	}
609
+        $this->assertSame($expectedExactIdMatch, $this->searchResult->hasExactIdMatch(new SearchResultType('emails')));
610
+        $this->assertEquals($expectedResult, $result);
611
+        $this->assertSame($expectedMoreResults, $moreResults);
612
+    }
613 613
 
614
-	public static function dataSearchUser(): array {
615
-		return [
616
-			// data set 0
617
-			['test', [], true, ['exact' => []], false, false],
618
-			// data set 1
619
-			['test', [], false, ['exact' => []], false, false],
620
-			// data set 2
621
-			[
622
-				'[email protected]',
623
-				[],
624
-				true,
625
-				['exact' => []],
626
-				false,
627
-				false,
628
-			],
629
-			// data set 3
630
-			[
631
-				'[email protected]',
632
-				[],
633
-				false,
634
-				['exact' => []],
635
-				false,
636
-				false,
637
-			],
638
-			// data set 4
639
-			[
640
-				'test',
641
-				[
642
-					[
643
-						'UID' => 'uid3',
644
-						'FN' => 'User3 @ Localhost',
645
-					],
646
-					[
647
-						'UID' => 'uid2',
648
-						'FN' => 'User2 @ Localhost',
649
-						'EMAIL' => [
650
-						],
651
-					],
652
-					[
653
-						'UID' => 'uid1',
654
-						'FN' => 'User @ Localhost',
655
-						'EMAIL' => [
656
-							'username@localhost',
657
-						],
658
-					],
659
-				],
660
-				true,
661
-				['exact' => []],
662
-				false,
663
-				false,
664
-			],
665
-			// data set 5
666
-			[
667
-				'test',
668
-				[
669
-					[
670
-						'UID' => 'uid3',
671
-						'FN' => 'User3 @ Localhost',
672
-					],
673
-					[
674
-						'UID' => 'uid2',
675
-						'FN' => 'User2 @ Localhost',
676
-						'EMAIL' => [
677
-						],
678
-					],
679
-					[
680
-						'isLocalSystemBook' => true,
681
-						'UID' => 'uid1',
682
-						'FN' => 'User @ Localhost',
683
-						'EMAIL' => [
684
-							'username@localhost',
685
-						],
686
-					],
687
-				],
688
-				false,
689
-				['exact' => []],
690
-				false,
691
-				false,
692
-			],
693
-			// data set 6
694
-			[
695
-				'[email protected]',
696
-				[
697
-					[
698
-						'UID' => 'uid3',
699
-						'FN' => 'User3 @ Localhost',
700
-					],
701
-					[
702
-						'UID' => 'uid2',
703
-						'FN' => 'User2 @ Localhost',
704
-						'EMAIL' => [
705
-						],
706
-					],
707
-					[
708
-						'UID' => 'uid1',
709
-						'FN' => 'User @ Localhost',
710
-						'EMAIL' => [
711
-							'username@localhost',
712
-						],
713
-					],
714
-				],
715
-				true,
716
-				['exact' => []],
717
-				false,
718
-				false,
719
-			],
720
-			// data set 7
721
-			[
722
-				'username@localhost',
723
-				[
724
-					[
725
-						'UID' => 'uid3',
726
-						'FN' => 'User3 @ Localhost',
727
-					],
728
-					[
729
-						'UID' => 'uid2',
730
-						'FN' => 'User2 @ Localhost',
731
-						'EMAIL' => [
732
-						],
733
-					],
734
-					[
735
-						'UID' => 'uid1',
736
-						'FN' => 'User @ Localhost',
737
-						'EMAIL' => [
738
-							'username@localhost',
739
-						],
740
-					],
741
-				],
742
-				true,
743
-				['exact' => []],
744
-				false,
745
-				false,
746
-			],
747
-			// data set 8
748
-			// Local user found by email
749
-			[
750
-				'[email protected]',
751
-				[
752
-					[
753
-						'UID' => 'uid1',
754
-						'FN' => 'User',
755
-						'EMAIL' => ['[email protected]'],
756
-						'CLOUD' => ['test@localhost'],
757
-						'isLocalSystemBook' => true,
758
-					]
759
-				],
760
-				false,
761
-				['users' => [], 'exact' => ['users' => [['uuid' => 'uid1', 'name' => 'User', 'label' => 'User ([email protected])','value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test'], 'shareWithDisplayNameUnique' => '[email protected]']]]],
762
-				true,
763
-				false,
764
-			],
765
-			// data set 9
766
-			// Current local user found by email => no result
767
-			[
768
-				'[email protected]',
769
-				[
770
-					[
771
-						'UID' => 'uid1',
772
-						'FN' => 'User',
773
-						'EMAIL' => ['[email protected]'],
774
-						'CLOUD' => ['current@localhost'],
775
-						'isLocalSystemBook' => true,
776
-					]
777
-				],
778
-				true,
779
-				['exact' => []],
780
-				false,
781
-				false,
782
-			],
783
-			// data set 10
784
-			// Pagination and "more results" for user matches by emails
785
-			[
786
-				'test@example',
787
-				[
788
-					[
789
-						'UID' => 'uid1',
790
-						'FN' => 'User1',
791
-						'EMAIL' => ['[email protected]'],
792
-						'CLOUD' => ['test1@localhost'],
793
-						'isLocalSystemBook' => true,
794
-					],
795
-					[
796
-						'UID' => 'uid2',
797
-						'FN' => 'User2',
798
-						'EMAIL' => ['[email protected]'],
799
-						'CLOUD' => ['test2@localhost'],
800
-						'isLocalSystemBook' => true,
801
-					],
802
-					[
803
-						'UID' => 'uid3',
804
-						'FN' => 'User3',
805
-						'EMAIL' => ['[email protected]'],
806
-						'CLOUD' => ['test3@localhost'],
807
-						'isLocalSystemBook' => true,
808
-					],
809
-					[
810
-						'UID' => 'uid4',
811
-						'FN' => 'User4',
812
-						'EMAIL' => ['[email protected]'],
813
-						'CLOUD' => ['test4@localhost'],
814
-						'isLocalSystemBook' => true,
815
-					],
816
-				],
817
-				true,
818
-				['users' => [
819
-					['uuid' => 'uid1', 'name' => 'User1', 'label' => 'User1 ([email protected])', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test1'], 'shareWithDisplayNameUnique' => '[email protected]'],
820
-					['uuid' => 'uid2', 'name' => 'User2', 'label' => 'User2 ([email protected])', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test2'], 'shareWithDisplayNameUnique' => '[email protected]'],
821
-				], 'exact' => ['users' => []]],
822
-				false,
823
-				true,
824
-			],
825
-			// data set 11
826
-			// Pagination and "more results" for normal emails
827
-			[
828
-				'test@example',
829
-				[
830
-					[
831
-						'UID' => 'uid1',
832
-						'FN' => 'User1',
833
-						'EMAIL' => ['[email protected]'],
834
-						'CLOUD' => ['test1@localhost'],
835
-					],
836
-					[
837
-						'UID' => 'uid2',
838
-						'FN' => 'User2',
839
-						'EMAIL' => ['[email protected]'],
840
-						'CLOUD' => ['test2@localhost'],
841
-					],
842
-					[
843
-						'UID' => 'uid3',
844
-						'FN' => 'User3',
845
-						'EMAIL' => ['[email protected]'],
846
-						'CLOUD' => ['test3@localhost'],
847
-					],
848
-					[
849
-						'UID' => 'uid4',
850
-						'FN' => 'User4',
851
-						'EMAIL' => ['[email protected]'],
852
-						'CLOUD' => ['test4@localhost'],
853
-					],
854
-				],
855
-				true,
856
-				['exact' => []],
857
-				false,
858
-				false,
859
-			],
860
-		];
861
-	}
614
+    public static function dataSearchUser(): array {
615
+        return [
616
+            // data set 0
617
+            ['test', [], true, ['exact' => []], false, false],
618
+            // data set 1
619
+            ['test', [], false, ['exact' => []], false, false],
620
+            // data set 2
621
+            [
622
+                '[email protected]',
623
+                [],
624
+                true,
625
+                ['exact' => []],
626
+                false,
627
+                false,
628
+            ],
629
+            // data set 3
630
+            [
631
+                '[email protected]',
632
+                [],
633
+                false,
634
+                ['exact' => []],
635
+                false,
636
+                false,
637
+            ],
638
+            // data set 4
639
+            [
640
+                'test',
641
+                [
642
+                    [
643
+                        'UID' => 'uid3',
644
+                        'FN' => 'User3 @ Localhost',
645
+                    ],
646
+                    [
647
+                        'UID' => 'uid2',
648
+                        'FN' => 'User2 @ Localhost',
649
+                        'EMAIL' => [
650
+                        ],
651
+                    ],
652
+                    [
653
+                        'UID' => 'uid1',
654
+                        'FN' => 'User @ Localhost',
655
+                        'EMAIL' => [
656
+                            'username@localhost',
657
+                        ],
658
+                    ],
659
+                ],
660
+                true,
661
+                ['exact' => []],
662
+                false,
663
+                false,
664
+            ],
665
+            // data set 5
666
+            [
667
+                'test',
668
+                [
669
+                    [
670
+                        'UID' => 'uid3',
671
+                        'FN' => 'User3 @ Localhost',
672
+                    ],
673
+                    [
674
+                        'UID' => 'uid2',
675
+                        'FN' => 'User2 @ Localhost',
676
+                        'EMAIL' => [
677
+                        ],
678
+                    ],
679
+                    [
680
+                        'isLocalSystemBook' => true,
681
+                        'UID' => 'uid1',
682
+                        'FN' => 'User @ Localhost',
683
+                        'EMAIL' => [
684
+                            'username@localhost',
685
+                        ],
686
+                    ],
687
+                ],
688
+                false,
689
+                ['exact' => []],
690
+                false,
691
+                false,
692
+            ],
693
+            // data set 6
694
+            [
695
+                '[email protected]',
696
+                [
697
+                    [
698
+                        'UID' => 'uid3',
699
+                        'FN' => 'User3 @ Localhost',
700
+                    ],
701
+                    [
702
+                        'UID' => 'uid2',
703
+                        'FN' => 'User2 @ Localhost',
704
+                        'EMAIL' => [
705
+                        ],
706
+                    ],
707
+                    [
708
+                        'UID' => 'uid1',
709
+                        'FN' => 'User @ Localhost',
710
+                        'EMAIL' => [
711
+                            'username@localhost',
712
+                        ],
713
+                    ],
714
+                ],
715
+                true,
716
+                ['exact' => []],
717
+                false,
718
+                false,
719
+            ],
720
+            // data set 7
721
+            [
722
+                'username@localhost',
723
+                [
724
+                    [
725
+                        'UID' => 'uid3',
726
+                        'FN' => 'User3 @ Localhost',
727
+                    ],
728
+                    [
729
+                        'UID' => 'uid2',
730
+                        'FN' => 'User2 @ Localhost',
731
+                        'EMAIL' => [
732
+                        ],
733
+                    ],
734
+                    [
735
+                        'UID' => 'uid1',
736
+                        'FN' => 'User @ Localhost',
737
+                        'EMAIL' => [
738
+                            'username@localhost',
739
+                        ],
740
+                    ],
741
+                ],
742
+                true,
743
+                ['exact' => []],
744
+                false,
745
+                false,
746
+            ],
747
+            // data set 8
748
+            // Local user found by email
749
+            [
750
+                '[email protected]',
751
+                [
752
+                    [
753
+                        'UID' => 'uid1',
754
+                        'FN' => 'User',
755
+                        'EMAIL' => ['[email protected]'],
756
+                        'CLOUD' => ['test@localhost'],
757
+                        'isLocalSystemBook' => true,
758
+                    ]
759
+                ],
760
+                false,
761
+                ['users' => [], 'exact' => ['users' => [['uuid' => 'uid1', 'name' => 'User', 'label' => 'User ([email protected])','value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test'], 'shareWithDisplayNameUnique' => '[email protected]']]]],
762
+                true,
763
+                false,
764
+            ],
765
+            // data set 9
766
+            // Current local user found by email => no result
767
+            [
768
+                '[email protected]',
769
+                [
770
+                    [
771
+                        'UID' => 'uid1',
772
+                        'FN' => 'User',
773
+                        'EMAIL' => ['[email protected]'],
774
+                        'CLOUD' => ['current@localhost'],
775
+                        'isLocalSystemBook' => true,
776
+                    ]
777
+                ],
778
+                true,
779
+                ['exact' => []],
780
+                false,
781
+                false,
782
+            ],
783
+            // data set 10
784
+            // Pagination and "more results" for user matches by emails
785
+            [
786
+                'test@example',
787
+                [
788
+                    [
789
+                        'UID' => 'uid1',
790
+                        'FN' => 'User1',
791
+                        'EMAIL' => ['[email protected]'],
792
+                        'CLOUD' => ['test1@localhost'],
793
+                        'isLocalSystemBook' => true,
794
+                    ],
795
+                    [
796
+                        'UID' => 'uid2',
797
+                        'FN' => 'User2',
798
+                        'EMAIL' => ['[email protected]'],
799
+                        'CLOUD' => ['test2@localhost'],
800
+                        'isLocalSystemBook' => true,
801
+                    ],
802
+                    [
803
+                        'UID' => 'uid3',
804
+                        'FN' => 'User3',
805
+                        'EMAIL' => ['[email protected]'],
806
+                        'CLOUD' => ['test3@localhost'],
807
+                        'isLocalSystemBook' => true,
808
+                    ],
809
+                    [
810
+                        'UID' => 'uid4',
811
+                        'FN' => 'User4',
812
+                        'EMAIL' => ['[email protected]'],
813
+                        'CLOUD' => ['test4@localhost'],
814
+                        'isLocalSystemBook' => true,
815
+                    ],
816
+                ],
817
+                true,
818
+                ['users' => [
819
+                    ['uuid' => 'uid1', 'name' => 'User1', 'label' => 'User1 ([email protected])', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test1'], 'shareWithDisplayNameUnique' => '[email protected]'],
820
+                    ['uuid' => 'uid2', 'name' => 'User2', 'label' => 'User2 ([email protected])', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test2'], 'shareWithDisplayNameUnique' => '[email protected]'],
821
+                ], 'exact' => ['users' => []]],
822
+                false,
823
+                true,
824
+            ],
825
+            // data set 11
826
+            // Pagination and "more results" for normal emails
827
+            [
828
+                'test@example',
829
+                [
830
+                    [
831
+                        'UID' => 'uid1',
832
+                        'FN' => 'User1',
833
+                        'EMAIL' => ['[email protected]'],
834
+                        'CLOUD' => ['test1@localhost'],
835
+                    ],
836
+                    [
837
+                        'UID' => 'uid2',
838
+                        'FN' => 'User2',
839
+                        'EMAIL' => ['[email protected]'],
840
+                        'CLOUD' => ['test2@localhost'],
841
+                    ],
842
+                    [
843
+                        'UID' => 'uid3',
844
+                        'FN' => 'User3',
845
+                        'EMAIL' => ['[email protected]'],
846
+                        'CLOUD' => ['test3@localhost'],
847
+                    ],
848
+                    [
849
+                        'UID' => 'uid4',
850
+                        'FN' => 'User4',
851
+                        'EMAIL' => ['[email protected]'],
852
+                        'CLOUD' => ['test4@localhost'],
853
+                    ],
854
+                ],
855
+                true,
856
+                ['exact' => []],
857
+                false,
858
+                false,
859
+            ],
860
+        ];
861
+    }
862 862
 
863
-	/**
864
-	 *
865
-	 * @param string $searchTerm
866
-	 * @param array $contacts
867
-	 * @param array $expectedResult
868
-	 * @param bool $expectedExactIdMatch
869
-	 * @param bool $expectedMoreResults
870
-	 * @param array $userToGroupMapping
871
-	 * @param bool $validEmail
872
-	 */
873
-	#[\PHPUnit\Framework\Attributes\DataProvider('dataSearchEmailGroupsOnly')]
874
-	public function testSearchEmailGroupsOnly($searchTerm, $contacts, $expectedResult, $expectedExactIdMatch, $expectedMoreResults, $userToGroupMapping, $validEmail): void {
875
-		$this->config->expects($this->any())
876
-			->method('getAppValue')
877
-			->willReturnCallback(
878
-				function ($appName, $key, $default) {
879
-					if ($appName === 'core' && $key === 'shareapi_allow_share_dialog_user_enumeration') {
880
-						return 'yes';
881
-					} elseif ($appName === 'core' && $key === 'shareapi_only_share_with_group_members') {
882
-						return 'yes';
883
-					}
884
-					return $default;
885
-				}
886
-			);
863
+    /**
864
+     *
865
+     * @param string $searchTerm
866
+     * @param array $contacts
867
+     * @param array $expectedResult
868
+     * @param bool $expectedExactIdMatch
869
+     * @param bool $expectedMoreResults
870
+     * @param array $userToGroupMapping
871
+     * @param bool $validEmail
872
+     */
873
+    #[\PHPUnit\Framework\Attributes\DataProvider('dataSearchEmailGroupsOnly')]
874
+    public function testSearchEmailGroupsOnly($searchTerm, $contacts, $expectedResult, $expectedExactIdMatch, $expectedMoreResults, $userToGroupMapping, $validEmail): void {
875
+        $this->config->expects($this->any())
876
+            ->method('getAppValue')
877
+            ->willReturnCallback(
878
+                function ($appName, $key, $default) {
879
+                    if ($appName === 'core' && $key === 'shareapi_allow_share_dialog_user_enumeration') {
880
+                        return 'yes';
881
+                    } elseif ($appName === 'core' && $key === 'shareapi_only_share_with_group_members') {
882
+                        return 'yes';
883
+                    }
884
+                    return $default;
885
+                }
886
+            );
887 887
 
888
-		$this->instantiatePlugin(IShare::TYPE_EMAIL);
888
+        $this->instantiatePlugin(IShare::TYPE_EMAIL);
889 889
 
890
-		/** @var IUser|\PHPUnit\Framework\MockObject\MockObject */
891
-		$currentUser = $this->createMock('\OCP\IUser');
890
+        /** @var IUser|\PHPUnit\Framework\MockObject\MockObject */
891
+        $currentUser = $this->createMock('\OCP\IUser');
892 892
 
893
-		$currentUser->expects($this->any())
894
-			->method('getUID')
895
-			->willReturn('currentUser');
893
+        $currentUser->expects($this->any())
894
+            ->method('getUID')
895
+            ->willReturn('currentUser');
896 896
 
897
-		$this->contactsManager->expects($this->any())
898
-			->method('search')
899
-			->willReturnCallback(function ($search, $searchAttributes) use ($searchTerm, $contacts) {
900
-				if ($search === $searchTerm) {
901
-					return $contacts;
902
-				}
903
-				return [];
904
-			});
897
+        $this->contactsManager->expects($this->any())
898
+            ->method('search')
899
+            ->willReturnCallback(function ($search, $searchAttributes) use ($searchTerm, $contacts) {
900
+                if ($search === $searchTerm) {
901
+                    return $contacts;
902
+                }
903
+                return [];
904
+            });
905 905
 
906
-		$this->userSession->expects($this->any())
907
-			->method('getUser')
908
-			->willReturn($currentUser);
906
+        $this->userSession->expects($this->any())
907
+            ->method('getUser')
908
+            ->willReturn($currentUser);
909 909
 
910
-		$this->groupManager->expects($this->any())
911
-			->method('getUserGroupIds')
912
-			->willReturnCallback(function (IUser $user) use ($userToGroupMapping) {
913
-				return $userToGroupMapping[$user->getUID()];
914
-			});
910
+        $this->groupManager->expects($this->any())
911
+            ->method('getUserGroupIds')
912
+            ->willReturnCallback(function (IUser $user) use ($userToGroupMapping) {
913
+                return $userToGroupMapping[$user->getUID()];
914
+            });
915 915
 
916
-		$this->groupManager->expects($this->any())
917
-			->method('isInGroup')
918
-			->willReturnCallback(function ($userId, $group) use ($userToGroupMapping) {
919
-				return in_array($group, $userToGroupMapping[$userId]);
920
-			});
916
+        $this->groupManager->expects($this->any())
917
+            ->method('isInGroup')
918
+            ->willReturnCallback(function ($userId, $group) use ($userToGroupMapping) {
919
+                return in_array($group, $userToGroupMapping[$userId]);
920
+            });
921 921
 
922
-		$moreResults = $this->plugin->search($searchTerm, 2, 0, $this->searchResult);
923
-		$result = $this->searchResult->asArray();
922
+        $moreResults = $this->plugin->search($searchTerm, 2, 0, $this->searchResult);
923
+        $result = $this->searchResult->asArray();
924 924
 
925
-		$this->assertSame($expectedExactIdMatch, $this->searchResult->hasExactIdMatch(new SearchResultType('emails')));
926
-		$this->assertEquals($expectedResult, $result);
927
-		$this->assertSame($expectedMoreResults, $moreResults);
928
-	}
925
+        $this->assertSame($expectedExactIdMatch, $this->searchResult->hasExactIdMatch(new SearchResultType('emails')));
926
+        $this->assertEquals($expectedResult, $result);
927
+        $this->assertSame($expectedMoreResults, $moreResults);
928
+    }
929 929
 
930
-	public static function dataSearchEmailGroupsOnly(): array {
931
-		return [
932
-			// The user `User` can share with the current user
933
-			[
934
-				'test',
935
-				[
936
-					[
937
-						'FN' => 'User',
938
-						'EMAIL' => ['[email protected]'],
939
-						'CLOUD' => ['test@localhost'],
940
-						'isLocalSystemBook' => true,
941
-						'UID' => 'User',
942
-					]
943
-				],
944
-				['emails' => [], 'exact' => ['emails' => []]],
945
-				false,
946
-				false,
947
-				[
948
-					'currentUser' => ['group1'],
949
-					'User' => ['group1'],
950
-				],
951
-				false,
952
-			],
953
-			// The user `User` cannot share with the current user
954
-			[
955
-				'test',
956
-				[
957
-					[
958
-						'FN' => 'User',
959
-						'EMAIL' => ['[email protected]'],
960
-						'CLOUD' => ['test@localhost'],
961
-						'isLocalSystemBook' => true,
962
-						'UID' => 'User',
963
-					]
964
-				],
965
-				['emails' => [], 'exact' => ['emails' => []]],
966
-				false,
967
-				false,
968
-				[
969
-					'currentUser' => ['group1'],
970
-					'User' => ['group2'],
971
-				],
972
-				false,
973
-			],
974
-			// The user `User` cannot share with the current user, but there is an exact match on the e-mail address -> share by e-mail
975
-			[
976
-				'[email protected]',
977
-				[
978
-					[
979
-						'FN' => 'User',
980
-						'EMAIL' => ['[email protected]'],
981
-						'CLOUD' => ['test@localhost'],
982
-						'isLocalSystemBook' => true,
983
-						'UID' => 'User',
984
-					]
985
-				],
986
-				['emails' => [], 'exact' => ['emails' => [['label' => '[email protected]', 'uuid' => '[email protected]', 'value' => ['shareType' => IShare::TYPE_EMAIL,'shareWith' => '[email protected]']]]]],
987
-				false,
988
-				false,
989
-				[
990
-					'currentUser' => ['group1'],
991
-					'User' => ['group2'],
992
-				],
993
-				true,
994
-			]
995
-		];
996
-	}
930
+    public static function dataSearchEmailGroupsOnly(): array {
931
+        return [
932
+            // The user `User` can share with the current user
933
+            [
934
+                'test',
935
+                [
936
+                    [
937
+                        'FN' => 'User',
938
+                        'EMAIL' => ['[email protected]'],
939
+                        'CLOUD' => ['test@localhost'],
940
+                        'isLocalSystemBook' => true,
941
+                        'UID' => 'User',
942
+                    ]
943
+                ],
944
+                ['emails' => [], 'exact' => ['emails' => []]],
945
+                false,
946
+                false,
947
+                [
948
+                    'currentUser' => ['group1'],
949
+                    'User' => ['group1'],
950
+                ],
951
+                false,
952
+            ],
953
+            // The user `User` cannot share with the current user
954
+            [
955
+                'test',
956
+                [
957
+                    [
958
+                        'FN' => 'User',
959
+                        'EMAIL' => ['[email protected]'],
960
+                        'CLOUD' => ['test@localhost'],
961
+                        'isLocalSystemBook' => true,
962
+                        'UID' => 'User',
963
+                    ]
964
+                ],
965
+                ['emails' => [], 'exact' => ['emails' => []]],
966
+                false,
967
+                false,
968
+                [
969
+                    'currentUser' => ['group1'],
970
+                    'User' => ['group2'],
971
+                ],
972
+                false,
973
+            ],
974
+            // The user `User` cannot share with the current user, but there is an exact match on the e-mail address -> share by e-mail
975
+            [
976
+                '[email protected]',
977
+                [
978
+                    [
979
+                        'FN' => 'User',
980
+                        'EMAIL' => ['[email protected]'],
981
+                        'CLOUD' => ['test@localhost'],
982
+                        'isLocalSystemBook' => true,
983
+                        'UID' => 'User',
984
+                    ]
985
+                ],
986
+                ['emails' => [], 'exact' => ['emails' => [['label' => '[email protected]', 'uuid' => '[email protected]', 'value' => ['shareType' => IShare::TYPE_EMAIL,'shareWith' => '[email protected]']]]]],
987
+                false,
988
+                false,
989
+                [
990
+                    'currentUser' => ['group1'],
991
+                    'User' => ['group2'],
992
+                ],
993
+                true,
994
+            ]
995
+        ];
996
+    }
997 997
 
998
-	/**
999
-	 *
1000
-	 * @param string $searchTerm
1001
-	 * @param array $contacts
1002
-	 * @param array $expectedResult
1003
-	 * @param bool $expectedExactIdMatch
1004
-	 * @param bool $expectedMoreResults
1005
-	 * @param array $userToGroupMapping
1006
-	 */
1007
-	#[\PHPUnit\Framework\Attributes\DataProvider('dataSearchUserGroupsOnly')]
1008
-	public function testSearchUserGroupsOnly($searchTerm, $contacts, $expectedResult, $expectedExactIdMatch, $expectedMoreResults, $userToGroupMapping): void {
1009
-		$this->config->expects($this->any())
1010
-			->method('getAppValue')
1011
-			->willReturnCallback(
1012
-				function ($appName, $key, $default) {
1013
-					if ($appName === 'core' && $key === 'shareapi_allow_share_dialog_user_enumeration') {
1014
-						return 'yes';
1015
-					} elseif ($appName === 'core' && $key === 'shareapi_only_share_with_group_members') {
1016
-						return 'yes';
1017
-					}
1018
-					return $default;
1019
-				}
1020
-			);
998
+    /**
999
+     *
1000
+     * @param string $searchTerm
1001
+     * @param array $contacts
1002
+     * @param array $expectedResult
1003
+     * @param bool $expectedExactIdMatch
1004
+     * @param bool $expectedMoreResults
1005
+     * @param array $userToGroupMapping
1006
+     */
1007
+    #[\PHPUnit\Framework\Attributes\DataProvider('dataSearchUserGroupsOnly')]
1008
+    public function testSearchUserGroupsOnly($searchTerm, $contacts, $expectedResult, $expectedExactIdMatch, $expectedMoreResults, $userToGroupMapping): void {
1009
+        $this->config->expects($this->any())
1010
+            ->method('getAppValue')
1011
+            ->willReturnCallback(
1012
+                function ($appName, $key, $default) {
1013
+                    if ($appName === 'core' && $key === 'shareapi_allow_share_dialog_user_enumeration') {
1014
+                        return 'yes';
1015
+                    } elseif ($appName === 'core' && $key === 'shareapi_only_share_with_group_members') {
1016
+                        return 'yes';
1017
+                    }
1018
+                    return $default;
1019
+                }
1020
+            );
1021 1021
 
1022
-		$this->instantiatePlugin(IShare::TYPE_USER);
1022
+        $this->instantiatePlugin(IShare::TYPE_USER);
1023 1023
 
1024
-		/** @var \OCP\IUser | \PHPUnit\Framework\MockObject\MockObject */
1025
-		$currentUser = $this->createMock('\OCP\IUser');
1024
+        /** @var \OCP\IUser | \PHPUnit\Framework\MockObject\MockObject */
1025
+        $currentUser = $this->createMock('\OCP\IUser');
1026 1026
 
1027
-		$currentUser->expects($this->any())
1028
-			->method('getUID')
1029
-			->willReturn('currentUser');
1027
+        $currentUser->expects($this->any())
1028
+            ->method('getUID')
1029
+            ->willReturn('currentUser');
1030 1030
 
1031
-		$this->contactsManager->expects($this->any())
1032
-			->method('search')
1033
-			->willReturnCallback(function ($search, $searchAttributes) use ($searchTerm, $contacts) {
1034
-				if ($search === $searchTerm) {
1035
-					return $contacts;
1036
-				}
1037
-				return [];
1038
-			});
1031
+        $this->contactsManager->expects($this->any())
1032
+            ->method('search')
1033
+            ->willReturnCallback(function ($search, $searchAttributes) use ($searchTerm, $contacts) {
1034
+                if ($search === $searchTerm) {
1035
+                    return $contacts;
1036
+                }
1037
+                return [];
1038
+            });
1039 1039
 
1040
-		$this->userSession->expects($this->any())
1041
-			->method('getUser')
1042
-			->willReturn($currentUser);
1040
+        $this->userSession->expects($this->any())
1041
+            ->method('getUser')
1042
+            ->willReturn($currentUser);
1043 1043
 
1044
-		$this->groupManager->expects($this->any())
1045
-			->method('getUserGroupIds')
1046
-			->willReturnCallback(function (\OCP\IUser $user) use ($userToGroupMapping) {
1047
-				return $userToGroupMapping[$user->getUID()];
1048
-			});
1044
+        $this->groupManager->expects($this->any())
1045
+            ->method('getUserGroupIds')
1046
+            ->willReturnCallback(function (\OCP\IUser $user) use ($userToGroupMapping) {
1047
+                return $userToGroupMapping[$user->getUID()];
1048
+            });
1049 1049
 
1050
-		$this->groupManager->expects($this->any())
1051
-			->method('isInGroup')
1052
-			->willReturnCallback(function ($userId, $group) use ($userToGroupMapping) {
1053
-				return in_array($group, $userToGroupMapping[$userId]);
1054
-			});
1050
+        $this->groupManager->expects($this->any())
1051
+            ->method('isInGroup')
1052
+            ->willReturnCallback(function ($userId, $group) use ($userToGroupMapping) {
1053
+                return in_array($group, $userToGroupMapping[$userId]);
1054
+            });
1055 1055
 
1056
-		$moreResults = $this->plugin->search($searchTerm, 2, 0, $this->searchResult);
1057
-		$result = $this->searchResult->asArray();
1056
+        $moreResults = $this->plugin->search($searchTerm, 2, 0, $this->searchResult);
1057
+        $result = $this->searchResult->asArray();
1058 1058
 
1059
-		$this->assertSame($expectedExactIdMatch, $this->searchResult->hasExactIdMatch(new SearchResultType('emails')));
1060
-		$this->assertEquals($expectedResult, $result);
1061
-		$this->assertSame($expectedMoreResults, $moreResults);
1062
-	}
1059
+        $this->assertSame($expectedExactIdMatch, $this->searchResult->hasExactIdMatch(new SearchResultType('emails')));
1060
+        $this->assertEquals($expectedResult, $result);
1061
+        $this->assertSame($expectedMoreResults, $moreResults);
1062
+    }
1063 1063
 
1064
-	public static function dataSearchUserGroupsOnly(): array {
1065
-		return [
1066
-			// The user `User` can share with the current user
1067
-			[
1068
-				'test',
1069
-				[
1070
-					[
1071
-						'FN' => 'User',
1072
-						'EMAIL' => ['[email protected]'],
1073
-						'CLOUD' => ['test@localhost'],
1074
-						'isLocalSystemBook' => true,
1075
-						'UID' => 'User',
1076
-					]
1077
-				],
1078
-				['users' => [['label' => 'User ([email protected])', 'uuid' => 'User', 'name' => 'User', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test'],'shareWithDisplayNameUnique' => '[email protected]',]], 'exact' => ['users' => []]],
1079
-				false,
1080
-				false,
1081
-				[
1082
-					'currentUser' => ['group1'],
1083
-					'User' => ['group1'],
1084
-				],
1085
-			],
1086
-			// The user `User` cannot share with the current user
1087
-			[
1088
-				'test',
1089
-				[
1090
-					[
1091
-						'FN' => 'User',
1092
-						'EMAIL' => ['[email protected]'],
1093
-						'CLOUD' => ['test@localhost'],
1094
-						'isLocalSystemBook' => true,
1095
-						'UID' => 'User',
1096
-					]
1097
-				],
1098
-				['exact' => []],
1099
-				false,
1100
-				false,
1101
-				[
1102
-					'currentUser' => ['group1'],
1103
-					'User' => ['group2'],
1104
-				],
1105
-			],
1106
-			// The user `User` cannot share with the current user, but there is an exact match on the e-mail address -> share by e-mail
1107
-			[
1108
-				'[email protected]',
1109
-				[
1110
-					[
1111
-						'FN' => 'User',
1112
-						'EMAIL' => ['[email protected]'],
1113
-						'CLOUD' => ['test@localhost'],
1114
-						'isLocalSystemBook' => true,
1115
-						'UID' => 'User',
1116
-					]
1117
-				],
1118
-				['exact' => []],
1119
-				false,
1120
-				false,
1121
-				[
1122
-					'currentUser' => ['group1'],
1123
-					'User' => ['group2'],
1124
-				],
1125
-			]
1126
-		];
1127
-	}
1064
+    public static function dataSearchUserGroupsOnly(): array {
1065
+        return [
1066
+            // The user `User` can share with the current user
1067
+            [
1068
+                'test',
1069
+                [
1070
+                    [
1071
+                        'FN' => 'User',
1072
+                        'EMAIL' => ['[email protected]'],
1073
+                        'CLOUD' => ['test@localhost'],
1074
+                        'isLocalSystemBook' => true,
1075
+                        'UID' => 'User',
1076
+                    ]
1077
+                ],
1078
+                ['users' => [['label' => 'User ([email protected])', 'uuid' => 'User', 'name' => 'User', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test'],'shareWithDisplayNameUnique' => '[email protected]',]], 'exact' => ['users' => []]],
1079
+                false,
1080
+                false,
1081
+                [
1082
+                    'currentUser' => ['group1'],
1083
+                    'User' => ['group1'],
1084
+                ],
1085
+            ],
1086
+            // The user `User` cannot share with the current user
1087
+            [
1088
+                'test',
1089
+                [
1090
+                    [
1091
+                        'FN' => 'User',
1092
+                        'EMAIL' => ['[email protected]'],
1093
+                        'CLOUD' => ['test@localhost'],
1094
+                        'isLocalSystemBook' => true,
1095
+                        'UID' => 'User',
1096
+                    ]
1097
+                ],
1098
+                ['exact' => []],
1099
+                false,
1100
+                false,
1101
+                [
1102
+                    'currentUser' => ['group1'],
1103
+                    'User' => ['group2'],
1104
+                ],
1105
+            ],
1106
+            // The user `User` cannot share with the current user, but there is an exact match on the e-mail address -> share by e-mail
1107
+            [
1108
+                '[email protected]',
1109
+                [
1110
+                    [
1111
+                        'FN' => 'User',
1112
+                        'EMAIL' => ['[email protected]'],
1113
+                        'CLOUD' => ['test@localhost'],
1114
+                        'isLocalSystemBook' => true,
1115
+                        'UID' => 'User',
1116
+                    ]
1117
+                ],
1118
+                ['exact' => []],
1119
+                false,
1120
+                false,
1121
+                [
1122
+                    'currentUser' => ['group1'],
1123
+                    'User' => ['group2'],
1124
+                ],
1125
+            ]
1126
+        ];
1127
+    }
1128 1128
 }
Please login to merge, or discard this patch.