Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion build/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4184,8 +4184,14 @@
</MoreSpecificImplementedParamType>
</file>
<file src="lib/private/Teams/TeamManager.php">
<LessSpecificReturnStatement>
<code><![CDATA[array_map($this->circleToTeam(...), $this->circlesManager->probeCircles())]]></code>
</LessSpecificReturnStatement>
<MoreSpecificReturnType>
<code><![CDATA[array]]></code>
</MoreSpecificReturnType>
<UndefinedDocblockClass>
<code><![CDATA[Circle]]></code>
<code><![CDATA[Circle[]]]></code>
</UndefinedDocblockClass>
</file>
<file src="lib/private/Template/Base.php">
Expand Down
49 changes: 31 additions & 18 deletions lib/private/Teams/TeamManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function getSharedWith(string $teamId, string $userId): array {
$probe = new CircleProbe();
$probe->mustBeMember();

if ($this->getTeam($teamId, $userId, $probe) === null) {
if ($this->getTeamInternal($teamId, $userId, $probe) === null) {
return [];
}

Expand Down Expand Up @@ -119,16 +119,10 @@ public function getTeamsForResource(string $providerId, string $resourceId, stri
}

$provider = $this->getProvider($providerId);
return array_map(function (Circle $team) {
return new Team(
$team->getSingleId(),
$team->getDisplayName(),
$this->urlGenerator->linkToRouteAbsolute('contacts.contacts.directcircle', ['singleId' => $team->getSingleId()]),
);
}, $this->getTeams($provider->getTeamsForResource($resourceId), $userId));
return array_map($this->circleToTeam(...), $this->getTeams($provider->getTeamsForResource($resourceId), $userId));
}

private function getTeam(string $teamId, string $userId, ?CircleProbe $probe = null): ?Circle {
private function getTeamInternal(string $teamId, string $userId, ?CircleProbe $probe = null): ?Circle {
if (!$this->hasTeamSupport()) {
return null;
}
Expand All @@ -149,7 +143,7 @@ private function getTeam(string $teamId, string $userId, ?CircleProbe $probe = n
*/
#[\Override]
public function getMembersOfTeam(string $teamId, string $userId): array {
$team = $this->getTeam($teamId, $userId);
$team = $this->getTeamInternal($teamId, $userId);
if ($team === null) {
return [];
}
Expand Down Expand Up @@ -182,15 +176,34 @@ public function getTeamsForUser(string $userId): array {

$federatedUser = $this->circlesManager->getFederatedUser($userId, Member::TYPE_USER);
$this->circlesManager->startSession($federatedUser);
$teams = [];
foreach ($this->circlesManager->probeCircles() as $team) {
$teams[] = new Team(
$team->getSingleId(),
$team->getDisplayName(),
$this->urlGenerator->linkToRouteAbsolute('contacts.contacts.directcircle', ['singleId' => $team->getSingleId()]),
);

return array_map($this->circleToTeam(...), $this->circlesManager->probeCircles());
}

#[\Override]
public function getTeam(string $teamId, ?string $userId = null): ?Team {
if (!$this->hasTeamSupport()) {
return null;
}

if ($userId !== null) {
$this->circlesManager->startSession($this->circlesManager->getLocalFederatedUser($userId));
Comment thread
provokateurin marked this conversation as resolved.
} else {
$this->circlesManager->startSuperSession();
}

return $teams;
try {
return $this->circleToTeam($this->circlesManager->getCircle($teamId));
} catch (CircleNotFoundException) {
return null;
}
}

private function circleToTeam(Circle $circle): Team {
return new Team(
$circle->getSingleId(),
$circle->getDisplayName(),
$this->urlGenerator->linkToRouteAbsolute('contacts.contacts.directcircle', ['singleId' => $circle->getSingleId()]),
);
}
}
5 changes: 5 additions & 0 deletions lib/public/Teams/ITeamManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,9 @@ public function getMembersOfTeam(string $teamId, string $userId): array;
* @since 34.0.0
*/
public function hasTeamSupport(): bool;

/**
* @since 35.0.0
*/
public function getTeam(string $teamId, ?string $userId = null): ?Team;
}
Loading