From 1a6bac58747165b3d8a8304e7ebaeb296b6e07a8 Mon Sep 17 00:00:00 2001
From: John Molakvoæ <skjnldsv@protonmail.com>
Date: Fri, 8 Oct 2021 11:35:27 +0200
Subject: Allow to whitelist apps from the apsptore
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
---
 lib/private/App/AppStore/Fetcher/AppFetcher.php | 26 +++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

(limited to 'lib/private/App/AppStore/Fetcher/AppFetcher.php')

diff --git a/lib/private/App/AppStore/Fetcher/AppFetcher.php b/lib/private/App/AppStore/Fetcher/AppFetcher.php
index 1605e5bd230..2216999e12f 100644
--- a/lib/private/App/AppStore/Fetcher/AppFetcher.php
+++ b/lib/private/App/AppStore/Fetcher/AppFetcher.php
@@ -35,6 +35,7 @@ use OC\Files\AppData\Factory;
 use OCP\AppFramework\Utility\ITimeFactory;
 use OCP\Http\Client\IClientService;
 use OCP\IConfig;
+use OCP\Support\Subscription\IRegistry;
 use Psr\Log\LoggerInterface;
 
 class AppFetcher extends Fetcher {
@@ -42,6 +43,9 @@ class AppFetcher extends Fetcher {
 	/** @var CompareVersion */
 	private $compareVersion;
 
+	/** @var IRegistry */
+	private $registry;
+
 	/** @var bool */
 	private $ignoreMaxVersion;
 
@@ -50,7 +54,8 @@ class AppFetcher extends Fetcher {
 								ITimeFactory $timeFactory,
 								IConfig $config,
 								CompareVersion $compareVersion,
-								LoggerInterface $logger) {
+								LoggerInterface $logger,
+								IRegistry $registry) {
 		parent::__construct(
 			$appDataFactory,
 			$clientService,
@@ -59,9 +64,11 @@ class AppFetcher extends Fetcher {
 			$logger
 		);
 
+		$this->compareVersion = $compareVersion;
+		$this->registry = $registry;
+
 		$this->fileName = 'apps.json';
 		$this->endpointName = 'apps.json';
-		$this->compareVersion = $compareVersion;
 		$this->ignoreMaxVersion = true;
 	}
 
@@ -172,4 +179,19 @@ class AppFetcher extends Fetcher {
 		$this->fileName = $fileName;
 		$this->ignoreMaxVersion = $ignoreMaxVersion;
 	}
+
+
+	public function get($allowUnstable = false) {
+		$apps = parent::get($allowUnstable);
+		$whitelist = $this->config->getSystemValue('appsallowlist');
+
+		// If the admin specified a whitelist, filter apps from the appstore
+		if (is_array($whitelist) && $this->registry->delegateHasValidSubscription()) {
+			return array_filter($apps, function ($app) use ($whitelist) {
+				return in_array($app['id'], $whitelist);
+			});
+		}
+
+		return $apps;
+	}
 }
-- 
cgit v1.2.3