diff --git a/apps/dav/lib/CalDAV/Schedule/IMipService.php b/apps/dav/lib/CalDAV/Schedule/IMipService.php
index 7b75cda6997..b091ea19ba1 100644
--- a/apps/dav/lib/CalDAV/Schedule/IMipService.php
+++ b/apps/dav/lib/CalDAV/Schedule/IMipService.php
@@ -11,7 +11,8 @@ namespace OCA\DAV\CalDAV\Schedule;
use OC\URLGenerator;
use OCA\DAV\CalDAV\EventReader;
use OCP\AppFramework\Utility\ITimeFactory;
-use OCP\IConfig;
+use OCP\Config\IUserConfig;
+use OCP\IAppConfig;
use OCP\IDBConnection;
use OCP\IL10N;
use OCP\IUserManager;
@@ -41,12 +42,13 @@ class IMipService {
public function __construct(
private URLGenerator $urlGenerator,
- private IConfig $config,
private IDBConnection $db,
private ISecureRandom $random,
private L10NFactory $l10nFactory,
private ITimeFactory $timeFactory,
private readonly IUserManager $userManager,
+ private readonly IUserConfig $userConfig,
+ private readonly IAppConfig $appConfig,
) {
$language = $this->l10nFactory->findGenericLanguage();
$locale = $this->l10nFactory->findLocale($language);
@@ -887,8 +889,8 @@ class IMipService {
$users = $this->userManager->getByEmail($userAddress);
if ($users !== []) {
$user = array_shift($users);
- $language = $this->config->getUserValue($user->getUID(), 'core', 'lang', null);
- $locale = $this->config->getUserValue($user->getUID(), 'core', 'locale', null);
+ $language = $this->userConfig->getValueString($user->getUID(), 'core', 'lang', '') ?: null;
+ $locale = $this->userConfig->getValueString($user->getUID(), 'core', 'locale', '') ?: null;
}
// fallback to attendee LANGUAGE parameter if language not set
if ($language === null && isset($attendee['LANGUAGE']) && $attendee['LANGUAGE'] instanceof Parameter) {
@@ -996,7 +998,7 @@ class IMipService {
* The default is 'no', which matches old behavior, and is privacy preserving.
*
* To enable including attendees in invitation emails:
- * % php occ config:app:set dav invitation_list_attendees --value yes
+ * % php occ config:app:set dav invitation_list_attendees --value yes --type bool
*
* @param IEMailTemplate $template
* @param IL10N $this->l10n
@@ -1004,12 +1006,12 @@ class IMipService {
* @author brad2014 on github.com
*/
public function addAttendees(IEMailTemplate $template, VEvent $vevent) {
- if ($this->config->getAppValue('dav', 'invitation_list_attendees', 'no') === 'no') {
+ if (!$this->appConfig->getValueBool('dav', 'invitation_list_attendees')) {
return;
}
if (isset($vevent->ORGANIZER)) {
- /** @var Property | Property\ICalendar\CalAddress $organizer */
+ /** @var Property&Property\ICalendar\CalAddress $organizer */
$organizer = $vevent->ORGANIZER;
$organizerEmail = substr($organizer->getNormalizedValue(), 7);
/** @var string|null $organizerName */
@@ -1039,8 +1041,14 @@ class IMipService {
$attendeesHTML = [];
$attendeesText = [];
foreach ($attendees as $attendee) {
+ /** @var Property&Property\ICalendar\CalAddress $attendee */
$attendeeEmail = substr($attendee->getNormalizedValue(), 7);
- $attendeeName = isset($attendee['CN']) ? $attendee['CN']->getValue() : null;
+ $attendeeName = null;
+ if (isset($attendee['CN'])) {
+ /** @var Parameter $cn */
+ $cn = $attendee['CN'];
+ $attendeeName = $cn->getValue();
+ }
$attendeeHTML = sprintf('%s',
htmlspecialchars($attendee->getNormalizedValue()),
htmlspecialchars($attendeeName ?: $attendeeEmail));
diff --git a/apps/dav/lib/CalDAV/TimezoneService.php b/apps/dav/lib/CalDAV/TimezoneService.php
index a7709bde0f9..54c4360d082 100644
--- a/apps/dav/lib/CalDAV/TimezoneService.php
+++ b/apps/dav/lib/CalDAV/TimezoneService.php
@@ -12,6 +12,7 @@ namespace OCA\DAV\CalDAV;
use OCA\DAV\Db\PropertyMapper;
use OCP\Calendar\ICalendar;
use OCP\Calendar\IManager;
+use OCP\Config\IUserConfig;
use OCP\IConfig;
use Sabre\VObject\Component\VCalendar;
use Sabre\VObject\Component\VTimeZone;
@@ -22,13 +23,14 @@ class TimezoneService {
public function __construct(
private IConfig $config,
+ private IUserConfig $userConfig,
private PropertyMapper $propertyMapper,
private IManager $calendarManager,
) {
}
public function getUserTimezone(string $userId): ?string {
- $fromConfig = $this->config->getUserValue(
+ $fromConfig = $this->userConfig->getValueString(
$userId,
'core',
'timezone',
@@ -51,7 +53,7 @@ class TimezoneService {
}
$principal = 'principals/users/' . $userId;
- $uri = $this->config->getUserValue($userId, 'dav', 'defaultCalendar', CalDavBackend::PERSONAL_CALENDAR_URI);
+ $uri = $this->userConfig->getValueString($userId, 'dav', 'defaultCalendar', CalDavBackend::PERSONAL_CALENDAR_URI);
$calendars = $this->calendarManager->getCalendarsForPrincipal($principal);
/** @var ?VTimeZone $personalCalendarTimezone */
diff --git a/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginCharsetTest.php b/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginCharsetTest.php
index 024c8cb11c1..ec6a4567e9c 100644
--- a/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginCharsetTest.php
+++ b/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginCharsetTest.php
@@ -14,9 +14,9 @@ use OCA\DAV\CalDAV\EventComparisonService;
use OCA\DAV\CalDAV\Schedule\IMipPlugin;
use OCA\DAV\CalDAV\Schedule\IMipService;
use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\Config\IUserConfig;
use OCP\Defaults;
use OCP\IAppConfig;
-use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IURLGenerator;
use OCP\IUser;
@@ -46,7 +46,7 @@ class IMipPluginCharsetTest extends TestCase {
// Dependencies
private Defaults&MockObject $defaults;
private IAppConfig&MockObject $appConfig;
- private IConfig&MockObject $config;
+ private IUserConfig&MockObject $userConfig;
private IDBConnection&MockObject $db;
private IFactory $l10nFactory;
private IManager&MockObject $mailManager;
@@ -77,7 +77,8 @@ class IMipPluginCharsetTest extends TestCase {
// IMipService
$this->urlGenerator = $this->createMock(URLGenerator::class);
- $this->config = $this->createMock(IConfig::class);
+ $this->userConfig = $this->createMock(IUserConfig::class);
+ $this->appConfig = $this->createMock(IAppConfig::class);
$this->db = $this->createMock(IDBConnection::class);
$this->random = $this->createMock(ISecureRandom::class);
$l10n = $this->createMock(L10N::class);
@@ -92,19 +93,19 @@ class IMipPluginCharsetTest extends TestCase {
$this->userManager->method('getByEmail')->willReturn([]);
$this->imipService = new IMipService(
$this->urlGenerator,
- $this->config,
$this->db,
$this->random,
$this->l10nFactory,
$this->timeFactory,
- $this->userManager
+ $this->userManager,
+ $this->userConfig,
+ $this->appConfig,
);
// EventComparisonService
$this->eventComparisonService = new EventComparisonService();
// IMipPlugin
- $this->appConfig = $this->createMock(IAppConfig::class);
$message = new \OC\Mail\Message(new Email(), false);
$this->mailer = $this->createMock(IMailer::class);
$this->mailer->method('createMessage')
@@ -177,8 +178,13 @@ class IMipPluginCharsetTest extends TestCase {
public function testCharsetMailProvider(): void {
// Arrange
$this->appConfig->method('getValueBool')
- ->with('core', 'mail_providers_enabled', true)
- ->willReturn(true);
+ ->willReturnCallback(function ($app, $key, $default) {
+ if ($app === 'core') {
+ $this->assertEquals($key, 'mail_providers_enabled');
+ return true;
+ }
+ return $default;
+ });
$mailMessage = new MailProviderMessage();
$mailService = $this->createMockForIntersectionOfInterfaces([IService::class, IMessageSend::class]);
$mailService->method('initiateMessage')
diff --git a/apps/dav/tests/unit/CalDAV/Schedule/IMipServiceTest.php b/apps/dav/tests/unit/CalDAV/Schedule/IMipServiceTest.php
index 9385daccb56..9b288822c00 100644
--- a/apps/dav/tests/unit/CalDAV/Schedule/IMipServiceTest.php
+++ b/apps/dav/tests/unit/CalDAV/Schedule/IMipServiceTest.php
@@ -13,7 +13,8 @@ use OC\URLGenerator;
use OCA\DAV\CalDAV\EventReader;
use OCA\DAV\CalDAV\Schedule\IMipService;
use OCP\AppFramework\Utility\ITimeFactory;
-use OCP\IConfig;
+use OCP\Config\IUserConfig;
+use OCP\IAppConfig;
use OCP\IDBConnection;
use OCP\IL10N;
use OCP\IUserManager;
@@ -26,7 +27,8 @@ use Test\TestCase;
class IMipServiceTest extends TestCase {
private URLGenerator&MockObject $urlGenerator;
- private IConfig&MockObject $config;
+ private IUserConfig&MockObject $userConfig;
+ private IAppConfig&MockObject $appConfig;
private IDBConnection&MockObject $db;
private ISecureRandom&MockObject $random;
private IFactory&MockObject $l10nFactory;
@@ -47,7 +49,8 @@ class IMipServiceTest extends TestCase {
parent::setUp();
$this->urlGenerator = $this->createMock(URLGenerator::class);
- $this->config = $this->createMock(IConfig::class);
+ $this->userConfig = $this->createMock(IUserConfig::class);
+ $this->appConfig = $this->createMock(IAppConfig::class);
$this->db = $this->createMock(IDBConnection::class);
$this->random = $this->createMock(ISecureRandom::class);
$this->l10nFactory = $this->createMock(IFactory::class);
@@ -63,12 +66,13 @@ class IMipServiceTest extends TestCase {
->willReturn($this->l10n);
$this->service = new IMipService(
$this->urlGenerator,
- $this->config,
$this->db,
$this->random,
$this->l10nFactory,
$this->timeFactory,
- $this->userManager
+ $this->userManager,
+ $this->userConfig,
+ $this->appConfig,
);
// construct calendar with a 1 hour event and same start/end time zones
diff --git a/apps/dav/tests/unit/CalDAV/TimezoneServiceTest.php b/apps/dav/tests/unit/CalDAV/TimezoneServiceTest.php
index 5bb87be67c1..0a01f4e06c9 100644
--- a/apps/dav/tests/unit/CalDAV/TimezoneServiceTest.php
+++ b/apps/dav/tests/unit/CalDAV/TimezoneServiceTest.php
@@ -9,12 +9,14 @@ declare(strict_types=1);
namespace OCA\DAV\Tests\unit\CalDAV;
use DateTimeZone;
+use OCA\DAV\CalDAV\CalDavBackend;
use OCA\DAV\CalDAV\CalendarImpl;
use OCA\DAV\CalDAV\TimezoneService;
use OCA\DAV\Db\Property;
use OCA\DAV\Db\PropertyMapper;
use OCP\Calendar\ICalendar;
use OCP\Calendar\IManager;
+use OCP\Config\IUserConfig;
use OCP\IConfig;
use PHPUnit\Framework\MockObject\MockObject;
use Sabre\VObject\Component\VTimeZone;
@@ -22,6 +24,7 @@ use Test\TestCase;
class TimezoneServiceTest extends TestCase {
private IConfig&MockObject $config;
+ private IUserConfig&MockObject $userConfig;
private PropertyMapper&MockObject $propertyMapper;
private IManager&MockObject $calendarManager;
private TimezoneService $service;
@@ -30,19 +33,21 @@ class TimezoneServiceTest extends TestCase {
parent::setUp();
$this->config = $this->createMock(IConfig::class);
+ $this->userConfig = $this->createMock(IUserConfig::class);
$this->propertyMapper = $this->createMock(PropertyMapper::class);
$this->calendarManager = $this->createMock(IManager::class);
$this->service = new TimezoneService(
$this->config,
+ $this->userConfig,
$this->propertyMapper,
$this->calendarManager,
);
}
public function testGetUserTimezoneFromSettings(): void {
- $this->config->expects(self::once())
- ->method('getUserValue')
+ $this->userConfig->expects(self::once())
+ ->method('getValueString')
->with('test123', 'core', 'timezone', '')
->willReturn('Europe/Warsaw');
@@ -52,8 +57,8 @@ class TimezoneServiceTest extends TestCase {
}
public function testGetUserTimezoneFromAvailability(): void {
- $this->config->expects(self::once())
- ->method('getUserValue')
+ $this->userConfig->expects(self::once())
+ ->method('getValueString')
->with('test123', 'core', 'timezone', '')
->willReturn('');
$property = new Property();
@@ -76,11 +81,11 @@ END:VCALENDAR');
}
public function testGetUserTimezoneFromPersonalCalendar(): void {
- $this->config->expects(self::exactly(2))
- ->method('getUserValue')
+ $this->userConfig->expects(self::exactly(2))
+ ->method('getValueString')
->willReturnMap([
- ['test123', 'core', 'timezone', '', ''],
- ['test123', 'dav', 'defaultCalendar', '', 'personal-1'],
+ ['test123', 'core', 'timezone', '', false, ''],
+ ['test123', 'dav', 'defaultCalendar', CalDavBackend::PERSONAL_CALENDAR_URI, false, 'personal-1'],
]);
$other = $this->createMock(ICalendar::class);
$other->method('getUri')->willReturn('other');
@@ -105,11 +110,11 @@ END:VCALENDAR');
}
public function testGetUserTimezoneFromAny(): void {
- $this->config->expects(self::exactly(2))
- ->method('getUserValue')
+ $this->userConfig->expects(self::exactly(2))
+ ->method('getValueString')
->willReturnMap([
- ['test123', 'core', 'timezone', '', ''],
- ['test123', 'dav', 'defaultCalendar', '', 'personal-1'],
+ ['test123', 'core', 'timezone', '', false, ''],
+ ['test123', 'dav', 'defaultCalendar', CalDavBackend::PERSONAL_CALENDAR_URI, false, 'personal-1'],
]);
$other = $this->createMock(ICalendar::class);
$other->method('getUri')->willReturn('other');
diff --git a/apps/files_trashbin/lib/Trashbin.php b/apps/files_trashbin/lib/Trashbin.php
index e957da8cbc7..e21da9b8cd0 100644
--- a/apps/files_trashbin/lib/Trashbin.php
+++ b/apps/files_trashbin/lib/Trashbin.php
@@ -24,6 +24,7 @@ use OCA\Files_Versions\Storage;
use OCP\App\IAppManager;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Command\IBus;
+use OCP\Config\IUserConfig;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\EventDispatcher\IEventListener;
@@ -38,6 +39,7 @@ use OCP\Files\NotPermittedException;
use OCP\Files\Storage\ILockingStorage;
use OCP\Files\Storage\IStorage;
use OCP\FilesMetadata\IFilesMetadataManager;
+use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IRequest;
@@ -368,12 +370,14 @@ class Trashbin implements IEventListener {
}
private static function getConfiguredTrashbinSize(string $user): int|float {
- $config = Server::get(IConfig::class);
- $userTrashbinSize = $config->getUserValue($user, 'files_trashbin', 'trashbin_size', '-1');
+ $userConfig = Server::get(IUserConfig::class);
+ $userTrashbinSize = $userConfig->getValueString($user, 'files_trashbin', 'trashbin_size', '-1');
if (is_numeric($userTrashbinSize) && ($userTrashbinSize > -1)) {
return Util::numericToNumber($userTrashbinSize);
}
- $systemTrashbinSize = $config->getAppValue('files_trashbin', 'trashbin_size', '-1');
+
+ $appConfig = Server::get(IAppConfig::class);
+ $systemTrashbinSize = $appConfig->getValueString('files_trashbin', 'trashbin_size', '-1');
if (is_numeric($systemTrashbinSize)) {
return Util::numericToNumber($systemTrashbinSize);
}
diff --git a/apps/theming/lib/ThemingDefaults.php b/apps/theming/lib/ThemingDefaults.php
index da92f31903b..445ab33e256 100644
--- a/apps/theming/lib/ThemingDefaults.php
+++ b/apps/theming/lib/ThemingDefaults.php
@@ -11,10 +11,10 @@ use OCA\Theming\Service\BackgroundService;
use OCP\App\AppPathNotFoundException;
use OCP\App\IAppManager;
use OCP\AppFramework\Services\IAppConfig;
+use OCP\Config\IUserConfig;
use OCP\Files\NotFoundException;
use OCP\Files\SimpleFS\ISimpleFile;
use OCP\ICacheFactory;
-use OCP\IConfig;
use OCP\IL10N;
use OCP\INavigationManager;
use OCP\IURLGenerator;
@@ -40,17 +40,17 @@ class ThemingDefaults extends \OC_Defaults {
* ThemingDefaults constructor.
*/
public function __construct(
- private IConfig $config,
- private IAppConfig $appConfig,
- private IL10N $l,
- private IUserSession $userSession,
- private IURLGenerator $urlGenerator,
- private ICacheFactory $cacheFactory,
- private Util $util,
- private ImageManager $imageManager,
- private IAppManager $appManager,
- private INavigationManager $navigationManager,
- private BackgroundService $backgroundService,
+ private readonly IAppConfig $appConfig,
+ private readonly IUserConfig $userConfig,
+ private readonly IL10N $l,
+ private readonly IUserSession $userSession,
+ private readonly IURLGenerator $urlGenerator,
+ private readonly ICacheFactory $cacheFactory,
+ private readonly Util $util,
+ private readonly ImageManager $imageManager,
+ private readonly IAppManager $appManager,
+ private readonly INavigationManager $navigationManager,
+ private readonly BackgroundService $backgroundService,
) {
parent::__construct();
@@ -183,7 +183,7 @@ class ThemingDefaults extends \OC_Defaults {
// user-defined primary color
if (!empty($user)) {
- $userPrimaryColor = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'primary_color', '');
+ $userPrimaryColor = $this->userConfig->getValueString($user->getUID(), Application::APP_ID, 'primary_color');
if (preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $userPrimaryColor)) {
return $userPrimaryColor;
}
@@ -209,7 +209,7 @@ class ThemingDefaults extends \OC_Defaults {
// user-defined background color
if (!empty($user)) {
- $userBackgroundColor = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'background_color', '');
+ $userBackgroundColor = $this->userConfig->getValueString($user->getUID(), Application::APP_ID, 'background_color');
if (preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $userBackgroundColor)) {
return $userBackgroundColor;
}
diff --git a/apps/theming/tests/ThemingDefaultsTest.php b/apps/theming/tests/ThemingDefaultsTest.php
index 86907b4b31c..54ea6e0c5ee 100644
--- a/apps/theming/tests/ThemingDefaultsTest.php
+++ b/apps/theming/tests/ThemingDefaultsTest.php
@@ -14,10 +14,10 @@ use OCA\Theming\ThemingDefaults;
use OCA\Theming\Util;
use OCP\App\IAppManager;
use OCP\AppFramework\Services\IAppConfig;
+use OCP\Config\IUserConfig;
use OCP\Files\NotFoundException;
use OCP\ICache;
use OCP\ICacheFactory;
-use OCP\IConfig;
use OCP\IL10N;
use OCP\INavigationManager;
use OCP\IURLGenerator;
@@ -28,7 +28,7 @@ use Test\TestCase;
class ThemingDefaultsTest extends TestCase {
private IAppConfig&MockObject $appConfig;
- private IConfig&MockObject $config;
+ private IUserConfig&MockObject $userConfig;
private IL10N&MockObject $l10n;
private IUserSession&MockObject $userSession;
private IURLGenerator&MockObject $urlGenerator;
@@ -46,7 +46,7 @@ class ThemingDefaultsTest extends TestCase {
protected function setUp(): void {
parent::setUp();
$this->appConfig = $this->createMock(IAppConfig::class);
- $this->config = $this->createMock(IConfig::class);
+ $this->userConfig = $this->createMock(IUserConfig::class);
$this->l10n = $this->createMock(IL10N::class);
$this->userSession = $this->createMock(IUserSession::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
@@ -63,8 +63,8 @@ class ThemingDefaultsTest extends TestCase {
->method('getBaseUrl')
->willReturn('');
$this->template = new ThemingDefaults(
- $this->config,
$this->appConfig,
+ $this->userConfig,
$this->l10n,
$this->userSession,
$this->urlGenerator,
@@ -468,9 +468,9 @@ class ThemingDefaultsTest extends TestCase {
->method('getAppValueString')
->with('primary_color', '')
->willReturn($primaryColor);
- $this->config
+ $this->userConfig
->expects($this->any())
- ->method('getUserValue')
+ ->method('getValueString')
->with('user', 'theming', 'primary_color', '')
->willReturn($userPrimaryColor);
diff --git a/apps/user_ldap/lib/Access.php b/apps/user_ldap/lib/Access.php
index 9fe0aa64268..a6a414d29bf 100644
--- a/apps/user_ldap/lib/Access.php
+++ b/apps/user_ldap/lib/Access.php
@@ -18,7 +18,6 @@ use OCA\User_LDAP\User\OfflineUser;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\HintException;
use OCP\IAppConfig;
-use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IUserManager;
use OCP\Server;
@@ -55,7 +54,6 @@ class Access extends LDAPUtility {
public Connection $connection,
public Manager $userManager,
private Helper $helper,
- private IConfig $config,
private IUserManager $ncUserManager,
private LoggerInterface $logger,
private IAppConfig $appConfig,
@@ -1572,14 +1570,12 @@ class Access extends LDAPUtility {
* a *
*/
private function prepareSearchTerm(string $term): string {
- $config = Server::get(IConfig::class);
-
- $allowEnum = $config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes');
+ $allowEnum = $this->appConfig->getValueBool('core', 'shareapi_allow_share_dialog_user_enumeration', true);
$result = $term;
if ($term === '') {
$result = '*';
- } elseif ($allowEnum !== 'no') {
+ } elseif ($allowEnum) {
$result = $term . '*';
}
return $result;
diff --git a/apps/user_ldap/lib/AccessFactory.php b/apps/user_ldap/lib/AccessFactory.php
index da114c467a7..739a19f46ef 100644
--- a/apps/user_ldap/lib/AccessFactory.php
+++ b/apps/user_ldap/lib/AccessFactory.php
@@ -9,7 +9,6 @@ namespace OCA\User_LDAP;
use OCA\User_LDAP\User\Manager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IAppConfig;
-use OCP\IConfig;
use OCP\IUserManager;
use OCP\Server;
use Psr\Log\LoggerInterface;
@@ -19,7 +18,6 @@ class AccessFactory {
public function __construct(
private ILDAPWrapper $ldap,
private Helper $helper,
- private IConfig $config,
private IAppConfig $appConfig,
private IUserManager $ncUserManager,
private LoggerInterface $logger,
@@ -34,7 +32,6 @@ class AccessFactory {
$connection,
Server::get(Manager::class),
$this->helper,
- $this->config,
$this->ncUserManager,
$this->logger,
$this->appConfig,
diff --git a/apps/user_ldap/lib/AppInfo/Application.php b/apps/user_ldap/lib/AppInfo/Application.php
index a01d6efb076..bc55f907732 100644
--- a/apps/user_ldap/lib/AppInfo/Application.php
+++ b/apps/user_ldap/lib/AppInfo/Application.php
@@ -37,7 +37,8 @@ use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\Image;
-use OCP\IServerContainer;
+use OCP\IRequest;
+use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\Notification\IManager as INotificationManager;
use OCP\Share\IManager as IShareManager;
@@ -56,27 +57,22 @@ class Application extends App implements IBootstrap {
/**
* Controller
*/
- $container->registerService('RenewPasswordController', function (IAppContainer $appContainer) {
- /** @var IServerContainer $server */
- $server = $appContainer->get(IServerContainer::class);
-
+ $container->registerService('RenewPasswordController', function (ContainerInterface $appContainer) {
return new RenewPasswordController(
$appContainer->get('AppName'),
- $server->getRequest(),
- $appContainer->get('UserManager'),
- $server->getConfig(),
+ $appContainer->get(IRequest::class),
+ $appContainer->get(IUserManager::class),
+ $appContainer->get(IConfig::class),
+ $appContainer->get(IUserConfig::class),
$appContainer->get(IL10N::class),
$appContainer->get('Session'),
- $server->getURLGenerator()
+ $appContainer->get(IURLGenerator::class),
);
});
- $container->registerService(ILDAPWrapper::class, function (IAppContainer $appContainer) {
- /** @var IServerContainer $server */
- $server = $appContainer->get(IServerContainer::class);
-
+ $container->registerService(ILDAPWrapper::class, function (ContainerInterface $appContainer) {
return new LDAP(
- $server->getConfig()->getSystemValueString('ldap_log_file')
+ $appContainer->get(IConfig::class)->getSystemValueString('ldap_log_file')
);
});
}
diff --git a/apps/user_ldap/lib/Controller/RenewPasswordController.php b/apps/user_ldap/lib/Controller/RenewPasswordController.php
index 8389a362b8f..04b919eeb67 100644
--- a/apps/user_ldap/lib/Controller/RenewPasswordController.php
+++ b/apps/user_ldap/lib/Controller/RenewPasswordController.php
@@ -13,6 +13,7 @@ use OCP\AppFramework\Http\Attribute\PublicPage;
use OCP\AppFramework\Http\Attribute\UseSession;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Http\TemplateResponse;
+use OCP\Config\IUserConfig;
use OCP\HintException;
use OCP\IConfig;
use OCP\IL10N;
@@ -24,18 +25,12 @@ use OCP\IUserManager;
#[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
class RenewPasswordController extends Controller {
- /**
- * @param string $appName
- * @param IRequest $request
- * @param IUserManager $userManager
- * @param IConfig $config
- * @param IURLGenerator $urlGenerator
- */
public function __construct(
- $appName,
+ string $appName,
IRequest $request,
private IUserManager $userManager,
private IConfig $config,
+ private IUserConfig $userConfig,
protected IL10N $l10n,
private ISession $session,
private IURLGenerator $urlGenerator,
@@ -43,25 +38,17 @@ class RenewPasswordController extends Controller {
parent::__construct($appName, $request);
}
- /**
- * @return RedirectResponse
- */
#[PublicPage]
#[NoCSRFRequired]
- public function cancel() {
+ public function cancel(): RedirectResponse {
return new RedirectResponse($this->urlGenerator->linkToRouteAbsolute('core.login.showLoginForm'));
}
- /**
- * @param string $user
- *
- * @return TemplateResponse|RedirectResponse
- */
#[PublicPage]
#[NoCSRFRequired]
#[UseSession]
- public function showRenewPasswordForm($user) {
- if ($this->config->getUserValue($user, 'user_ldap', 'needsPasswordReset') !== 'true') {
+ public function showRenewPasswordForm(string $user): TemplateResponse|RedirectResponse {
+ if (!$this->userConfig->getValueBool($user, 'user_ldap', 'needsPasswordReset')) {
return new RedirectResponse($this->urlGenerator->linkToRouteAbsolute('core.login.showLoginForm'));
}
$parameters = [];
@@ -94,17 +81,10 @@ class RenewPasswordController extends Controller {
);
}
- /**
- * @param string $user
- * @param string $oldPassword
- * @param string $newPassword
- *
- * @return RedirectResponse
- */
#[PublicPage]
#[UseSession]
- public function tryRenewPassword($user, $oldPassword, $newPassword) {
- if ($this->config->getUserValue($user, 'user_ldap', 'needsPasswordReset') !== 'true') {
+ public function tryRenewPassword(?string $user, string $oldPassword, ?string $newPassword): RedirectResponse {
+ if ($user !== null && !$this->userConfig->getValueBool($user, 'user_ldap', 'needsPasswordReset')) {
return new RedirectResponse($this->urlGenerator->linkToRouteAbsolute('core.login.showLoginForm'));
}
$args = !is_null($user) ? ['user' => $user] : [];
@@ -121,7 +101,7 @@ class RenewPasswordController extends Controller {
$this->session->set('loginMessages', [
[], [$this->l10n->t('Please login with the new password')]
]);
- $this->config->setUserValue($user, 'user_ldap', 'needsPasswordReset', 'false');
+ $this->userConfig->setValueBool($user, 'user_ldap', 'needsPasswordReset', false);
return new RedirectResponse($this->urlGenerator->linkToRoute('core.login.showLoginForm', $args));
} else {
$this->session->set('renewPasswordMessages', [
@@ -137,13 +117,10 @@ class RenewPasswordController extends Controller {
return new RedirectResponse($this->urlGenerator->linkToRoute('user_ldap.renewPassword.showRenewPasswordForm', $args));
}
- /**
- * @return RedirectResponse
- */
#[PublicPage]
#[NoCSRFRequired]
#[UseSession]
- public function showLoginFormInvalidPassword($user) {
+ public function showLoginFormInvalidPassword(?string $user): RedirectResponse {
$args = !is_null($user) ? ['user' => $user] : [];
$this->session->set('loginMessages', [
['invalidpassword'], []
diff --git a/apps/user_ldap/lib/Group_LDAP.php b/apps/user_ldap/lib/Group_LDAP.php
index 271cc96afbd..301793c1362 100644
--- a/apps/user_ldap/lib/Group_LDAP.php
+++ b/apps/user_ldap/lib/Group_LDAP.php
@@ -11,16 +11,15 @@ use Exception;
use OC\ServerNotAvailableException;
use OCA\User_LDAP\User\OfflineUser;
use OCP\Cache\CappedMemoryCache;
+use OCP\Config\IUserConfig;
use OCP\Group\Backend\ABackend;
use OCP\Group\Backend\IDeleteGroupBackend;
use OCP\Group\Backend\IGetDisplayNameBackend;
use OCP\Group\Backend\IIsAdminBackend;
use OCP\GroupInterface;
-use OCP\IConfig;
use OCP\IUserManager;
use OCP\Server;
use Psr\Log\LoggerInterface;
-use function json_decode;
class Group_LDAP extends ABackend implements GroupInterface, IGroupLDAP, IGetDisplayNameBackend, IDeleteGroupBackend, IIsAdminBackend {
protected bool $enabled = false;
@@ -41,7 +40,7 @@ class Group_LDAP extends ABackend implements GroupInterface, IGroupLDAP, IGetDis
public function __construct(
protected Access $access,
protected GroupPluginManager $groupPluginManager,
- private IConfig $config,
+ private IUserConfig $userConfig,
private IUserManager $ncUserManager,
) {
$filter = $this->access->connection->ldapGroupFilter;
@@ -643,8 +642,9 @@ class Group_LDAP extends ABackend implements GroupInterface, IGroupLDAP, IGetDis
* @return list
*/
protected function getCachedGroupsForUserId(string $uid): array {
- $groupStr = $this->config->getUserValue($uid, 'user_ldap', 'cached-group-memberships-' . $this->access->connection->getConfigPrefix(), '[]');
- return json_decode($groupStr, true) ?? [];
+ /** @var list $cache */
+ $cache = $this->userConfig->getValueArray($uid, 'user_ldap', 'cached-group-memberships-' . $this->access->connection->getConfigPrefix());
+ return $cache;
}
/**
@@ -800,8 +800,7 @@ class Group_LDAP extends ABackend implements GroupInterface, IGroupLDAP, IGetDis
$groups = array_values(array_unique($groups, SORT_LOCALE_STRING));
$this->access->connection->writeToCache($cacheKey, $groups);
- $groupStr = \json_encode($groups);
- $this->config->setUserValue($ncUid, 'user_ldap', 'cached-group-memberships-' . $this->access->connection->getConfigPrefix(), $groupStr);
+ $this->userConfig->setValueArray($ncUid, 'user_ldap', 'cached-group-memberships-' . $this->access->connection->getConfigPrefix(), $groups);
return $groups;
}
diff --git a/apps/user_ldap/lib/Group_Proxy.php b/apps/user_ldap/lib/Group_Proxy.php
index f0cdc7a465d..c08fe7117bf 100644
--- a/apps/user_ldap/lib/Group_Proxy.php
+++ b/apps/user_ldap/lib/Group_Proxy.php
@@ -8,6 +8,7 @@
namespace OCA\User_LDAP;
use OC\ServerNotAvailableException;
+use OCP\Config\IUserConfig;
use OCP\Group\Backend\IBatchMethodsBackend;
use OCP\Group\Backend\IDeleteGroupBackend;
use OCP\Group\Backend\IGetDisplayNameBackend;
@@ -15,7 +16,6 @@ use OCP\Group\Backend\IGroupDetailsBackend;
use OCP\Group\Backend\IIsAdminBackend;
use OCP\Group\Backend\INamedBackend;
use OCP\GroupInterface;
-use OCP\IConfig;
use OCP\IUserManager;
/**
@@ -23,11 +23,11 @@ use OCP\IUserManager;
*/
class Group_Proxy extends Proxy implements GroupInterface, IGroupLDAP, IGetDisplayNameBackend, INamedBackend, IDeleteGroupBackend, IBatchMethodsBackend, IIsAdminBackend {
public function __construct(
- private Helper $helper,
+ Helper $helper,
ILDAPWrapper $ldap,
AccessFactory $accessFactory,
private GroupPluginManager $groupPluginManager,
- private IConfig $config,
+ private IUserConfig $userConfig,
private IUserManager $ncUserManager,
) {
parent::__construct($helper, $ldap, $accessFactory);
@@ -35,7 +35,7 @@ class Group_Proxy extends Proxy implements GroupInterface, IGroupLDAP, IGetDispl
protected function newInstance(string $configPrefix): Group_LDAP {
- return new Group_LDAP($this->getAccess($configPrefix), $this->groupPluginManager, $this->config, $this->ncUserManager);
+ return new Group_LDAP($this->getAccess($configPrefix), $this->groupPluginManager, $this->userConfig, $this->ncUserManager);
}
/**
diff --git a/apps/user_ldap/lib/Jobs/Sync.php b/apps/user_ldap/lib/Jobs/Sync.php
index 26888ae96ae..e49a2f0f59d 100644
--- a/apps/user_ldap/lib/Jobs/Sync.php
+++ b/apps/user_ldap/lib/Jobs/Sync.php
@@ -14,15 +14,10 @@ use OCA\User_LDAP\ConnectionFactory;
use OCA\User_LDAP\Helper;
use OCA\User_LDAP\LDAP;
use OCA\User_LDAP\Mapping\UserMapping;
+use OCP\AppFramework\Services\IAppConfig;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;
-use OCP\EventDispatcher\IEventDispatcher;
-use OCP\IAvatarManager;
use OCP\IConfig;
-use OCP\IDBConnection;
-use OCP\IUserManager;
-use OCP\Notification\IManager;
-use Psr\Log\LoggerInterface;
class Sync extends TimedJob {
public const MAX_INTERVAL = 12 * 60 * 60; // 12h
@@ -32,13 +27,9 @@ class Sync extends TimedJob {
public function __construct(
ITimeFactory $timeFactory,
- private IEventDispatcher $dispatcher,
private IConfig $config,
- private IDBConnection $dbc,
- private IAvatarManager $avatarManager,
- private IUserManager $ncUserManager,
- private LoggerInterface $logger,
- private IManager $notificationManager,
+ private IAppConfig $appConfig,
+ private \OCP\IAppConfig $globalAppConfig,
private UserMapping $mapper,
private Helper $ldapHelper,
private ConnectionFactory $connectionFactory,
@@ -46,10 +37,9 @@ class Sync extends TimedJob {
) {
parent::__construct($timeFactory);
$this->setInterval(
- (int)$this->config->getAppValue(
- 'user_ldap',
+ $this->appConfig->getAppValueInt(
'background_sync_interval',
- (string)self::MIN_INTERVAL
+ self::MIN_INTERVAL
)
);
$this->ldap = new LDAP($this->config->getSystemValueString('ldap_log_file'));
@@ -71,31 +61,31 @@ class Sync extends TimedJob {
$interval = floor(24 * 60 * 60 / $runsPerDay);
$interval = min(max($interval, self::MIN_INTERVAL), self::MAX_INTERVAL);
- $this->config->setAppValue('user_ldap', 'background_sync_interval', (string)$interval);
+ $this->appConfig->setAppValueInt('background_sync_interval', (int)$interval);
}
/**
* returns the smallest configured paging size
*/
protected function getMinPagingSize(): int {
- $configKeys = $this->config->getAppKeys('user_ldap');
+ $configKeys = $this->appConfig->getAppKeys();
$configKeys = array_filter($configKeys, function ($key) {
return str_contains($key, 'ldap_paging_size');
});
- $minPagingSize = null;
+ $minPagingSize = 0;
foreach ($configKeys as $configKey) {
- $pagingSize = $this->config->getAppValue('user_ldap', $configKey, $minPagingSize);
- $minPagingSize = $minPagingSize === null ? $pagingSize : min($minPagingSize, $pagingSize);
+ $pagingSize = $this->appConfig->getAppValueInt($configKey, $minPagingSize);
+ $minPagingSize = $minPagingSize === 0 ? $pagingSize : min($minPagingSize, $pagingSize);
}
- return (int)$minPagingSize;
+ return $minPagingSize;
}
/**
* @param array $argument
*/
public function run($argument) {
- $isBackgroundJobModeAjax = $this->config
- ->getAppValue('core', 'backgroundjobs_mode', 'ajax') === 'ajax';
+ $isBackgroundJobModeAjax = $this->globalAppConfig
+ ->getValueString('core', 'backgroundjobs_mode', 'ajax') === 'ajax';
if ($isBackgroundJobModeAjax) {
return;
}
@@ -158,6 +148,7 @@ class Sync extends TimedJob {
/**
* Returns the info about the current cycle that should be run, if any,
* otherwise null
+ * @return ?array{prefix: string, offset: int}
*/
public function getCycle(): ?array {
$prefixes = $this->ldapHelper->getServerConfigurationPrefixes(true);
@@ -166,8 +157,8 @@ class Sync extends TimedJob {
}
$cycleData = [
- 'prefix' => $this->config->getAppValue('user_ldap', 'background_sync_prefix', 'none'),
- 'offset' => (int)$this->config->getAppValue('user_ldap', 'background_sync_offset', '0'),
+ 'prefix' => $this->appConfig->getAppValueString('background_sync_prefix', 'none'),
+ 'offset' => $this->appConfig->getAppValueInt('background_sync_offset'),
];
if (
@@ -186,8 +177,8 @@ class Sync extends TimedJob {
* @param array{prefix: ?string, offset: int} $cycleData
*/
public function setCycle(array $cycleData): void {
- $this->config->setAppValue('user_ldap', 'background_sync_prefix', $cycleData['prefix']);
- $this->config->setAppValue('user_ldap', 'background_sync_offset', (string)$cycleData['offset']);
+ $this->appConfig->setAppValueString('background_sync_prefix', $cycleData['prefix'] ?? '');
+ $this->appConfig->setAppValueInt('background_sync_offset', $cycleData['offset']);
}
/**
@@ -220,10 +211,10 @@ class Sync extends TimedJob {
* Checks whether the provided cycle should be run. Currently, only the
* last configuration change goes into account (at least one hour).
*
- * @param array{prefix: string} $cycleData
+ * @param array{prefix: string, offset: int} $cycleData
*/
public function qualifiesToRun(array $cycleData): bool {
- $lastChange = (int)$this->config->getAppValue('user_ldap', $cycleData['prefix'] . '_lastChange', '0');
+ $lastChange = $this->appConfig->getAppValueInt($cycleData['prefix'] . '_lastChange');
if ((time() - $lastChange) > 60 * 30) {
return true;
}
diff --git a/apps/user_ldap/lib/Jobs/UpdateGroups.php b/apps/user_ldap/lib/Jobs/UpdateGroups.php
index 9e72bcd8432..2ed4c8c74b4 100644
--- a/apps/user_ldap/lib/Jobs/UpdateGroups.php
+++ b/apps/user_ldap/lib/Jobs/UpdateGroups.php
@@ -10,21 +10,21 @@ declare(strict_types=1);
namespace OCA\User_LDAP\Jobs;
use OCA\User_LDAP\Service\UpdateGroupsService;
+use OCP\AppFramework\Services\IAppConfig;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;
use OCP\DB\Exception;
-use OCP\IConfig;
use Psr\Log\LoggerInterface;
class UpdateGroups extends TimedJob {
public function __construct(
private UpdateGroupsService $service,
private LoggerInterface $logger,
- IConfig $config,
+ IAppConfig $appConfig,
ITimeFactory $timeFactory,
) {
parent::__construct($timeFactory);
- $this->interval = (int)$config->getAppValue('user_ldap', 'bgjRefreshInterval', '3600');
+ $this->interval = $appConfig->getAppValueInt('bgjRefreshInterval', 3600);
}
/**
diff --git a/apps/user_ldap/lib/Migration/UUIDFixInsert.php b/apps/user_ldap/lib/Migration/UUIDFixInsert.php
index bb92314d93a..88c9859b809 100644
--- a/apps/user_ldap/lib/Migration/UUIDFixInsert.php
+++ b/apps/user_ldap/lib/Migration/UUIDFixInsert.php
@@ -8,41 +8,27 @@ namespace OCA\User_LDAP\Migration;
use OCA\User_LDAP\Mapping\GroupMapping;
use OCA\User_LDAP\Mapping\UserMapping;
+use OCP\AppFramework\Services\IAppConfig;
use OCP\BackgroundJob\IJobList;
-use OCP\IConfig;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
class UUIDFixInsert implements IRepairStep {
public function __construct(
- protected IConfig $config,
+ protected IAppConfig $appConfig,
protected UserMapping $userMapper,
protected GroupMapping $groupMapper,
protected IJobList $jobList,
) {
}
- /**
- * Returns the step's name
- *
- * @return string
- * @since 9.1.0
- */
- public function getName() {
+ public function getName(): string {
return 'Insert UUIDFix background job for user and group in batches';
}
- /**
- * Run repair step.
- * Must throw exception on error.
- *
- * @param IOutput $output
- * @throws \Exception in case of failure
- * @since 9.1.0
- */
- public function run(IOutput $output) {
- $installedVersion = $this->config->getAppValue('user_ldap', 'installed_version', '1.2.1');
+ public function run(IOutput $output): void {
+ $installedVersion = $this->appConfig->getAppValueString('installed_version', '1.2.1');
if (version_compare($installedVersion, '1.2.1') !== -1) {
return;
}
diff --git a/apps/user_ldap/lib/User/DeletedUsersIndex.php b/apps/user_ldap/lib/User/DeletedUsersIndex.php
index f57f71a9d47..55f2b764bc4 100644
--- a/apps/user_ldap/lib/User/DeletedUsersIndex.php
+++ b/apps/user_ldap/lib/User/DeletedUsersIndex.php
@@ -7,7 +7,7 @@
namespace OCA\User_LDAP\User;
use OCA\User_LDAP\Mapping\UserMapping;
-use OCP\IConfig;
+use OCP\Config\IUserConfig;
use OCP\PreConditionNotMetException;
use OCP\Share\IManager;
@@ -19,22 +19,23 @@ class DeletedUsersIndex {
protected ?array $deletedUsers = null;
public function __construct(
- protected IConfig $config,
+ protected IUserConfig $userConfig,
protected UserMapping $mapping,
private IManager $shareManager,
) {
}
/**
- * reads LDAP users marked as deleted from the database
+ * Reads LDAP users marked as deleted from the database.
+ *
* @return OfflineUser[]
*/
private function fetchDeletedUsers(): array {
- $deletedUsers = $this->config->getUsersForUserValue('user_ldap', 'isDeleted', '1');
+ $deletedUsers = $this->userConfig->searchUsersByValueBool('user_ldap', 'isDeleted', true);
$userObjects = [];
foreach ($deletedUsers as $user) {
- $userObject = new OfflineUser($user, $this->config, $this->mapping, $this->shareManager);
+ $userObject = new OfflineUser($user, $this->userConfig, $this->mapping, $this->shareManager);
if ($userObject->getLastLogin() > $userObject->getDetectedOn()) {
$userObject->unmark();
} else {
@@ -47,7 +48,8 @@ class DeletedUsersIndex {
}
/**
- * returns all LDAP users that are marked as deleted
+ * Returns all LDAP users that are marked as deleted.
+ *
* @return OfflineUser[]
*/
public function getUsers(): array {
@@ -58,7 +60,7 @@ class DeletedUsersIndex {
}
/**
- * whether at least one user was detected as deleted
+ * Whether at least one user was detected as deleted.
*/
public function hasUsers(): bool {
if (!is_array($this->deletedUsers)) {
@@ -68,7 +70,7 @@ class DeletedUsersIndex {
}
/**
- * marks a user as deleted
+ * Marks a user as deleted.
*
* @throws PreConditionNotMetException
*/
@@ -77,12 +79,12 @@ class DeletedUsersIndex {
// the user is already marked, do not write to DB again
return;
}
- $this->config->setUserValue($ocName, 'user_ldap', 'isDeleted', '1');
- $this->config->setUserValue($ocName, 'user_ldap', 'foundDeleted', (string)time());
+ $this->userConfig->setValueBool($ocName, 'user_ldap', 'isDeleted', true);
+ $this->userConfig->setValueInt($ocName, 'user_ldap', 'foundDeleted', time());
$this->deletedUsers = null;
}
public function isUserMarked(string $ocName): bool {
- return ($this->config->getUserValue($ocName, 'user_ldap', 'isDeleted', '0') === '1');
+ return ($this->userConfig->getValueBool($ocName, 'user_ldap', 'isDeleted', false) === true);
}
}
diff --git a/apps/user_ldap/lib/User/Manager.php b/apps/user_ldap/lib/User/Manager.php
index 24ca655a55a..539c667b897 100644
--- a/apps/user_ldap/lib/User/Manager.php
+++ b/apps/user_ldap/lib/User/Manager.php
@@ -162,25 +162,21 @@ class Manager {
}
/**
- * Checks whether the specified user is marked as deleted
- * @param string $id the Nextcloud user name
- * @return bool
+ * Checks whether the specified user is marked as deleted.
+ * @param string $id the Nextcloud username
*/
- public function isDeletedUser($id) {
- $isDeleted = $this->ocConfig->getUserValue(
- $id, 'user_ldap', 'isDeleted', 0);
- return (int)$isDeleted === 1;
+ public function isDeletedUser(string $id): bool {
+ return $this->userConfig->getValueBool(
+ $id, 'user_ldap', 'isDeleted');
}
/**
- * creates and returns an instance of OfflineUser for the specified user
- * @param string $id
- * @return OfflineUser
+ * Creates and returns an instance of OfflineUser for the specified user.
*/
- public function getDeletedUser($id) {
+ public function getDeletedUser(string $id): OfflineUser {
return new OfflineUser(
$id,
- $this->ocConfig,
+ $this->userConfig,
$this->access->getUserMapper(),
$this->shareManager
);
diff --git a/apps/user_ldap/lib/User/OfflineUser.php b/apps/user_ldap/lib/User/OfflineUser.php
index ecaab7188ba..ee2906e4b6f 100644
--- a/apps/user_ldap/lib/User/OfflineUser.php
+++ b/apps/user_ldap/lib/User/OfflineUser.php
@@ -7,75 +7,45 @@
*/
namespace OCA\User_LDAP\User;
-use OCA\User_LDAP\Mapping\UserMapping;
-use OCP\IConfig;
-use OCP\IDBConnection;
+use OCA\User_LDAP\Mapping\AbstractMapping;
+use OCP\Config\IUserConfig;
use OCP\Share\IManager;
use OCP\Share\IShare;
class OfflineUser {
- /**
- * @var string $dn
- */
- protected $dn;
- /**
- * @var string $uid the UID as provided by LDAP
- */
- protected $uid;
- /**
- * @var string $displayName
- */
- protected $displayName;
- /**
- * @var string $homePath
- */
- protected $homePath;
- /**
- * @var string $lastLogin the timestamp of the last login
- */
- protected $lastLogin;
- /**
- * @var string $foundDeleted the timestamp when the user was detected as unavailable
- */
- protected $foundDeleted;
+ protected ?string $dn = null;
+ /** @var ?string $uid the UID as provided by LDAP */
+ protected ?string $uid = null;
+ protected ?string $displayName = null;
+ protected ?string $homePath = null;
+ /** @var ?int $lastLogin the timestamp of the last login */
+ protected ?int $lastLogin = null;
+ /** @var ?int $foundDeleted the timestamp when the user was detected as unavailable */
+ protected ?int $foundDeleted = null;
protected ?string $extStorageHome = null;
- /**
- * @var string $email
- */
- protected $email;
- /**
- * @var bool $hasActiveShares
- */
- protected $hasActiveShares;
- /**
- * @var IDBConnection $db
- */
- protected $db;
+ protected ?string $email = null;
+ protected ?bool $hasActiveShares = null;
- /**
- * @param string $ocName
- */
public function __construct(
- protected $ocName,
- protected IConfig $config,
- protected UserMapping $mapping,
+ protected string $ocName,
+ protected IUserConfig $userConfig,
+ protected AbstractMapping $mapping,
private IManager $shareManager,
) {
}
/**
- * remove the Delete-flag from the user.
+ * Remove the Delete-flag from the user.
*/
- public function unmark() {
- $this->config->deleteUserValue($this->ocName, 'user_ldap', 'isDeleted');
- $this->config->deleteUserValue($this->ocName, 'user_ldap', 'foundDeleted');
+ public function unmark(): void {
+ $this->userConfig->deleteUserConfig($this->ocName, 'user_ldap', 'isDeleted');
+ $this->userConfig->deleteUserConfig($this->ocName, 'user_ldap', 'foundDeleted');
}
/**
- * exports the user details in an assoc array
- * @return array
+ * Exports the user details in an assoc array.
*/
- public function export() {
+ public function export(): array {
$data = [];
$data['ocName'] = $this->getOCName();
$data['dn'] = $this->getDN();
@@ -90,29 +60,26 @@ class OfflineUser {
}
/**
- * getter for Nextcloud internal name
- * @return string
+ * Getter for Nextcloud internal name.
*/
- public function getOCName() {
+ public function getOCName(): string {
return $this->ocName;
}
/**
- * getter for LDAP uid
- * @return string
+ * Getter for LDAP uid.
*/
- public function getUID() {
+ public function getUID(): string {
if ($this->uid === null) {
$this->fetchDetails();
}
- return $this->uid;
+ return $this->uid ?? '';
}
/**
- * getter for LDAP DN
- * @return string
+ * Getter for LDAP DN.
*/
- public function getDN() {
+ public function getDN(): string {
if ($this->dn === null) {
$dn = $this->mapping->getDNByName($this->ocName);
$this->dn = ($dn !== false) ? $dn : '';
@@ -121,101 +88,90 @@ class OfflineUser {
}
/**
- * getter for display name
- * @return string
+ * Getter for display name.
*/
- public function getDisplayName() {
+ public function getDisplayName(): string {
if ($this->displayName === null) {
$this->fetchDetails();
}
- return $this->displayName;
+ return $this->displayName ?? '';
}
/**
- * getter for email
- * @return string
+ * Getter for email.
*/
- public function getEmail() {
+ public function getEmail(): string {
if ($this->email === null) {
$this->fetchDetails();
}
- return $this->email;
+ return $this->email ?? '';
}
/**
- * getter for home directory path
- * @return string
+ * Getter for home directory path.
*/
- public function getHomePath() {
+ public function getHomePath(): string {
if ($this->homePath === null) {
$this->fetchDetails();
}
- return $this->homePath;
+ return $this->homePath ?? '';
}
/**
- * getter for the last login timestamp
- * @return int
+ * Getter for the last login timestamp.
*/
- public function getLastLogin() {
+ public function getLastLogin(): int {
if ($this->lastLogin === null) {
$this->fetchDetails();
}
- return (int)$this->lastLogin;
+ return $this->lastLogin ?? -1;
}
/**
- * getter for the detection timestamp
- * @return int
+ * Getter for the detection timestamp.
*/
- public function getDetectedOn() {
+ public function getDetectedOn(): int {
if ($this->foundDeleted === null) {
$this->fetchDetails();
}
- return (int)$this->foundDeleted;
+ return $this->foundDeleted ?? -1;
}
public function getExtStorageHome(): string {
if ($this->extStorageHome === null) {
$this->fetchDetails();
}
- return (string)$this->extStorageHome;
+ return $this->extStorageHome ?? '';
}
/**
- * getter for having active shares
- * @return bool
+ * Getter for having active shares.
*/
- public function getHasActiveShares() {
+ public function getHasActiveShares(): bool {
if ($this->hasActiveShares === null) {
$this->determineShares();
}
- return $this->hasActiveShares;
+ return $this->hasActiveShares ?? false;
}
/**
- * reads the user details
+ * Reads the user details.
*/
- protected function fetchDetails() {
- $properties = [
- 'displayName' => 'user_ldap',
- 'uid' => 'user_ldap',
- 'homePath' => 'user_ldap',
- 'foundDeleted' => 'user_ldap',
- 'extStorageHome' => 'user_ldap',
- 'email' => 'settings',
- 'lastLogin' => 'login',
- ];
- foreach ($properties as $property => $app) {
- $this->$property = $this->config->getUserValue($this->ocName, $app, $property, '');
- }
+ protected function fetchDetails(): void {
+ $this->displayName = $this->userConfig->getValueString($this->ocName, 'user_ldap', 'displayName');
+ $this->uid = $this->userConfig->getValueString($this->ocName, 'user_ldap', 'uid');
+ $this->homePath = $this->userConfig->getValueString($this->ocName, 'user_ldap', 'homePath');
+ $this->foundDeleted = $this->userConfig->getValueInt($this->ocName, 'user_ldap', 'foundDeleted');
+ $this->extStorageHome = $this->userConfig->getValueString($this->ocName, 'user_ldap', 'extStorageHome');
+ $this->email = $this->userConfig->getValueString($this->ocName, 'user_ldap', 'email');
+ $this->lastLogin = $this->userConfig->getValueInt($this->ocName, 'user_ldap', 'email');
}
/**
- * finds out whether the user has active shares. The result is stored in
- * $this->hasActiveShares
+ * Finds out whether the user has active shares. The result is stored in
+ * $this->hasActiveShares.
*/
- protected function determineShares() {
+ protected function determineShares(): void {
$shareInterface = new \ReflectionClass(IShare::class);
$shareConstants = $shareInterface->getConstants();
diff --git a/apps/user_ldap/tests/AccessTest.php b/apps/user_ldap/tests/AccessTest.php
index 1a45d71e257..9154580cc92 100644
--- a/apps/user_ldap/tests/AccessTest.php
+++ b/apps/user_ldap/tests/AccessTest.php
@@ -50,7 +50,6 @@ class AccessTest extends TestCase {
private LDAP&MockObject $ldap;
private Manager&MockObject $userManager;
private Helper&MockObject $helper;
- private IConfig&MockObject $config;
private IUserManager&MockObject $ncUserManager;
private LoggerInterface&MockObject $logger;
private IAppConfig&MockObject $appConfig;
@@ -64,7 +63,6 @@ class AccessTest extends TestCase {
->getMock();
$this->userManager = $this->createMock(Manager::class);
$this->helper = $this->createMock(Helper::class);
- $this->config = $this->createMock(IConfig::class);
$this->userMapper = $this->createMock(UserMapping::class);
$this->groupMapper = $this->createMock(GroupMapping::class);
$this->ncUserManager = $this->createMock(IUserManager::class);
@@ -78,7 +76,6 @@ class AccessTest extends TestCase {
$this->connection,
$this->userManager,
$this->helper,
- $this->config,
$this->ncUserManager,
$this->logger,
$this->appConfig,
@@ -225,9 +222,7 @@ class AccessTest extends TestCase {
#[\PHPUnit\Framework\Attributes\DataProvider('dnInputDataProvider')]
public function testStringResemblesDN(string $input, array|bool $interResult, bool $expectedResult): void {
[$lw, $con, $um, $helper] = $this->getConnectorAndLdapMock();
- /** @var IConfig&MockObject $config */
- $config = $this->createMock(IConfig::class);
- $access = new Access($lw, $con, $um, $helper, $config, $this->ncUserManager, $this->logger, $this->appConfig, $this->dispatcher);
+ $access = new Access($lw, $con, $um, $helper, $this->ncUserManager, $this->logger, $this->appConfig, $this->dispatcher);
$lw->expects($this->exactly(1))
->method('explodeDN')
@@ -244,10 +239,8 @@ class AccessTest extends TestCase {
#[\PHPUnit\Framework\Attributes\DataProvider('dnInputDataProvider')]
public function testStringResemblesDNLDAPmod(string $input, array|bool $interResult, bool $expectedResult): void {
[, $con, $um, $helper] = $this->getConnectorAndLdapMock();
- /** @var IConfig&MockObject $config */
- $config = $this->createMock(IConfig::class);
$lw = new LDAP();
- $access = new Access($lw, $con, $um, $helper, $config, $this->ncUserManager, $this->logger, $this->appConfig, $this->dispatcher);
+ $access = new Access($lw, $con, $um, $helper, $this->ncUserManager, $this->logger, $this->appConfig, $this->dispatcher);
if (!function_exists('ldap_explode_dn')) {
$this->markTestSkipped('LDAP Module not available');
@@ -416,9 +409,6 @@ class AccessTest extends TestCase {
#[\PHPUnit\Framework\Attributes\DataProvider('dNAttributeProvider')]
public function testSanitizeDN(string $attribute): void {
[$lw, $con, $um, $helper] = $this->getConnectorAndLdapMock();
- /** @var IConfig&MockObject $config */
- $config = $this->createMock(IConfig::class);
-
$dnFromServer = 'cn=Mixed Cases,ou=Are Sufficient To,ou=Test,dc=example,dc=org';
$lw->expects($this->any())
@@ -430,7 +420,7 @@ class AccessTest extends TestCase {
$attribute => ['count' => 1, $dnFromServer]
]);
- $access = new Access($lw, $con, $um, $helper, $config, $this->ncUserManager, $this->logger, $this->appConfig, $this->dispatcher);
+ $access = new Access($lw, $con, $um, $helper, $this->ncUserManager, $this->logger, $this->appConfig, $this->dispatcher);
$values = $access->readAttribute('uid=whoever,dc=example,dc=org', $attribute);
$this->assertSame($values[0], strtolower($dnFromServer));
}
diff --git a/apps/user_ldap/tests/Group_LDAPTest.php b/apps/user_ldap/tests/Group_LDAPTest.php
index 28c37ec6053..036b5fd2e71 100644
--- a/apps/user_ldap/tests/Group_LDAPTest.php
+++ b/apps/user_ldap/tests/Group_LDAPTest.php
@@ -18,8 +18,8 @@ use OCA\User_LDAP\User\Manager;
use OCA\User_LDAP\User\OfflineUser;
use OCA\User_LDAP\User\User;
use OCA\User_LDAP\User_Proxy;
+use OCP\Config\IUserConfig;
use OCP\GroupInterface;
-use OCP\IConfig;
use OCP\IUser;
use OCP\IUserManager;
use OCP\Security\ISecureRandom;
@@ -37,7 +37,7 @@ use Test\TestCase;
class Group_LDAPTest extends TestCase {
private Access&MockObject $access;
private GroupPluginManager&MockObject $pluginManager;
- private IConfig&MockObject $config;
+ private IUserConfig&MockObject $userConfig;
private IUserManager&MockObject $ncUserManager;
private GroupLDAP $groupBackend;
@@ -46,12 +46,12 @@ class Group_LDAPTest extends TestCase {
$this->access = $this->getAccessMock();
$this->pluginManager = $this->createMock(GroupPluginManager::class);
- $this->config = $this->createMock(IConfig::class);
+ $this->userConfig = $this->createMock(IUserConfig::class);
$this->ncUserManager = $this->createMock(IUserManager::class);
}
public function initBackend(): void {
- $this->groupBackend = new GroupLDAP($this->access, $this->pluginManager, $this->config, $this->ncUserManager);
+ $this->groupBackend = new GroupLDAP($this->access, $this->pluginManager, $this->userConfig, $this->ncUserManager);
}
public function testCountEmptySearchString(): void {
@@ -772,9 +772,9 @@ class Group_LDAPTest extends TestCase {
->method('isDNPartOfBase')
->willReturn(true);
- $this->config->expects($this->once())
- ->method('setUserValue')
- ->with('userX', 'user_ldap', 'cached-group-memberships-', \json_encode($expectedGroups));
+ $this->userConfig->expects($this->once())
+ ->method('setValueArray')
+ ->with('userX', 'user_ldap', 'cached-group-memberships-', $expectedGroups);
$this->initBackend();
$groups = $this->groupBackend->getUserGroups('userX');
@@ -810,9 +810,9 @@ class Group_LDAPTest extends TestCase {
->willReturn([]);
// empty group result should not be oer
- $this->config->expects($this->once())
- ->method('setUserValue')
- ->with('userX', 'user_ldap', 'cached-group-memberships-', '[]');
+ $this->userConfig->expects($this->once())
+ ->method('setValueArray')
+ ->with('userX', 'user_ldap', 'cached-group-memberships-', []);
$ldapUser = $this->createMock(User::class);
@@ -846,10 +846,10 @@ class Group_LDAPTest extends TestCase {
$offlineUser = $this->createMock(OfflineUser::class);
- $this->config->expects($this->any())
- ->method('getUserValue')
+ $this->userConfig->expects($this->any())
+ ->method('getValueArray')
->with('userX', 'user_ldap', 'cached-group-memberships-', $this->anything())
- ->willReturn(\json_encode(['groupB', 'groupF']));
+ ->willReturn(['groupB', 'groupF']);
$this->access->userManager->expects($this->any())
->method('get')
@@ -872,11 +872,11 @@ class Group_LDAPTest extends TestCase {
$offlineUser = $this->createMock(OfflineUser::class);
- $this->config->expects($this->any())
- ->method('getUserValue')
+ $this->userConfig->expects($this->any())
+ ->method('getValueArray')
->with('userX', 'user_ldap', 'cached-group-memberships-', $this->anything())
// results in a json object: {"0":"groupB","2":"groupF"}
- ->willReturn(\json_encode([0 => 'groupB', 2 => 'groupF']));
+ ->willReturn([0 => 'groupB', 2 => 'groupF']);
$this->access->userManager->expects($this->any())
->method('get')
@@ -907,10 +907,10 @@ class Group_LDAPTest extends TestCase {
->method('getBackend')
->willReturn($userBackend);
- $this->config->expects($this->atLeastOnce())
- ->method('getUserValue')
+ $this->userConfig->expects($this->atLeastOnce())
+ ->method('getValueArray')
->with('userX', 'user_ldap', 'cached-group-memberships-', $this->anything())
- ->willReturn(\json_encode(['groupB', 'groupF']));
+ ->willReturn(['groupB', 'groupF']);
$this->access->expects($this->any())
->method('username2dn')
diff --git a/apps/user_ldap/tests/Jobs/SyncTest.php b/apps/user_ldap/tests/Jobs/SyncTest.php
index 0e46685375c..e1ff30a1724 100644
--- a/apps/user_ldap/tests/Jobs/SyncTest.php
+++ b/apps/user_ldap/tests/Jobs/SyncTest.php
@@ -15,16 +15,16 @@ use OCA\User_LDAP\Jobs\Sync;
use OCA\User_LDAP\LDAP;
use OCA\User_LDAP\Mapping\UserMapping;
use OCA\User_LDAP\User\Manager;
+use OCP\AppFramework\Services\IAppConfig;
use OCP\AppFramework\Utility\ITimeFactory;
-use OCP\EventDispatcher\IEventDispatcher;
use OCP\IAvatarManager;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IUserManager;
use OCP\Notification\IManager;
use OCP\Server;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\MockObject\MockObject;
-use Psr\Log\LoggerInterface;
use Test\TestCase;
#[\PHPUnit\Framework\Attributes\Group('DB')]
@@ -34,6 +34,8 @@ class SyncTest extends TestCase {
protected Manager&MockObject $userManager;
protected UserMapping&MockObject $mapper;
protected IConfig&MockObject $config;
+ protected IAppConfig&MockObject $appConfig;
+ protected \OCP\IAppConfig&MockObject $globalAppConfig;
protected IAvatarManager&MockObject $avatarManager;
protected IDBConnection&MockObject $dbc;
protected IUserManager&MockObject $ncUserManager;
@@ -51,6 +53,8 @@ class SyncTest extends TestCase {
$this->userManager = $this->createMock(Manager::class);
$this->mapper = $this->createMock(UserMapping::class);
$this->config = $this->createMock(IConfig::class);
+ $this->appConfig = $this->createMock(IAppConfig::class);
+ $this->globalAppConfig = $this->createMock(\OCP\IAppConfig::class);
$this->avatarManager = $this->createMock(IAvatarManager::class);
$this->dbc = $this->createMock(IDBConnection::class);
$this->ncUserManager = $this->createMock(IUserManager::class);
@@ -64,13 +68,9 @@ class SyncTest extends TestCase {
$this->sync = new Sync(
Server::get(ITimeFactory::class),
- Server::get(IEventDispatcher::class),
$this->config,
- $this->dbc,
- $this->avatarManager,
- $this->ncUserManager,
- Server::get(LoggerInterface::class),
- $this->notificationManager,
+ $this->appConfig,
+ $this->globalAppConfig,
$this->mapper,
$this->helper,
$this->connectionFactory,
@@ -100,17 +100,17 @@ class SyncTest extends TestCase {
];
}
- #[\PHPUnit\Framework\Attributes\DataProvider('intervalDataProvider')]
+ #[DataProvider('intervalDataProvider')]
public function testUpdateInterval(int $userCount, int $pagingSize1, int $pagingSize2): void {
- $this->config->expects($this->once())
- ->method('setAppValue')
- ->with('user_ldap', 'background_sync_interval', $this->anything())
- ->willReturnCallback(function ($a, $k, $interval) {
+ $this->appConfig->expects($this->once())
+ ->method('setAppValueInt')
+ ->with('background_sync_interval', $this->anything())
+ ->willReturnCallback(function ($key, $interval) {
$this->assertTrue($interval >= SYNC::MIN_INTERVAL);
$this->assertTrue($interval <= SYNC::MAX_INTERVAL);
return true;
});
- $this->config->expects($this->atLeastOnce())
+ $this->appConfig->expects($this->atLeastOnce())
->method('getAppKeys')
->willReturn([
'blabla',
@@ -119,8 +119,8 @@ class SyncTest extends TestCase {
'installed',
's07ldap_paging_size'
]);
- $this->config->expects($this->exactly(2))
- ->method('getAppValue')
+ $this->appConfig->expects($this->exactly(2))
+ ->method('getAppValueInt')
->willReturnOnConsecutiveCalls($pagingSize1, $pagingSize2);
$this->mapper->expects($this->atLeastOnce())
@@ -141,7 +141,7 @@ class SyncTest extends TestCase {
];
}
- #[\PHPUnit\Framework\Attributes\DataProvider('moreResultsProvider')]
+ #[DataProvider('moreResultsProvider')]
public function testMoreResults($pagingSize, $results, $expected): void {
$connection = $this->getMockBuilder(Connection::class)
->setConstructorArgs([
@@ -198,7 +198,7 @@ class SyncTest extends TestCase {
];
}
- #[\PHPUnit\Framework\Attributes\DataProvider('cycleDataProvider')]
+ #[DataProvider('cycleDataProvider')]
public function testDetermineNextCycle(?array $cycleData, array $prefixes, ?array $expectedCycle): void {
$this->helper->expects($this->any())
->method('getServerConfigurationPrefixes')
@@ -206,19 +206,18 @@ class SyncTest extends TestCase {
->willReturn($prefixes);
if (is_array($expectedCycle)) {
- $calls = [
- ['user_ldap', 'background_sync_prefix', $expectedCycle['prefix']],
- ['user_ldap', 'background_sync_offset', $expectedCycle['offset']],
- ];
- $this->config->expects($this->exactly(2))
- ->method('setAppValue')
- ->willReturnCallback(function () use (&$calls): void {
- $expected = array_shift($calls);
- $this->assertEquals($expected, func_get_args());
- });
+ $this->appConfig->expects($this->once())
+ ->method('setAppValueInt')
+ ->with('background_sync_offset', $expectedCycle['offset']);
+
+ $this->appConfig->expects($this->once())
+ ->method('setAppValueString')
+ ->with('background_sync_prefix', $expectedCycle['prefix']);
} else {
- $this->config->expects($this->never())
- ->method('setAppValue');
+ $this->appConfig->expects($this->never())
+ ->method('setAppValueString');
+ $this->appConfig->expects($this->never())
+ ->method('setAppValueInt');
}
$this->sync->setArgument($this->arguments);
@@ -235,8 +234,8 @@ class SyncTest extends TestCase {
public function testQualifiesToRun(): void {
$cycleData = ['prefix' => 's01'];
- $this->config->expects($this->exactly(2))
- ->method('getAppValue')
+ $this->appConfig->expects($this->exactly(2))
+ ->method('getAppValueInt')
->willReturnOnConsecutiveCalls(time() - 60 * 40, time() - 60 * 20);
$this->sync->setArgument($this->arguments);
@@ -249,76 +248,94 @@ class SyncTest extends TestCase {
#0 - one LDAP server, reset
[[
'prefixes' => [''],
- 'scheduledCycle' => ['prefix' => '', 'offset' => '4500'],
+ 'scheduledCycle' => ['prefix' => '', 'offset' => 4500],
'pagingSize' => 500,
'usersThisCycle' => 0,
- 'expectedNextCycle' => ['prefix' => '', 'offset' => '0'],
+ 'expectedNextCycle' => ['prefix' => '', 'offset' => 0],
'mappedUsers' => 123,
]],
#1 - 2 LDAP servers, next prefix
[[
'prefixes' => ['', 's01'],
- 'scheduledCycle' => ['prefix' => '', 'offset' => '4500'],
+ 'scheduledCycle' => ['prefix' => '', 'offset' => 4500],
'pagingSize' => 500,
'usersThisCycle' => 0,
- 'expectedNextCycle' => ['prefix' => 's01', 'offset' => '0'],
+ 'expectedNextCycle' => ['prefix' => 's01', 'offset' => 0],
'mappedUsers' => 123,
]],
#2 - 2 LDAP servers, rotate prefix
[[
'prefixes' => ['', 's01'],
- 'scheduledCycle' => ['prefix' => 's01', 'offset' => '4500'],
+ 'scheduledCycle' => ['prefix' => 's01', 'offset' => 4500],
'pagingSize' => 500,
'usersThisCycle' => 0,
- 'expectedNextCycle' => ['prefix' => '', 'offset' => '0'],
+ 'expectedNextCycle' => ['prefix' => '', 'offset' => 0],
'mappedUsers' => 123,
]],
];
}
- #[\PHPUnit\Framework\Attributes\DataProvider('runDataProvider')]
+ #[DataProvider('runDataProvider')]
public function testRun(array $runData): void {
- $this->config->expects($this->any())
- ->method('getAppValue')
- ->willReturnCallback(function ($app, $key, $default) use ($runData) {
+ $this->globalAppConfig->expects($this->any())
+ ->method('getValueString')
+ ->willReturnCallback(function (string $app, string $key, $default) use ($runData) {
if ($app === 'core' && $key === 'backgroundjobs_mode') {
return 'cron';
}
- if ($app = 'user_ldap') {
- // for getCycle()
- if ($key === 'background_sync_prefix') {
- return $runData['scheduledCycle']['prefix'];
- }
- if ($key === 'background_sync_offset') {
- return $runData['scheduledCycle']['offset'];
- }
- // for qualifiesToRun()
- if ($key === $runData['scheduledCycle']['prefix'] . '_lastChange') {
- return time() - 60 * 40;
- }
- // for getMinPagingSize
- if ($key === $runData['scheduledCycle']['prefix'] . 'ldap_paging_size') {
- return $runData['pagingSize'];
- }
+ return $default;
+ });
+
+ $this->appConfig->expects($this->any())
+ ->method('getAppValueInt')
+ ->willReturnCallback(function (string $key, int $default) use ($runData): int {
+ if ($key === 'background_sync_offset') {
+ return $runData['scheduledCycle']['offset'];
+ }
+ // for getMinPagingSize
+ if ($key === $runData['scheduledCycle']['prefix'] . 'ldap_paging_size') {
+ return $runData['pagingSize'];
+ }
+ // for qualifiesToRun()
+ if ($key === $runData['scheduledCycle']['prefix'] . '_lastChange') {
+ return time() - 60 * 40;
}
return $default;
});
+ $this->appConfig->expects($this->any())
+ ->method('getAppValueString')
+ ->willReturnCallback(function (string $key, string $default) use ($runData): string {
+ // for getCycle()
+ if ($key === 'background_sync_prefix') {
+ return $runData['scheduledCycle']['prefix'];
+ }
+ return $default;
+ });
+
$calls = [
- ['user_ldap', 'background_sync_prefix', $runData['expectedNextCycle']['prefix']],
- ['user_ldap', 'background_sync_offset', $runData['expectedNextCycle']['offset']],
- ['user_ldap', 'background_sync_interval', '43200'],
+ ['background_sync_prefix', $runData['expectedNextCycle']['prefix'], false, false],
+ ['background_sync_offset', $runData['expectedNextCycle']['offset'], false, false],
+ ['background_sync_interval', 43200, false, false],
];
- $this->config->expects($this->exactly(3))
- ->method('setAppValue')
- ->willReturnCallback(function () use (&$calls): void {
+ $this->appConfig->expects($this->once())
+ ->method('setAppValueString')
+ ->willReturnCallback(function () use (&$calls): bool {
$expected = array_shift($calls);
$this->assertEquals($expected, func_get_args());
+ return true;
});
- $this->config->expects($this->any())
+ $this->appConfig->expects($this->exactly(2))
+ ->method('setAppValueInt')
+ ->willReturnCallback(function () use (&$calls): bool {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected, func_get_args());
+ return true;
+ });
+
+ $this->appConfig->expects($this->any())
->method('getAppKeys')
- ->with('user_ldap')
->willReturn([$runData['scheduledCycle']['prefix'] . 'ldap_paging_size']);
$this->helper->expects($this->any())
diff --git a/apps/user_ldap/tests/Migration/UUIDFixInsertTest.php b/apps/user_ldap/tests/Migration/UUIDFixInsertTest.php
index 6215ffcb6a1..1033a64cd0b 100644
--- a/apps/user_ldap/tests/Migration/UUIDFixInsertTest.php
+++ b/apps/user_ldap/tests/Migration/UUIDFixInsertTest.php
@@ -10,14 +10,14 @@ namespace OCA\User_LDAP\Tests\Migration;
use OCA\User_LDAP\Mapping\GroupMapping;
use OCA\User_LDAP\Mapping\UserMapping;
use OCA\User_LDAP\Migration\UUIDFixInsert;
+use OCP\AppFramework\Services\IAppConfig;
use OCP\BackgroundJob\IJobList;
-use OCP\IConfig;
use OCP\Migration\IOutput;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class UUIDFixInsertTest extends TestCase {
- protected IConfig&MockObject $config;
+ protected IAppConfig&MockObject $appConfig;
protected UserMapping&MockObject $userMapper;
protected GroupMapping&MockObject $groupMapper;
protected IJobList&MockObject $jobList;
@@ -27,11 +27,11 @@ class UUIDFixInsertTest extends TestCase {
parent::setUp();
$this->jobList = $this->createMock(IJobList::class);
- $this->config = $this->createMock(IConfig::class);
+ $this->appConfig = $this->createMock(IAppConfig::class);
$this->userMapper = $this->createMock(UserMapping::class);
$this->groupMapper = $this->createMock(GroupMapping::class);
$this->job = new UUIDFixInsert(
- $this->config,
+ $this->appConfig,
$this->userMapper,
$this->groupMapper,
$this->jobList
@@ -88,9 +88,9 @@ class UUIDFixInsertTest extends TestCase {
#[\PHPUnit\Framework\Attributes\DataProvider('recordProvider')]
public function testRun(array $userBatches, array $groupBatches): void {
- $this->config->expects($this->once())
- ->method('getAppValue')
- ->with('user_ldap', 'installed_version', '1.2.1')
+ $this->appConfig->expects($this->once())
+ ->method('getAppValueString')
+ ->with('installed_version', '1.2.1')
->willReturn('1.2.0');
$this->userMapper->expects($this->exactly(3))
@@ -116,9 +116,9 @@ class UUIDFixInsertTest extends TestCase {
#[\PHPUnit\Framework\Attributes\DataProvider('recordProviderTooLongAndNone')]
public function testRunWithManyAndNone(array $userBatches, array $groupBatches): void {
- $this->config->expects($this->once())
- ->method('getAppValue')
- ->with('user_ldap', 'installed_version', '1.2.1')
+ $this->appConfig->expects($this->once())
+ ->method('getAppValueString')
+ ->with('installed_version', '1.2.1')
->willReturn('1.2.0');
$this->userMapper->expects($this->exactly(5))
@@ -152,9 +152,9 @@ class UUIDFixInsertTest extends TestCase {
}
public function testDonNotRun(): void {
- $this->config->expects($this->once())
- ->method('getAppValue')
- ->with('user_ldap', 'installed_version', '1.2.1')
+ $this->appConfig->expects($this->once())
+ ->method('getAppValueString')
+ ->with('installed_version', '1.2.1')
->willReturn('1.2.1');
$this->userMapper->expects($this->never())
->method('getList');
diff --git a/apps/user_ldap/tests/User/DeletedUsersIndexTest.php b/apps/user_ldap/tests/User/DeletedUsersIndexTest.php
index 96a8913195c..841a4d70f9f 100644
--- a/apps/user_ldap/tests/User/DeletedUsersIndexTest.php
+++ b/apps/user_ldap/tests/User/DeletedUsersIndexTest.php
@@ -9,7 +9,7 @@ namespace OCA\User_LDAP\Tests\User;
use OCA\User_LDAP\Mapping\UserMapping;
use OCA\User_LDAP\User\DeletedUsersIndex;
-use OCP\IConfig;
+use OCP\Config\IUserConfig;
use OCP\IDBConnection;
use OCP\Server;
use OCP\Share\IManager;
@@ -24,7 +24,7 @@ use PHPUnit\Framework\MockObject\MockObject;
#[\PHPUnit\Framework\Attributes\Group('DB')]
class DeletedUsersIndexTest extends \Test\TestCase {
protected DeletedUsersIndex $dui;
- protected IConfig $config;
+ protected IUserConfig $userConfig;
protected IDBConnection $db;
protected UserMapping&MockObject $mapping;
protected IManager&MockObject $shareManager;
@@ -33,20 +33,20 @@ class DeletedUsersIndexTest extends \Test\TestCase {
parent::setUp();
// no mocks for those as tests go against DB
- $this->config = Server::get(IConfig::class);
+ $this->userConfig = Server::get(IUserConfig::class);
$this->db = Server::get(IDBConnection::class);
// ensure a clean database
- $this->config->deleteAppFromAllUsers('user_ldap');
+ $this->userConfig->deleteApp('user_ldap');
$this->mapping = $this->createMock(UserMapping::class);
$this->shareManager = $this->createMock(IManager::class);
- $this->dui = new DeletedUsersIndex($this->config, $this->mapping, $this->shareManager);
+ $this->dui = new DeletedUsersIndex($this->userConfig, $this->mapping, $this->shareManager);
}
protected function tearDown(): void {
- $this->config->deleteAppFromAllUsers('user_ldap');
+ $this->userConfig->deleteApp('user_ldap');
parent::tearDown();
}
diff --git a/apps/user_ldap/tests/User/OfflineUserTest.php b/apps/user_ldap/tests/User/OfflineUserTest.php
index 223e63421ad..932dac77e79 100644
--- a/apps/user_ldap/tests/User/OfflineUserTest.php
+++ b/apps/user_ldap/tests/User/OfflineUserTest.php
@@ -10,7 +10,7 @@ namespace OCA\User_LDAP\Tests\User;
use OCA\User_LDAP\Mapping\UserMapping;
use OCA\User_LDAP\User\OfflineUser;
-use OCP\IConfig;
+use OCP\Config\IUserConfig;
use OCP\Share\IManager;
use OCP\Share\IShare;
use PHPUnit\Framework\MockObject\MockObject;
@@ -19,19 +19,19 @@ use Test\TestCase;
class OfflineUserTest extends TestCase {
protected UserMapping&MockObject $mapping;
protected string $uid;
- protected IConfig&MockObject $config;
+ protected IUserConfig&MockObject $userConfig;
protected IManager&MockObject $shareManager;
protected OfflineUser $offlineUser;
public function setUp(): void {
$this->uid = 'deborah';
- $this->config = $this->createMock(IConfig::class);
+ $this->userConfig = $this->createMock(IUserConfig::class);
$this->mapping = $this->createMock(UserMapping::class);
$this->shareManager = $this->createMock(IManager::class);
$this->offlineUser = new OfflineUser(
$this->uid,
- $this->config,
+ $this->userConfig,
$this->mapping,
$this->shareManager
);
diff --git a/apps/weather_status/lib/Service/WeatherStatusService.php b/apps/weather_status/lib/Service/WeatherStatusService.php
index 6c606dc175d..f5a986904ab 100644
--- a/apps/weather_status/lib/Service/WeatherStatusService.php
+++ b/apps/weather_status/lib/Service/WeatherStatusService.php
@@ -73,8 +73,9 @@ class WeatherStatusService {
* @return list
*/
public function getFavorites(): array {
- $favoritesJson = $this->userConfig->getValueString($this->userId, Application::APP_ID, 'favorites', '');
- return json_decode($favoritesJson, true) ?: [];
+ /** @var list $favorites */
+ $favorites = $this->userConfig->getValueArray($this->userId, Application::APP_ID, 'favorites', []);
+ return $favorites;
}
/**
@@ -83,7 +84,7 @@ class WeatherStatusService {
* @return WeatherStatusSuccess success state
*/
public function setFavorites(array $favorites): array {
- $this->userConfig->setValueString($this->userId, Application::APP_ID, 'favorites', json_encode($favorites));
+ $this->userConfig->setValueArray($this->userId, Application::APP_ID, 'favorites', $favorites);
return ['success' => true];
}
diff --git a/build/psalm-baseline.xml b/build/psalm-baseline.xml
index f4851a1e152..edece01c1bd 100644
--- a/build/psalm-baseline.xml
+++ b/build/psalm-baseline.xml
@@ -410,15 +410,6 @@
-
-
-
-
-
-
-
-
-
@@ -2020,7 +2011,6 @@
Filesystem::normalizePath($file_path),
'trashPath' => Filesystem::normalizePath(static::getTrashFilename($filename, $timestamp))])]]>
$targetPath, 'trashPath' => $sourcePath])]]>
-
@@ -2430,8 +2420,6 @@
-
-
@@ -2854,7 +2842,6 @@
-
@@ -2869,10 +2856,6 @@
-
-
-
-
@@ -2884,10 +2867,6 @@
'loginName2UserName'
)]]>
-
-
-
-
@@ -2908,18 +2887,7 @@
break;]]>
-
-
-
-
-
-
-
-
-
-
-
@@ -2937,27 +2905,10 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -2989,11 +2940,6 @@
-
-
-
-
-
@@ -3005,29 +2951,11 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/lib/private/Server.php b/lib/private/Server.php
index f3997759539..51682ec3630 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -1034,12 +1034,12 @@ class Server extends ServerContainer implements IServerContainer {
$backgroundService,
);
return new ThemingDefaults(
- $c->get(\OCP\IConfig::class),
new AppConfig(
$c->get(\OCP\IConfig::class),
$c->get(\OCP\IAppConfig::class),
'theming',
),
+ $c->get(IUserConfig::class),
$c->get(IFactory::class)->get('theming'),
$c->get(IUserSession::class),
$c->get(IURLGenerator::class),
diff --git a/lib/private/User/Manager.php b/lib/private/User/Manager.php
index 1546f0d46a9..4a42a397a8e 100644
--- a/lib/private/User/Manager.php
+++ b/lib/private/User/Manager.php
@@ -68,7 +68,7 @@ class Manager extends PublicEmitter implements IUserManager {
private DisplayNameCache $displayNameCache;
- // FIXME: This constructor can't autoload any class requiring a DB connection.
+ // This constructor can't autoload any class requiring a DB connection.
public function __construct(
private IConfig $config,
ICacheFactory $cacheFactory,
diff --git a/lib/public/IConfig.php b/lib/public/IConfig.php
index 6961855ec1d..a2587aa571d 100644
--- a/lib/public/IConfig.php
+++ b/lib/public/IConfig.php
@@ -177,7 +177,7 @@ interface IConfig {
* @param mixed $default the default value to be returned if the value isn't set
* @return string
* @since 6.0.0 - parameter $default was added in 7.0.0
- * @deprecated 31.0.0 - use {@see IUserConfig::getValuesByUsers} directly
+ * @deprecated 31.0.0 - use {@see IUserConfig} directly
*/
public function getUserValue($userId, $appName, $key, $default = '');