fix(TeamShareRecipientType): Defer getting CirclesManager class as it might not exist yet

Signed-off-by: provokateurin <kate@provokateurin.de>
pull/62366/head
provokateurin 1 month ago
parent e8afe36ed0
commit c2a1ee615a
No known key found for this signature in database
  1. 15
      core/Sharing/Recipient/TeamShareRecipientType.php
  2. 2
      tests/Core/Sharing/Recipient/TeamShareRecipientTypeTest.php

@ -20,6 +20,7 @@ use OCP\Interaction\InteractionReceiver;
use OCP\Interaction\Receivers\CircleReceiver;
use OCP\IUser;
use OCP\L10N\IFactory;
use OCP\Server;
use OCP\Share\IShare;
use OCP\Sharing\Icon\ShareIconSVG;
use OCP\Sharing\Icon\ShareIconURL;
@ -34,15 +35,21 @@ use OCP\Teams\Team;
* @template-implements IEventListener<DestroyingCircleEvent>
*/
final class TeamShareRecipientType extends AShareRecipientTypeSearchCollaborator implements IEventListener {
private ?ITeamManager $teamManager = null;
public function __construct(
IEventDispatcher $eventDispatcher,
private readonly IDBConnection $dbConnection,
private readonly ITeamManager $teamManager,
private readonly ISharingManager $manager,
) {
$eventDispatcher->addServiceListener(DestroyingCircleEvent::class, self::class);
}
// CirclesManager class is not registered yet when the class is instantiated.
private function getTeamManager(): ITeamManager {
return $this->teamManager ??= Server::get(ITeamManager::class);
}
#[\Override]
public function getDisplayName(IFactory $l10nFactory): string {
return $l10nFactory->get(Application::APP_ID)->t('Team');
@ -50,7 +57,7 @@ final class TeamShareRecipientType extends AShareRecipientTypeSearchCollaborator
#[\Override]
public function validateRecipient(string $recipient): bool {
return $this->teamManager->getTeam($recipient) instanceof Team;
return $this->getTeamManager()->getTeam($recipient) instanceof Team;
}
#[\Override]
@ -59,12 +66,12 @@ final class TeamShareRecipientType extends AShareRecipientTypeSearchCollaborator
return [];
}
return array_map(static fn (Team $team): string => $team->getId(), $this->teamManager->getTeamsForUser($currentUser->getUID()));
return array_map(static fn (Team $team): string => $team->getId(), $this->getTeamManager()->getTeamsForUser($currentUser->getUID()));
}
#[\Override]
public function getRecipientDisplayName(string $recipient): ?string {
return $this->teamManager->getTeam($recipient)?->getDisplayName();
return $this->getTeamManager()->getTeam($recipient)?->getDisplayName();
}
#[\Override]

@ -98,7 +98,7 @@ final class TeamShareRecipientTypeTest extends TestCase {
$this->team2 = $this->createTeam($teamManager, 'team2');
$this->team3 = $this->createTeam($teamManager, 'team3');
$this->recipientType = new TeamShareRecipientType(Server::get(IEventDispatcher::class), $this->dbConnection, $teamManager, $this->manager);
$this->recipientType = new TeamShareRecipientType(Server::get(IEventDispatcher::class), $this->dbConnection, $this->manager);
}
#[\Override]

Loading…
Cancel
Save