diff --git a/composer.lock b/composer.lock index 0dad806cb..86fd2109b 100644 --- a/composer.lock +++ b/composer.lock @@ -183,12 +183,12 @@ "source": { "type": "git", "url": "https://github.com/nextcloud-deps/ocp.git", - "reference": "ecc412f29a227848dd101912ec925fdc5fa214d7" + "reference": "c0e3b941c8344673024c6fab8ff3f46897d44b3c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nextcloud-deps/ocp/zipball/ecc412f29a227848dd101912ec925fdc5fa214d7", - "reference": "ecc412f29a227848dd101912ec925fdc5fa214d7", + "url": "https://api.github.com/repos/nextcloud-deps/ocp/zipball/c0e3b941c8344673024c6fab8ff3f46897d44b3c", + "reference": "c0e3b941c8344673024c6fab8ff3f46897d44b3c", "shasum": "" }, "require": { @@ -220,7 +220,7 @@ "issues": "https://github.com/nextcloud-deps/ocp/issues", "source": "https://github.com/nextcloud-deps/ocp/tree/master" }, - "time": "2024-02-17T00:31:36+00:00" + "time": "2024-03-08T00:32:08+00:00" }, { "name": "nikic/php-parser", diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 4931be566..74d34c97a 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -46,6 +46,7 @@ use OCA\Circles\Events\PreparingCircleMemberEvent; use OCA\Circles\Events\RemovingCircleMemberEvent; use OCA\Circles\Events\RequestingCircleMemberEvent; +use OCA\Circles\FileSharingTeamResourceProvider; use OCA\Circles\Handlers\WebfingerHandler; use OCA\Circles\Listeners\AccountUpdated; use OCA\Circles\Listeners\Files\AddingMemberSendMail as ListenerFilesAddingMemberSendMail; @@ -140,6 +141,7 @@ public function register(IRegistrationContext $context): void { $context->registerWellKnownHandler(WebfingerHandler::class); $context->registerDashboardWidget(TeamDashboardWidget::class); + $context->registerTeamResourceProvider(FileSharingTeamResourceProvider::class); } diff --git a/lib/FileSharingTeamResourceProvider.php b/lib/FileSharingTeamResourceProvider.php new file mode 100644 index 000000000..3a830a8e3 --- /dev/null +++ b/lib/FileSharingTeamResourceProvider.php @@ -0,0 +1,101 @@ + + * + * @author Julius Härtl + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace OCA\Circles; + +use OCA\Circles\Model\ShareWrapper; +use OCA\Circles\Service\ShareWrapperService; +use OCP\IL10N; +use OCP\IURLGenerator; +use OCP\Teams\ITeamResourceProvider; +use OCP\Teams\TeamResource; + +class FileSharingTeamResourceProvider implements ITeamResourceProvider { + public function __construct( + private IL10N $l10n, + private ?CirclesManager $circlesManager, + private ShareWrapperService $shareByCircleProvider, + private IURLGenerator $urlGenerator + ) { + } + + public function getId(): string { + return 'files'; + } + + public function getName(): string { + return $this->l10n->t('Files'); + } + + public function getIconSvg(): string { + return ''; + } + + public function getSharedWith(string $teamId): array { + if (!$this->circlesManager) { + return []; + } + + $shares = $this->shareByCircleProvider->getSharesToCircle($teamId); + usort($shares, function ($a, $b) { + return (int)($b->getItemType() === 'folder') - (int)($a->getItemType() === 'folder'); + }); + return array_map(function (ShareWrapper $shareWrapper) { + $isFolder = $shareWrapper->getItemType() === 'folder'; + return new TeamResource( + $this, + (string)$shareWrapper->getFileSource(), + basename($shareWrapper->getFileTarget()), + $this->urlGenerator->getAbsoluteURL('/index.php/f/' . $shareWrapper->getFileSource()), + iconSvg: $isFolder ? '' : null, + iconURL: !$isFolder ? + $this->urlGenerator->linkToRouteAbsolute('core.preview.getPreviewByFileId', ['fileId' => $shareWrapper->getFileSource(), 'mimeFallback' => true, ]) + : null, + ); + }, $shares); + } + + public function isSharedWithTeam(string $teamId, string $resourceId): bool { + if (!$this->circlesManager) { + return false; + } + + return count(array_filter($this->getSharedWith($teamId), function (TeamResource $resource) use ($resourceId) { + return $resource->getId() === $resourceId; + })) !== 0; + } + + public function getTeamsForResource(string $resourceId): array { + if (!$this->circlesManager) { + return []; + } + + $shares = $this->shareByCircleProvider->getSharesByFileId((int)$resourceId); + + return array_map(function ($share) { + return $share->getSharedWith(); + }, $shares); + } +}