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
15 changes: 11 additions & 4 deletions core/Sharing/Recipient/TeamShareRecipientType.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
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;
Expand All @@ -34,23 +35,29 @@
* @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');
}

#[\Override]
public function validateRecipient(string $recipient): bool {
return $this->teamManager->getTeam($recipient) instanceof Team;
return $this->getTeamManager()->getTeam($recipient) instanceof Team;
}

#[\Override]
Expand All @@ -59,12 +66,12 @@ public function getRecipients(?IUser $currentUser, mixed $arguments): array {
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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function setUp(): void {
$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]
Expand Down
Loading