Skip to content
Snippets Groups Projects
Unverified Commit 5e4ee4dc authored by Roeland Jago Douma's avatar Roeland Jago Douma Committed by GitHub
Browse files

Merge pull request #19812 from nextcloud/enh/noid/subscription-config

Add config flag for subscription and hide server development notice
parents c82c1da8 dbd63222
No related branches found
No related tags found
No related merge requests found
...@@ -27,8 +27,17 @@ namespace OCA\Settings\Settings\Personal; ...@@ -27,8 +27,17 @@ namespace OCA\Settings\Settings\Personal;
use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Http\TemplateResponse;
use OCP\Settings\ISettings; use OCP\Settings\ISettings;
use OCP\Support\Subscription\IRegistry;
class ServerDevNotice implements ISettings { class ServerDevNotice implements ISettings {
/** @var IRegistry */
private $registry;
public function __construct(IRegistry $registry) {
$this->registry = $registry;
}
/** /**
* @return TemplateResponse * @return TemplateResponse
*/ */
...@@ -40,6 +49,10 @@ class ServerDevNotice implements ISettings { ...@@ -40,6 +49,10 @@ class ServerDevNotice implements ISettings {
* @return string the section ID, e.g. 'sharing' * @return string the section ID, e.g. 'sharing'
*/ */
public function getSection() { public function getSection() {
if ($this->registry->delegateHasValidSubscription()) {
return null;
}
return 'personal-info'; return 'personal-info';
} }
......
...@@ -37,6 +37,7 @@ use OCP\IRequest; ...@@ -37,6 +37,7 @@ use OCP\IRequest;
use OCP\IUser; use OCP\IUser;
use OCP\IUserSession; use OCP\IUserSession;
use OCP\Settings\IManager; use OCP\Settings\IManager;
use OCP\Support\Subscription\IRegistry;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase; use Test\TestCase;
...@@ -99,6 +100,7 @@ class AdminSettingsControllerTest extends TestCase { ...@@ -99,6 +100,7 @@ class AdminSettingsControllerTest extends TestCase {
public function testIndex() { public function testIndex() {
$user = $this->createMock(IUser::class); $user = $this->createMock(IUser::class);
$registry = $this->createMock(IRegistry::class);
$this->userSession $this->userSession
->method('getUser') ->method('getUser')
->willReturn($user); ->willReturn($user);
...@@ -123,7 +125,7 @@ class AdminSettingsControllerTest extends TestCase { ...@@ -123,7 +125,7 @@ class AdminSettingsControllerTest extends TestCase {
->expects($this->once()) ->expects($this->once())
->method('getAdminSettings') ->method('getAdminSettings')
->with('test') ->with('test')
->willReturn([5 => new ServerDevNotice()]); ->willReturn([5 => new ServerDevNotice($registry)]);
$idx = $this->adminSettingsController->index('test'); $idx = $this->adminSettingsController->index('test');
......
...@@ -27,6 +27,7 @@ declare(strict_types=1); ...@@ -27,6 +27,7 @@ declare(strict_types=1);
namespace OC\Support\Subscription; namespace OC\Support\Subscription;
use OCP\IConfig;
use OCP\Support\Subscription\Exception\AlreadyRegisteredException; use OCP\Support\Subscription\Exception\AlreadyRegisteredException;
use OCP\Support\Subscription\IRegistry; use OCP\Support\Subscription\IRegistry;
use OCP\Support\Subscription\ISubscription; use OCP\Support\Subscription\ISubscription;
...@@ -37,6 +38,13 @@ class Registry implements IRegistry { ...@@ -37,6 +38,13 @@ class Registry implements IRegistry {
/** @var ISubscription */ /** @var ISubscription */
private $subscription = null; 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 * Register a subscription instance. In case it is called multiple times the
* first one is used. * first one is used.
...@@ -71,6 +79,11 @@ class Registry implements IRegistry { ...@@ -71,6 +79,11 @@ class Registry implements IRegistry {
* @since 17.0.0 * @since 17.0.0
*/ */
public function delegateHasValidSubscription(): bool { 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) { if ($this->subscription instanceof ISubscription) {
return $this->subscription->hasValidSubscription(); return $this->subscription->hasValidSubscription();
} }
......
...@@ -23,8 +23,10 @@ ...@@ -23,8 +23,10 @@
namespace Test\Support\Subscription; namespace Test\Support\Subscription;
use OC\Support\Subscription\Registry; use OC\Support\Subscription\Registry;
use OCP\IConfig;
use OCP\Support\Subscription\ISubscription; use OCP\Support\Subscription\ISubscription;
use OCP\Support\Subscription\ISupportedApps; use OCP\Support\Subscription\ISupportedApps;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase; use Test\TestCase;
class RegistryTest extends TestCase { class RegistryTest extends TestCase {
...@@ -32,10 +34,14 @@ class RegistryTest extends TestCase { ...@@ -32,10 +34,14 @@ class RegistryTest extends TestCase {
/** @var Registry */ /** @var Registry */
private $registry; private $registry;
/** @var MockObject|IConfig */
private $config;
protected function setUp(): void { protected function setUp(): void {
parent::setUp(); 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 { ...@@ -74,6 +80,16 @@ class RegistryTest extends TestCase {
$this->assertSame(true, $this->registry->delegateHasValidSubscription()); $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() { public function testDelegateHasExtendedSupport() {
/* @var ISubscription|\PHPUnit_Framework_MockObject_MockObject $subscription */ /* @var ISubscription|\PHPUnit_Framework_MockObject_MockObject $subscription */
$subscription = $this->createMock(ISubscription::class); $subscription = $this->createMock(ISubscription::class);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment