Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 3 additions & 5 deletions apps/dav/lib/Settings/AvailabilitySettings.php
Expand Up @@ -33,6 +33,7 @@
use OCP\AppFramework\Services\IInitialState;
use OCP\IConfig;
use OCP\Settings\ISettings;
use OCP\User\IAvailabilityCoordinator;
use Psr\Log\LoggerInterface;

class AvailabilitySettings implements ISettings {
Expand All @@ -44,6 +45,7 @@ public function __construct(IConfig $config,
IInitialState $initialState,
?string $userId,
private LoggerInterface $logger,
private IAvailabilityCoordinator $coordinator,
private AbsenceMapper $absenceMapper) {
$this->config = $config;
$this->initialState = $initialState;
Expand All @@ -60,11 +62,7 @@ public function getForm(): TemplateResponse {
'no'
)
);
$hideAbsenceSettings = $this->config->getAppValue(
Application::APP_ID,
'hide_absence_settings',
'yes',
) === 'yes';
$hideAbsenceSettings = !$this->coordinator->isEnabled();
$this->initialState->provideInitialState('hide_absence_settings', $hideAbsenceSettings);
if (!$hideAbsenceSettings) {
try {
Expand Down
11 changes: 11 additions & 0 deletions lib/private/User/AvailabilityCoordinator.php
Expand Up @@ -27,10 +27,12 @@
namespace OC\User;

use JsonException;
use OCA\DAV\AppInfo\Application;
use OCA\DAV\Db\AbsenceMapper;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IUser;
use OCP\User\IAvailabilityCoordinator;
use OCP\User\IOutOfOfficeData;
Expand All @@ -42,11 +44,20 @@ class AvailabilityCoordinator implements IAvailabilityCoordinator {
public function __construct(
ICacheFactory $cacheFactory,
private AbsenceMapper $absenceMapper,
private IConfig $config,
private LoggerInterface $logger,
) {
$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 {
$cachedString = $this->cache->get($user->getUID());
if ($cachedString === null) {
Expand Down
9 changes: 9 additions & 0 deletions lib/public/User/IAvailabilityCoordinator.php
Expand Up @@ -33,6 +33,15 @@
* @since 28.0.0
*/
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
*
Expand Down
16 changes: 16 additions & 0 deletions tests/lib/User/AvailabilityCoordinatorTest.php
Expand Up @@ -32,14 +32,17 @@
use OCA\DAV\Db\AbsenceMapper;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IUser;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Test\TestCase;

class AvailabilityCoordinatorTest extends TestCase {
private AvailabilityCoordinator $availabilityCoordinator;
private ICacheFactory $cacheFactory;
private ICache $cache;
private IConfig|MockObject $config;
private AbsenceMapper $absenceMapper;
private LoggerInterface $logger;

Expand All @@ -49,6 +52,7 @@ protected function setUp(): void {
$this->cacheFactory = $this->createMock(ICacheFactory::class);
$this->cache = $this->createMock(ICache::class);
$this->absenceMapper = $this->createMock(AbsenceMapper::class);
$this->config = $this->createMock(IConfig::class);
$this->logger = $this->createMock(LoggerInterface::class);

$this->cacheFactory->expects(self::once())
Expand All @@ -58,10 +62,22 @@ protected function setUp(): void {
$this->availabilityCoordinator = new AvailabilityCoordinator(
$this->cacheFactory,
$this->absenceMapper,
$this->config,
$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 {
$absence = new Absence();
$absence->setId(420);
Expand Down