summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorLouis Chemineau <louis@chmn.me>2023-01-18 16:53:22 +0100
committerLouis Chemineau <louis@chmn.me>2023-02-02 15:41:26 +0100
commit4ab3c16403e69811cf2353ba2bfeafcbcf259c42 (patch)
tree981b24806dfde120a7170957cac022b3bfdb74b9 /lib
parentfc4e87a2dfc5ff53bc9f15da13f355dd285769a9 (diff)
downloadnextcloud-server-4ab3c16403e69811cf2353ba2bfeafcbcf259c42.tar.gz
nextcloud-server-4ab3c16403e69811cf2353ba2bfeafcbcf259c42.zip
Pluggable share provider
Signed-off-by: Carl Schwan <carl@carlschwan.eu> Signed-off-by: Louis Chemineau <louis@chmn.me>
Diffstat (limited to 'lib')
-rw-r--r--lib/composer/composer/autoload_classmap.php3
-rw-r--r--lib/composer/composer/autoload_static.php3
-rw-r--r--lib/private/AppFramework/Bootstrap/RegistrationContext.php22
-rw-r--r--lib/private/Server.php2
-rw-r--r--lib/private/Share20/PublicShareTemplateFactory.php63
-rw-r--r--lib/public/AppFramework/Bootstrap/IRegistrationContext.php10
-rw-r--r--lib/public/Share/IPublicShareTemplateFactory.php35
-rw-r--r--lib/public/Share/IPublicShareTemplateProvider.php42
8 files changed, 180 insertions, 0 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index 3968834c11b..b58b675cf9d 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -557,6 +557,8 @@ return array(
'OCP\\Share\\IAttributes' => $baseDir . '/lib/public/Share/IAttributes.php',
'OCP\\Share\\IManager' => $baseDir . '/lib/public/Share/IManager.php',
'OCP\\Share\\IProviderFactory' => $baseDir . '/lib/public/Share/IProviderFactory.php',
+ 'OCP\\Share\\IPublicShareTemplateFactory' => $baseDir . '/lib/public/Share/IPublicShareTemplateFactory.php',
+ 'OCP\\Share\\IPublicShareTemplateProvider' => $baseDir . '/lib/public/Share/IPublicShareTemplateProvider.php',
'OCP\\Share\\IShare' => $baseDir . '/lib/public/Share/IShare.php',
'OCP\\Share\\IShareHelper' => $baseDir . '/lib/public/Share/IShareHelper.php',
'OCP\\Share\\IShareProvider' => $baseDir . '/lib/public/Share/IShareProvider.php',
@@ -1557,6 +1559,7 @@ return array(
'OC\\Share20\\LegacyHooks' => $baseDir . '/lib/private/Share20/LegacyHooks.php',
'OC\\Share20\\Manager' => $baseDir . '/lib/private/Share20/Manager.php',
'OC\\Share20\\ProviderFactory' => $baseDir . '/lib/private/Share20/ProviderFactory.php',
+ 'OC\\Share20\\PublicShareTemplateFactory' => $baseDir . '/lib/private/Share20/PublicShareTemplateFactory.php',
'OC\\Share20\\Share' => $baseDir . '/lib/private/Share20/Share.php',
'OC\\Share20\\ShareAttributes' => $baseDir . '/lib/private/Share20/ShareAttributes.php',
'OC\\Share20\\ShareHelper' => $baseDir . '/lib/private/Share20/ShareHelper.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index fea7903e58c..50f520205ce 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -590,6 +590,8 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OCP\\Share\\IAttributes' => __DIR__ . '/../../..' . '/lib/public/Share/IAttributes.php',
'OCP\\Share\\IManager' => __DIR__ . '/../../..' . '/lib/public/Share/IManager.php',
'OCP\\Share\\IProviderFactory' => __DIR__ . '/../../..' . '/lib/public/Share/IProviderFactory.php',
+ 'OCP\\Share\\IPublicShareTemplateFactory' => __DIR__ . '/../../..' . '/lib/public/Share/IPublicShareTemplateFactory.php',
+ 'OCP\\Share\\IPublicShareTemplateProvider' => __DIR__ . '/../../..' . '/lib/public/Share/IPublicShareTemplateProvider.php',
'OCP\\Share\\IShare' => __DIR__ . '/../../..' . '/lib/public/Share/IShare.php',
'OCP\\Share\\IShareHelper' => __DIR__ . '/../../..' . '/lib/public/Share/IShareHelper.php',
'OCP\\Share\\IShareProvider' => __DIR__ . '/../../..' . '/lib/public/Share/IShareProvider.php',
@@ -1590,6 +1592,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OC\\Share20\\LegacyHooks' => __DIR__ . '/../../..' . '/lib/private/Share20/LegacyHooks.php',
'OC\\Share20\\Manager' => __DIR__ . '/../../..' . '/lib/private/Share20/Manager.php',
'OC\\Share20\\ProviderFactory' => __DIR__ . '/../../..' . '/lib/private/Share20/ProviderFactory.php',
+ 'OC\\Share20\\PublicShareTemplateFactory' => __DIR__ . '/../../..' . '/lib/private/Share20/PublicShareTemplateFactory.php',
'OC\\Share20\\Share' => __DIR__ . '/../../..' . '/lib/private/Share20/Share.php',
'OC\\Share20\\ShareAttributes' => __DIR__ . '/../../..' . '/lib/private/Share20/ShareAttributes.php',
'OC\\Share20\\ShareHelper' => __DIR__ . '/../../..' . '/lib/private/Share20/ShareHelper.php',
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);
+ }
+ }
+}
diff --git a/lib/public/AppFramework/Bootstrap/IRegistrationContext.php b/lib/public/AppFramework/Bootstrap/IRegistrationContext.php
index 3748714bb79..6350169510f 100644
--- a/lib/public/AppFramework/Bootstrap/IRegistrationContext.php
+++ b/lib/public/AppFramework/Bootstrap/IRegistrationContext.php
@@ -328,4 +328,14 @@ interface IRegistrationContext {
* @since 25.0.0
*/
public function registerSensitiveMethods(string $class, array $methods): void;
+
+ /**
+ * Register an implementation of IPublicShareTemplateProvider.
+ *
+ * @param string $class
+ * @psalm-param class-string<\OCP\Share\IPublicShareTemplateProvider> $class
+ * @return void
+ * @since 26.0.0
+ */
+ public function registerPublicShareTemplateProvider(string $class): void;
}
diff --git a/lib/public/Share/IPublicShareTemplateFactory.php b/lib/public/Share/IPublicShareTemplateFactory.php
new file mode 100644
index 00000000000..248473c145d
--- /dev/null
+++ b/lib/public/Share/IPublicShareTemplateFactory.php
@@ -0,0 +1,35 @@
+<?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 OCP\Share;
+
+/**
+ * @since 26.0.0
+ */
+interface IPublicShareTemplateFactory {
+ /**
+ * Returns a provider that is willing to respond for given share.
+ * @since 26.0.0
+ */
+ public function getProvider(IShare $share): IPublicShareTemplateProvider;
+}
diff --git a/lib/public/Share/IPublicShareTemplateProvider.php b/lib/public/Share/IPublicShareTemplateProvider.php
new file mode 100644
index 00000000000..5ef5adaed13
--- /dev/null
+++ b/lib/public/Share/IPublicShareTemplateProvider.php
@@ -0,0 +1,42 @@
+<?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 OCP\Share;
+
+use OCP\AppFramework\Http\TemplateResponse;
+
+/**
+ * @since 26.0.0
+ */
+interface IPublicShareTemplateProvider {
+ /**
+ * Returns whether the provider can respond for the given share.
+ * @since 26.0.0
+ */
+ public function shouldRespond(IShare $share): bool;
+ /**
+ * Returns the a template for a given share.
+ * @since 26.0.0
+ */
+ public function renderPage(IShare $share, string $token, string $path): TemplateResponse;
+}