Skip to content

Commit b6a3ba1

Browse files
authored
Merge pull request #29235 from nextcloud/feat/appstore/enterprise
2 parents 8df577b + 1f76423 commit b6a3ba1

6 files changed

Lines changed: 33 additions & 10 deletions

File tree

lib/private/App/AppStore/Fetcher/AppFetcher.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class AppFetcher extends Fetcher {
4444
private $compareVersion;
4545

4646
/** @var IRegistry */
47-
private $registry;
47+
protected $registry;
4848

4949
/** @var bool */
5050
private $ignoreMaxVersion;
@@ -61,7 +61,8 @@ public function __construct(Factory $appDataFactory,
6161
$clientService,
6262
$timeFactory,
6363
$config,
64-
$logger
64+
$logger,
65+
$registry
6566
);
6667

6768
$this->compareVersion = $compareVersion;

lib/private/App/AppStore/Fetcher/CategoryFetcher.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,25 @@
3030
use OCP\AppFramework\Utility\ITimeFactory;
3131
use OCP\Http\Client\IClientService;
3232
use OCP\IConfig;
33+
use OCP\Support\Subscription\IRegistry;
3334
use Psr\Log\LoggerInterface;
3435

3536
class CategoryFetcher extends Fetcher {
3637
public function __construct(Factory $appDataFactory,
3738
IClientService $clientService,
3839
ITimeFactory $timeFactory,
3940
IConfig $config,
40-
LoggerInterface $logger) {
41+
LoggerInterface $logger,
42+
IRegistry $registry) {
4143
parent::__construct(
4244
$appDataFactory,
4345
$clientService,
4446
$timeFactory,
4547
$config,
46-
$logger
48+
$logger,
49+
$registry
4750
);
51+
4852
$this->fileName = 'categories.json';
4953
$this->endpointName = 'categories.json';
5054
}

lib/private/App/AppStore/Fetcher/Fetcher.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
use OCP\Files\NotFoundException;
3939
use OCP\Http\Client\IClientService;
4040
use OCP\IConfig;
41+
use OCP\Support\Subscription\IRegistry;
4142
use Psr\Log\LoggerInterface;
4243

4344
abstract class Fetcher {
@@ -54,6 +55,9 @@ abstract class Fetcher {
5455
protected $config;
5556
/** @var LoggerInterface */
5657
protected $logger;
58+
/** @var IRegistry */
59+
protected $registry;
60+
5761
/** @var string */
5862
protected $fileName;
5963
/** @var string */
@@ -67,12 +71,14 @@ public function __construct(Factory $appDataFactory,
6771
IClientService $clientService,
6872
ITimeFactory $timeFactory,
6973
IConfig $config,
70-
LoggerInterface $logger) {
74+
LoggerInterface $logger,
75+
IRegistry $registry) {
7176
$this->appData = $appDataFactory->get('appstore');
7277
$this->clientService = $clientService;
7378
$this->timeFactory = $timeFactory;
7479
$this->config = $config;
7580
$this->logger = $logger;
81+
$this->registry = $registry;
7682
}
7783

7884
/**
@@ -103,6 +109,12 @@ protected function fetch($ETag, $content) {
103109
];
104110
}
105111

112+
// If we have a valid subscription key, send it to the appstore
113+
$subscriptionKey = $this->config->getAppValue('support', 'subscription_key');
114+
if ($this->registry->delegateHasValidSubscription() && $subscriptionKey) {
115+
$options['headers']['X-NC-Subscription-Key'] = $subscriptionKey;
116+
}
117+
106118
$client = $this->clientService->newClient();
107119
try {
108120
$response = $client->get($this->getEndpoint(), $options);

tests/lib/App/AppStore/Fetcher/AppFetcherTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class AppFetcherTest extends TestCase {
5151
protected $compareVersion;
5252
/** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
5353
protected $logger;
54-
/** @var IRegistry */
54+
/** @var IRegistry|\PHPUnit\Framework\MockObject\MockObject */
5555
protected $registry;
5656
/** @var AppFetcher */
5757
protected $fetcher;
@@ -2067,7 +2067,7 @@ public function testSetVersion() {
20672067
$this->assertEquals(self::$expectedResponse['data'], $this->fetcher->get());
20682068
}
20692069

2070-
public function testGetWhitelist() {
2070+
public function testGetAppsAllowlist() {
20712071
$this->config->method('getSystemValue')
20722072
->willReturnCallback(function ($key, $default) {
20732073
if ($key === 'appstoreenabled') {
@@ -2082,7 +2082,7 @@ public function testGetWhitelist() {
20822082
return $default;
20832083
}
20842084
});
2085-
2085+
20862086
$file = $this->createMock(ISimpleFile::class);
20872087
$folder = $this->createMock(ISimpleFolder::class);
20882088
$folder
@@ -2107,6 +2107,7 @@ public function testGetWhitelist() {
21072107
->willReturn($client);
21082108
$response = $this->createMock(IResponse::class);
21092109
$client
2110+
->expects($this->once())
21102111
->method('get')
21112112
->with('https://custom.appsstore.endpoint/api/v1/apps.json')
21122113
->willReturn($response);
@@ -2123,7 +2124,7 @@ public function testGetWhitelist() {
21232124
->willReturn(1234);
21242125

21252126
$this->registry
2126-
->expects($this->once())
2127+
->expects($this->exactly(2))
21272128
->method('delegateHasValidSubscription')
21282129
->willReturn(true);
21292130

tests/lib/App/AppStore/Fetcher/CategoryFetcherTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ protected function setUp(): void {
3434
$this->clientService,
3535
$this->timeFactory,
3636
$this->config,
37-
$this->logger
37+
$this->logger,
38+
$this->registry
3839
);
3940
}
4041

tests/lib/App/AppStore/Fetcher/FetcherBase.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
use OCP\Http\Client\IClientService;
3434
use OCP\Http\Client\IResponse;
3535
use OCP\IConfig;
36+
use OCP\Support\Subscription\IRegistry;
3637
use Psr\Log\LoggerInterface;
3738
use Test\TestCase;
3839

@@ -49,6 +50,8 @@ abstract class FetcherBase extends TestCase {
4950
protected $config;
5051
/** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
5152
protected $logger;
53+
/** @var IRegistry|\PHPUnit\Framework\MockObject\MockObject */
54+
protected $registry;
5255
/** @var Fetcher */
5356
protected $fetcher;
5457
/** @var string */
@@ -68,6 +71,7 @@ protected function setUp(): void {
6871
$this->timeFactory = $this->createMock(ITimeFactory::class);
6972
$this->config = $this->createMock(IConfig::class);
7073
$this->logger = $this->createMock(LoggerInterface::class);
74+
$this->registry = $this->createMock(IRegistry::class);
7175
}
7276

7377
public function testGetWithAlreadyExistingFileAndUpToDateTimestampAndVersion() {

0 commit comments

Comments
 (0)