Skip to content

Commit 33e0712

Browse files
Merge pull request #41501 from nextcloud/feat/dav/show-ooo-ui-by-default
feat(dav): Enable OOO UI and expose enabled via OCP
2 parents d06ee45 + 45541eb commit 33e0712

File tree

4 files changed

+39
-5
lines changed

4 files changed

+39
-5
lines changed

apps/dav/lib/Settings/AvailabilitySettings.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
use OCP\AppFramework\Services\IInitialState;
3434
use OCP\IConfig;
3535
use OCP\Settings\ISettings;
36+
use OCP\User\IAvailabilityCoordinator;
3637
use Psr\Log\LoggerInterface;
3738

3839
class AvailabilitySettings implements ISettings {
@@ -44,6 +45,7 @@ public function __construct(IConfig $config,
4445
IInitialState $initialState,
4546
?string $userId,
4647
private LoggerInterface $logger,
48+
private IAvailabilityCoordinator $coordinator,
4749
private AbsenceMapper $absenceMapper) {
4850
$this->config = $config;
4951
$this->initialState = $initialState;
@@ -60,11 +62,7 @@ public function getForm(): TemplateResponse {
6062
'no'
6163
)
6264
);
63-
$hideAbsenceSettings = $this->config->getAppValue(
64-
Application::APP_ID,
65-
'hide_absence_settings',
66-
'yes',
67-
) === 'yes';
65+
$hideAbsenceSettings = !$this->coordinator->isEnabled();
6866
$this->initialState->provideInitialState('hide_absence_settings', $hideAbsenceSettings);
6967
if (!$hideAbsenceSettings) {
7068
try {

lib/private/User/AvailabilityCoordinator.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@
2727
namespace OC\User;
2828

2929
use JsonException;
30+
use OCA\DAV\AppInfo\Application;
3031
use OCA\DAV\Db\AbsenceMapper;
3132
use OCP\AppFramework\Db\DoesNotExistException;
3233
use OCP\ICache;
3334
use OCP\ICacheFactory;
35+
use OCP\IConfig;
3436
use OCP\IUser;
3537
use OCP\User\IAvailabilityCoordinator;
3638
use OCP\User\IOutOfOfficeData;
@@ -42,11 +44,20 @@ class AvailabilityCoordinator implements IAvailabilityCoordinator {
4244
public function __construct(
4345
ICacheFactory $cacheFactory,
4446
private AbsenceMapper $absenceMapper,
47+
private IConfig $config,
4548
private LoggerInterface $logger,
4649
) {
4750
$this->cache = $cacheFactory->createLocal('OutOfOfficeData');
4851
}
4952

53+
public function isEnabled(): bool {
54+
return $this->config->getAppValue(
55+
Application::APP_ID,
56+
'hide_absence_settings',
57+
'no',
58+
) === 'no';
59+
}
60+
5061
private function getCachedOutOfOfficeData(IUser $user): ?OutOfOfficeData {
5162
$cachedString = $this->cache->get($user->getUID());
5263
if ($cachedString === null) {

lib/public/User/IAvailabilityCoordinator.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@
3333
* @since 28.0.0
3434
*/
3535
interface IAvailabilityCoordinator {
36+
/**
37+
* Check if the feature is enabled on this instance
38+
*
39+
* @return bool
40+
*
41+
* @since 28.0.0
42+
*/
43+
public function isEnabled(): bool;
44+
3645
/**
3746
* Get the user's out-of-office message, if any
3847
*

tests/lib/User/AvailabilityCoordinatorTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,17 @@
3232
use OCA\DAV\Db\AbsenceMapper;
3333
use OCP\ICache;
3434
use OCP\ICacheFactory;
35+
use OCP\IConfig;
3536
use OCP\IUser;
37+
use PHPUnit\Framework\MockObject\MockObject;
3638
use Psr\Log\LoggerInterface;
3739
use Test\TestCase;
3840

3941
class AvailabilityCoordinatorTest extends TestCase {
4042
private AvailabilityCoordinator $availabilityCoordinator;
4143
private ICacheFactory $cacheFactory;
4244
private ICache $cache;
45+
private IConfig|MockObject $config;
4346
private AbsenceMapper $absenceMapper;
4447
private LoggerInterface $logger;
4548

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

5458
$this->cacheFactory->expects(self::once())
@@ -58,10 +62,22 @@ protected function setUp(): void {
5862
$this->availabilityCoordinator = new AvailabilityCoordinator(
5963
$this->cacheFactory,
6064
$this->absenceMapper,
65+
$this->config,
6166
$this->logger,
6267
);
6368
}
6469

70+
public function testIsEnabled(): void {
71+
$this->config->expects(self::once())
72+
->method('getAppValue')
73+
->with('dav', 'hide_absence_settings', 'no')
74+
->willReturn('no');
75+
76+
$isEnabled = $this->availabilityCoordinator->isEnabled();
77+
78+
self::assertTrue($isEnabled);
79+
}
80+
6581
public function testGetOutOfOfficeData(): void {
6682
$absence = new Absence();
6783
$absence->setId(420);

0 commit comments

Comments
 (0)