feat(dav): Enable OOO UI and expose enabled via OCP

Makes the feature opt-out now that we have meaningful integrations based
on OOO data. Allows instances still to turn the feature off.

For apps like Mail that build on top of this feature we need to know if
the instance has the feature turned on or off. This is exposed as OCP
API, too.

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
pull/41501/head
Christoph Wurst 1 year ago
parent ce6e3a3a01
commit 45541eb685
No known key found for this signature in database
GPG Key ID: CC42AC2A7F0E56D8
  1. 8
      apps/dav/lib/Settings/AvailabilitySettings.php
  2. 11
      lib/private/User/AvailabilityCoordinator.php
  3. 9
      lib/public/User/IAvailabilityCoordinator.php
  4. 16
      tests/lib/User/AvailabilityCoordinatorTest.php

@ -33,6 +33,7 @@ use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState; use OCP\AppFramework\Services\IInitialState;
use OCP\IConfig; use OCP\IConfig;
use OCP\Settings\ISettings; use OCP\Settings\ISettings;
use OCP\User\IAvailabilityCoordinator;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
class AvailabilitySettings implements ISettings { class AvailabilitySettings implements ISettings {
@ -44,6 +45,7 @@ class AvailabilitySettings implements ISettings {
IInitialState $initialState, IInitialState $initialState,
?string $userId, ?string $userId,
private LoggerInterface $logger, private LoggerInterface $logger,
private IAvailabilityCoordinator $coordinator,
private AbsenceMapper $absenceMapper) { private AbsenceMapper $absenceMapper) {
$this->config = $config; $this->config = $config;
$this->initialState = $initialState; $this->initialState = $initialState;
@ -60,11 +62,7 @@ class AvailabilitySettings implements ISettings {
'no' 'no'
) )
); );
$hideAbsenceSettings = $this->config->getAppValue( $hideAbsenceSettings = !$this->coordinator->isEnabled();
Application::APP_ID,
'hide_absence_settings',
'yes',
) === 'yes';
$this->initialState->provideInitialState('hide_absence_settings', $hideAbsenceSettings); $this->initialState->provideInitialState('hide_absence_settings', $hideAbsenceSettings);
if (!$hideAbsenceSettings) { if (!$hideAbsenceSettings) {
try { try {

@ -27,10 +27,12 @@ declare(strict_types=1);
namespace OC\User; namespace OC\User;
use JsonException; use JsonException;
use OCA\DAV\AppInfo\Application;
use OCA\DAV\Db\AbsenceMapper; use OCA\DAV\Db\AbsenceMapper;
use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Db\DoesNotExistException;
use OCP\ICache; use OCP\ICache;
use OCP\ICacheFactory; use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IUser; use OCP\IUser;
use OCP\User\IAvailabilityCoordinator; use OCP\User\IAvailabilityCoordinator;
use OCP\User\IOutOfOfficeData; use OCP\User\IOutOfOfficeData;
@ -42,11 +44,20 @@ class AvailabilityCoordinator implements IAvailabilityCoordinator {
public function __construct( public function __construct(
ICacheFactory $cacheFactory, ICacheFactory $cacheFactory,
private AbsenceMapper $absenceMapper, private AbsenceMapper $absenceMapper,
private IConfig $config,
private LoggerInterface $logger, private LoggerInterface $logger,
) { ) {
$this->cache = $cacheFactory->createLocal('OutOfOfficeData'); $this->cache = $cacheFactory->createLocal('OutOfOfficeData');
} }
public function isEnabled(): bool {
return $this->config->getAppValue(
Application::APP_ID,
'hide_absence_settings',
'no',
) === 'no';
}
private function getCachedOutOfOfficeData(IUser $user): ?OutOfOfficeData { private function getCachedOutOfOfficeData(IUser $user): ?OutOfOfficeData {
$cachedString = $this->cache->get($user->getUID()); $cachedString = $this->cache->get($user->getUID());
if ($cachedString === null) { if ($cachedString === null) {

@ -33,6 +33,15 @@ use OCP\IUser;
* @since 28.0.0 * @since 28.0.0
*/ */
interface IAvailabilityCoordinator { interface IAvailabilityCoordinator {
/**
* Check if the feature is enabled on this instance
*
* @return bool
*
* @since 28.0.0
*/
public function isEnabled(): bool;
/** /**
* Get the user's out-of-office message, if any * Get the user's out-of-office message, if any
* *

@ -32,7 +32,9 @@ use OCA\DAV\Db\Absence;
use OCA\DAV\Db\AbsenceMapper; use OCA\DAV\Db\AbsenceMapper;
use OCP\ICache; use OCP\ICache;
use OCP\ICacheFactory; use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IUser; use OCP\IUser;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Test\TestCase; use Test\TestCase;
@ -40,6 +42,7 @@ class AvailabilityCoordinatorTest extends TestCase {
private AvailabilityCoordinator $availabilityCoordinator; private AvailabilityCoordinator $availabilityCoordinator;
private ICacheFactory $cacheFactory; private ICacheFactory $cacheFactory;
private ICache $cache; private ICache $cache;
private IConfig|MockObject $config;
private AbsenceMapper $absenceMapper; private AbsenceMapper $absenceMapper;
private LoggerInterface $logger; private LoggerInterface $logger;
@ -49,6 +52,7 @@ class AvailabilityCoordinatorTest extends TestCase {
$this->cacheFactory = $this->createMock(ICacheFactory::class); $this->cacheFactory = $this->createMock(ICacheFactory::class);
$this->cache = $this->createMock(ICache::class); $this->cache = $this->createMock(ICache::class);
$this->absenceMapper = $this->createMock(AbsenceMapper::class); $this->absenceMapper = $this->createMock(AbsenceMapper::class);
$this->config = $this->createMock(IConfig::class);
$this->logger = $this->createMock(LoggerInterface::class); $this->logger = $this->createMock(LoggerInterface::class);
$this->cacheFactory->expects(self::once()) $this->cacheFactory->expects(self::once())
@ -58,10 +62,22 @@ class AvailabilityCoordinatorTest extends TestCase {
$this->availabilityCoordinator = new AvailabilityCoordinator( $this->availabilityCoordinator = new AvailabilityCoordinator(
$this->cacheFactory, $this->cacheFactory,
$this->absenceMapper, $this->absenceMapper,
$this->config,
$this->logger, $this->logger,
); );
} }
public function testIsEnabled(): void {
$this->config->expects(self::once())
->method('getAppValue')
->with('dav', 'hide_absence_settings', 'no')
->willReturn('no');
$isEnabled = $this->availabilityCoordinator->isEnabled();
self::assertTrue($isEnabled);
}
public function testGetOutOfOfficeData(): void { public function testGetOutOfOfficeData(): void {
$absence = new Absence(); $absence = new Absence();
$absence->setId(420); $absence->setId(420);

Loading…
Cancel
Save