Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/dav/appinfo/v1/caldav.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
// Backends
use OC\KnownUser\KnownUserService;
use OCA\DAV\AppInfo\Application;
use OCA\DAV\CalDAV\CalDavBackend;
use OCA\DAV\CalDAV\CalendarRoot;
use OCA\DAV\CalDAV\DefaultCalendarValidator;
Expand All @@ -17,6 +18,7 @@
use OCA\DAV\CalDAV\Schedule\IMipPlugin;
use OCA\DAV\CalDAV\Security\RateLimitingPlugin;
use OCA\DAV\CalDAV\Validation\CalDavValidatePlugin;
use OCA\DAV\ConfigLexicon;
use OCA\DAV\Connector\LegacyDAVACL;
use OCA\DAV\Connector\Sabre\Auth;
use OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin;
Expand Down Expand Up @@ -86,7 +88,7 @@
);

$debugging = Server::get(IConfig::class)->getSystemValue('debug', false);
$sendInvitations = Server::get(IAppConfig::class)->getValueBool('dav', 'sendInvitations', true);
$sendInvitations = Server::get(IAppConfig::class)->getValueBool(Application::APP_ID, ConfigLexicon::SEND_INVITATIONS);

// Root nodes
$principalCollection = new PrincipalCollection($principalBackend);
Expand Down
8 changes: 6 additions & 2 deletions apps/dav/lib/CalDAV/CalendarHome.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use OCA\DAV\CalDAV\Integration\ICalendarProvider;
use OCA\DAV\CalDAV\Trashbin\TrashbinHome;
use OCP\App\IAppManager;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IL10N;
use OCP\Server;
Expand All @@ -36,6 +37,8 @@ class CalendarHome extends \Sabre\CalDAV\CalendarHome {
/** @var IConfig */
private $config;

private IAppConfig $appConfig;

/** @var PluginManager */
private $pluginManager;

Expand All @@ -51,6 +54,7 @@ public function __construct(
parent::__construct($caldavBackend, $principalInfo);
$this->l10n = \OC::$server->getL10N('dav');
$this->config = Server::get(IConfig::class);
$this->appConfig = Server::get(IAppConfig::class);
$this->pluginManager = new PluginManager(
\OC::$server,
Server::get(IAppManager::class)
Expand Down Expand Up @@ -97,7 +101,7 @@ public function getChildren() {

if ($this->caldavBackend instanceof SchedulingSupport) {
$objects[] = new Inbox($this->caldavBackend, $this->principalInfo['uri']);
$objects[] = new Outbox($this->config, $this->principalInfo['uri']);
$objects[] = new Outbox($this->appConfig, $this->principalInfo['uri']);
}

// We're adding a notifications node, if it's supported by the backend.
Expand Down Expand Up @@ -153,7 +157,7 @@ public function getChild($name) {
return new Inbox($this->caldavBackend, $this->principalInfo['uri']);
}
if ($name === 'outbox' && $this->caldavBackend instanceof SchedulingSupport) {
return new Outbox($this->config, $this->principalInfo['uri']);
return new Outbox($this->appConfig, $this->principalInfo['uri']);
}
if ($name === 'notifications' && $this->caldavBackend instanceof NotificationSupport) {
return new \Sabre\CalDAV\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']);
Expand Down
4 changes: 3 additions & 1 deletion apps/dav/lib/CalDAV/EmbeddedCalDavServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@

namespace OCA\DAV\CalDAV;

use OCA\DAV\AppInfo\Application;
use OCA\DAV\AppInfo\PluginManager;
use OCA\DAV\CalDAV\Auth\CustomPrincipalPlugin;
use OCA\DAV\CalDAV\Auth\PublicPrincipalPlugin;
use OCA\DAV\CalDAV\Publishing\PublishPlugin;
use OCA\DAV\CalDAV\Schedule\IMipPlugin;
use OCA\DAV\ConfigLexicon;
use OCA\DAV\Connector\Sabre\AnonymousOptionsPlugin;
use OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin;
use OCA\DAV\Connector\Sabre\CachingTree;
Expand Down Expand Up @@ -93,7 +95,7 @@ public function __construct(bool $public = true) {
$this->server->addPlugin(new PublishPlugin(
Server::get(IURLGenerator::class)
));
if ($appConfig->getValueString('dav', 'sendInvitations', 'yes') === 'yes') {
if ($appConfig->getValueBool(Application::APP_ID, ConfigLexicon::SEND_INVITATIONS)) {
$this->server->addPlugin(Server::get(IMipPlugin::class));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

namespace OCA\DAV\CalDAV\Federation;

use OCA\DAV\AppInfo\Application;
use OCA\DAV\ConfigLexicon;
use OCP\IAppConfig;

class CalendarFederationConfig {
Expand All @@ -19,7 +21,7 @@ public function __construct(
}

public function isFederationEnabled(): bool {
return $this->appConfig->getValueBool('dav', 'enableCalendarFederation', true);
return $this->appConfig->getValueBool(Application::APP_ID, ConfigLexicon::ENABLE_CALENDAR_FEDERATION, true);
}

/**
Expand Down
10 changes: 6 additions & 4 deletions apps/dav/lib/CalDAV/Outbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
*/
namespace OCA\DAV\CalDAV;

use OCP\IConfig;
use OCA\DAV\AppInfo\Application;
use OCA\DAV\ConfigLexicon;
use OCP\IAppConfig;
use Sabre\CalDAV\Plugin as CalDAVPlugin;

/**
Expand All @@ -24,11 +26,11 @@ class Outbox extends \Sabre\CalDAV\Schedule\Outbox {
/**
* Outbox constructor.
*
* @param IConfig $config
* @param IAppConfig $appConfig
* @param string $principalUri
*/
public function __construct(
private IConfig $config,
private IAppConfig $appConfig,
string $principalUri,
) {
parent::__construct($principalUri);
Expand All @@ -50,7 +52,7 @@ public function __construct(
public function getACL() {
// getACL is called so frequently that we cache the config result
if ($this->disableFreeBusy === null) {
$this->disableFreeBusy = ($this->config->getAppValue('dav', 'disableFreeBusy', 'no') === 'yes');
$this->disableFreeBusy = $this->appConfig->getValueBool(Application::APP_ID, ConfigLexicon::DISABLE_FREE_BUSY);
}

$commonAcl = [
Expand Down
35 changes: 35 additions & 0 deletions apps/dav/lib/ConfigLexicon.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
* {@see ILexicon}
*/
class ConfigLexicon implements ILexicon {
public const ENABLE_CALENDAR_FEDERATION = 'enableCalendarFederation';
public const SEND_INVITATIONS = 'sendInvitations';
public const HIDE_ABSENCE_SETTINGS = 'hide_absence_settings';
public const ALLOW_CALENDAR_LINK_SUBSCRIPTIONS = 'allow_calendar_link_subscriptions';
public const DISABLE_FREE_BUSY = 'disableFreeBusy';
public const SYSTEM_ADDRESSBOOK_EXPOSED = 'system_addressbook_exposed';

#[\Override]
Expand All @@ -31,6 +36,36 @@ public function getStrictness(): Strictness {
#[\Override]
public function getAppConfigs(): array {
return [
new Entry(
self::ENABLE_CALENDAR_FEDERATION,
ValueType::BOOL,
defaultRaw: true,
definition: 'Whether calendars can be shared with and received from other Nextcloud servers',
),
new Entry(
self::SEND_INVITATIONS,
ValueType::BOOL,
defaultRaw: true,
definition: 'Whether to send invitation emails for events with attendees',
),
new Entry(
self::HIDE_ABSENCE_SETTINGS,
ValueType::BOOL,
defaultRaw: false,
definition: 'Whether to hide the absence (out-of-office) settings from users',
),
new Entry(
self::ALLOW_CALENDAR_LINK_SUBSCRIPTIONS,
ValueType::BOOL,
defaultRaw: true,
definition: 'Whether users can subscribe to calendars by link',
),
new Entry(
self::DISABLE_FREE_BUSY,
ValueType::BOOL,
defaultRaw: false,
definition: 'Whether to disable the free/busy lookup on user outboxes',
),
new Entry(
self::SYSTEM_ADDRESSBOOK_EXPOSED,
ValueType::BOOL,
Expand Down
5 changes: 3 additions & 2 deletions apps/dav/lib/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace OCA\DAV;

use OC\Files\Filesystem;
use OCA\DAV\AppInfo\Application;
use OCA\DAV\AppInfo\PluginManager;
use OCA\DAV\BulkUpload\BulkUploadPlugin;
use OCA\DAV\CalDAV\BirthdayCalendar\EnablePlugin;
Expand Down Expand Up @@ -210,7 +211,7 @@ public function __construct(

$this->server->addPlugin(\OCP\Server::get(\OCA\DAV\CalDAV\Trashbin\Plugin::class));
$this->server->addPlugin(new \OCA\DAV\CalDAV\WebcalCaching\Plugin($this->request));
if (\OCP\Server::get(IConfig::class)->getAppValue('dav', 'allow_calendar_link_subscriptions', 'yes') === 'yes') {
if (\OCP\Server::get(IAppConfig::class)->getValueBool(Application::APP_ID, ConfigLexicon::ALLOW_CALENDAR_LINK_SUBSCRIPTIONS)) {
$this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin());
}

Expand Down Expand Up @@ -346,7 +347,7 @@ public function __construct(
\OCP\Server::get(ICommentsManager::class),
$userSession
));
if (\OCP\Server::get(IConfig::class)->getAppValue('dav', 'sendInvitations', 'yes') === 'yes') {
if (\OCP\Server::get(IAppConfig::class)->getValueBool(Application::APP_ID, ConfigLexicon::SEND_INVITATIONS)) {
$this->server->addPlugin(new IMipPlugin(
\OCP\Server::get(IAppConfig::class),
\OCP\Server::get(IMailer::class),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

namespace OCA\DAV\Tests\unit\CalDAV\Federation;

use OCA\DAV\AppInfo\Application;
use OCA\DAV\CalDAV\Federation\CalendarFederationConfig;
use OCA\DAV\ConfigLexicon;
use OCP\GlobalScale\IConfig;
use OCP\IAppConfig;
use PHPUnit\Framework\Attributes\DataProvider;
Expand Down Expand Up @@ -45,7 +47,7 @@ public static function provideIsFederationEnabledData(): array {
public function testIsFederationEnabled(bool $configValue): void {
$this->appConfig->expects(self::once())
->method('getValueBool')
->with('dav', 'enableCalendarFederation', true)
->with(Application::APP_ID, ConfigLexicon::ENABLE_CALENDAR_FEDERATION, true)
->willReturn($configValue);

$this->assertEquals($configValue, $this->config->isFederationEnabled());
Expand Down
26 changes: 14 additions & 12 deletions apps/dav/tests/unit/CalDAV/OutboxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,29 @@
*/
namespace OCA\DAV\Tests\unit\CalDAV;

use OCA\DAV\AppInfo\Application;
use OCA\DAV\CalDAV\Outbox;
use OCP\IConfig;
use OCA\DAV\ConfigLexicon;
use OCP\IAppConfig;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;

class OutboxTest extends TestCase {
private IConfig&MockObject $config;
private IAppConfig&MockObject $appConfig;
private Outbox $outbox;

protected function setUp(): void {
parent::setUp();

$this->config = $this->createMock(IConfig::class);
$this->outbox = new Outbox($this->config, 'user-principal-123');
$this->appConfig = $this->createMock(IAppConfig::class);
$this->outbox = new Outbox($this->appConfig, 'user-principal-123');
}

public function testGetACLFreeBusyEnabled(): void {
$this->config->expects($this->once())
->method('getAppValue')
->with('dav', 'disableFreeBusy', 'no')
->willReturn('no');
$this->appConfig->expects($this->once())
->method('getValueBool')
->with(Application::APP_ID, ConfigLexicon::DISABLE_FREE_BUSY)
->willReturn(false);

$this->assertEquals([
[
Expand Down Expand Up @@ -59,10 +61,10 @@ public function testGetACLFreeBusyEnabled(): void {
}

public function testGetACLFreeBusyDisabled(): void {
$this->config->expects($this->once())
->method('getAppValue')
->with('dav', 'disableFreeBusy', 'no')
->willReturn('yes');
$this->appConfig->expects($this->once())
->method('getValueBool')
->with(Application::APP_ID, ConfigLexicon::DISABLE_FREE_BUSY)
->willReturn(true);

$this->assertEquals([
[
Expand Down
7 changes: 0 additions & 7 deletions build/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,6 @@
<code><![CDATA[getL10N]]></code>
</DeprecatedMethod>
</file>
<file src="apps/dav/lib/CalDAV/Outbox.php">
<DeprecatedMethod>
<code><![CDATA[getAppValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/dav/lib/CalDAV/Plugin.php">
<ImplementedReturnTypeMismatch>
<code><![CDATA[string|null]]></code>
Expand Down Expand Up @@ -1059,8 +1054,6 @@
<DeprecatedMethod>
<code><![CDATA[dispatch]]></code>
<code><![CDATA[dispatch]]></code>
<code><![CDATA[getAppValue]]></code>
<code><![CDATA[getAppValue]]></code>
<code><![CDATA[getL10N]]></code>
<code><![CDATA[getL10N]]></code>
<code><![CDATA[getUserFolder]]></code>
Expand Down
7 changes: 4 additions & 3 deletions lib/private/User/AvailabilityCoordinator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
use JsonException;
use OCA\DAV\AppInfo\Application;
use OCA\DAV\CalDAV\TimezoneService;
use OCA\DAV\ConfigLexicon;
use OCA\DAV\Service\AbsenceService;
use OCP\IAppConfig;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IUser;
use OCP\User\IAvailabilityCoordinator;
use OCP\User\IOutOfOfficeData;
Expand All @@ -26,7 +27,7 @@ class AvailabilityCoordinator implements IAvailabilityCoordinator {

public function __construct(
ICacheFactory $cacheFactory,
private IConfig $config,
private IAppConfig $appConfig,
private AbsenceService $absenceService,
private LoggerInterface $logger,
private TimezoneService $timezoneService,
Expand All @@ -36,7 +37,7 @@ public function __construct(

#[\Override]
public function isEnabled(): bool {
return $this->config->getAppValue(Application::APP_ID, 'hide_absence_settings', 'no') === 'no';
return !$this->appConfig->getValueBool(Application::APP_ID, ConfigLexicon::HIDE_ABSENCE_SETTINGS);
}

private function getCachedOutOfOfficeData(IUser $user): ?OutOfOfficeData {
Expand Down
18 changes: 10 additions & 8 deletions tests/lib/User/AvailabilityCoordinatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@

use OC\User\AvailabilityCoordinator;
use OC\User\OutOfOfficeData;
use OCA\DAV\AppInfo\Application;
use OCA\DAV\CalDAV\TimezoneService;
use OCA\DAV\ConfigLexicon;
use OCA\DAV\Db\Absence;
use OCA\DAV\Service\AbsenceService;
use OCP\IAppConfig;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IUser;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
Expand All @@ -26,7 +28,7 @@ class AvailabilityCoordinatorTest extends TestCase {
private AvailabilityCoordinator $availabilityCoordinator;
private ICacheFactory $cacheFactory;
private ICache $cache;
private IConfig|MockObject $config;
private IAppConfig&MockObject $appConfig;
private AbsenceService $absenceService;
private LoggerInterface $logger;
private MockObject|TimezoneService $timezoneService;
Expand All @@ -38,7 +40,7 @@ protected function setUp(): void {
$this->cacheFactory = $this->createMock(ICacheFactory::class);
$this->cache = $this->createMock(ICache::class);
$this->absenceService = $this->createMock(AbsenceService::class);
$this->config = $this->createMock(IConfig::class);
$this->appConfig = $this->createMock(IAppConfig::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->timezoneService = $this->createMock(TimezoneService::class);

Expand All @@ -48,18 +50,18 @@ protected function setUp(): void {

$this->availabilityCoordinator = new AvailabilityCoordinator(
$this->cacheFactory,
$this->config,
$this->appConfig,
$this->absenceService,
$this->logger,
$this->timezoneService,
);
}

public function testIsEnabled(): void {
$this->config->expects(self::once())
->method('getAppValue')
->with('dav', 'hide_absence_settings', 'no')
->willReturn('no');
$this->appConfig->expects(self::once())
->method('getValueBool')
->with(Application::APP_ID, ConfigLexicon::HIDE_ABSENCE_SETTINGS)
->willReturn(false);

$isEnabled = $this->availabilityCoordinator->isEnabled();

Expand Down
Loading