Skip to content
Open
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
12 changes: 12 additions & 0 deletions lib/private/Teams/TeamManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use OCP\IURLGenerator;
use OCP\Server;
use OCP\Teams\ITeamManager;
use OCP\Teams\ITeamFolderProvider;
use OCP\Teams\ITeamResourceProvider;
use OCP\Teams\Team;
use Psr\Container\ContainerExceptionInterface;
Expand Down Expand Up @@ -70,6 +71,17 @@ public function getProvider(string $providerId): ITeamResourceProvider {
throw new \RuntimeException('No provider found for id ' . $providerId);
}

#[\Override]
public function getTeamFolderProvider(): ?ITeamFolderProvider {
foreach ($this->getProviders() as $provider) {
if ($provider instanceof ITeamFolderProvider) {
return $provider;
}
}

return null;
}

#[\Override]
public function getSharedWith(string $teamId, string $userId): array {
if (!$this->hasTeamSupport()) {
Expand Down
51 changes: 51 additions & 0 deletions lib/public/Teams/ITeamFolderProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCP\Teams;

/**
* Provides the exclusive folder belonging to a team.
*
* Register implementations through
* {@see \OCP\AppFramework\Bootstrap\IRegistrationContext::registerTeamResourceProvider()}.
*
* @since 35.0.0
*/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
*/
*/
#[Consunable(since: '35.0.0')]
#[Implementable(since: '35.0.0')]

And need use OCP\AppFramework\Attribute\Consumable; and use OCP\AppFramework\Attribute\Implementable; at the top of the file

interface ITeamFolderProvider extends ITeamResourceProvider {
/**
* Return the folder exclusively linked to the team.
*
* @since 35.0.0
*/
public function getTeamFolder(string $teamId): ?TeamFolder;

/**
* Create the exclusive folder for a team, or return its existing folder.
*
* @param Team $team The team that owns the folder.
* @param int $quota Quota in bytes; zero means unlimited.
* @since 35.0.0
*/
public function createTeamFolder(Team $team, int $quota = 0): TeamFolder;

/**
* Remove the exclusive relationship but retain the folder and its contents.
*
* @return TeamFolder|null The unlinked folder, if one existed.
* @since 35.0.0
*/
public function unlinkTeamFolder(string $teamId): ?TeamFolder;

/**
* Remove the team folder and its contents.
*
* @since 35.0.0
*/
public function removeTeamFolder(string $teamId): bool;
}
8 changes: 8 additions & 0 deletions lib/public/Teams/ITeamManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ public function getProviders(): array;
*/
public function getProvider(string $providerId): ITeamResourceProvider;

/**
* Get the registered provider of exclusive team folders.
*
* @return ITeamFolderProvider|null Null when no folder provider is enabled.
* @since 35.0.0
*/
public function getTeamFolderProvider(): ?ITeamFolderProvider;

/**
* Returns all team resources for a given team and user
*
Expand Down
52 changes: 52 additions & 0 deletions lib/public/Teams/TeamFolder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCP\Teams;

/**
* A folder exclusively linked to a team.
*
* @since 35.0.0
*/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
*/
*/
#[Consumable(since: '35.0.0')]

And need a corresponding use OCP\AppFramework\Attribute\Consumable; at the top of the file

class TeamFolder implements \JsonSerializable {
/**
* @since 35.0.0
*/
public function __construct(
private int $id,
private string $mountPoint,
) {
}

/**
* @since 35.0.0
*/
public function getId(): int {
return $this->id;
}

/**
* @since 35.0.0
*/
public function getMountPoint(): string {
return $this->mountPoint;
}

/**
* @return array{id: int, mountPoint: string}
* @since 35.0.0
*/
#[\Override]
public function jsonSerialize(): array {
return [
'id' => $this->id,
'mountPoint' => $this->mountPoint,
];
}
}
23 changes: 23 additions & 0 deletions tests/lib/Teams/TeamFolderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace Test\Teams;

use OCP\Teams\TeamFolder;
use Test\TestCase;

class TeamFolderTest extends TestCase {
public function testSerializesFolderIdentity(): void {
$folder = new TeamFolder(42, 'Engineering');

$this->assertSame(42, $folder->getId());
$this->assertSame('Engineering', $folder->getMountPoint());
$this->assertSame(['id' => 42, 'mountPoint' => 'Engineering'], $folder->jsonSerialize());
}
}
61 changes: 61 additions & 0 deletions tests/lib/Teams/TeamManagerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace Test\Teams;

use OC\AppFramework\Bootstrap\Coordinator;
use OC\Teams\TeamManager;
use OCA\Circles\CirclesManager;
use OCP\IURLGenerator;
use OCP\Teams\ITeamFolderProvider;
use OCP\Teams\ITeamResourceProvider;
use Test\TestCase;

class TeamManagerTest extends TestCase {
public function testGetTeamFolderProviderReturnsNullWithoutTeamSupport(): void {
$teamManager = $this->createTeamManager(null);

$this->assertNull($teamManager->getTeamFolderProvider());
}

public function testGetTeamFolderProviderReturnsNullWithoutFolderProvider(): void {
$teamManager = $this->createTeamManager($this->createMock(CirclesManager::class));
$this->setProviders($teamManager, [
'other' => $this->createMock(ITeamResourceProvider::class),
]);

$this->assertNull($teamManager->getTeamFolderProvider());
}

public function testGetTeamFolderProviderReturnsRegisteredFolderProvider(): void {
$teamManager = $this->createTeamManager($this->createMock(CirclesManager::class));
$folderProvider = $this->createMock(ITeamFolderProvider::class);
$this->setProviders($teamManager, [
'other' => $this->createMock(ITeamResourceProvider::class),
'folder' => $folderProvider,
]);

$this->assertSame($folderProvider, $teamManager->getTeamFolderProvider());
}

private function createTeamManager(?CirclesManager $circlesManager): TeamManager {
return new TeamManager(
$this->createMock(Coordinator::class),
$this->createMock(IURLGenerator::class),
$circlesManager,
);
}

/**
* @param array<string, ITeamResourceProvider> $providers
*/
private function setProviders(TeamManager $teamManager, array $providers): void {
(new \ReflectionProperty(TeamManager::class, 'providers'))->setValue($teamManager, $providers);
}
}
Loading