aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2020-03-10 19:39:03 +0100
committerGitHub <noreply@github.com>2020-03-10 19:39:03 +0100
commit5e4ee4dc59c3542cdee6c72209c8d75bcd977399 (patch)
tree4abe7ae75a7cf818eccd5abfb5980f18db4bdcec
parentc82c1da8f763d7b2e2fff2df1e37664b54698468 (diff)
parentdbd63222c890127307a0106db5fda35b74929523 (diff)
downloadnextcloud-server-5e4ee4dc59c3542cdee6c72209c8d75bcd977399.tar.gz
nextcloud-server-5e4ee4dc59c3542cdee6c72209c8d75bcd977399.zip
Merge pull request #19812 from nextcloud/enh/noid/subscription-config
Add config flag for subscription and hide server development notice
-rw-r--r--apps/settings/lib/Settings/Personal/ServerDevNotice.php13
-rw-r--r--apps/settings/tests/Controller/AdminSettingsControllerTest.php4
-rw-r--r--lib/private/Support/Subscription/Registry.php13
-rw-r--r--tests/lib/Support/Subscription/RegistryTest.php18
4 files changed, 46 insertions, 2 deletions
diff --git a/apps/settings/lib/Settings/Personal/ServerDevNotice.php b/apps/settings/lib/Settings/Personal/ServerDevNotice.php
index f69863fe35e..578211dcc00 100644
--- a/apps/settings/lib/Settings/Personal/ServerDevNotice.php
+++ b/apps/settings/lib/Settings/Personal/ServerDevNotice.php
@@ -27,8 +27,17 @@ namespace OCA\Settings\Settings\Personal;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\Settings\ISettings;
+use OCP\Support\Subscription\IRegistry;
class ServerDevNotice implements ISettings {
+
+ /** @var IRegistry */
+ private $registry;
+
+ public function __construct(IRegistry $registry) {
+ $this->registry = $registry;
+ }
+
/**
* @return TemplateResponse
*/
@@ -40,6 +49,10 @@ class ServerDevNotice implements ISettings {
* @return string the section ID, e.g. 'sharing'
*/
public function getSection() {
+ if ($this->registry->delegateHasValidSubscription()) {
+ return null;
+ }
+
return 'personal-info';
}
diff --git a/apps/settings/tests/Controller/AdminSettingsControllerTest.php b/apps/settings/tests/Controller/AdminSettingsControllerTest.php
index 9a82fd97854..c20067ddfc3 100644
--- a/apps/settings/tests/Controller/AdminSettingsControllerTest.php
+++ b/apps/settings/tests/Controller/AdminSettingsControllerTest.php
@@ -37,6 +37,7 @@ use OCP\IRequest;
use OCP\IUser;
use OCP\IUserSession;
use OCP\Settings\IManager;
+use OCP\Support\Subscription\IRegistry;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
@@ -99,6 +100,7 @@ class AdminSettingsControllerTest extends TestCase {
public function testIndex() {
$user = $this->createMock(IUser::class);
+ $registry = $this->createMock(IRegistry::class);
$this->userSession
->method('getUser')
->willReturn($user);
@@ -123,7 +125,7 @@ class AdminSettingsControllerTest extends TestCase {
->expects($this->once())
->method('getAdminSettings')
->with('test')
- ->willReturn([5 => new ServerDevNotice()]);
+ ->willReturn([5 => new ServerDevNotice($registry)]);
$idx = $this->adminSettingsController->index('test');
diff --git a/lib/private/Support/Subscription/Registry.php b/lib/private/Support/Subscription/Registry.php
index dfcff8ff96a..f0d946a2911 100644
--- a/lib/private/Support/Subscription/Registry.php
+++ b/lib/private/Support/Subscription/Registry.php
@@ -27,6 +27,7 @@ declare(strict_types=1);
namespace OC\Support\Subscription;
+use OCP\IConfig;
use OCP\Support\Subscription\Exception\AlreadyRegisteredException;
use OCP\Support\Subscription\IRegistry;
use OCP\Support\Subscription\ISubscription;
@@ -37,6 +38,13 @@ class Registry implements IRegistry {
/** @var ISubscription */
private $subscription = null;
+ /** @var IConfig */
+ private $config;
+
+ public function __construct(IConfig $config) {
+ $this->config = $config;
+ }
+
/**
* Register a subscription instance. In case it is called multiple times the
* first one is used.
@@ -71,6 +79,11 @@ class Registry implements IRegistry {
* @since 17.0.0
*/
public function delegateHasValidSubscription(): bool {
+ // Allow overwriting this manually for environments where the subscription information cannot be fetched
+ if ($this->config->getSystemValueBool('has_valid_subscription')) {
+ return true;
+ }
+
if ($this->subscription instanceof ISubscription) {
return $this->subscription->hasValidSubscription();
}
diff --git a/tests/lib/Support/Subscription/RegistryTest.php b/tests/lib/Support/Subscription/RegistryTest.php
index 3793026be0f..3e316792682 100644
--- a/tests/lib/Support/Subscription/RegistryTest.php
+++ b/tests/lib/Support/Subscription/RegistryTest.php
@@ -23,8 +23,10 @@
namespace Test\Support\Subscription;
use OC\Support\Subscription\Registry;
+use OCP\IConfig;
use OCP\Support\Subscription\ISubscription;
use OCP\Support\Subscription\ISupportedApps;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class RegistryTest extends TestCase {
@@ -32,10 +34,14 @@ class RegistryTest extends TestCase {
/** @var Registry */
private $registry;
+ /** @var MockObject|IConfig */
+ private $config;
+
protected function setUp(): void {
parent::setUp();
- $this->registry = new Registry();
+ $this->config = $this->createMock(IConfig::class);
+ $this->registry = new Registry($this->config);
}
/**
@@ -74,6 +80,16 @@ class RegistryTest extends TestCase {
$this->assertSame(true, $this->registry->delegateHasValidSubscription());
}
+ public function testDelegateHasValidSubscriptionConfig() {
+ /* @var ISubscription|\PHPUnit_Framework_MockObject_MockObject $subscription */
+ $this->config->expects($this->once())
+ ->method('getSystemValueBool')
+ ->with('has_valid_subscription')
+ ->willReturn(true);
+
+ $this->assertSame(true, $this->registry->delegateHasValidSubscription());
+ }
+
public function testDelegateHasExtendedSupport() {
/* @var ISubscription|\PHPUnit_Framework_MockObject_MockObject $subscription */
$subscription = $this->createMock(ISubscription::class);