@@ -11,118 +11,118 @@ |
||
| 11 | 11 | * @since 29.0.0 |
| 12 | 12 | */ |
| 13 | 13 | class TeamResource implements \JsonSerializable { |
| 14 | - /** |
|
| 15 | - * @since 29.0.0 |
|
| 16 | - */ |
|
| 17 | - public function __construct( |
|
| 18 | - private ITeamResourceProvider $teamResourceProvider, |
|
| 19 | - private string $resourceId, |
|
| 20 | - private string $label, |
|
| 21 | - private string $url, |
|
| 22 | - private ?string $iconSvg = null, |
|
| 23 | - private ?string $iconURL = null, |
|
| 24 | - private ?string $iconEmoji = null, |
|
| 25 | - ) { |
|
| 26 | - } |
|
| 14 | + /** |
|
| 15 | + * @since 29.0.0 |
|
| 16 | + */ |
|
| 17 | + public function __construct( |
|
| 18 | + private ITeamResourceProvider $teamResourceProvider, |
|
| 19 | + private string $resourceId, |
|
| 20 | + private string $label, |
|
| 21 | + private string $url, |
|
| 22 | + private ?string $iconSvg = null, |
|
| 23 | + private ?string $iconURL = null, |
|
| 24 | + private ?string $iconEmoji = null, |
|
| 25 | + ) { |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Returns the provider details for the current resource |
|
| 30 | - * |
|
| 31 | - * @since 29.0.0 |
|
| 32 | - */ |
|
| 33 | - public function getProvider(): ITeamResourceProvider { |
|
| 34 | - return $this->teamResourceProvider; |
|
| 35 | - } |
|
| 28 | + /** |
|
| 29 | + * Returns the provider details for the current resource |
|
| 30 | + * |
|
| 31 | + * @since 29.0.0 |
|
| 32 | + */ |
|
| 33 | + public function getProvider(): ITeamResourceProvider { |
|
| 34 | + return $this->teamResourceProvider; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Unique id of the resource (e.g. primary key id) |
|
| 39 | - * @since 29.0.0 |
|
| 40 | - */ |
|
| 41 | - public function getId(): string { |
|
| 42 | - return $this->resourceId; |
|
| 43 | - } |
|
| 37 | + /** |
|
| 38 | + * Unique id of the resource (e.g. primary key id) |
|
| 39 | + * @since 29.0.0 |
|
| 40 | + */ |
|
| 41 | + public function getId(): string { |
|
| 42 | + return $this->resourceId; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * User visible label when listing resources |
|
| 47 | - * |
|
| 48 | - * @since 29.0.0 |
|
| 49 | - */ |
|
| 50 | - public function getLabel(): string { |
|
| 51 | - return $this->label; |
|
| 52 | - } |
|
| 45 | + /** |
|
| 46 | + * User visible label when listing resources |
|
| 47 | + * |
|
| 48 | + * @since 29.0.0 |
|
| 49 | + */ |
|
| 50 | + public function getLabel(): string { |
|
| 51 | + return $this->label; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Absolute url to navigate the user to the resource |
|
| 56 | - * |
|
| 57 | - * @since 29.0.0 |
|
| 58 | - */ |
|
| 59 | - public function getUrl(): string { |
|
| 60 | - return $this->url; |
|
| 61 | - } |
|
| 54 | + /** |
|
| 55 | + * Absolute url to navigate the user to the resource |
|
| 56 | + * |
|
| 57 | + * @since 29.0.0 |
|
| 58 | + */ |
|
| 59 | + public function getUrl(): string { |
|
| 60 | + return $this->url; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * Svg icon to show next to the name for the resource |
|
| 65 | - * |
|
| 66 | - * From all icons the first one returning not null will be picked in order: iconEmoji, iconSvg, iconUrl |
|
| 67 | - * |
|
| 68 | - * @since 29.0.0 |
|
| 69 | - */ |
|
| 70 | - public function getIconSvg(): ?string { |
|
| 71 | - return $this->iconSvg; |
|
| 72 | - } |
|
| 63 | + /** |
|
| 64 | + * Svg icon to show next to the name for the resource |
|
| 65 | + * |
|
| 66 | + * From all icons the first one returning not null will be picked in order: iconEmoji, iconSvg, iconUrl |
|
| 67 | + * |
|
| 68 | + * @since 29.0.0 |
|
| 69 | + */ |
|
| 70 | + public function getIconSvg(): ?string { |
|
| 71 | + return $this->iconSvg; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * Image url of the icon to show next to the name for the resource |
|
| 76 | - * |
|
| 77 | - * From all icons the first one returning not null will be picked in order: iconEmoji, iconSvg, iconUrl |
|
| 78 | - * |
|
| 79 | - * @since 29.0.0 |
|
| 80 | - */ |
|
| 81 | - public function getIconURL(): ?string { |
|
| 82 | - return $this->iconURL; |
|
| 83 | - } |
|
| 74 | + /** |
|
| 75 | + * Image url of the icon to show next to the name for the resource |
|
| 76 | + * |
|
| 77 | + * From all icons the first one returning not null will be picked in order: iconEmoji, iconSvg, iconUrl |
|
| 78 | + * |
|
| 79 | + * @since 29.0.0 |
|
| 80 | + */ |
|
| 81 | + public function getIconURL(): ?string { |
|
| 82 | + return $this->iconURL; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * Emoji show next to the name for the resource |
|
| 87 | - * |
|
| 88 | - * From all icons the first one returning not null will be picked in order: iconEmoji, iconSvg, iconUrl |
|
| 89 | - * |
|
| 90 | - * @since 29.0.0 |
|
| 91 | - */ |
|
| 92 | - public function getIconEmoji(): ?string { |
|
| 93 | - return $this->iconEmoji; |
|
| 94 | - } |
|
| 85 | + /** |
|
| 86 | + * Emoji show next to the name for the resource |
|
| 87 | + * |
|
| 88 | + * From all icons the first one returning not null will be picked in order: iconEmoji, iconSvg, iconUrl |
|
| 89 | + * |
|
| 90 | + * @since 29.0.0 |
|
| 91 | + */ |
|
| 92 | + public function getIconEmoji(): ?string { |
|
| 93 | + return $this->iconEmoji; |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * @return array{ |
|
| 98 | - * id: string, |
|
| 99 | - * label: string, |
|
| 100 | - * url: string, |
|
| 101 | - * iconSvg: ?string, |
|
| 102 | - * iconURL: ?string, |
|
| 103 | - * iconEmoji: ?string, |
|
| 104 | - * provider: array{ |
|
| 105 | - * id: string, |
|
| 106 | - * name: string, |
|
| 107 | - * icon: string, |
|
| 108 | - * }, |
|
| 109 | - * } |
|
| 110 | - * |
|
| 111 | - * @since 29.0.0 |
|
| 112 | - */ |
|
| 113 | - public function jsonSerialize(): array { |
|
| 114 | - return [ |
|
| 115 | - 'id' => $this->resourceId, |
|
| 116 | - 'label' => $this->label, |
|
| 117 | - 'url' => $this->url, |
|
| 118 | - 'iconSvg' => $this->iconSvg, |
|
| 119 | - 'iconURL' => $this->iconURL, |
|
| 120 | - 'iconEmoji' => $this->iconEmoji, |
|
| 121 | - 'provider' => [ |
|
| 122 | - 'id' => $this->teamResourceProvider->getId(), |
|
| 123 | - 'name' => $this->teamResourceProvider->getName(), |
|
| 124 | - 'icon' => $this->teamResourceProvider->getIconSvg(), |
|
| 125 | - ] |
|
| 126 | - ]; |
|
| 127 | - } |
|
| 96 | + /** |
|
| 97 | + * @return array{ |
|
| 98 | + * id: string, |
|
| 99 | + * label: string, |
|
| 100 | + * url: string, |
|
| 101 | + * iconSvg: ?string, |
|
| 102 | + * iconURL: ?string, |
|
| 103 | + * iconEmoji: ?string, |
|
| 104 | + * provider: array{ |
|
| 105 | + * id: string, |
|
| 106 | + * name: string, |
|
| 107 | + * icon: string, |
|
| 108 | + * }, |
|
| 109 | + * } |
|
| 110 | + * |
|
| 111 | + * @since 29.0.0 |
|
| 112 | + */ |
|
| 113 | + public function jsonSerialize(): array { |
|
| 114 | + return [ |
|
| 115 | + 'id' => $this->resourceId, |
|
| 116 | + 'label' => $this->label, |
|
| 117 | + 'url' => $this->url, |
|
| 118 | + 'iconSvg' => $this->iconSvg, |
|
| 119 | + 'iconURL' => $this->iconURL, |
|
| 120 | + 'iconEmoji' => $this->iconEmoji, |
|
| 121 | + 'provider' => [ |
|
| 122 | + 'id' => $this->teamResourceProvider->getId(), |
|
| 123 | + 'name' => $this->teamResourceProvider->getName(), |
|
| 124 | + 'icon' => $this->teamResourceProvider->getIconSvg(), |
|
| 125 | + ] |
|
| 126 | + ]; |
|
| 127 | + } |
|
| 128 | 128 | } |
@@ -16,53 +16,53 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class Team implements \JsonSerializable { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @since 29.0.0 |
|
| 21 | - */ |
|
| 22 | - public function __construct( |
|
| 23 | - private string $teamId, |
|
| 24 | - private string $displayName, |
|
| 25 | - private ?string $link, |
|
| 26 | - ) { |
|
| 27 | - } |
|
| 19 | + /** |
|
| 20 | + * @since 29.0.0 |
|
| 21 | + */ |
|
| 22 | + public function __construct( |
|
| 23 | + private string $teamId, |
|
| 24 | + private string $displayName, |
|
| 25 | + private ?string $link, |
|
| 26 | + ) { |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Unique identifier of the team (singleId of the circle) |
|
| 31 | - * |
|
| 32 | - * @since 29.0.0 |
|
| 33 | - */ |
|
| 34 | - public function getId(): string { |
|
| 35 | - return $this->teamId; |
|
| 36 | - } |
|
| 29 | + /** |
|
| 30 | + * Unique identifier of the team (singleId of the circle) |
|
| 31 | + * |
|
| 32 | + * @since 29.0.0 |
|
| 33 | + */ |
|
| 34 | + public function getId(): string { |
|
| 35 | + return $this->teamId; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @since 29.0.0 |
|
| 40 | - */ |
|
| 41 | - public function getDisplayName(): string { |
|
| 42 | - return $this->displayName; |
|
| 43 | - } |
|
| 38 | + /** |
|
| 39 | + * @since 29.0.0 |
|
| 40 | + */ |
|
| 41 | + public function getDisplayName(): string { |
|
| 42 | + return $this->displayName; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @since 29.0.0 |
|
| 47 | - */ |
|
| 48 | - public function getLink(): ?string { |
|
| 49 | - return $this->link; |
|
| 50 | - } |
|
| 45 | + /** |
|
| 46 | + * @since 29.0.0 |
|
| 47 | + */ |
|
| 48 | + public function getLink(): ?string { |
|
| 49 | + return $this->link; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @return array{ |
|
| 54 | - * teamId: string, |
|
| 55 | - * displayName: string, |
|
| 56 | - * link: ?string, |
|
| 57 | - * } |
|
| 58 | - * |
|
| 59 | - * @since 29.0.0 |
|
| 60 | - */ |
|
| 61 | - public function jsonSerialize(): array { |
|
| 62 | - return [ |
|
| 63 | - 'teamId' => $this->teamId, |
|
| 64 | - 'displayName' => $this->displayName, |
|
| 65 | - 'link' => $this->link, |
|
| 66 | - ]; |
|
| 67 | - } |
|
| 52 | + /** |
|
| 53 | + * @return array{ |
|
| 54 | + * teamId: string, |
|
| 55 | + * displayName: string, |
|
| 56 | + * link: ?string, |
|
| 57 | + * } |
|
| 58 | + * |
|
| 59 | + * @since 29.0.0 |
|
| 60 | + */ |
|
| 61 | + public function jsonSerialize(): array { |
|
| 62 | + return [ |
|
| 63 | + 'teamId' => $this->teamId, |
|
| 64 | + 'displayName' => $this->displayName, |
|
| 65 | + 'link' => $this->link, |
|
| 66 | + ]; |
|
| 67 | + } |
|
| 68 | 68 | } |
@@ -11,41 +11,41 @@ |
||
| 11 | 11 | * @since 29.0.0 |
| 12 | 12 | */ |
| 13 | 13 | interface ITeamManager { |
| 14 | - /** |
|
| 15 | - * Get all providers that have registered as a team resource provider |
|
| 16 | - * |
|
| 17 | - * @return ITeamResourceProvider[] |
|
| 18 | - * @since 29.0.0 |
|
| 19 | - */ |
|
| 20 | - public function getProviders(): array; |
|
| 14 | + /** |
|
| 15 | + * Get all providers that have registered as a team resource provider |
|
| 16 | + * |
|
| 17 | + * @return ITeamResourceProvider[] |
|
| 18 | + * @since 29.0.0 |
|
| 19 | + */ |
|
| 20 | + public function getProviders(): array; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Get a specific team resource provider by its id |
|
| 24 | - * |
|
| 25 | - * @since 29.0.0 |
|
| 26 | - */ |
|
| 27 | - public function getProvider(string $providerId): ITeamResourceProvider; |
|
| 22 | + /** |
|
| 23 | + * Get a specific team resource provider by its id |
|
| 24 | + * |
|
| 25 | + * @since 29.0.0 |
|
| 26 | + */ |
|
| 27 | + public function getProvider(string $providerId): ITeamResourceProvider; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Returns all team resources for a given team and user |
|
| 31 | - * |
|
| 32 | - * @return list<TeamResource> |
|
| 33 | - * @since 29.0.0 |
|
| 34 | - */ |
|
| 35 | - public function getSharedWith(string $teamId, string $userId): array; |
|
| 29 | + /** |
|
| 30 | + * Returns all team resources for a given team and user |
|
| 31 | + * |
|
| 32 | + * @return list<TeamResource> |
|
| 33 | + * @since 29.0.0 |
|
| 34 | + */ |
|
| 35 | + public function getSharedWith(string $teamId, string $userId): array; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Returns all teams for a given resource and user |
|
| 39 | - * |
|
| 40 | - * @since 29.0.0 |
|
| 41 | - */ |
|
| 42 | - public function getTeamsForResource(string $providerId, string $resourceId, string $userId): array; |
|
| 37 | + /** |
|
| 38 | + * Returns all teams for a given resource and user |
|
| 39 | + * |
|
| 40 | + * @since 29.0.0 |
|
| 41 | + */ |
|
| 42 | + public function getTeamsForResource(string $providerId, string $resourceId, string $userId): array; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @param list<Team> $teams |
|
| 46 | - * @return array<string, list<TeamResource>> |
|
| 47 | - * |
|
| 48 | - * @since 33.0.0 |
|
| 49 | - */ |
|
| 50 | - public function getSharedWithList(array $teams, string $userId): array; |
|
| 44 | + /** |
|
| 45 | + * @param list<Team> $teams |
|
| 46 | + * @return array<string, list<TeamResource>> |
|
| 47 | + * |
|
| 48 | + * @since 33.0.0 |
|
| 49 | + */ |
|
| 50 | + public function getSharedWithList(array $teams, string $userId): array; |
|
| 51 | 51 | } |
@@ -22,126 +22,126 @@ |
||
| 22 | 22 | |
| 23 | 23 | class TeamManager implements ITeamManager { |
| 24 | 24 | |
| 25 | - /** @var ?ITeamResourceProvider[] */ |
|
| 26 | - private ?array $providers = null; |
|
| 27 | - |
|
| 28 | - public function __construct( |
|
| 29 | - private Coordinator $bootContext, |
|
| 30 | - private IURLGenerator $urlGenerator, |
|
| 31 | - private ?CirclesManager $circlesManager, |
|
| 32 | - ) { |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - public function hasTeamSupport(): bool { |
|
| 36 | - return $this->circlesManager !== null; |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - public function getProviders(): array { |
|
| 40 | - if (!$this->hasTeamSupport()) { |
|
| 41 | - return []; |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - if ($this->providers !== null) { |
|
| 45 | - return $this->providers; |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - $this->providers = []; |
|
| 49 | - foreach ($this->bootContext->getRegistrationContext()->getTeamResourceProviders() as $providerRegistration) { |
|
| 50 | - try { |
|
| 51 | - /** @var ITeamResourceProvider $provider */ |
|
| 52 | - $provider = Server::get($providerRegistration->getService()); |
|
| 53 | - $this->providers[$provider->getId()] = $provider; |
|
| 54 | - } catch (NotFoundExceptionInterface|ContainerExceptionInterface $e) { |
|
| 55 | - } |
|
| 56 | - } |
|
| 57 | - return $this->providers; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - public function getProvider(string $providerId): ITeamResourceProvider { |
|
| 61 | - $providers = $this->getProviders(); |
|
| 62 | - if (isset($providers[$providerId])) { |
|
| 63 | - return $providers[$providerId]; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - throw new \RuntimeException('No provider found for id ' . $providerId); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - public function getSharedWith(string $teamId, string $userId): array { |
|
| 70 | - if (!$this->hasTeamSupport()) { |
|
| 71 | - return []; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - if ($this->getTeam($teamId, $userId) === null) { |
|
| 75 | - return []; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - $resources = []; |
|
| 79 | - |
|
| 80 | - foreach ($this->getProviders() as $provider) { |
|
| 81 | - array_push($resources, ...$provider->getSharedWith($teamId)); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - return array_values($resources); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - public function getSharedWithList(array $teams, string $userId): array { |
|
| 88 | - if (!$this->hasTeamSupport()) { |
|
| 89 | - return []; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - $resources = []; |
|
| 93 | - foreach ($this->getProviders() as $provider) { |
|
| 94 | - if (method_exists($provider, 'getSharedWithList')) { |
|
| 95 | - $resources[] = $provider->getSharedWithList($teams, $userId); |
|
| 96 | - } else { |
|
| 97 | - foreach ($teams as $team) { |
|
| 98 | - $resources[] = [$team->getId() => $provider->getSharedWith($team->getId())]; |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - return array_merge_recursive(...$resources); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - public function getTeamsForResource(string $providerId, string $resourceId, string $userId): array { |
|
| 107 | - if (!$this->hasTeamSupport()) { |
|
| 108 | - return []; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - $provider = $this->getProvider($providerId); |
|
| 112 | - return array_map(function (Circle $team) { |
|
| 113 | - return new Team( |
|
| 114 | - $team->getSingleId(), |
|
| 115 | - $team->getDisplayName(), |
|
| 116 | - $this->urlGenerator->linkToRouteAbsolute('contacts.contacts.directcircle', ['singleId' => $team->getSingleId()]), |
|
| 117 | - ); |
|
| 118 | - }, $this->getTeams($provider->getTeamsForResource($resourceId), $userId)); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - private function getTeam(string $teamId, string $userId): ?Circle { |
|
| 122 | - if (!$this->hasTeamSupport()) { |
|
| 123 | - return null; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - try { |
|
| 127 | - $federatedUser = $this->circlesManager->getFederatedUser($userId, Member::TYPE_USER); |
|
| 128 | - $this->circlesManager->startSession($federatedUser); |
|
| 129 | - return $this->circlesManager->getCircle($teamId); |
|
| 130 | - } catch (CircleNotFoundException) { |
|
| 131 | - return null; |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * @return Circle[] |
|
| 137 | - */ |
|
| 138 | - private function getTeams(array $teams, string $userId): array { |
|
| 139 | - if (!$this->hasTeamSupport()) { |
|
| 140 | - return []; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - $federatedUser = $this->circlesManager->getFederatedUser($userId, Member::TYPE_USER); |
|
| 144 | - $this->circlesManager->startSession($federatedUser); |
|
| 145 | - return $this->circlesManager->getCirclesByIds($teams); |
|
| 146 | - } |
|
| 25 | + /** @var ?ITeamResourceProvider[] */ |
|
| 26 | + private ?array $providers = null; |
|
| 27 | + |
|
| 28 | + public function __construct( |
|
| 29 | + private Coordinator $bootContext, |
|
| 30 | + private IURLGenerator $urlGenerator, |
|
| 31 | + private ?CirclesManager $circlesManager, |
|
| 32 | + ) { |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + public function hasTeamSupport(): bool { |
|
| 36 | + return $this->circlesManager !== null; |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + public function getProviders(): array { |
|
| 40 | + if (!$this->hasTeamSupport()) { |
|
| 41 | + return []; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + if ($this->providers !== null) { |
|
| 45 | + return $this->providers; |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + $this->providers = []; |
|
| 49 | + foreach ($this->bootContext->getRegistrationContext()->getTeamResourceProviders() as $providerRegistration) { |
|
| 50 | + try { |
|
| 51 | + /** @var ITeamResourceProvider $provider */ |
|
| 52 | + $provider = Server::get($providerRegistration->getService()); |
|
| 53 | + $this->providers[$provider->getId()] = $provider; |
|
| 54 | + } catch (NotFoundExceptionInterface|ContainerExceptionInterface $e) { |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | + return $this->providers; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + public function getProvider(string $providerId): ITeamResourceProvider { |
|
| 61 | + $providers = $this->getProviders(); |
|
| 62 | + if (isset($providers[$providerId])) { |
|
| 63 | + return $providers[$providerId]; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + throw new \RuntimeException('No provider found for id ' . $providerId); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + public function getSharedWith(string $teamId, string $userId): array { |
|
| 70 | + if (!$this->hasTeamSupport()) { |
|
| 71 | + return []; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + if ($this->getTeam($teamId, $userId) === null) { |
|
| 75 | + return []; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + $resources = []; |
|
| 79 | + |
|
| 80 | + foreach ($this->getProviders() as $provider) { |
|
| 81 | + array_push($resources, ...$provider->getSharedWith($teamId)); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + return array_values($resources); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + public function getSharedWithList(array $teams, string $userId): array { |
|
| 88 | + if (!$this->hasTeamSupport()) { |
|
| 89 | + return []; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + $resources = []; |
|
| 93 | + foreach ($this->getProviders() as $provider) { |
|
| 94 | + if (method_exists($provider, 'getSharedWithList')) { |
|
| 95 | + $resources[] = $provider->getSharedWithList($teams, $userId); |
|
| 96 | + } else { |
|
| 97 | + foreach ($teams as $team) { |
|
| 98 | + $resources[] = [$team->getId() => $provider->getSharedWith($team->getId())]; |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + return array_merge_recursive(...$resources); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + public function getTeamsForResource(string $providerId, string $resourceId, string $userId): array { |
|
| 107 | + if (!$this->hasTeamSupport()) { |
|
| 108 | + return []; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + $provider = $this->getProvider($providerId); |
|
| 112 | + return array_map(function (Circle $team) { |
|
| 113 | + return new Team( |
|
| 114 | + $team->getSingleId(), |
|
| 115 | + $team->getDisplayName(), |
|
| 116 | + $this->urlGenerator->linkToRouteAbsolute('contacts.contacts.directcircle', ['singleId' => $team->getSingleId()]), |
|
| 117 | + ); |
|
| 118 | + }, $this->getTeams($provider->getTeamsForResource($resourceId), $userId)); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + private function getTeam(string $teamId, string $userId): ?Circle { |
|
| 122 | + if (!$this->hasTeamSupport()) { |
|
| 123 | + return null; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + try { |
|
| 127 | + $federatedUser = $this->circlesManager->getFederatedUser($userId, Member::TYPE_USER); |
|
| 128 | + $this->circlesManager->startSession($federatedUser); |
|
| 129 | + return $this->circlesManager->getCircle($teamId); |
|
| 130 | + } catch (CircleNotFoundException) { |
|
| 131 | + return null; |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * @return Circle[] |
|
| 137 | + */ |
|
| 138 | + private function getTeams(array $teams, string $userId): array { |
|
| 139 | + if (!$this->hasTeamSupport()) { |
|
| 140 | + return []; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + $federatedUser = $this->circlesManager->getFederatedUser($userId, Member::TYPE_USER); |
|
| 144 | + $this->circlesManager->startSession($federatedUser); |
|
| 145 | + return $this->circlesManager->getCirclesByIds($teams); |
|
| 146 | + } |
|
| 147 | 147 | } |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | /** @var ITeamResourceProvider $provider */ |
| 52 | 52 | $provider = Server::get($providerRegistration->getService()); |
| 53 | 53 | $this->providers[$provider->getId()] = $provider; |
| 54 | - } catch (NotFoundExceptionInterface|ContainerExceptionInterface $e) { |
|
| 54 | + } catch (NotFoundExceptionInterface | ContainerExceptionInterface $e) { |
|
| 55 | 55 | } |
| 56 | 56 | } |
| 57 | 57 | return $this->providers; |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | return $providers[$providerId]; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - throw new \RuntimeException('No provider found for id ' . $providerId); |
|
| 66 | + throw new \RuntimeException('No provider found for id '.$providerId); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | public function getSharedWith(string $teamId, string $userId): array { |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | $provider = $this->getProvider($providerId); |
| 112 | - return array_map(function (Circle $team) { |
|
| 112 | + return array_map(function(Circle $team) { |
|
| 113 | 113 | return new Team( |
| 114 | 114 | $team->getSingleId(), |
| 115 | 115 | $team->getDisplayName(), |
@@ -26,55 +26,55 @@ |
||
| 26 | 26 | * @property $userId string |
| 27 | 27 | */ |
| 28 | 28 | class TeamsApiController extends OCSController { |
| 29 | - public function __construct( |
|
| 30 | - string $appName, |
|
| 31 | - IRequest $request, |
|
| 32 | - private ITeamManager $teamManager, |
|
| 33 | - private ?string $userId, |
|
| 34 | - ) { |
|
| 35 | - parent::__construct($appName, $request); |
|
| 36 | - } |
|
| 29 | + public function __construct( |
|
| 30 | + string $appName, |
|
| 31 | + IRequest $request, |
|
| 32 | + private ITeamManager $teamManager, |
|
| 33 | + private ?string $userId, |
|
| 34 | + ) { |
|
| 35 | + parent::__construct($appName, $request); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Get all resources of a team |
|
| 40 | - * |
|
| 41 | - * @param string $teamId Unique id of the team |
|
| 42 | - * @return DataResponse<Http::STATUS_OK, array{resources: list<CoreTeamResource>}, array{}> |
|
| 43 | - * |
|
| 44 | - * 200: Resources returned |
|
| 45 | - */ |
|
| 46 | - #[NoAdminRequired] |
|
| 47 | - #[ApiRoute(verb: 'GET', url: '/{teamId}/resources', root: '/teams')] |
|
| 48 | - public function resolveOne(string $teamId): DataResponse { |
|
| 49 | - /** @psalm-suppress PossiblyNullArgument The route is limited to logged-in users */ |
|
| 50 | - $resolvedResources = $this->teamManager->getSharedWith($teamId, $this->userId); |
|
| 38 | + /** |
|
| 39 | + * Get all resources of a team |
|
| 40 | + * |
|
| 41 | + * @param string $teamId Unique id of the team |
|
| 42 | + * @return DataResponse<Http::STATUS_OK, array{resources: list<CoreTeamResource>}, array{}> |
|
| 43 | + * |
|
| 44 | + * 200: Resources returned |
|
| 45 | + */ |
|
| 46 | + #[NoAdminRequired] |
|
| 47 | + #[ApiRoute(verb: 'GET', url: '/{teamId}/resources', root: '/teams')] |
|
| 48 | + public function resolveOne(string $teamId): DataResponse { |
|
| 49 | + /** @psalm-suppress PossiblyNullArgument The route is limited to logged-in users */ |
|
| 50 | + $resolvedResources = $this->teamManager->getSharedWith($teamId, $this->userId); |
|
| 51 | 51 | |
| 52 | - return new DataResponse(['resources' => array_map(static fn (TeamResource $resource) => $resource->jsonSerialize(), $resolvedResources)]); |
|
| 53 | - } |
|
| 52 | + return new DataResponse(['resources' => array_map(static fn (TeamResource $resource) => $resource->jsonSerialize(), $resolvedResources)]); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Get all teams of a resource |
|
| 57 | - * |
|
| 58 | - * @param string $providerId Identifier of the provider (e.g. deck, talk, collectives) |
|
| 59 | - * @param string $resourceId Unique id of the resource to list teams for (e.g. deck board id) |
|
| 60 | - * @return DataResponse<Http::STATUS_OK, array{teams: list<CoreTeamWithResources>}, array{}> |
|
| 61 | - * |
|
| 62 | - * 200: Teams returned |
|
| 63 | - */ |
|
| 64 | - #[NoAdminRequired] |
|
| 65 | - #[ApiRoute(verb: 'GET', url: '/resources/{providerId}/{resourceId}', root: '/teams')] |
|
| 66 | - public function listTeams(string $providerId, string $resourceId): DataResponse { |
|
| 67 | - /** @psalm-suppress PossiblyNullArgument The route is limited to logged-in users */ |
|
| 68 | - $teams = $this->teamManager->getTeamsForResource($providerId, $resourceId, $this->userId); |
|
| 69 | - $sharesPerTeams = $this->teamManager->getSharedWithList(array_map(fn (Team $team): string => $team->getId(), $teams), $this->userId); |
|
| 70 | - $listTeams = array_values(array_map(function (Team $team) use ($sharesPerTeams) { |
|
| 71 | - $response = $team->jsonSerialize(); |
|
| 72 | - $response['resources'] = array_map(static fn (TeamResource $resource) => $resource->jsonSerialize(), $sharesPerTeams[$team->getId()] ?? []); |
|
| 73 | - return $response; |
|
| 74 | - }, $teams)); |
|
| 55 | + /** |
|
| 56 | + * Get all teams of a resource |
|
| 57 | + * |
|
| 58 | + * @param string $providerId Identifier of the provider (e.g. deck, talk, collectives) |
|
| 59 | + * @param string $resourceId Unique id of the resource to list teams for (e.g. deck board id) |
|
| 60 | + * @return DataResponse<Http::STATUS_OK, array{teams: list<CoreTeamWithResources>}, array{}> |
|
| 61 | + * |
|
| 62 | + * 200: Teams returned |
|
| 63 | + */ |
|
| 64 | + #[NoAdminRequired] |
|
| 65 | + #[ApiRoute(verb: 'GET', url: '/resources/{providerId}/{resourceId}', root: '/teams')] |
|
| 66 | + public function listTeams(string $providerId, string $resourceId): DataResponse { |
|
| 67 | + /** @psalm-suppress PossiblyNullArgument The route is limited to logged-in users */ |
|
| 68 | + $teams = $this->teamManager->getTeamsForResource($providerId, $resourceId, $this->userId); |
|
| 69 | + $sharesPerTeams = $this->teamManager->getSharedWithList(array_map(fn (Team $team): string => $team->getId(), $teams), $this->userId); |
|
| 70 | + $listTeams = array_values(array_map(function (Team $team) use ($sharesPerTeams) { |
|
| 71 | + $response = $team->jsonSerialize(); |
|
| 72 | + $response['resources'] = array_map(static fn (TeamResource $resource) => $resource->jsonSerialize(), $sharesPerTeams[$team->getId()] ?? []); |
|
| 73 | + return $response; |
|
| 74 | + }, $teams)); |
|
| 75 | 75 | |
| 76 | - return new DataResponse([ |
|
| 77 | - 'teams' => $listTeams, |
|
| 78 | - ]); |
|
| 79 | - } |
|
| 76 | + return new DataResponse([ |
|
| 77 | + 'teams' => $listTeams, |
|
| 78 | + ]); |
|
| 79 | + } |
|
| 80 | 80 | } |
@@ -67,7 +67,7 @@ |
||
| 67 | 67 | /** @psalm-suppress PossiblyNullArgument The route is limited to logged-in users */ |
| 68 | 68 | $teams = $this->teamManager->getTeamsForResource($providerId, $resourceId, $this->userId); |
| 69 | 69 | $sharesPerTeams = $this->teamManager->getSharedWithList(array_map(fn (Team $team): string => $team->getId(), $teams), $this->userId); |
| 70 | - $listTeams = array_values(array_map(function (Team $team) use ($sharesPerTeams) { |
|
| 70 | + $listTeams = array_values(array_map(function(Team $team) use ($sharesPerTeams) { |
|
| 71 | 71 | $response = $team->jsonSerialize(); |
| 72 | 72 | $response['resources'] = array_map(static fn (TeamResource $resource) => $resource->jsonSerialize(), $sharesPerTeams[$team->getId()] ?? []); |
| 73 | 73 | return $response; |