Merge pull request #33565 from nextcloud/debt/remove_todo_push_service_fairuse

Remove time check in isFairUseOfFreePushService
mountcache-lazy-user
Louis 2 years ago committed by GitHub
commit a2d145734a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -27,7 +27,6 @@ declare(strict_types=1);
namespace OC\Notification;
use OC\AppFramework\Bootstrap\Coordinator;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\IUserManager;
@ -50,8 +49,6 @@ class Manager implements IManager {
private $userManager;
/** @var ICache */
protected $cache;
/** @var ITimeFactory */
protected $timeFactory;
/** @var IRegistry */
protected $subscription;
/** @var LoggerInterface */
@ -79,14 +76,12 @@ class Manager implements IManager {
public function __construct(IValidator $validator,
IUserManager $userManager,
ICacheFactory $cacheFactory,
ITimeFactory $timeFactory,
IRegistry $subscription,
LoggerInterface $logger,
Coordinator $coordinator) {
$this->validator = $validator;
$this->userManager = $userManager;
$this->cache = $cacheFactory->createDistributed('notifications');
$this->timeFactory = $timeFactory;
$this->subscription = $subscription;
$this->logger = $logger;
$this->coordinator = $coordinator;
@ -310,10 +305,7 @@ class Manager implements IManager {
* users overload our infrastructure. For this reason we have to rate-limit the
* use of push notifications. If you need this feature, consider using Nextcloud Enterprise.
*/
// TODO Remove time check after 1st March 2022
$isFairUse = $this->timeFactory->getTime() < 1646089200
|| $this->subscription->delegateHasValidSubscription()
|| $this->userManager->countSeenUsers() < 5000;
$isFairUse = $this->subscription->delegateHasValidSubscription() || $this->userManager->countSeenUsers() < 5000;
$pushAllowed = $isFairUse ? 'yes' : 'no';
$this->cache->set('push_fair_use', $pushAllowed, 3600);
}

@ -27,7 +27,6 @@ use OC\AppFramework\Bootstrap\Coordinator;
use OC\AppFramework\Bootstrap\RegistrationContext;
use OC\AppFramework\Bootstrap\ServiceRegistration;
use OC\Notification\Manager;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\IUserManager;
@ -51,8 +50,6 @@ class ManagerTest extends TestCase {
protected $cacheFactory;
/** @var ICache|MockObject */
protected $cache;
/** @var ITimeFactory|MockObject */
protected $timeFactory;
/** @var IRegistry|MockObject */
protected $subscriptionRegistry;
/** @var LoggerInterface|MockObject */
@ -68,7 +65,6 @@ class ManagerTest extends TestCase {
$this->validator = $this->createMock(IValidator::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->cache = $this->createMock(ICache::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
$this->subscriptionRegistry = $this->createMock(IRegistry::class);
$this->logger = $this->createMock(LoggerInterface::class);
@ -82,10 +78,10 @@ class ManagerTest extends TestCase {
$this->coordinator->method('getRegistrationContext')
->willReturn($this->registrationContext);
$this->manager = new Manager($this->validator, $this->userManager, $this->cacheFactory, $this->timeFactory, $this->subscriptionRegistry, $this->logger, $this->coordinator);
$this->manager = new Manager($this->validator, $this->userManager, $this->cacheFactory, $this->subscriptionRegistry, $this->logger, $this->coordinator);
}
public function testRegisterApp() {
public function testRegisterApp(): void {
$this->assertEquals([], self::invokePrivate($this->manager, 'getApps'));
$this->manager->registerApp(DummyApp::class);
@ -98,7 +94,7 @@ class ManagerTest extends TestCase {
$this->assertCount(2, self::invokePrivate($this->manager, 'getApps'));
}
public function testRegisterAppInvalid() {
public function testRegisterAppInvalid(): void {
$this->manager->registerApp(DummyNotifier::class);
$this->logger->expects($this->once())
@ -106,7 +102,7 @@ class ManagerTest extends TestCase {
self::invokePrivate($this->manager, 'getApps');
}
public function testRegisterNotifier() {
public function testRegisterNotifier(): void {
$this->assertEquals([], self::invokePrivate($this->manager, 'getNotifiers'));
$this->manager->registerNotifierService(DummyNotifier::class);
@ -119,7 +115,7 @@ class ManagerTest extends TestCase {
$this->assertCount(2, self::invokePrivate($this->manager, 'getNotifiers'));
}
public function testRegisterNotifierBootstrap() {
public function testRegisterNotifierBootstrap(): void {
$this->registrationContext->method('getNotifierServices')
->willReturn([
new ServiceRegistration('app', DummyNotifier::class),
@ -129,7 +125,7 @@ class ManagerTest extends TestCase {
$this->assertCount(1, self::invokePrivate($this->manager, 'getNotifiers'));
}
public function testRegisterNotifierInvalid() {
public function testRegisterNotifierInvalid(): void {
$this->manager->registerNotifierService(DummyApp::class);
$this->logger->expects($this->once())
@ -137,13 +133,13 @@ class ManagerTest extends TestCase {
self::invokePrivate($this->manager, 'getNotifiers');
}
public function testCreateNotification() {
public function testCreateNotification(): void {
$action = $this->manager->createNotification();
$this->assertInstanceOf('OCP\Notification\INotification', $action);
$this->assertInstanceOf(INotification::class, $action);
}
public function testNotify() {
/** @var \OCP\Notification\INotification|\PHPUnit\Framework\MockObject\MockObject $notification */
public function testNotify(): void {
/** @var INotification|MockObject $notification */
$notification = $this->getMockBuilder(INotification::class)
->disableOriginalConstructor()
->getMock();
@ -156,7 +152,6 @@ class ManagerTest extends TestCase {
$this->validator,
$this->userManager,
$this->cacheFactory,
$this->timeFactory,
$this->subscriptionRegistry,
$this->logger,
$this->coordinator,
@ -172,10 +167,10 @@ class ManagerTest extends TestCase {
}
public function testNotifyInvalid() {
public function testNotifyInvalid(): void {
$this->expectException(\InvalidArgumentException::class);
/** @var \OCP\Notification\INotification|\PHPUnit\Framework\MockObject\MockObject $notification */
/** @var INotification|MockObject $notification */
$notification = $this->getMockBuilder(INotification::class)
->disableOriginalConstructor()
->getMock();
@ -188,7 +183,6 @@ class ManagerTest extends TestCase {
$this->validator,
$this->userManager,
$this->cacheFactory,
$this->timeFactory,
$this->subscriptionRegistry,
$this->logger,
$this->coordinator,
@ -202,8 +196,8 @@ class ManagerTest extends TestCase {
$manager->notify($notification);
}
public function testMarkProcessed() {
/** @var \OCP\Notification\INotification|\PHPUnit\Framework\MockObject\MockObject $notification */
public function testMarkProcessed(): void {
/** @var INotification|MockObject $notification */
$notification = $this->getMockBuilder(INotification::class)
->disableOriginalConstructor()
->getMock();
@ -213,7 +207,6 @@ class ManagerTest extends TestCase {
$this->validator,
$this->userManager,
$this->cacheFactory,
$this->timeFactory,
$this->subscriptionRegistry,
$this->logger,
$this->coordinator,
@ -228,8 +221,8 @@ class ManagerTest extends TestCase {
$manager->markProcessed($notification);
}
public function testGetCount() {
/** @var \OCP\Notification\INotification|\PHPUnit\Framework\MockObject\MockObject $notification */
public function testGetCount(): void {
/** @var INotification|MockObject $notification */
$notification = $this->getMockBuilder(INotification::class)
->disableOriginalConstructor()
->getMock();
@ -239,7 +232,6 @@ class ManagerTest extends TestCase {
$this->validator,
$this->userManager,
$this->cacheFactory,
$this->timeFactory,
$this->subscriptionRegistry,
$this->logger,
$this->coordinator,
@ -254,33 +246,22 @@ class ManagerTest extends TestCase {
$manager->getCount($notification);
}
public function dataIsFairUseOfFreePushService() {
public function dataIsFairUseOfFreePushService(): array {
return [
// Before 1st March
[1646089199, true, 4999, true],
[1646089199, true, 5000, true],
[1646089199, false, 4999, true],
[1646089199, false, 5000, true],
// After 1st March
[1646089200, true, 4999, true],
[1646089200, true, 5000, true],
[1646089200, false, 4999, true],
[1646089200, false, 5000, false],
[true, 4999, true],
[true, 5000, true],
[false, 4999, true],
[false, 5000, false],
];
}
/**
* @dataProvider dataIsFairUseOfFreePushService
* @param int $time
* @param bool $hasValidSubscription
* @param int $userCount
* @param bool $isFair
*/
public function testIsFairUseOfFreePushService(int $time, bool $hasValidSubscription, int $userCount, bool $isFair): void {
$this->timeFactory->method('getTime')
->willReturn($time);
public function testIsFairUseOfFreePushService(bool $hasValidSubscription, int $userCount, bool $isFair): void {
$this->subscriptionRegistry->method('delegateHasValidSubscription')
->willReturn($hasValidSubscription);

Loading…
Cancel
Save