diff options
author | blizzz <blizzz@arthur-schiwon.de> | 2023-02-02 17:33:34 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-02 17:33:34 +0100 |
commit | d83ea282c4bddd332623c3c0a8c4dea01146047f (patch) | |
tree | fb889c10a27209cba912a005a2b86530f4fa6d68 /lib/private | |
parent | 6f3c4f2255ed73601fa5eac3048d679caa3065e0 (diff) | |
parent | 4ab3c16403e69811cf2353ba2bfeafcbcf259c42 (diff) | |
download | nextcloud-server-d83ea282c4bddd332623c3c0a8c4dea01146047f.tar.gz nextcloud-server-d83ea282c4bddd332623c3c0a8c4dea01146047f.zip |
Merge pull request #35736 from nextcloud/pluggable-share-display
Allow to register public share template provider
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/AppFramework/Bootstrap/RegistrationContext.php | 22 | ||||
-rw-r--r-- | lib/private/Server.php | 2 | ||||
-rw-r--r-- | lib/private/Share20/PublicShareTemplateFactory.php | 63 |
3 files changed, 87 insertions, 0 deletions
diff --git a/lib/private/AppFramework/Bootstrap/RegistrationContext.php b/lib/private/AppFramework/Bootstrap/RegistrationContext.php index 236aa106d02..a78a895d029 100644 --- a/lib/private/AppFramework/Bootstrap/RegistrationContext.php +++ b/lib/private/AppFramework/Bootstrap/RegistrationContext.php @@ -52,6 +52,7 @@ use OCP\Http\WellKnown\IHandler; use OCP\Notification\INotifier; use OCP\Profile\ILinkAction; use OCP\Search\IProvider; +use OCP\Share\IPublicShareTemplateProvider; use OCP\Support\CrashReport\IReporter; use OCP\UserMigration\IMigrator as IUserMigrator; use Psr\Log\LoggerInterface; @@ -127,6 +128,9 @@ class RegistrationContext { /** @var ParameterRegistration[] */ private $sensitiveMethods = []; + /** @var ServiceRegistration<IPublicShareTemplateProvider>[] */ + private $publicShareTemplateProviders = []; + /** @var LoggerInterface */ private $logger; @@ -326,6 +330,13 @@ class RegistrationContext { $methods ); } + + public function registerPublicShareTemplateProvider(string $class): void { + $this->context->registerPublicShareTemplateProvider( + $this->appId, + $class + ); + } }; } @@ -461,6 +472,10 @@ class RegistrationContext { $this->sensitiveMethods[] = new ParameterRegistration($appId, $class, $methods); } + public function registerPublicShareTemplateProvider(string $appId, string $class): void { + $this->publicShareTemplateProviders[] = new ServiceRegistration($appId, $class); + } + /** * @param App[] $apps */ @@ -738,4 +753,11 @@ class RegistrationContext { public function getSensitiveMethods(): array { return $this->sensitiveMethods; } + + /** + * @return ServiceRegistration<IPublicShareTemplateProvider>[] + */ + public function getPublicShareTemplateProviders(): array { + return $this->publicShareTemplateProviders; + } } diff --git a/lib/private/Server.php b/lib/private/Server.php index d8857b4efc6..bd33cdf58bd 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -1451,6 +1451,8 @@ class Server extends ServerContainer implements IServerContainer { $this->registerAlias(IBinaryFinder::class, BinaryFinder::class); + $this->registerAlias(\OCP\Share\IPublicShareTemplateFactory::class, \OC\Share20\PublicShareTemplateFactory::class); + $this->connectDispatcher(); } diff --git a/lib/private/Share20/PublicShareTemplateFactory.php b/lib/private/Share20/PublicShareTemplateFactory.php new file mode 100644 index 00000000000..222f327496a --- /dev/null +++ b/lib/private/Share20/PublicShareTemplateFactory.php @@ -0,0 +1,63 @@ +<?php + +declare(strict_types=1); +/** + * @copyright Copyright (c) 2023 Louis Chemineau <louis@chmn.me> + * + * @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 <http://www.gnu.org/licenses/>. + * + */ + +namespace OC\Share20; + +use Exception; +use OC\AppFramework\Bootstrap\Coordinator; +use OCA\Files_Sharing\DefaultPublicShareTemplateProvider; +use OCP\Server; +use OCP\Share\IShare; +use OCP\Share\IPublicShareTemplateFactory; +use OCP\Share\IPublicShareTemplateProvider; + +class PublicShareTemplateFactory implements IPublicShareTemplateFactory { + public function __construct( + private Coordinator $coordinator, + private DefaultPublicShareTemplateProvider $defaultProvider, + ) { + } + + public function getProvider(IShare $share): IPublicShareTemplateProvider { + $context = $this->coordinator->getRegistrationContext(); + if ($context === null) { + throw new Exception("Can't retrieve public share template providers as context is not defined"); + } + + $providers = array_map( + fn ($registration) => Server::get($registration->getService()), + $context->getPublicShareTemplateProviders() + ); + + $filteredProviders = array_filter( + $providers, + fn (IPublicShareTemplateProvider $provider) => $provider->shouldRespond($share) + ); + + if (count($filteredProviders) === 0) { + return $this->defaultProvider; + } else { + return array_shift($filteredProviders); + } + } +} |