diff --git a/apps/dav/appinfo/v1/caldav.php b/apps/dav/appinfo/v1/caldav.php index 9547ff88c8dc9..062a2b83cd65c 100644 --- a/apps/dav/appinfo/v1/caldav.php +++ b/apps/dav/appinfo/v1/caldav.php @@ -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; @@ -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; @@ -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); diff --git a/apps/dav/lib/CalDAV/CalendarHome.php b/apps/dav/lib/CalDAV/CalendarHome.php index 311f4568df019..62ec97966c791 100644 --- a/apps/dav/lib/CalDAV/CalendarHome.php +++ b/apps/dav/lib/CalDAV/CalendarHome.php @@ -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; @@ -36,6 +37,8 @@ class CalendarHome extends \Sabre\CalDAV\CalendarHome { /** @var IConfig */ private $config; + private IAppConfig $appConfig; + /** @var PluginManager */ private $pluginManager; @@ -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) @@ -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. @@ -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']); diff --git a/apps/dav/lib/CalDAV/EmbeddedCalDavServer.php b/apps/dav/lib/CalDAV/EmbeddedCalDavServer.php index 7d53a91890e3a..755bdb07815ea 100644 --- a/apps/dav/lib/CalDAV/EmbeddedCalDavServer.php +++ b/apps/dav/lib/CalDAV/EmbeddedCalDavServer.php @@ -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; @@ -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)); } diff --git a/apps/dav/lib/CalDAV/Federation/CalendarFederationConfig.php b/apps/dav/lib/CalDAV/Federation/CalendarFederationConfig.php index 11e94eb9a647b..f9322f0a7c6bd 100644 --- a/apps/dav/lib/CalDAV/Federation/CalendarFederationConfig.php +++ b/apps/dav/lib/CalDAV/Federation/CalendarFederationConfig.php @@ -9,6 +9,8 @@ namespace OCA\DAV\CalDAV\Federation; +use OCA\DAV\AppInfo\Application; +use OCA\DAV\ConfigLexicon; use OCP\IAppConfig; class CalendarFederationConfig { @@ -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); } /** diff --git a/apps/dav/lib/CalDAV/Outbox.php b/apps/dav/lib/CalDAV/Outbox.php index 22907fad07f6e..68fcf47a2c677 100644 --- a/apps/dav/lib/CalDAV/Outbox.php +++ b/apps/dav/lib/CalDAV/Outbox.php @@ -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; /** @@ -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); @@ -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 = [ diff --git a/apps/dav/lib/ConfigLexicon.php b/apps/dav/lib/ConfigLexicon.php index e036a3b4b547f..a626ff1325949 100644 --- a/apps/dav/lib/ConfigLexicon.php +++ b/apps/dav/lib/ConfigLexicon.php @@ -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] @@ -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, diff --git a/apps/dav/lib/Server.php b/apps/dav/lib/Server.php index 49fdf4c3398fe..987eba9eddd5b 100644 --- a/apps/dav/lib/Server.php +++ b/apps/dav/lib/Server.php @@ -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; @@ -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()); } @@ -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), diff --git a/apps/dav/tests/unit/CalDAV/Federation/CalendarFederationConfigTest.php b/apps/dav/tests/unit/CalDAV/Federation/CalendarFederationConfigTest.php index 6878ad1aadfaa..f1250f0c28518 100644 --- a/apps/dav/tests/unit/CalDAV/Federation/CalendarFederationConfigTest.php +++ b/apps/dav/tests/unit/CalDAV/Federation/CalendarFederationConfigTest.php @@ -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; @@ -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()); diff --git a/apps/dav/tests/unit/CalDAV/OutboxTest.php b/apps/dav/tests/unit/CalDAV/OutboxTest.php index cc0a3f0405f0b..55645f653f47f 100644 --- a/apps/dav/tests/unit/CalDAV/OutboxTest.php +++ b/apps/dav/tests/unit/CalDAV/OutboxTest.php @@ -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([ [ @@ -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([ [ diff --git a/build/psalm-baseline.xml b/build/psalm-baseline.xml index 98d07a2ab20b6..723aef4ef7599 100644 --- a/build/psalm-baseline.xml +++ b/build/psalm-baseline.xml @@ -318,11 +318,6 @@ - - - - - @@ -1059,8 +1054,6 @@ - - diff --git a/lib/private/User/AvailabilityCoordinator.php b/lib/private/User/AvailabilityCoordinator.php index 32535711817da..81411b1c88bb0 100644 --- a/lib/private/User/AvailabilityCoordinator.php +++ b/lib/private/User/AvailabilityCoordinator.php @@ -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; @@ -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, @@ -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 { diff --git a/tests/lib/User/AvailabilityCoordinatorTest.php b/tests/lib/User/AvailabilityCoordinatorTest.php index 8244ec427e630..bcbb827a65437 100644 --- a/tests/lib/User/AvailabilityCoordinatorTest.php +++ b/tests/lib/User/AvailabilityCoordinatorTest.php @@ -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; @@ -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; @@ -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); @@ -48,7 +50,7 @@ protected function setUp(): void { $this->availabilityCoordinator = new AvailabilityCoordinator( $this->cacheFactory, - $this->config, + $this->appConfig, $this->absenceService, $this->logger, $this->timezoneService, @@ -56,10 +58,10 @@ protected function setUp(): void { } 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();