|
| 1 | +===== |
| 2 | +Teams |
| 3 | +===== |
| 4 | + |
| 5 | +Teams are user-defined groups of accounts, provided by the **Teams** app (app id ``circles``). Apps do not store |
| 6 | +anything in a team themselves: they *contribute* to it, by telling the server which of their own resources are shared |
| 7 | +with a given team. A team's overview is assembled from every app that does so. |
| 8 | + |
| 9 | +The API lives in the ``OCP\Teams`` namespace and has been available since Nextcloud 29. |
| 10 | + |
| 11 | +Contributing resources to a team |
| 12 | +-------------------------------- |
| 13 | + |
| 14 | +Implement ``OCP\Teams\ITeamResourceProvider`` and register it from your ``Application`` class: |
| 15 | + |
| 16 | +.. code-block:: php |
| 17 | +
|
| 18 | + <?php |
| 19 | + namespace OCA\MyApp\AppInfo; |
| 20 | +
|
| 21 | + use OCA\MyApp\Teams\MyAppResourceProvider; |
| 22 | + use OCP\AppFramework\App; |
| 23 | + use OCP\AppFramework\Bootstrap\IBootContext; |
| 24 | + use OCP\AppFramework\Bootstrap\IBootstrap; |
| 25 | + use OCP\AppFramework\Bootstrap\IRegistrationContext; |
| 26 | +
|
| 27 | + class Application extends App implements IBootstrap { |
| 28 | + public function register(IRegistrationContext $context): void { |
| 29 | + $context->registerTeamResourceProvider(MyAppResourceProvider::class); |
| 30 | + } |
| 31 | +
|
| 32 | + public function boot(IBootContext $context): void { |
| 33 | + } |
| 34 | + } |
| 35 | +
|
| 36 | +The provider answers three questions about your app's resources: |
| 37 | + |
| 38 | +.. code-block:: php |
| 39 | +
|
| 40 | + interface ITeamResourceProvider { |
| 41 | + public function getId(): string; // your provider id, e.g. 'deck' |
| 42 | + public function getName(): string; // translated, shown to users |
| 43 | + public function getIconSvg(): string; // inline SVG |
| 44 | +
|
| 45 | + /** @return TeamResource[] resources of yours shared with this team */ |
| 46 | + public function getSharedWith(string $teamId): array; |
| 47 | +
|
| 48 | + public function isSharedWithTeam(string $teamId, string $resourceId): bool; |
| 49 | +
|
| 50 | + /** @return string[] team ids a resource of yours is shared with */ |
| 51 | + public function getTeamsForResource(string $resourceId): array; |
| 52 | + } |
| 53 | +
|
| 54 | +Each resource is returned as an ``OCP\Teams\TeamResource``, carrying the provider, an id, a label, a URL and an icon |
| 55 | +- as inline SVG, a URL or an emoji. |
| 56 | + |
| 57 | +.. note:: |
| 58 | + |
| 59 | + A resource contributed this way is still owned by whoever created it. Nothing about registering a provider makes |
| 60 | + the team the owner of anything. |
| 61 | + |
| 62 | +Reading teams and their resources |
| 63 | +--------------------------------- |
| 64 | + |
| 65 | +``OCP\Teams\ITeamManager`` is the consumer side: |
| 66 | + |
| 67 | +.. code-block:: php |
| 68 | +
|
| 69 | + $providers = $teamManager->getProviders(); // since 29.0.0 |
| 70 | + $provider = $teamManager->getProvider('deck'); // since 29.0.0 |
| 71 | + $resources = $teamManager->getSharedWith($teamId, $userId); // since 29.0.0 |
| 72 | + $teams = $teamManager->getTeamsForResource('deck', $boardId, $userId); // since 29.0.0 |
| 73 | + $teams = $teamManager->getTeamsForUser($userId); // since 33.0.0 |
| 74 | + $lists = $teamManager->getSharedWithList($teams, $userId, $resourceId); // since 33.0.0 |
| 75 | + $members = $teamManager->getMembersOfTeam($teamId, $userId); // since 34.0.0 |
| 76 | +
|
| 77 | +``getSharedWithList()`` gained its ``$resourceId`` parameter in 34.0.0, so guard for the server version if your app |
| 78 | +supports older releases. |
| 79 | + |
| 80 | +The team folder provider |
| 81 | +------------------------ |
| 82 | + |
| 83 | +Since Nextcloud 35 a team can also have **one exclusive folder** - a team space. That folder is supplied by an |
| 84 | +implementation of ``OCP\Teams\ITeamFolderProvider``, which extends ``ITeamResourceProvider``: |
| 85 | + |
| 86 | +.. code-block:: php |
| 87 | +
|
| 88 | + interface ITeamFolderProvider extends ITeamResourceProvider { |
| 89 | + public function getTeamFolder(string $teamId): ?TeamFolder; |
| 90 | + public function createTeamFolder(Team $team, int $quota = 0): TeamFolder; // quota 0 = unlimited |
| 91 | + public function getLinkableTeamFolders(string $circleId): array; |
| 92 | + public function linkTeamFolder(string $circleId, int $folderId): TeamFolder; |
| 93 | + public function updateTeamFolderQuota(string $teamId, int $quota): TeamFolder; |
| 94 | + public function unlinkTeamFolder(string $teamId): ?TeamFolder; // keeps the folder |
| 95 | + public function removeTeamFolder(string $teamId): bool; // deletes the folder |
| 96 | + } |
| 97 | +
|
| 98 | +Implementations are registered the same way as any other resource provider, through |
| 99 | +``registerTeamResourceProvider()``. Retrieve the active one with ``ITeamManager::getTeamFolderProvider()``, which |
| 100 | +returns ``null`` when no app provides team folders - always handle that case. |
| 101 | + |
| 102 | +.. warning:: |
| 103 | + |
| 104 | + ``unlinkTeamFolder()`` ends the relationship and preserves the folder and its contents; ``removeTeamFolder()`` |
| 105 | + deletes them. If you expose either in a user interface, make the difference obvious. |
| 106 | + |
| 107 | +Implementations to look at |
| 108 | +-------------------------- |
| 109 | + |
| 110 | +- **Files** - ``FileSharingTeamResourceProvider`` in the ``circles`` app, for files and folders shared with a team. |
| 111 | +- **Talk** - ``TalkTeamResourceProvider`` in ``spreed``, for conversations. |
| 112 | +- **Deck** - ``DeckTeamResourceProvider``, for boards. |
| 113 | +- **Team folders** - ``TeamSpaceProvider`` in ``groupfolders``, the reference implementation of |
| 114 | + ``ITeamFolderProvider``. |
0 commit comments