diff options
Diffstat (limited to 'lib/public/Teams')
-rw-r--r-- | lib/public/Teams/ITeamManager.php | 43 | ||||
-rw-r--r-- | lib/public/Teams/ITeamResourceProvider.php | 61 | ||||
-rw-r--r-- | lib/public/Teams/Team.php | 62 | ||||
-rw-r--r-- | lib/public/Teams/TeamResource.php | 114 |
4 files changed, 280 insertions, 0 deletions
diff --git a/lib/public/Teams/ITeamManager.php b/lib/public/Teams/ITeamManager.php new file mode 100644 index 00000000000..3f737b4229c --- /dev/null +++ b/lib/public/Teams/ITeamManager.php @@ -0,0 +1,43 @@ +<?php + +/** + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +namespace OCP\Teams; + +/** + * @since 29.0.0 + */ +interface ITeamManager { + /** + * Get all providers that have registered as a team resource provider + * + * @return ITeamResourceProvider[] + * @since 29.0.0 + */ + public function getProviders(): array; + + /** + * Get a specific team resource provider by its id + * + * @since 29.0.0 + */ + public function getProvider(string $providerId): ITeamResourceProvider; + + /** + * Returns all team resources for a given team and user + * + * @return list<TeamResource> + * @since 29.0.0 + */ + public function getSharedWith(string $teamId, string $userId): array; + + /** + * Returns all teams for a given resource and user + * + * @since 29.0.0 + */ + public function getTeamsForResource(string $providerId, string $resourceId, string $userId): array; +} diff --git a/lib/public/Teams/ITeamResourceProvider.php b/lib/public/Teams/ITeamResourceProvider.php new file mode 100644 index 00000000000..ff724ab8ae2 --- /dev/null +++ b/lib/public/Teams/ITeamResourceProvider.php @@ -0,0 +1,61 @@ +<?php + +/** + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +namespace OCP\Teams; + +/** + * Implement a provider of resources that are shared or owned by a team + * + * @since 29.0.0 + */ +interface ITeamResourceProvider { + + /** + * Unique identifier used to identify the provider (app id) + * + * @since 29.0.0 + */ + public function getId(): string; + + /** + * User visible name of the provider (app name) + * + * @since 29.0.0 + */ + public function getName(): string; + + /** + * Svg icon to show next to the provider (app icon) + * + * @since 29.0.0 + */ + public function getIconSvg(): string; + + /** + * Return all resources that are shared to the given team id for the current provider + * + * @param string $teamId + * @return TeamResource[] + * @since 29.0.0 + */ + public function getSharedWith(string $teamId): array; + + /** + * Check if a resource is shared with the given team + * + * @since 29.0.0 + */ + public function isSharedWithTeam(string $teamId, string $resourceId): bool; + + /** + * Return team ids that a resource is shared with or owned by + * + * @return string[] + * @since 29.0.0 + */ + public function getTeamsForResource(string $resourceId): array; +} diff --git a/lib/public/Teams/Team.php b/lib/public/Teams/Team.php new file mode 100644 index 00000000000..474ebaed84f --- /dev/null +++ b/lib/public/Teams/Team.php @@ -0,0 +1,62 @@ +<?php + +/** + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +namespace OCP\Teams; + +/** + * Simple abstraction to represent a team in the public API + * + * In the backend a team is a circle identified by the circles singleId + * + * @since 29.0.0 + */ +class Team implements \JsonSerializable { + + /** + * @since 29.0.0 + */ + public function __construct( + private string $teamId, + private string $displayName, + private ?string $link, + ) { + } + + /** + * Unique identifier of the team (singleId of the circle) + * + * @since 29.0.0 + */ + public function getId(): string { + return $this->teamId; + } + + /** + * @since 29.0.0 + */ + public function getDisplayName(): string { + return $this->displayName; + } + + /** + * @since 29.0.0 + */ + public function getLink(): ?string { + return $this->link; + } + + /** + * @since 29.0.0 + */ + public function jsonSerialize(): array { + return [ + 'teamId' => $this->teamId, + 'displayName' => $this->displayName, + 'link' => $this->link, + ]; + } +} diff --git a/lib/public/Teams/TeamResource.php b/lib/public/Teams/TeamResource.php new file mode 100644 index 00000000000..acb98380562 --- /dev/null +++ b/lib/public/Teams/TeamResource.php @@ -0,0 +1,114 @@ +<?php + +/** + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +namespace OCP\Teams; + +/** + * @since 29.0.0 + */ +class TeamResource implements \JsonSerializable { + /** + * @since 29.0.0 + */ + public function __construct( + private ITeamResourceProvider $teamResourceProvider, + private string $resourceId, + private string $label, + private string $url, + private ?string $iconSvg = null, + private ?string $iconURL = null, + private ?string $iconEmoji = null, + ) { + } + + /** + * Returns the provider details for the current resource + * + * @since 29.0.0 + */ + public function getProvider(): ITeamResourceProvider { + return $this->teamResourceProvider; + } + + /** + * Unique id of the resource (e.g. primary key id) + * @since 29.0.0 + */ + public function getId(): string { + return $this->resourceId; + } + + /** + * User visible label when listing resources + * + * @since 29.0.0 + */ + public function getLabel(): string { + return $this->label; + } + + /** + * Absolute url to navigate the user to the resource + * + * @since 29.0.0 + */ + public function getUrl(): string { + return $this->url; + } + + /** + * Svg icon to show next to the name for the resource + * + * From all icons the first one returning not null will be picked in order: iconEmoji, iconSvg, iconUrl + * + * @since 29.0.0 + */ + public function getIconSvg(): ?string { + return $this->iconSvg; + } + + /** + * Image url of the icon to show next to the name for the resource + * + * From all icons the first one returning not null will be picked in order: iconEmoji, iconSvg, iconUrl + * + * @since 29.0.0 + */ + public function getIconURL(): ?string { + return $this->iconURL; + } + + /** + * Emoji show next to the name for the resource + * + * From all icons the first one returning not null will be picked in order: iconEmoji, iconSvg, iconUrl + * + * @since 29.0.0 + */ + public function getIconEmoji(): ?string { + return $this->iconEmoji; + } + + /** + * @since 29.0.0 + */ + public function jsonSerialize(): array { + return [ + 'id' => $this->resourceId, + 'label' => $this->label, + 'url' => $this->url, + 'iconSvg' => $this->iconSvg, + 'iconURL' => $this->iconURL, + 'iconEmoji' => $this->iconEmoji, + 'provider' => [ + 'id' => $this->teamResourceProvider->getId(), + 'name' => $this->teamResourceProvider->getName(), + 'icon' => $this->teamResourceProvider->getIconSvg(), + ] + ]; + } +} |