Completed
Pull Request — master (#551)
by Maxence
84:52
created

FederatedUserService::getFederatedUser_User()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
6
/**
7
 * Circles - Bring cloud-users closer together.
8
 *
9
 * This file is licensed under the Affero General Public License version 3 or
10
 * later. See the COPYING file.
11
 *
12
 * @author Maxence Lange <[email protected]>
13
 * @copyright 2021
14
 * @license GNU AGPL version 3 or any later version
15
 *
16
 * This program is free software: you can redistribute it and/or modify
17
 * it under the terms of the GNU Affero General Public License as
18
 * published by the Free Software Foundation, either version 3 of the
19
 * License, or (at your option) any later version.
20
 *
21
 * This program is distributed in the hope that it will be useful,
22
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
 * GNU Affero General Public License for more details.
25
 *
26
 * You should have received a copy of the GNU Affero General Public License
27
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
28
 *
29
 */
30
31
32
namespace OCA\Circles\Service;
33
34
35
use daita\MySmallPhpTools\Exceptions\InvalidItemException;
36
use daita\MySmallPhpTools\Exceptions\RequestNetworkException;
37
use daita\MySmallPhpTools\Exceptions\SignatoryException;
38
use daita\MySmallPhpTools\Traits\Nextcloud\nc21\TNC21Logger;
39
use daita\MySmallPhpTools\Traits\TArrayTools;
40
use daita\MySmallPhpTools\Traits\TStringTools;
41
use Exception;
42
use OCA\Circles\Db\CircleRequest;
43
use OCA\Circles\Db\MemberRequest;
44
use OCA\Circles\Db\MembershipRequest;
45
use OCA\Circles\Exceptions\CircleNotFoundException;
46
use OCA\Circles\Exceptions\FederatedUserException;
47
use OCA\Circles\Exceptions\FederatedUserNotFoundException;
48
use OCA\Circles\Exceptions\InitiatorNotFoundException;
49
use OCA\Circles\Exceptions\InvalidIdException;
50
use OCA\Circles\Exceptions\MemberNotFoundException;
51
use OCA\Circles\Exceptions\OwnerNotFoundException;
52
use OCA\Circles\Exceptions\RemoteInstanceException;
53
use OCA\Circles\Exceptions\RemoteNotFoundException;
54
use OCA\Circles\Exceptions\RemoteResourceNotFoundException;
55
use OCA\Circles\Exceptions\UnknownRemoteException;
56
use OCA\Circles\Exceptions\UserTypeNotFoundException;
57
use OCA\Circles\IFederatedUser;
58
use OCA\Circles\Model\Circle;
59
use OCA\Circles\Model\Federated\RemoteInstance;
60
use OCA\Circles\Model\FederatedUser;
61
use OCA\Circles\Model\ManagedModel;
62
use OCA\Circles\Model\Member;
63
use OCP\IUserManager;
64
65
66
/**
67
 * Class FederatedUserService
68
 *
69
 * @package OCA\Circles\Service
70
 */
71
class FederatedUserService {
72
73
74
	use TArrayTools;
75
	use TStringTools;
76
	use TNC21Logger;
77
78
79
	/** @var IUserManager */
80
	private $userManager;
81
82
	/** @var MembershipRequest */
83
	private $membershipRequest;
84
85
	/** @var CircleRequest */
86
	private $circleRequest;
87
88
	/** @var MemberRequest */
89
	private $memberRequest;
90
91
	/** @var RemoteService */
92
	private $remoteService;
93
94
	/** @var ConfigService */
95
	private $configService;
96
97
98
	/** @var FederatedUser */
99
	private $currentUser = null;
100
101
	/** @var RemoteInstance */
102
	private $remoteInstance = null;
103
104
	/** @var bool */
105
	private $bypass = false;
106
107
108
	/**
109
	 * FederatedUserService constructor.
110
	 *
111
	 * @param IUserManager $userManager
112
	 * @param MembershipRequest $membershipRequest
113
	 * @param CircleRequest $circleRequest
114
	 * @param MemberRequest $memberRequest
115
	 * @param RemoteService $remoteService
116
	 * @param ConfigService $configService
117
	 */
118
	public function __construct(
119
		IUserManager $userManager, MembershipRequest $membershipRequest, CircleRequest $circleRequest,
120
		MemberRequest $memberRequest, RemoteService $remoteService, ConfigService $configService
121
	) {
122
		$this->userManager = $userManager;
123
		$this->membershipRequest = $membershipRequest;
124
		$this->circleRequest = $circleRequest;
125
		$this->memberRequest = $memberRequest;
126
		$this->remoteService = $remoteService;
127
		$this->configService = $configService;
128
	}
129
130
131
//	/**
132
//	 * @param string $userId
133
//	 *
134
//	 * @throws CircleNotFoundException
135
//	 * @throws NoUserException
136
//	 */
137
//	public function setLocalInitiator(string $userId): void {
138
//		$this->currentUser = $this->createLocalFederatedUser($userId);
139
//	}
140
141
	/**
142
	 * set a CurrentUser, based on a IFederatedUser.
143
	 * CurrentUser is mainly used to manage rights when requesting the database.
144
	 *
145
	 * @param IFederatedUser $federatedUser
146
	 *
147
	 * @throws FederatedUserException
148
	 */
149
	public function setCurrentUser(IFederatedUser $federatedUser): void {
150
		if (!($federatedUser instanceof FederatedUser)) {
151
			$tmp = new FederatedUser();
152
			$tmp->importFromIFederatedUser($federatedUser);
153
			$federatedUser = $tmp;
154
		}
155
156
		$this->confirmFederatedUser($federatedUser);
157
158
		$this->currentUser = $federatedUser;
159
	}
160
161
	/**
162
	 * @return FederatedUser|null
163
	 */
164
	public function getCurrentUser(): ?FederatedUser {
165
		return $this->currentUser;
166
	}
167
168
	/**
169
	 * @return bool
170
	 */
171
	public function hasCurrentUser(): bool {
172
		return !is_null($this->currentUser);
173
	}
174
175
	/**
176
	 * @throws InitiatorNotFoundException
177
	 */
178
	public function mustHaveCurrentUser(): void {
179
		if ($this->bypass) {
180
			return;
181
		}
182
		if (!$this->hasCurrentUser() && !$this->hasRemoteInstance()) {
183
			throw new InitiatorNotFoundException();
184
		}
185
	}
186
187
	/**
188
	 * @param bool $bypass
189
	 */
190
	public function bypassCurrentUserCondition(bool $bypass): void {
191
		$this->bypass = $bypass;
192
	}
193
194
195
	/**
196
	 * set a RemoteInstance, mostly from a remote request (RemoteController)
197
	 * Used to limit rights in some request in the local database.
198
	 *
199
	 * @param RemoteInstance $remoteInstance
200
	 */
201
	public function setRemoteInstance(RemoteInstance $remoteInstance): void {
202
		$this->remoteInstance = $remoteInstance;
203
	}
204
205
	/**
206
	 * @return RemoteInstance|null
207
	 */
208
	public function getRemoteInstance(): ?RemoteInstance {
209
		return $this->remoteInstance;
210
	}
211
212
	/**
213
	 * @return bool
214
	 */
215
	public function hasRemoteInstance(): bool {
216
		return !is_null($this->remoteInstance);
217
	}
218
219
220
	/**
221
	 * Get the full FederatedUser for a local user.
222
	 * Will generate the SingleId if none exist
223
	 *
224
	 * @param string $userId
225
	 *
226
	 * @return FederatedUser
227
	 * @throws CircleNotFoundException
228
	 * @throws FederatedUserNotFoundException
229
	 * @throws InvalidIdException
230
	 */
231
	public function getLocalFederatedUser(string $userId): FederatedUser {
232
		$user = $this->userManager->get($userId);
233
		if ($user === null) {
234
			throw new FederatedUserNotFoundException('user ' . $userId . ' not found');
235
		}
236
237
		$federatedUser = new FederatedUser();
238
		$federatedUser->set($user->getUID());
239
		$this->fillSingleCircleId($federatedUser);
240
241
		return $federatedUser;
242
	}
243
244
245
	/**
246
	 * some ./occ commands allows to add an Initiator, or force the PoV from the local circles' owner
247
	 *
248
	 * TODO: manage non-user type ?
249
	 *
250
	 * @param string $userId
251
	 * @param string $circleId
252
	 * @param bool $bypass
253
	 *
254
	 * @throws CircleNotFoundException
255
	 * @throws FederatedUserException
256
	 * @throws FederatedUserNotFoundException
257
	 * @throws InvalidIdException
258
	 * @throws InvalidItemException
259
	 * @throws OwnerNotFoundException
260
	 * @throws RemoteInstanceException
261
	 * @throws RemoteNotFoundException
262
	 * @throws RemoteResourceNotFoundException
263
	 * @throws RequestNetworkException
264
	 * @throws SignatoryException
265
	 * @throws UnknownRemoteException
266
	 * @throws UserTypeNotFoundException
267
	 * @throws MemberNotFoundException
268
	 */
269
	public function commandLineInitiator(string $userId, string $circleId = '', bool $bypass = false): void {
270
		if ($userId !== '') {
271
			$this->setCurrentUser($this->getFederatedUser($userId));
272
273
			return;
274
		}
275
276
		if ($circleId !== '') {
277
			$localCircle = $this->circleRequest->getCircle($circleId);
278
			if ($this->configService->isLocalInstance($localCircle->getInstance())) {
279
				// TODO: manage NO_OWNER circles
280
				$this->setCurrentUser($localCircle->getOwner());
281
282
				return;
283
			}
284
		}
285
286
		if (!$bypass) {
287
			throw new CircleNotFoundException(
288
				'This Circle is not managed from this instance, please use --initiator'
289
			);
290
		}
291
292
		$this->bypassCurrentUserCondition($bypass);
293
	}
294
295
296
	/**
297
	 * Works like getFederatedUser, but returns a member.
298
	 * Allow to specify a level: handle@instance,level
299
	 *
300
	 * Used for filters when searching for Circles
301
	 * TODO: Used outside of ./occ circles:manage:list ?
302
	 *
303
	 * @param string $userId
304
	 * @param int $level
305
	 *
306
	 * @return Member
307
	 * @throws CircleNotFoundException
308
	 * @throws FederatedUserException
309
	 * @throws FederatedUserNotFoundException
310
	 * @throws InvalidItemException
311
	 * @throws MemberNotFoundException
312
	 * @throws OwnerNotFoundException
313
	 * @throws RemoteInstanceException
314
	 * @throws RemoteNotFoundException
315
	 * @throws RemoteResourceNotFoundException
316
	 * @throws RequestNetworkException
317
	 * @throws SignatoryException
318
	 * @throws UnknownRemoteException
319
	 * @throws UserTypeNotFoundException
320
	 */
321
	public function getFederatedMember(string $userId, int $level = Member::LEVEL_MEMBER): Member {
322
		$userId = trim($userId, ',');
323
		if (strpos($userId, ',') !== false) {
324
			list($userId, $level) = explode(',', $userId);
325
		}
326
327
		$federatedUser = $this->getFederatedUser($userId);
328
		$member = new Member();
329
		$member->importFromIFederatedUser($federatedUser);
330
		$member->setLevel((int)$level);
331
332
		return $member;
333
	}
334
335
336
	/**
337
	 * Generate a FederatedUser based on local data.
338
	 * WARNING: There is no confirmation that the returned FederatedUser exists or is valid at this point.
339
	 * Use getFederatedUser() instead if a valid and confirmed FederatedUser is needed.
340
	 *
341
	 * if $federatedId is a known SingleId, will returns data from the local database.
342
	 * if $federatedId is a local username, will returns data from the local database.
343
	 * Otherwise, the FederatedUser will not contains a SingleId.
344
	 *
345
	 * @param string $userId
346
	 * @param int $type
347
	 *
348
	 * @return FederatedUser
349
	 */
350
	public function generateFederatedUser(string $userId, int $type = 0): FederatedUser {
351
		$userId = trim($userId, '@');
352
		if (strpos($userId, '@') === false) {
353
			$instance = '';
354
		} else {
355
			list($userId, $instance) = $this->extractIdAndInstance($userId);
356
		}
357
358
		try {
359
			if (($type === 0 || $type === Member::TYPE_USER)
360
				&& ($instance === '' || $this->configService->isLocalInstance($instance))) {
361
				return $this->getLocalFederatedUser($userId);
362
			}
363
		} catch (CircleNotFoundException | FederatedUserNotFoundException | InvalidIdException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
364
		}
365
366
		try {
367
			if ($type === 0 || $type === Member::TYPE_SINGLE) {
368
				$federatedUser = $this->memberRequest->getFederatedUserBySingleId($userId);
369
				if ($instance === '' || $federatedUser->getInstance() === $instance) {
370
					return $federatedUser;
371
				}
372
			}
373
		} catch (MemberNotFoundException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
374
		}
375
376
		try {
377
			if ($type === 0 || $type === Member::TYPE_CIRCLE) {
378
				$federatedUser = $this->circleRequest->getFederatedUserByCircleId($userId);
379
				if ($instance === '' || $federatedUser->getInstance() === $instance) {
380
					return $federatedUser;
381
				}
382
			}
383
		} catch (CircleNotFoundException | OwnerNotFoundException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
384
		}
385
386
		// TODO: search for other possible entries, like mail address
387
388
		if ($type === 0) {
389
			$type = Member::TYPE_USER;
390
		}
391
392
		$federatedUser = new FederatedUser();
393
		$federatedUser->set($userId, $instance, $type);
394
395
		return $federatedUser;
396
	}
397
398
399
	/**
400
	 * get a valid FederatedUser, based on the federatedId (userId@instance) its the type.
401
	 * If instance is local, get the local valid FederatedUser
402
	 * If instance is not local, get the remote valid FederatedUser
403
	 *
404
	 * @param string $federatedId
405
	 * @param int $userType
406
	 *
407
	 * @return FederatedUser
408
	 * @throws CircleNotFoundException
409
	 * @throws FederatedUserException
410
	 * @throws FederatedUserNotFoundException
411
	 * @throws InvalidItemException
412
	 * @throws MemberNotFoundException
413
	 * @throws OwnerNotFoundException
414
	 * @throws RemoteInstanceException
415
	 * @throws RemoteNotFoundException
416
	 * @throws RemoteResourceNotFoundException
417
	 * @throws RequestNetworkException
418
	 * @throws SignatoryException
419
	 * @throws UnknownRemoteException
420
	 * @throws UserTypeNotFoundException
421
	 */
422
	public function getFederatedUser(string $federatedId, int $userType = Member::TYPE_USER): FederatedUser {
423
		list($singleId, $instance) = $this->extractIdAndInstance($federatedId);
424
425
		switch ($userType) {
426
			case Member::TYPE_USER:
427
				try {
428
					return $this->getFederatedUser_User($singleId, $instance);
429
				} catch (Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
430
				}
431
432
				return $this->getFederatedUser_SingleId($singleId, $instance);
433
			case Member::TYPE_CIRCLE:
434
				return $this->getFederatedUser_Circle($singleId, $instance);
435
			case Member::TYPE_SINGLE:
436
				return $this->getFederatedUser_SingleId($singleId, $instance);
437
		}
438
439
		throw new UserTypeNotFoundException();
440
	}
441
442
443
	/**
444
	 * @param string $singleId
445
	 * @param string $instance
446
	 *
447
	 * @return FederatedUser
448
	 * @throws FederatedUserException
449
	 * @throws FederatedUserNotFoundException
450
	 * @throws InvalidItemException
451
	 * @throws MemberNotFoundException
452
	 * @throws RemoteInstanceException
453
	 * @throws RemoteNotFoundException
454
	 * @throws RemoteResourceNotFoundException
455
	 * @throws RequestNetworkException
456
	 * @throws SignatoryException
457
	 * @throws UnknownRemoteException
458
	 */
459
	private function getFederatedUser_SingleId(string $singleId, string $instance): FederatedUser {
460
		if (strlen($singleId) !== ManagedModel::ID_LENGTH) {
461
			throw new MemberNotFoundException();
462
		}
463
464
		if ($this->configService->isLocalInstance($instance)) {
465
			return $this->memberRequest->getFederatedUserBySingleId($singleId);
466
		} else {
467
			$federatedUser =
468
				$this->remoteService->getFederatedUserFromInstance($singleId, $instance, Member::TYPE_SINGLE);
469
			$this->confirmLocalSingleId($federatedUser);
470
471
			return $federatedUser;
472
		}
473
	}
474
475
476
	/**
477
	 * @param string $userId
478
	 * @param string $instance
479
	 *
480
	 * @return FederatedUser
481
	 * @throws CircleNotFoundException
482
	 * @throws FederatedUserException
483
	 * @throws FederatedUserNotFoundException
484
	 * @throws InvalidIdException
485
	 * @throws InvalidItemException
486
	 * @throws RemoteInstanceException
487
	 * @throws RemoteNotFoundException
488
	 * @throws RemoteResourceNotFoundException
489
	 * @throws RequestNetworkException
490
	 * @throws SignatoryException
491
	 * @throws UnknownRemoteException
492
	 */
493
	private function getFederatedUser_User(string $userId, string $instance): FederatedUser {
494
		if ($this->configService->isLocalInstance($instance)) {
495
			return $this->getLocalFederatedUser($userId);
496
		} else {
497
			$federatedUser =
498
				$this->remoteService->getFederatedUserFromInstance($userId, $instance, Member::TYPE_USER);
499
			$this->confirmLocalSingleId($federatedUser);
500
501
			return $federatedUser;
502
		}
503
	}
504
505
506
	/**
507
	 * // TODO: do we need to have this working on remote instance ?
508
	 *
509
	 * @param string $circleId
510
	 * @param string $instance
511
	 *
512
	 * @return FederatedUser
513
	 * @throws CircleNotFoundException
514
	 * @throws OwnerNotFoundException
515
	 */
516
	private function getFederatedUser_Circle(string $circleId, string $instance): FederatedUser {
0 ignored issues
show
Unused Code introduced by
The parameter $instance is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
517
		// TODO: check remote instance for existing circle
518
//		if ($this->configService->isLocalInstance($instance)) {
519
		$circle = $this->circleRequest->getCircle($circleId);
520
		$federatedUser = new FederatedUser();
521
		$federatedUser->set($circleId, $circle->getInstance(), Member::TYPE_CIRCLE);
522
		$federatedUser->setSingleId($circleId);
523
//		} else {
524
//		}
525
526
		return $federatedUser;
527
	}
528
529
530
	/**
531
	 * extract userID and instance from a federatedId
532
	 *
533
	 * @param string $federatedId
534
	 *
535
	 * @return array
536
	 */
537
	private function extractIdAndInstance(string $federatedId): array {
538
		$federatedId = trim($federatedId, '@');
539
		if (strpos($federatedId, '@') === false) {
540
			$userId = $federatedId;
541
			$instance = $this->configService->getLocalInstance();
542
		} else {
543
			list($userId, $instance) = explode('@', $federatedId);
544
		}
545
546
		return [$userId, $instance];
547
	}
548
549
550
	/**
551
	 * @param FederatedUser $federatedUser
552
	 *
553
	 * @throws CircleNotFoundException
554
	 * @throws InvalidIdException
555
	 */
556
	private function fillSingleCircleId(FederatedUser $federatedUser): void {
557
		if ($federatedUser->getSingleId() !== '') {
558
			return;
559
		}
560
561
		$circle = $this->getSingleCircle($federatedUser);
562
		$federatedUser->setSingleId($circle->getId());
563
	}
564
565
566
	/**
567
	 * get the Single Circle from a local user
568
	 *
569
	 * @param FederatedUser $federatedUser
570
	 *
571
	 * @return Circle
572
	 * @throws CircleNotFoundException
573
	 * @throws InvalidIdException
574
	 * @throws FederatedUserException
575
	 */
576
	private function getSingleCircle(FederatedUser $federatedUser): Circle {
577
		if (!$this->configService->isLocalInstance($federatedUser->getInstance())) {
578
			throw new FederatedUserException('FederatedUser must be local');
579
		}
580
581
		try {
582
			return $this->circleRequest->getInitiatorCircle($federatedUser);
583
		} catch (CircleNotFoundException $e) {
584
			$circle = new Circle();
585
			$id = $this->token(ManagedModel::ID_LENGTH);
586
587
			$circle->setName('single:' . $federatedUser->getUserId() . ':' . $id)
588
				   ->setId($id)
589
				   ->setConfig(Circle::CFG_SINGLE);
590
			$this->circleRequest->save($circle);
591
592
			$owner = new Member();
593
			$owner->importFromIFederatedUser($federatedUser);
594
			$owner->setLevel(Member::LEVEL_OWNER)
595
				  ->setCircleId($id)
596
				  ->setSingleId($id)
597
				  ->setId($id)
598
				  ->setCachedName($owner->getUserId())
599
				  ->setStatus('Member');
600
			$this->memberRequest->save($owner);
601
		}
602
603
		return $this->circleRequest->getInitiatorCircle($federatedUser);
604
	}
605
606
607
	/**
608
	 * Confirm that all field of a FederatedUser are filled.
609
	 *
610
	 * @param FederatedUser $federatedUser
611
	 *
612
	 * @throws FederatedUserException
613
	 */
614
	private function confirmFederatedUser(FederatedUser $federatedUser): void {
615
		if ($federatedUser->getUserId() === ''
616
			|| $federatedUser->getSingleId() === ''
617
			|| $federatedUser->getUserType() === ''
0 ignored issues
show
Unused Code Bug introduced by
The strict comparison === seems to always evaluate to false as the types of $federatedUser->getUserType() (integer) and '' (string) can never be identical. Maybe you want to use a loose comparison == instead?
Loading history...
618
			|| $federatedUser->getInstance() === '') {
619
			$this->debug('FederatedUser is not empty', ['federatedUser' => $federatedUser]);
620
			throw new FederatedUserException('FederatedUser is not complete');
621
		}
622
	}
623
624
	/**
625
	 * Confirm that the singleId of a FederatedUser is unique and not used to any other member of the
626
	 * database.
627
	 *
628
	 * @param FederatedUser $federatedUser
629
	 *
630
	 * @throws FederatedUserException
631
	 */
632
	public function confirmLocalSingleId(FederatedUser $federatedUser): void {
633
		$members = $this->memberRequest->getMembersBySingleId($federatedUser->getSingleId());
634
635
		foreach ($members as $member) {
636
			if (!$federatedUser->compareWith($member)) {
637
				$this->debug(
638
					'uniqueness of SingleId could not be confirmed',
639
					['federatedUser' => $federatedUser, 'localMember' => $member]
640
				);
641
				throw new FederatedUserException('uniqueness of SingleId could not be confirmed');
642
			}
643
		}
644
	}
645
646
647
//	/**
648
//	 * @param FederatedUser $federatedUser
649
//	 *
650
//	 * @return Membership[]
651
//	 */
652
//	public function generateMemberships(FederatedUser $federatedUser): array {
653
//		$circles = $this->circleRequest->getCircles(null, $federatedUser);
654
//		$memberships = [];
655
//		foreach ($circles as $circle) {
656
//			$initiator = $circle->getInitiator();
657
//			if (!$initiator->isMember()) {
658
//				continue;
659
//			}
660
//
661
//			$memberships[] = new Membership(
662
//				$initiator->getId(), $circle->getId(), $federatedUser->getSingleId(), $initiator->getLevel()
663
//			);
664
//
665
////			$newUser = new CurrentUser($circle->getId(), Member::TYPE_CIRCLE, '');
666
////			$circles = $this->circleRequest->getCircles(null, $currentUser);
667
//		}
668
//
669
//		return $memberships;
670
//	}
671
//
672
//
673
//	/**
674
//	 * @param FederatedUser|null $federatedUser
675
//	 */
676
//	public function updateMemberships(?FederatedUser $federatedUser = null) {
677
//		if (is_null($federatedUser)) {
678
//			$federatedUser = $this->getCurrentUser();
679
//		} else {
680
//			$federatedUser->setMemberships($this->membershipRequest->getMemberships($federatedUser));
681
//		}
682
//
683
//		if (is_null($federatedUser)) {
684
//			return;
685
//		}
686
//
687
//		$last = $this->generateMemberships($federatedUser);
688
//
689
//		echo 'known: ' . json_encode($federatedUser->getMemberships()) . "\n";
690
//		echo 'last: ' . json_encode($last) . "\n";
691
//
692
////
693
////		$circles = $this->circleRequest->getCircles(null, $viewer);
694
////		foreach ($circles as $circle) {
695
////			$viewer = $circle->getViewer();
696
////			if (!$viewer->isMember()) {
697
////				continue;
698
////			}
699
////
700
////			echo 'new member: ' . json_encode($viewer) . "\n";
701
//////			$this->federatedUserService->updateMembership($circle);
702
////		}
703
//
704
//
705
//	}
706
707
708
}
709
710