diff --git a/apps/dav/lib/CalDAV/Schedule/IMipService.php b/apps/dav/lib/CalDAV/Schedule/IMipService.php
index 7b75cda699752..b091ea19ba133 100644
--- a/apps/dav/lib/CalDAV/Schedule/IMipService.php
+++ b/apps/dav/lib/CalDAV/Schedule/IMipService.php
@@ -11,7 +11,8 @@
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 @@ public function setL10nFromAttendee(Property $attendee) {
$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 @@ public function getAbsoluteImagePath($path): string {
* 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 @@ public function getAbsoluteImagePath($path): string {
* @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 @@ public function addAttendees(IEMailTemplate $template, VEvent $vevent) {
$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 a7709bde0f9e4..54c4360d08253 100644
--- a/apps/dav/lib/CalDAV/TimezoneService.php
+++ b/apps/dav/lib/CalDAV/TimezoneService.php
@@ -12,6 +12,7 @@
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 @@ public function getUserTimezone(string $userId): ?string {
}
$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 024c8cb11c11a..ec6a4567e9c92 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\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 @@ protected function setUp(): void {
// 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 @@ protected function setUp(): void {
$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 @@ public function testCharsetMailer(): void {
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 9385daccb56b9..9b288822c0083 100644
--- a/apps/dav/tests/unit/CalDAV/Schedule/IMipServiceTest.php
+++ b/apps/dav/tests/unit/CalDAV/Schedule/IMipServiceTest.php
@@ -13,7 +13,8 @@
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 @@
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 @@ protected function setUp(): void {
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 @@ protected function setUp(): void {
->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 5bb87be67c175..0a01f4e06c9ea 100644
--- a/apps/dav/tests/unit/CalDAV/TimezoneServiceTest.php
+++ b/apps/dav/tests/unit/CalDAV/TimezoneServiceTest.php
@@ -9,12 +9,14 @@
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 @@
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 @@ protected function setUp(): void {
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 @@ public function testGetUserTimezoneFromSettings(): void {
}
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 @@ public function testGetUserTimezoneFromAvailability(): void {
}
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 @@ public function testGetUserTimezoneFromPersonalCalendar(): void {
}
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 e957da8cbc738..e21da9b8cd0b3 100644
--- a/apps/files_trashbin/lib/Trashbin.php
+++ b/apps/files_trashbin/lib/Trashbin.php
@@ -24,6 +24,7 @@
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\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 @@ public static function move2trash($file_path, $ownerOnly = false) {
}
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 da92f31903b23..445ab33e2563a 100644
--- a/apps/theming/lib/ThemingDefaults.php
+++ b/apps/theming/lib/ThemingDefaults.php
@@ -11,10 +11,10 @@
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 @@ public function getColorPrimary(): string {
// 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 @@ public function getColorBackground(): string {
// 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 86907b4b31c56..54ea6e0c5ee44 100644
--- a/apps/theming/tests/ThemingDefaultsTest.php
+++ b/apps/theming/tests/ThemingDefaultsTest.php
@@ -14,10 +14,10 @@
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 @@
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 @@ protected function setUp(): void {
->method('getBaseUrl')
->willReturn('');
$this->template = new ThemingDefaults(
- $this->config,
$this->appConfig,
+ $this->userConfig,
$this->l10n,
$this->userSession,
$this->urlGenerator,
@@ -468,9 +468,9 @@ public function testGetColorPrimary(bool $disableTheming, string $primaryColor,
->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 9fe0aa6426856..a6a414d29bf93 100644
--- a/apps/user_ldap/lib/Access.php
+++ b/apps/user_ldap/lib/Access.php
@@ -18,7 +18,6 @@
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 @@ public function __construct(
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 @@ private function getFilterPartForSearch(string $search, $searchAttributes, strin
* 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 da114c467a7ef..739a19f46ef39 100644
--- a/apps/user_ldap/lib/AccessFactory.php
+++ b/apps/user_ldap/lib/AccessFactory.php
@@ -9,7 +9,6 @@
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 @@ public function get(Connection $connection): Access {
$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 25ca6f3a7baea..bc55f907732ec 100644
--- a/apps/user_ldap/lib/AppInfo/Application.php
+++ b/apps/user_ldap/lib/AppInfo/Application.php
@@ -29,13 +29,16 @@
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\AppFramework\IAppContainer;
+use OCP\AppFramework\Services\IAppConfig;
+use OCP\Config\IUserConfig;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IAvatarManager;
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;
@@ -54,27 +57,22 @@ public function __construct() {
/**
* 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')
);
});
}
@@ -87,6 +85,8 @@ public function register(IRegistrationContext $context): void {
function (ContainerInterface $c) {
return new Manager(
$c->get(IConfig::class),
+ $c->get(IUserConfig::class),
+ $c->get(IAppConfig::class),
$c->get(LoggerInterface::class),
$c->get(IAvatarManager::class),
$c->get(Image::class),
diff --git a/apps/user_ldap/lib/Controller/RenewPasswordController.php b/apps/user_ldap/lib/Controller/RenewPasswordController.php
index 8389a362b8f5b..04b919eeb6765 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\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 @@
#[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 @@ public function __construct(
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 @@ public function showRenewPasswordForm($user) {
);
}
- /**
- * @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 @@ public function tryRenewPassword($user, $oldPassword, $newPassword) {
$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 @@ public function tryRenewPassword($user, $oldPassword, $newPassword) {
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 271cc96afbdfc..301793c136275 100644
--- a/apps/user_ldap/lib/Group_LDAP.php
+++ b/apps/user_ldap/lib/Group_LDAP.php
@@ -11,16 +11,15 @@
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 @@ private function isUserOnLDAP(string $uid): bool {
* @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 @@ public function getUserGroups($uid): array {
$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 f0cdc7a465db0..c08fe7117bfa1 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\IIsAdminBackend;
use OCP\Group\Backend\INamedBackend;
use OCP\GroupInterface;
-use OCP\IConfig;
use OCP\IUserManager;
/**
@@ -23,11 +23,11 @@
*/
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 @@ public function __construct(
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 26888ae96aeb1..e49a2f0f59d6d 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\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 @@ public function __construct(
) {
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 @@ public function updateInterval() {
$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 @@ public function runCycle(array $cycleData): bool {
/**
* 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 @@ public function getCycle(): ?array {
}
$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 @@ public function getCycle(): ?array {
* @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 @@ public function determineNextCycle(?array $cycleData = null): ?array {
* 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 9e72bcd8432c8..2ed4c8c74b443 100644
--- a/apps/user_ldap/lib/Jobs/UpdateGroups.php
+++ b/apps/user_ldap/lib/Jobs/UpdateGroups.php
@@ -10,21 +10,21 @@
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 bb92314d93a88..88c9859b80994 100644
--- a/apps/user_ldap/lib/Migration/UUIDFixInsert.php
+++ b/apps/user_ldap/lib/Migration/UUIDFixInsert.php
@@ -8,41 +8,27 @@
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 f57f71a9d47fb..dd05af7f01a13 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 @@ private function fetchDeletedUsers(): array {
}
/**
- * 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 @@ public function getUsers(): array {
}
/**
- * 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 @@ public function hasUsers(): bool {
}
/**
- * marks a user as deleted
+ * Marks a user as deleted.
*
* @throws PreConditionNotMetException
*/
@@ -77,12 +79,12 @@ public function markUser(string $ocName): void {
// 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');
}
}
diff --git a/apps/user_ldap/lib/User/Manager.php b/apps/user_ldap/lib/User/Manager.php
index 88a001dd9650d..539c667b8973c 100644
--- a/apps/user_ldap/lib/User/Manager.php
+++ b/apps/user_ldap/lib/User/Manager.php
@@ -8,7 +8,9 @@
namespace OCA\User_LDAP\User;
use OCA\User_LDAP\Access;
+use OCP\AppFramework\Services\IAppConfig;
use OCP\Cache\CappedMemoryCache;
+use OCP\Config\IUserConfig;
use OCP\IAvatarManager;
use OCP\IConfig;
use OCP\IDBConnection;
@@ -34,6 +36,8 @@ class Manager {
public function __construct(
protected IConfig $ocConfig,
+ protected IUserConfig $userConfig,
+ protected IAppConfig $appConfig,
protected LoggerInterface $logger,
protected IAvatarManager $avatarManager,
protected Image $image,
@@ -63,7 +67,7 @@ public function setLdapAccess(Access $access) {
*/
private function createAndCache($dn, $uid) {
$this->checkAccess();
- $user = new User($uid, $dn, $this->access, $this->ocConfig,
+ $user = new User($uid, $dn, $this->access, $this->ocConfig, $this->userConfig, $this->appConfig,
clone $this->image, $this->logger,
$this->avatarManager, $this->userManager,
$this->notificationManager);
@@ -158,25 +162,21 @@ function ($list, $attribute) {
}
/**
- * 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 ecaab7188ba37..ee2906e4b6fad 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 @@ public function export() {
}
/**
- * 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 @@ public function getDN() {
}
/**
- * 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/lib/User/User.php b/apps/user_ldap/lib/User/User.php
index 8f97ec1701f24..809067d0737a5 100644
--- a/apps/user_ldap/lib/User/User.php
+++ b/apps/user_ldap/lib/User/User.php
@@ -15,6 +15,8 @@
use OCA\User_LDAP\Service\BirthdateParserService;
use OCP\Accounts\IAccountManager;
use OCP\Accounts\PropertyDoesNotExistException;
+use OCP\AppFramework\Services\IAppConfig;
+use OCP\Config\IUserConfig;
use OCP\IAvatarManager;
use OCP\IConfig;
use OCP\Image;
@@ -56,6 +58,8 @@ public function __construct(
protected string $dn,
protected Access $access,
protected IConfig $config,
+ protected IUserConfig $userConfig,
+ protected IAppConfig $appConfig,
protected Image $image,
protected LoggerInterface $logger,
protected IAvatarManager $avatarManager,
@@ -78,13 +82,13 @@ public function __construct(
* @throws PreConditionNotMetException
*/
public function markUser(): void {
- $curValue = $this->config->getUserValue($this->getUsername(), 'user_ldap', 'isDeleted', '0');
- if ($curValue === '1') {
+ $curValue = $this->userConfig->getValueBool($this->getUsername(), 'user_ldap', 'isDeleted');
+ if ($curValue) {
// the user is already marked, do not write to DB again
return;
}
- $this->config->setUserValue($this->getUsername(), 'user_ldap', 'isDeleted', '1');
- $this->config->setUserValue($this->getUsername(), 'user_ldap', 'foundDeleted', (string)time());
+ $this->userConfig->setValueBool($this->getUsername(), 'user_ldap', 'isDeleted', true);
+ $this->userConfig->setValueInt($this->getUsername(), 'user_ldap', 'foundDeleted', time());
}
/**
@@ -286,8 +290,8 @@ public function processAttributes(array $ldapEntry): void {
$this->connection->writeToCache($cacheKey, $checksum // write array to cache. is waste of cache space
, null); // use ldapCacheTTL from configuration
// Update user profile
- if ($this->config->getUserValue($username, 'user_ldap', 'lastProfileChecksum', null) !== $checksum) {
- $this->config->setUserValue($username, 'user_ldap', 'lastProfileChecksum', $checksum);
+ if ($this->userConfig->getValueString($username, 'user_ldap', 'lastProfileChecksum') !== $checksum) {
+ $this->userConfig->setValueString($username, 'user_ldap', 'lastProfileChecksum', $checksum);
$this->updateProfile($profileValues);
$this->logger->info("updated profile uid=$username", ['app' => 'user_ldap']);
} else {
@@ -361,21 +365,21 @@ public function getHomePath(?string $valueFromLDAP = null): string|false {
}
//we need it to store it in the DB as well in case a user gets
//deleted so we can clean up afterwards
- $this->config->setUserValue(
+ $this->userConfig->setValueString(
$this->getUsername(), 'user_ldap', 'homePath', $path
);
return $path;
}
if (!is_null($attr)
- && $this->config->getAppValue('user_ldap', 'enforce_home_folder_naming_rule', 'true')
+ && $this->appConfig->getAppValueBool('enforce_home_folder_naming_rule', true)
) {
// a naming rule attribute is defined, but it doesn't exist for that LDAP user
throw new \Exception('Home dir attribute can\'t be read from LDAP for uid: ' . $this->getUsername());
}
- //false will apply default behaviour as defined and done by OC_User
- $this->config->setUserValue($this->getUsername(), 'user_ldap', 'homePath', '');
+ // false will apply default behaviour as defined and done by OC_User
+ $this->userConfig->setValueString($this->getUsername(), 'user_ldap', 'homePath', '');
return false;
}
@@ -418,15 +422,15 @@ public function getAvatarImage(): string|false {
* @brief marks the user as having logged in at least once
*/
public function markLogin(): void {
- $this->config->setUserValue(
- $this->uid, 'user_ldap', self::USER_PREFKEY_FIRSTLOGIN, '1');
+ $this->userConfig->setValueBool(
+ $this->uid, 'user_ldap', self::USER_PREFKEY_FIRSTLOGIN, true);
}
/**
* Stores a key-value pair in relation to this user
*/
private function store(string $key, string $value): void {
- $this->config->setUserValue($this->uid, 'user_ldap', $key, $value);
+ $this->userConfig->setValueString($this->uid, 'user_ldap', $key, $value);
}
/**
@@ -439,7 +443,7 @@ public function composeAndStoreDisplayName(string $displayName, string $displayN
if ($displayName2 !== '') {
$displayName .= ' (' . $displayName2 . ')';
}
- $oldName = $this->config->getUserValue($this->uid, 'user_ldap', 'displayName', null);
+ $oldName = $this->userConfig->getValueString($this->uid, 'user_ldap', 'displayName', '');
if ($oldName !== $displayName) {
$this->store('displayName', $displayName);
$user = $this->userManager->get($this->getUsername());
@@ -637,7 +641,7 @@ public function updateAvatar(bool $force = false): bool {
// use the checksum before modifications
$checksum = md5($this->image->data());
- if ($checksum === $this->config->getUserValue($this->uid, 'user_ldap', 'lastAvatarChecksum', '') && $this->avatarExists()) {
+ if ($checksum === $this->userConfig->getValueString($this->uid, 'user_ldap', 'lastAvatarChecksum', '') && $this->avatarExists()) {
return true;
}
@@ -645,7 +649,7 @@ public function updateAvatar(bool $force = false): bool {
if ($isSet) {
// save checksum only after successful setting
- $this->config->setUserValue($this->uid, 'user_ldap', 'lastAvatarChecksum', $checksum);
+ $this->userConfig->setValueString($this->uid, 'user_ldap', 'lastAvatarChecksum', $checksum);
}
return $isSet;
@@ -693,7 +697,7 @@ private function setNextcloudAvatar(): bool {
* @throws PreConditionNotMetException
*/
public function getExtStorageHome():string {
- $value = $this->config->getUserValue($this->getUsername(), 'user_ldap', 'extStorageHome', '');
+ $value = $this->userConfig->getValueString($this->getUsername(), 'user_ldap', 'extStorageHome', '');
if ($value !== '') {
return $value;
}
@@ -720,10 +724,10 @@ public function updateExtStorageHome(?string $valueFromLDAP = null):string {
}
if ($extHomeValues !== false && isset($extHomeValues[0])) {
$extHome = $extHomeValues[0];
- $this->config->setUserValue($this->getUsername(), 'user_ldap', 'extStorageHome', $extHome);
+ $this->userConfig->setValueString($this->getUsername(), 'user_ldap', 'extStorageHome', $extHome);
return $extHome;
} else {
- $this->config->deleteUserValue($this->getUsername(), 'user_ldap', 'extStorageHome');
+ $this->userConfig->deleteUserConfig($this->getUsername(), 'user_ldap', 'extStorageHome');
return '';
}
}
@@ -771,7 +775,7 @@ public function handlePasswordExpiry(array $params): void {
if (!empty($pwdGraceUseTime)) { //was this a grace login?
if (!empty($pwdGraceAuthNLimit)
&& count($pwdGraceUseTime) < (int)$pwdGraceAuthNLimit[0]) { //at least one more grace login available?
- $this->config->setUserValue($uid, 'user_ldap', 'needsPasswordReset', 'true');
+ $this->userConfig->setValueBool($uid, 'user_ldap', 'needsPasswordReset', true);
header('Location: ' . Server::get(IURLGenerator::class)->linkToRouteAbsolute(
'user_ldap.renewPassword.showRenewPasswordForm', ['user' => $uid]));
} else { //no more grace login available
@@ -782,7 +786,7 @@ public function handlePasswordExpiry(array $params): void {
}
//handle pwdReset attribute
if (!empty($pwdReset) && $pwdReset[0] === 'TRUE') { //user must change their password
- $this->config->setUserValue($uid, 'user_ldap', 'needsPasswordReset', 'true');
+ $this->userConfig->setValueBool($uid, 'user_ldap', 'needsPasswordReset', true);
header('Location: ' . Server::get(IURLGenerator::class)->linkToRouteAbsolute(
'user_ldap.renewPassword.showRenewPasswordForm', ['user' => $uid]));
exit();
diff --git a/apps/user_ldap/tests/AccessTest.php b/apps/user_ldap/tests/AccessTest.php
index 5bda7b8086bb8..9154580cc92ec 100644
--- a/apps/user_ldap/tests/AccessTest.php
+++ b/apps/user_ldap/tests/AccessTest.php
@@ -20,6 +20,7 @@
use OCA\User_LDAP\User\Manager;
use OCA\User_LDAP\User\OfflineUser;
use OCA\User_LDAP\User\User;
+use OCP\Config\IUserConfig;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\HintException;
use OCP\IAppConfig;
@@ -49,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;
@@ -63,7 +63,6 @@ protected function setUp(): void {
->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);
@@ -77,7 +76,6 @@ protected function setUp(): void {
$this->connection,
$this->userManager,
$this->helper,
- $this->config,
$this->ncUserManager,
$this->logger,
$this->appConfig,
@@ -102,6 +100,8 @@ private function getConnectorAndLdapMock() {
$um = $this->getMockBuilder(Manager::class)
->setConstructorArgs([
$this->createMock(IConfig::class),
+ $this->createMock(IUserConfig::class),
+ $this->createMock(\OCP\AppFramework\Services\IAppConfig::class),
$this->createMock(LoggerInterface::class),
$this->createMock(IAvatarManager::class),
$this->createMock(Image::class),
@@ -222,9 +222,7 @@ public static function dnInputDataProvider(): array {
#[\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')
@@ -241,10 +239,8 @@ public function testStringResemblesDN(string $input, array|bool $interResult, bo
#[\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');
@@ -413,9 +409,6 @@ public static function dNAttributeProvider(): array {
#[\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())
@@ -427,7 +420,7 @@ public function testSanitizeDN(string $attribute): void {
$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 28c37ec605368..036b5fd2e7106 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\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 @@
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 @@ public function setUp(): void {
$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 @@ public function testGetUserGroupsMemberOf(): void {
->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 @@ public function testGetUserGroupsMemberOfDisabled(): void {
->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 @@ public function testGetUserGroupsOfflineUser(): void {
$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 @@ public function testGetUserGroupsOfflineUserUnexpectedJson(): void {
$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 @@ public function testGetUserGroupsUnrecognizedOfflineUser(): void {
->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 0e46685375c88..e1ff30a1724c5 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\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 @@ protected function setUp(): void {
$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 @@ protected function setUp(): void {
$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 @@ public static function intervalDataProvider(): array {
];
}
- #[\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 @@ public function testUpdateInterval(int $userCount, int $pagingSize1, int $paging
'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 @@ public static function moreResultsProvider(): array {
];
}
- #[\PHPUnit\Framework\Attributes\DataProvider('moreResultsProvider')]
+ #[DataProvider('moreResultsProvider')]
public function testMoreResults($pagingSize, $results, $expected): void {
$connection = $this->getMockBuilder(Connection::class)
->setConstructorArgs([
@@ -198,7 +198,7 @@ public static function cycleDataProvider(): array {
];
}
- #[\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 @@ public function testDetermineNextCycle(?array $cycleData, array $prefixes, ?arra
->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 @@ public function testDetermineNextCycle(?array $cycleData, array $prefixes, ?arra
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 @@ public static function runDataProvider(): array {
#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->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->config->expects($this->any())
+
+ $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 6215ffcb6a1e9..1033a64cd0b81 100644
--- a/apps/user_ldap/tests/Migration/UUIDFixInsertTest.php
+++ b/apps/user_ldap/tests/Migration/UUIDFixInsertTest.php
@@ -10,14 +10,14 @@
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 @@ protected function setUp(): void {
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 @@ public static function recordProviderTooLongAndNone(): array {
#[\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 @@ public function testRun(array $userBatches, array $groupBatches): void {
#[\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 @@ public function testRunWithManyAndNone(array $userBatches, array $groupBatches):
}
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 96a8913195ced..841a4d70f9f65 100644
--- a/apps/user_ldap/tests/User/DeletedUsersIndexTest.php
+++ b/apps/user_ldap/tests/User/DeletedUsersIndexTest.php
@@ -9,7 +9,7 @@
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 @@
#[\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 @@ protected function setUp(): void {
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/ManagerTest.php b/apps/user_ldap/tests/User/ManagerTest.php
index a8ce9cb3120df..2140cbf272eba 100644
--- a/apps/user_ldap/tests/User/ManagerTest.php
+++ b/apps/user_ldap/tests/User/ManagerTest.php
@@ -13,6 +13,8 @@
use OCA\User_LDAP\ILDAPWrapper;
use OCA\User_LDAP\User\Manager;
use OCA\User_LDAP\User\User;
+use OCP\AppFramework\Services\IAppConfig;
+use OCP\Config\IUserConfig;
use OCP\IAvatarManager;
use OCP\IConfig;
use OCP\IDBConnection;
@@ -33,6 +35,8 @@
class ManagerTest extends \Test\TestCase {
protected Access&MockObject $access;
protected IConfig&MockObject $config;
+ protected IUserConfig&MockObject $userConfig;
+ protected IAppConfig&MockObject $appConfig;
protected LoggerInterface&MockObject $logger;
protected IAvatarManager&MockObject $avatarManager;
protected Image&MockObject $image;
@@ -49,6 +53,8 @@ protected function setUp(): void {
$this->access = $this->createMock(Access::class);
$this->config = $this->createMock(IConfig::class);
+ $this->userConfig = $this->createMock(IUserConfig::class);
+ $this->appConfig = $this->createMock(IAppConfig::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->avatarManager = $this->createMock(IAvatarManager::class);
$this->image = $this->createMock(Image::class);
@@ -66,6 +72,8 @@ protected function setUp(): void {
/** @noinspection PhpUnhandledExceptionInspection */
$this->manager = new Manager(
$this->config,
+ $this->userConfig,
+ $this->appConfig,
$this->logger,
$this->avatarManager,
$this->image,
diff --git a/apps/user_ldap/tests/User/OfflineUserTest.php b/apps/user_ldap/tests/User/OfflineUserTest.php
index 223e63421ad4a..932dac77e7905 100644
--- a/apps/user_ldap/tests/User/OfflineUserTest.php
+++ b/apps/user_ldap/tests/User/OfflineUserTest.php
@@ -10,7 +10,7 @@
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 @@
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/user_ldap/tests/User/UserTest.php b/apps/user_ldap/tests/User/UserTest.php
index 737ab5f6a86a9..4bf775efa9db3 100644
--- a/apps/user_ldap/tests/User/UserTest.php
+++ b/apps/user_ldap/tests/User/UserTest.php
@@ -12,6 +12,8 @@
use OCA\User_LDAP\Connection;
use OCA\User_LDAP\ILDAPWrapper;
use OCA\User_LDAP\User\User;
+use OCP\AppFramework\Services\IAppConfig;
+use OCP\Config\IUserConfig;
use OCP\IAvatar;
use OCP\IAvatarManager;
use OCP\IConfig;
@@ -35,6 +37,8 @@ class UserTest extends \Test\TestCase {
protected Access&MockObject $access;
protected Connection&MockObject $connection;
protected IConfig&MockObject $config;
+ protected IUserConfig&MockObject $userConfig;
+ protected IAppConfig&MockObject $appConfig;
protected INotificationManager&MockObject $notificationManager;
protected IUserManager&MockObject $userManager;
protected Image&MockObject $image;
@@ -58,6 +62,8 @@ protected function setUp(): void {
->willReturn($this->connection);
$this->config = $this->createMock(IConfig::class);
+ $this->userConfig = $this->createMock(IUserConfig::class);
+ $this->appConfig = $this->createMock(IAppConfig::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->avatarManager = $this->createMock(IAvatarManager::class);
$this->image = $this->createMock(Image::class);
@@ -69,6 +75,8 @@ protected function setUp(): void {
$this->dn,
$this->access,
$this->config,
+ $this->userConfig,
+ $this->appConfig,
$this->image,
$this->logger,
$this->avatarManager,
@@ -118,8 +126,8 @@ public function testUpdateEmailNotProvided(): void {
$this->equalTo('email'))
->willReturn(false);
- $this->config->expects($this->never())
- ->method('setUserValue');
+ $this->userConfig->expects($this->never())
+ ->method('setValueString');
$this->user->updateEmail();
}
@@ -133,8 +141,8 @@ public function testUpdateEmailNotConfigured(): void {
$this->access->expects($this->never())
->method('readAttribute');
- $this->config->expects($this->never())
- ->method('setUserValue');
+ $this->userConfig->expects($this->never())
+ ->method('setValueString');
$this->user->updateEmail();
}
@@ -296,8 +304,8 @@ public function testUpdateQuotaNoneProvided(): void {
->method('get')
->with($this->uid);
- $this->config->expects($this->never())
- ->method('setUserValue');
+ $this->userConfig->expects($this->never())
+ ->method('setValueString');
$this->user->updateQuota();
}
@@ -320,8 +328,8 @@ public function testUpdateQuotaNoneConfigured(): void {
$this->access->expects($this->never())
->method('readAttribute');
- $this->config->expects($this->never())
- ->method('setUserValue');
+ $this->userConfig->expects($this->never())
+ ->method('setValueFloat');
$this->user->updateQuota();
}
@@ -487,12 +495,12 @@ public function XtestUpdateAvatarJpegPhotoProvided() {
->method('data')
->willReturn('this is a photo');
- $this->config->expects($this->once())
- ->method('getUserValue')
+ $this->userConfig->expects($this->once())
+ ->method('getValueString')
->with($this->uid, 'user_ldap', 'lastAvatarChecksum', '')
->willReturn('');
- $this->config->expects($this->once())
- ->method('setUserValue')
+ $this->userConfig->expects($this->once())
+ ->method('setValueString')
->with($this->uid, 'user_ldap', 'lastAvatarChecksum', md5('this is a photo'));
$avatar = $this->createMock(IAvatar::class);
@@ -535,12 +543,12 @@ public function testUpdateAvatarKnownJpegPhotoProvided(): void {
->method('data')
->willReturn('this is a photo');
- $this->config->expects($this->once())
- ->method('getUserValue')
+ $this->userConfig->expects($this->once())
+ ->method('getValueString')
->with($this->uid, 'user_ldap', 'lastAvatarChecksum', '')
->willReturn(md5('this is a photo'));
- $this->config->expects($this->never())
- ->method('setUserValue');
+ $this->userConfig->expects($this->never())
+ ->method('setValueString');
$avatar = $this->createMock(IAvatar::class);
$avatar->expects($this->never())
@@ -598,12 +606,12 @@ public function XtestUpdateAvatarThumbnailPhotoProvided() {
->method('data')
->willReturn('this is a photo');
- $this->config->expects($this->once())
- ->method('getUserValue')
+ $this->userConfig->expects($this->once())
+ ->method('getValueString')
->with($this->uid, 'user_ldap', 'lastAvatarChecksum', '')
->willReturn('');
- $this->config->expects($this->once())
- ->method('setUserValue')
+ $this->userConfig->expects($this->once())
+ ->method('setValueString')
->with($this->uid, 'user_ldap', 'lastAvatarChecksum', md5('this is a photo'));
$avatar = $this->createMock(IAvatar::class);
@@ -652,10 +660,10 @@ public function testUpdateAvatarCorruptPhotoProvided(): void {
$this->image->expects($this->never())
->method('data');
- $this->config->expects($this->never())
- ->method('getUserValue');
- $this->config->expects($this->never())
- ->method('setUserValue');
+ $this->userConfig->expects($this->never())
+ ->method('getValueString');
+ $this->userConfig->expects($this->never())
+ ->method('setValueString');
$avatar = $this->createMock(IAvatar::class);
$avatar->expects($this->never())
@@ -705,12 +713,12 @@ public function XtestUpdateAvatarUnsupportedThumbnailPhotoProvided() {
->method('data')
->willReturn('this is a photo');
- $this->config->expects($this->once())
- ->method('getUserValue')
+ $this->userConfig->expects($this->once())
+ ->method('getValueString')
->with($this->uid, 'user_ldap', 'lastAvatarChecksum', '')
->willReturn('');
- $this->config->expects($this->never())
- ->method('setUserValue');
+ $this->userConfig->expects($this->never())
+ ->method('setValueString');
$avatar = $this->createMock(IAvatar::class);
$avatar->expects($this->once())
@@ -756,10 +764,10 @@ public function testUpdateAvatarNotProvided(): void {
$this->image->expects($this->never())
->method('data');
- $this->config->expects($this->never())
- ->method('getUserValue');
- $this->config->expects($this->never())
- ->method('setUserValue');
+ $this->userConfig->expects($this->never())
+ ->method('getValueString');
+ $this->userConfig->expects($this->never())
+ ->method('setValueString');
$this->avatarManager->expects($this->never())
->method('getAvatar');
@@ -800,12 +808,12 @@ public function testUpdateExtStorageHome(string $expected, ?string $valueFromLDA
}
if ($expected !== '') {
- $this->config->expects($this->once())
- ->method('setUserValue')
+ $this->userConfig->expects($this->once())
+ ->method('setValueString')
->with($this->uid, 'user_ldap', 'extStorageHome', $expected);
} else {
- $this->config->expects($this->once())
- ->method('deleteUserValue')
+ $this->userConfig->expects($this->once())
+ ->method('deleteUserConfig')
->with($this->uid, 'user_ldap', 'extStorageHome');
}
@@ -814,12 +822,12 @@ public function testUpdateExtStorageHome(string $expected, ?string $valueFromLDA
}
public function testMarkLogin(): void {
- $this->config->expects($this->once())
- ->method('setUserValue')
+ $this->userConfig->expects($this->once())
+ ->method('setValueBool')
->with($this->equalTo($this->uid),
$this->equalTo('user_ldap'),
$this->equalTo(User::USER_PREFKEY_FIRSTLOGIN),
- $this->equalTo(1))
+ $this->equalTo(true))
->willReturn(true);
$this->user->markLogin();
@@ -881,6 +889,8 @@ public function testProcessAttributes(): void {
$this->dn,
$this->access,
$this->config,
+ $this->userConfig,
+ $this->appConfig,
$this->image,
$this->logger,
$this->avatarManager,
@@ -944,8 +954,8 @@ public function testGetHomePathNotConfigured(string $attributeValue): void {
$this->access->expects($this->never())
->method('readAttribute');
- $this->config->expects($this->never())
- ->method('getAppValue');
+ $this->appConfig->expects($this->never())
+ ->method('getAppValueBool');
/** @noinspection PhpUnhandledExceptionInspection */
$this->assertFalse($this->user->getHomePath());
@@ -966,8 +976,8 @@ public function testGetHomePathConfiguredNotAvailableAllowed(): void {
->willReturn($this->dn);
// asks for "enforce_home_folder_naming_rule"
- $this->config->expects($this->once())
- ->method('getAppValue')
+ $this->appConfig->expects($this->once())
+ ->method('getAppValueBool')
->willReturn(false);
/** @noinspection PhpUnhandledExceptionInspection */
@@ -992,8 +1002,8 @@ public function testGetHomePathConfiguredNotAvailableNotAllowed(): void {
->willReturn($this->dn);
// asks for "enforce_home_folder_naming_rule"
- $this->config->expects($this->once())
- ->method('getAppValue')
+ $this->appConfig->expects($this->once())
+ ->method('getAppValueBool')
->willReturn(true);
$this->user->getHomePath();
@@ -1010,12 +1020,12 @@ public static function displayNameProvider(): array {
#[\PHPUnit\Framework\Attributes\DataProvider('displayNameProvider')]
public function testComposeAndStoreDisplayName(string $part1, string $part2, string $expected, bool $expectTriggerChange): void {
- $this->config->expects($this->once())
- ->method('setUserValue');
- $oldName = $expectTriggerChange ? 'xxGunslingerxx' : null;
- $this->config->expects($this->once())
- ->method('getUserValue')
- ->with($this->user->getUsername(), 'user_ldap', 'displayName', null)
+ $this->userConfig->expects($this->once())
+ ->method('setValueString');
+ $oldName = $expectTriggerChange ? 'xxGunslingerxx' : '';
+ $this->userConfig->expects($this->once())
+ ->method('getValueString')
+ ->with($this->user->getUsername(), 'user_ldap', 'displayName', '')
->willReturn($oldName);
$ncUserObj = $this->createMock(\OC\User\User::class);
@@ -1037,10 +1047,10 @@ public function testComposeAndStoreDisplayName(string $part1, string $part2, str
public function testComposeAndStoreDisplayNameNoOverwrite(): void {
$displayName = 'Randall Flagg';
- $this->config->expects($this->never())
- ->method('setUserValue');
- $this->config->expects($this->once())
- ->method('getUserValue')
+ $this->userConfig->expects($this->never())
+ ->method('setValueString');
+ $this->userConfig->expects($this->once())
+ ->method('getValueString')
->willReturn($displayName);
$this->userManager->expects($this->never())
diff --git a/apps/weather_status/lib/Service/WeatherStatusService.php b/apps/weather_status/lib/Service/WeatherStatusService.php
index c93010e7f5858..c2856ab611e7b 100644
--- a/apps/weather_status/lib/Service/WeatherStatusService.php
+++ b/apps/weather_status/lib/Service/WeatherStatusService.php
@@ -13,11 +13,11 @@
use OCP\Accounts\IAccountManager;
use OCP\Accounts\PropertyDoesNotExistException;
use OCP\App\IAppManager;
+use OCP\Config\IUserConfig;
use OCP\Http\Client\IClient;
use OCP\Http\Client\IClientService;
use OCP\ICache;
use OCP\ICacheFactory;
-use OCP\IConfig;
use OCP\IL10N;
use OCP\IUserManager;
use Psr\Log\LoggerInterface;
@@ -41,14 +41,14 @@ class WeatherStatusService {
private string $version;
public function __construct(
- private IClientService $clientService,
- private IConfig $config,
+ IClientService $clientService,
+ private IUserConfig $userConfig,
private IL10N $l10n,
private LoggerInterface $logger,
private IAccountManager $accountManager,
private IUserManager $userManager,
- private IAppManager $appManager,
- private ICacheFactory $cacheFactory,
+ IAppManager $appManager,
+ ICacheFactory $cacheFactory,
private ?string $userId,
) {
$this->version = $appManager->getAppVersion(Application::APP_ID);
@@ -64,7 +64,7 @@ public function __construct(
* @return WeatherStatusSuccess success state
*/
public function setMode(int $mode): array {
- $this->config->setUserValue($this->userId, Application::APP_ID, 'mode', strval($mode));
+ $this->userConfig->setValueInt($this->userId, Application::APP_ID, 'mode', $mode);
return ['success' => true];
}
@@ -73,8 +73,9 @@ public function setMode(int $mode): array {
* @return list
*/
public function getFavorites(): array {
- $favoritesJson = $this->config->getUserValue($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 @@ public function getFavorites(): array {
* @return WeatherStatusSuccess success state
*/
public function setFavorites(array $favorites): array {
- $this->config->setUserValue($this->userId, Application::APP_ID, 'favorites', json_encode($favorites));
+ $this->userConfig->setValueArray($this->userId, Application::APP_ID, 'favorites', $favorites);
return ['success' => true];
}
@@ -117,15 +118,15 @@ public function usePersonalAddress(): array {
public function setLocation(?string $address, ?float $lat, ?float $lon): array {
if (!is_null($lat) && !is_null($lon)) {
// store coordinates
- $this->config->setUserValue($this->userId, Application::APP_ID, 'lat', strval($lat));
- $this->config->setUserValue($this->userId, Application::APP_ID, 'lon', strval($lon));
+ $this->userConfig->setValueFloat($this->userId, Application::APP_ID, 'lat', $lat);
+ $this->userConfig->setValueFloat($this->userId, Application::APP_ID, 'lon', $lon);
// resolve and store formatted address
$address = $this->resolveLocation($lat, $lon);
$address = $address ?: $this->l10n->t('Unknown address');
- $this->config->setUserValue($this->userId, Application::APP_ID, 'address', $address);
+ $this->userConfig->setValueString($this->userId, Application::APP_ID, 'address', $address);
// get and store altitude
$altitude = $this->getAltitude($lat, $lon);
- $this->config->setUserValue($this->userId, Application::APP_ID, 'altitude', strval($altitude));
+ $this->userConfig->setValueFloat($this->userId, Application::APP_ID, 'altitude', $altitude);
return [
'address' => $address,
'success' => true,
@@ -222,13 +223,13 @@ public function setAddress(string $address): array {
$addressInfo = $this->searchForAddress($address);
if (isset($addressInfo['display_name']) && isset($addressInfo['lat']) && isset($addressInfo['lon'])) {
$formattedAddress = $this->formatOsmAddress($addressInfo);
- $this->config->setUserValue($this->userId, Application::APP_ID, 'address', $formattedAddress);
- $this->config->setUserValue($this->userId, Application::APP_ID, 'lat', strval($addressInfo['lat']));
- $this->config->setUserValue($this->userId, Application::APP_ID, 'lon', strval($addressInfo['lon']));
- $this->config->setUserValue($this->userId, Application::APP_ID, 'mode', strval(self::MODE_MANUAL_LOCATION));
+ $this->userConfig->setValueString($this->userId, Application::APP_ID, 'address', $formattedAddress);
+ $this->userConfig->setValueFloat($this->userId, Application::APP_ID, 'lat', floatval($addressInfo['lat']));
+ $this->userConfig->setValueFloat($this->userId, Application::APP_ID, 'lon', floatval($addressInfo['lon']));
+ $this->userConfig->setValueInt($this->userId, Application::APP_ID, 'mode', self::MODE_MANUAL_LOCATION);
// get and store altitude
$altitude = $this->getAltitude(floatval($addressInfo['lat']), floatval($addressInfo['lon']));
- $this->config->setUserValue($this->userId, Application::APP_ID, 'altitude', strval($altitude));
+ $this->userConfig->setValueFloat($this->userId, Application::APP_ID, 'altitude', $altitude);
return [
'lat' => $addressInfo['lat'],
'lon' => $addressInfo['lon'],
@@ -279,15 +280,15 @@ private function searchForAddress(string $address): array {
* @return WeatherStatusLocationWithMode which contains coordinates, formatted address and current weather status mode
*/
public function getLocation(): array {
- $lat = $this->config->getUserValue($this->userId, Application::APP_ID, 'lat', '');
- $lon = $this->config->getUserValue($this->userId, Application::APP_ID, 'lon', '');
- $address = $this->config->getUserValue($this->userId, Application::APP_ID, 'address', '');
- $mode = $this->config->getUserValue($this->userId, Application::APP_ID, 'mode', self::MODE_MANUAL_LOCATION);
+ $lat = $this->userConfig->getValueFloat($this->userId, Application::APP_ID, 'lat');
+ $lon = $this->userConfig->getValueFloat($this->userId, Application::APP_ID, 'lon');
+ $address = $this->userConfig->getValueString($this->userId, Application::APP_ID, 'address');
+ $mode = $this->userConfig->getValueInt($this->userId, Application::APP_ID, 'mode', self::MODE_MANUAL_LOCATION);
return [
- 'lat' => $lat,
- 'lon' => $lon,
+ 'lat' => abs($lat) < PHP_FLOAT_EPSILON ? '' : (string)$lat,
+ 'lon' => abs($lon) < PHP_FLOAT_EPSILON ? '' : (string)$lon,
'address' => $address,
- 'mode' => intval($mode),
+ 'mode' => $mode,
];
}
@@ -297,14 +298,12 @@ public function getLocation(): array {
* @return list|array{error: string}|WeatherStatusSuccess which contains success state and filtered forecast data
*/
public function getForecast(): array {
- $lat = $this->config->getUserValue($this->userId, Application::APP_ID, 'lat', '');
- $lon = $this->config->getUserValue($this->userId, Application::APP_ID, 'lon', '');
- $alt = $this->config->getUserValue($this->userId, Application::APP_ID, 'altitude', '');
- if (!is_numeric($alt)) {
- $alt = 0;
- }
- if (is_numeric($lat) && is_numeric($lon)) {
- return $this->forecastRequest(floatval($lat), floatval($lon), floatval($alt));
+ $lat = $this->userConfig->getValueFloat($this->userId, Application::APP_ID, 'lat');
+ $lon = $this->userConfig->getValueFloat($this->userId, Application::APP_ID, 'lon');
+ $alt = $this->userConfig->getValueFloat($this->userId, Application::APP_ID, 'altitude');
+
+ if ($lat !== 0.0 && $lon !== 0.0) {
+ return $this->forecastRequest($lat, $lon, $alt);
} else {
return ['success' => false];
}
diff --git a/build/psalm-baseline.xml b/build/psalm-baseline.xml
index 712dc3bc3bbb3..edece01c1bd97 100644
--- a/build/psalm-baseline.xml
+++ b/build/psalm-baseline.xml
@@ -63,6 +63,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -161,6 +180,7 @@
+
@@ -174,9 +194,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
@@ -221,6 +253,11 @@
+
+
+
+
+
@@ -373,18 +410,10 @@
-
-
-
-
-
-
-
-
-
+
@@ -512,6 +541,9 @@
+
+
+
@@ -847,6 +879,17 @@
+
+
+
+
+
+
+
+
+
+
+
@@ -943,6 +986,11 @@
+
+
+
+
+
@@ -1158,8 +1206,10 @@
+
+
@@ -1188,7 +1238,9 @@
+
+
@@ -1340,6 +1392,14 @@
+
+
+
+
+
+
+
+
@@ -1363,6 +1423,14 @@
+
+
+
+
+
+
+
+
@@ -1372,6 +1440,11 @@
+
+
+
+
+
@@ -1422,6 +1495,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -1554,6 +1640,13 @@
+
+
+
+
+
+
+
@@ -1632,6 +1725,7 @@
+
@@ -1650,6 +1744,16 @@
+
+
+
+
+
+
+
+
+
+
@@ -1692,6 +1796,11 @@
+
+
+
+
+
@@ -1824,7 +1933,10 @@
+
+
+
@@ -1899,7 +2011,6 @@
Filesystem::normalizePath($file_path),
'trashPath' => Filesystem::normalizePath(static::getTrashFilename($filename, $timestamp))])]]>
$targetPath, 'trashPath' => $sourcePath])]]>
-
@@ -2192,6 +2303,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -2209,10 +2333,21 @@
+
+
+
+
+
+
+
+
+
+
+
@@ -2223,16 +2358,22 @@
+
+
+
+
+
+
@@ -2279,8 +2420,6 @@
-
-
@@ -2299,6 +2438,7 @@
+
@@ -2342,6 +2482,11 @@
getEMailAddress() => $user->getDisplayName()]]]>
+
+
+
+
+
@@ -2392,6 +2537,13 @@
+
+
+
+
+
+
+
@@ -2460,6 +2612,10 @@
+
+
+
+
getObjectId()]]>
getObjectId()]]>
@@ -2478,6 +2634,11 @@
+
+
+
+
+
@@ -2509,6 +2670,16 @@
+
+
+
+
+
+
+
+
+
+
@@ -2547,6 +2718,7 @@
+
@@ -2563,6 +2735,14 @@
+
+
+
+
+
+
+
+
@@ -2578,6 +2758,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -2589,11 +2802,22 @@
+
+
+
+
+
+
+
+
+
+
+
@@ -2601,6 +2825,7 @@
+
getRgb())]]>
@@ -2617,7 +2842,6 @@
-
@@ -2632,10 +2856,6 @@
-
-
-
-
@@ -2647,10 +2867,6 @@
'loginName2UserName'
)]]>
-
-
-
-
@@ -2689,27 +2905,10 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -2741,11 +2940,6 @@
-
-
-
-
-
@@ -2768,7 +2962,6 @@
-
@@ -2875,6 +3068,12 @@
+
+
+
+
+
+
@@ -3055,10 +3254,19 @@
+
+
+
+
+
+
+
+
+
@@ -3095,6 +3303,7 @@
+
@@ -3105,6 +3314,7 @@
'preLoginNameUsedAsUserName',
['uid' => &$user]
)]]>
+
getCode()]]>
@@ -3115,6 +3325,11 @@
+
+
+
+
+
@@ -3181,6 +3396,12 @@
)]]>
+
+
+
+
+
+
@@ -4174,7 +4395,6 @@
-
diff --git a/lib/base.php b/lib/base.php
index b890cdb6dd74f..b656158b53070 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -447,14 +447,14 @@ public static function initSession(): void {
}
private static function getSessionLifeTime(): int {
- return Server::get(\OC\AllConfig::class)->getSystemValueInt('session_lifetime', 60 * 60 * 24);
+ return Server::get(IConfig::class)->getSystemValueInt('session_lifetime', 60 * 60 * 24);
}
/**
* @return bool true if the session expiry should only be done by gc instead of an explicit timeout
*/
public static function hasSessionRelaxedExpiry(): bool {
- return Server::get(\OC\AllConfig::class)->getSystemValueBool('session_relaxed_expiry', false);
+ return Server::get(IConfig::class)->getSystemValueBool('session_relaxed_expiry', false);
}
/**
diff --git a/lib/private/AllConfig.php b/lib/private/AllConfig.php
index c4a6989df1317..6356188bab66f 100644
--- a/lib/private/AllConfig.php
+++ b/lib/private/AllConfig.php
@@ -8,69 +8,23 @@
namespace OC;
use OC\Config\UserConfig;
-use OCP\Cache\CappedMemoryCache;
use OCP\Config\Exceptions\TypeConflictException;
use OCP\Config\IUserConfig;
use OCP\Config\ValueType;
use OCP\IConfig;
-use OCP\IDBConnection;
use OCP\PreConditionNotMetException;
/**
- * Class to combine all the configuration options ownCloud offers
+ * Class to combine all the configuration options Nextcloud offers
*/
class AllConfig implements IConfig {
- private ?IDBConnection $connection = null;
-
- /**
- * 3 dimensional array with the following structure:
- * [ $userId =>
- * [ $appId =>
- * [ $key => $value ]
- * ]
- * ]
- *
- * database table: preferences
- *
- * methods that use this:
- * - setUserValue
- * - getUserValue
- * - getUserKeys
- * - deleteUserValue
- * - deleteAllUserValues
- * - deleteAppFromAllUsers
- *
- * @var CappedMemoryCache $userCache
- */
- private CappedMemoryCache $userCache;
-
public function __construct(
private SystemConfig $systemConfig,
) {
- $this->userCache = new CappedMemoryCache();
- }
-
- /**
- * TODO - FIXME This fixes an issue with base.php that cause cyclic
- * dependencies, especially with autoconfig setup
- *
- * Replace this by properly injected database connection. Currently the
- * base.php triggers the getDatabaseConnection too early which causes in
- * autoconfig setup case a too early distributed database connection and
- * the autoconfig then needs to reinit all already initialized dependencies
- * that use the database connection.
- *
- * otherwise a SQLite database is created in the wrong directory
- * because the database connection was created with an uninitialized config
- */
- private function fixDIInit() {
- if ($this->connection === null) {
- $this->connection = \OC::$server->get(IDBConnection::class);
- }
}
/**
- * Sets and deletes system wide values
+ * Sets and deletes system-wide values
*
* @param array $configs Associative array with `key => value` pairs
* If value is null, the config key will be deleted
@@ -80,7 +34,7 @@ public function setSystemValues(array $configs) {
}
/**
- * Sets a new system wide value
+ * Sets a new system-wide value
*
* @param string $key the key of the value, under which will be saved
* @param mixed $value the value that should be stored
@@ -394,26 +348,6 @@ public function getUsersForUserValue($appName, $key, $value) {
return $result;
}
- /**
- * Determines the users that have the given value set for a specific app-key-pair
- *
- * @param string $appName the app to get the user for
- * @param string $key the key to get the user for
- * @param string $value the value to get the user for
- *
- * @return list of user IDs
- * @deprecated 31.0.0 - use {@see IUserConfig::searchUsersByValueString} directly
- */
- public function getUsersForUserValueCaseInsensitive($appName, $key, $value) {
- if ($appName === 'settings' && $key === 'email') {
- return $this->getUsersForUserValue($appName, $key, strtolower($value));
- }
-
- /** @var list $result */
- $result = iterator_to_array(\OCP\Server::get(IUserConfig::class)->searchUsersByValueString($appName, $key, $value, true));
- return $result;
- }
-
public function getSystemConfig() {
return $this->systemConfig;
}
diff --git a/lib/private/Server.php b/lib/private/Server.php
index f3997759539bf..51682ec36302d 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -1034,12 +1034,12 @@ public function __construct($webRoot, \OC\Config $config) {
$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 36885d1963fb5..4a42a397a8e47 100644
--- a/lib/private/User/Manager.php
+++ b/lib/private/User/Manager.php
@@ -9,6 +9,7 @@
use OC\Hooks\PublicEmitter;
use OC\Memcache\WithLocalCache;
+use OCP\Config\IUserConfig;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\HintException;
@@ -67,6 +68,7 @@ class Manager extends PublicEmitter implements IUserManager {
private DisplayNameCache $displayNameCache;
+ // This constructor can't autoload any class requiring a DB connection.
public function __construct(
private IConfig $config,
ICacheFactory $cacheFactory,
@@ -656,22 +658,30 @@ private function getSeenUserIds($limit = null, $offset = null) {
return $result;
}
+ /**
+ * @internal Only for mocks it in unit tests.
+ */
+ public function getUserConfig(): IUserConfig {
+ return \OCP\Server::get(IUserConfig::class);
+ }
+
/**
* @param string $email
* @return IUser[]
* @since 9.1.0
*/
- public function getByEmail($email) {
+ public function getByEmail($email): array {
+ $users = [];
+ $userConfig = $this->getUserConfig();
// looking for 'email' only (and not primary_mail) is intentional
- $userIds = $this->config->getUsersForUserValueCaseInsensitive('settings', 'email', $email);
-
- $users = array_map(function ($uid) {
- return $this->get($uid);
- }, $userIds);
-
- return array_values(array_filter($users, function ($u) {
- return ($u instanceof IUser);
- }));
+ $userIds = $userConfig->searchUsersByValueString('settings', 'email', $email, caseInsensitive: true);
+ foreach ($userIds as $userId) {
+ $user = $this->get($userId);
+ if ($user !== null) {
+ $users[] = $user;
+ }
+ }
+ return $users;
}
/**
diff --git a/lib/public/IConfig.php b/lib/public/IConfig.php
index d22606672aae4..4734f40cb3f7d 100644
--- a/lib/public/IConfig.php
+++ b/lib/public/IConfig.php
@@ -164,6 +164,7 @@ public function deleteAppValues($appName);
* @throws \OCP\PreConditionNotMetException if a precondition is specified and is not met
* @throws \UnexpectedValueException when trying to store an unexpected value
* @since 6.0.0 - parameter $precondition was added in 8.0.0
+ * @deprecated 33.0.0 - use {@see IUserConfig} directly
*/
public function setUserValue($userId, $appName, $key, $value, $preCondition = null);
@@ -176,6 +177,7 @@ public function setUserValue($userId, $appName, $key, $value, $preCondition = nu
* @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 33.0.0 - use {@see IUserConfig} directly
*/
public function getUserValue($userId, $appName, $key, $default = '');
@@ -186,6 +188,7 @@ public function getUserValue($userId, $appName, $key, $default = '');
* @param string $key the key to get the value for
* @param array $userIds the user IDs to fetch the values for
* @return array Mapped values: userId => value
+ * @deprecated 33.0.0 - use {@see IUserConfig::getValuesByUsers} directly
* @since 8.0.0
*/
public function getUserValueForUsers($appName, $key, $userIds);
@@ -197,6 +200,7 @@ public function getUserValueForUsers($appName, $key, $userIds);
* @param string $appName the appName that we stored the value under
* @return string[]
* @since 8.0.0
+ * @deprecated 33.0.0 - use {@see IUserConfig::getKeys} directly
*/
public function getUserKeys($userId, $appName);
@@ -210,6 +214,7 @@ public function getUserKeys($userId, $appName);
* [ $key => $value ]
* ]
* @since 24.0.0
+ * @deprecated 33.0.0 - use {@see IUserConfig::getAllValues} directly
*/
public function getAllUserValues(string $userId): array;
@@ -220,6 +225,7 @@ public function getAllUserValues(string $userId): array;
* @param string $appName the appName that we stored the value under
* @param string $key the key under which the value is being stored
* @since 8.0.0
+ * @deprecated 33.0.0 - use {@see IUserConfig::deleteUserConfig} directly
*/
public function deleteUserValue($userId, $appName, $key);
@@ -228,6 +234,7 @@ public function deleteUserValue($userId, $appName, $key);
*
* @param string $userId the userId of the user that we want to remove all values from
* @since 8.0.0
+ * @deprecated 33.0.0 - use {@see IUserConfig::deleteAllUserConfig} directly
*/
public function deleteAllUserValues($userId);
@@ -236,6 +243,7 @@ public function deleteAllUserValues($userId);
*
* @param string $appName the appName of the app that we want to remove all values from
* @since 8.0.0
+ * @deprecated 33.0.0 - use {@see IUserConfig::deleteApp} directly
*/
public function deleteAppFromAllUsers($appName);
@@ -246,8 +254,9 @@ public function deleteAppFromAllUsers($appName);
* @param string $key the key to get the user for
* @param string $value the value to get the user for
* @return list of user IDs
- * @since 31.0.0 return type of `list`
+ * @since 33.0.0 return type of `list`
* @since 8.0.0
+ * @deprecated 33.0.0 - use {@see IUserConfig::searchUsersByValueString} directly
*/
public function getUsersForUserValue($appName, $key, $value);
}
diff --git a/tests/lib/AllConfigTest.php b/tests/lib/AllConfigTest.php
index 9eb0fc832a3a3..798e23423a6f9 100644
--- a/tests/lib/AllConfigTest.php
+++ b/tests/lib/AllConfigTest.php
@@ -9,7 +9,6 @@
namespace Test;
use OC\AllConfig;
-use OC\SystemConfig;
use OCP\IDBConnection;
use OCP\PreConditionNotMetException;
use OCP\Server;
@@ -516,18 +515,4 @@ public function testGetUsersForUserValue(): void {
// cleanup
$this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences`');
}
-
- public function testGetUsersForUserValueCaseInsensitive(): void {
- // mock the check for the database to run the correct SQL statements for each database type
- $systemConfig = $this->createMock(SystemConfig::class);
- $config = $this->getConfig($systemConfig);
-
- $config->setUserValue('user1', 'myApp', 'myKey', 'test123');
- $config->setUserValue('user2', 'myApp', 'myKey', 'TEST123');
- $config->setUserValue('user3', 'myApp', 'myKey', 'test12345');
-
- $users = $config->getUsersForUserValueCaseInsensitive('myApp', 'myKey', 'test123');
- $this->assertSame(2, count($users));
- $this->assertSame(['user1', 'user2'], $users);
- }
}
diff --git a/tests/lib/User/ManagerTest.php b/tests/lib/User/ManagerTest.php
index bfc09ef82f6b1..7dadc4e9e8f11 100644
--- a/tests/lib/User/ManagerTest.php
+++ b/tests/lib/User/ManagerTest.php
@@ -13,6 +13,7 @@
use OC\User\Database;
use OC\User\Manager;
use OC\User\User;
+use OCP\Config\IUserConfig;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\ICache;
use OCP\ICacheFactory;
@@ -53,7 +54,7 @@ protected function setUp(): void {
public function testGetBackends(): void {
$userDummyBackend = $this->createMock(\Test\Util\User\Dummy::class);
- $manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
+ $manager = new Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
$manager->registerBackend($userDummyBackend);
$this->assertEquals([$userDummyBackend], $manager->getBackends());
$dummyDatabaseBackend = $this->createMock(Database::class);
@@ -63,77 +64,64 @@ public function testGetBackends(): void {
public function testUserExistsSingleBackendExists(): void {
- /**
- * @var \Test\Util\User\Dummy&MockObject $backend
- */
$backend = $this->createMock(\Test\Util\User\Dummy::class);
$backend->expects($this->once())
->method('userExists')
->with($this->equalTo('foo'))
->willReturn(true);
- $manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
+ $manager = new Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
$manager->registerBackend($backend);
$this->assertTrue($manager->userExists('foo'));
}
public function testUserExistsTooLong(): void {
- /** @var \Test\Util\User\Dummy|MockObject $backend */
$backend = $this->createMock(\Test\Util\User\Dummy::class);
$backend->expects($this->never())
->method('userExists')
->with($this->equalTo('foo'))
->willReturn(true);
- $manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
+ $manager = new Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
$manager->registerBackend($backend);
$this->assertFalse($manager->userExists('foo' . str_repeat('a', 62)));
}
public function testUserExistsSingleBackendNotExists(): void {
- /**
- * @var \Test\Util\User\Dummy&MockObject $backend
- */
$backend = $this->createMock(\Test\Util\User\Dummy::class);
$backend->expects($this->once())
->method('userExists')
->with($this->equalTo('foo'))
->willReturn(false);
- $manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
+ $manager = new Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
$manager->registerBackend($backend);
$this->assertFalse($manager->userExists('foo'));
}
public function testUserExistsNoBackends(): void {
- $manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
+ $manager = new Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
$this->assertFalse($manager->userExists('foo'));
}
public function testUserExistsTwoBackendsSecondExists(): void {
- /**
- * @var \Test\Util\User\Dummy&MockObject $backend1
- */
$backend1 = $this->createMock(\Test\Util\User\Dummy::class);
$backend1->expects($this->once())
->method('userExists')
->with($this->equalTo('foo'))
->willReturn(false);
- /**
- * @var \Test\Util\User\Dummy&MockObject $backend2
- */
$backend2 = $this->createMock(\Test\Util\User\Dummy::class);
$backend2->expects($this->once())
->method('userExists')
->with($this->equalTo('foo'))
->willReturn(true);
- $manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
+ $manager = new Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
$manager->registerBackend($backend1);
$manager->registerBackend($backend2);
@@ -141,23 +129,17 @@ public function testUserExistsTwoBackendsSecondExists(): void {
}
public function testUserExistsTwoBackendsFirstExists(): void {
- /**
- * @var \Test\Util\User\Dummy&MockObject $backend1
- */
$backend1 = $this->createMock(\Test\Util\User\Dummy::class);
$backend1->expects($this->once())
->method('userExists')
->with($this->equalTo('foo'))
->willReturn(true);
- /**
- * @var \Test\Util\User\Dummy&MockObject $backend2
- */
$backend2 = $this->createMock(\Test\Util\User\Dummy::class);
$backend2->expects($this->never())
->method('userExists');
- $manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
+ $manager = new Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
$manager->registerBackend($backend1);
$manager->registerBackend($backend2);
@@ -165,9 +147,6 @@ public function testUserExistsTwoBackendsFirstExists(): void {
}
public function testCheckPassword(): void {
- /**
- * @var \OC\User\Backend&MockObject $backend
- */
$backend = $this->createMock(\Test\Util\User\Dummy::class);
$backend->expects($this->once())
->method('checkPassword')
@@ -184,7 +163,7 @@ public function testCheckPassword(): void {
}
});
- $manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
+ $manager = new Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
$manager->registerBackend($backend);
$user = $manager->checkPassword('foo', 'bar');
@@ -192,9 +171,6 @@ public function testCheckPassword(): void {
}
public function testCheckPasswordNotSupported(): void {
- /**
- * @var \OC\User\Backend&MockObject $backend
- */
$backend = $this->createMock(\Test\Util\User\Dummy::class);
$backend->expects($this->never())
->method('checkPassword');
@@ -203,16 +179,13 @@ public function testCheckPasswordNotSupported(): void {
->method('implementsActions')
->willReturn(false);
- $manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
+ $manager = new Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
$manager->registerBackend($backend);
$this->assertFalse($manager->checkPassword('foo', 'bar'));
}
public function testGetOneBackendExists(): void {
- /**
- * @var \Test\Util\User\Dummy&MockObject $backend
- */
$backend = $this->createMock(\Test\Util\User\Dummy::class);
$backend->expects($this->once())
->method('userExists')
@@ -221,46 +194,39 @@ public function testGetOneBackendExists(): void {
$backend->expects($this->never())
->method('loginName2UserName');
- $manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
+ $manager = new Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
$manager->registerBackend($backend);
$this->assertEquals('foo', $manager->get('foo')->getUID());
}
public function testGetOneBackendNotExists(): void {
- /**
- * @var \Test\Util\User\Dummy&MockObject $backend
- */
$backend = $this->createMock(\Test\Util\User\Dummy::class);
$backend->expects($this->once())
->method('userExists')
->with($this->equalTo('foo'))
->willReturn(false);
- $manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
+ $manager = new Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
$manager->registerBackend($backend);
$this->assertEquals(null, $manager->get('foo'));
}
public function testGetTooLong(): void {
- /** @var \Test\Util\User\Dummy|MockObject $backend */
$backend = $this->createMock(\Test\Util\User\Dummy::class);
$backend->expects($this->never())
->method('userExists')
->with($this->equalTo('foo'))
->willReturn(false);
- $manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
+ $manager = new Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
$manager->registerBackend($backend);
$this->assertEquals(null, $manager->get('foo' . str_repeat('a', 62)));
}
public function testGetOneBackendDoNotTranslateLoginNames(): void {
- /**
- * @var \Test\Util\User\Dummy&MockObject $backend
- */
$backend = $this->createMock(\Test\Util\User\Dummy::class);
$backend->expects($this->once())
->method('userExists')
@@ -269,16 +235,13 @@ public function testGetOneBackendDoNotTranslateLoginNames(): void {
$backend->expects($this->never())
->method('loginName2UserName');
- $manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
+ $manager = new Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
$manager->registerBackend($backend);
$this->assertEquals('bLeNdEr', $manager->get('bLeNdEr')->getUID());
}
public function testSearchOneBackend(): void {
- /**
- * @var \Test\Util\User\Dummy&MockObject $backend
- */
$backend = $this->createMock(\Test\Util\User\Dummy::class);
$backend->expects($this->once())
->method('getUsers')
@@ -287,7 +250,7 @@ public function testSearchOneBackend(): void {
$backend->expects($this->never())
->method('loginName2UserName');
- $manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
+ $manager = new Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
$manager->registerBackend($backend);
$result = $manager->search('fo');
@@ -299,9 +262,6 @@ public function testSearchOneBackend(): void {
}
public function testSearchTwoBackendLimitOffset(): void {
- /**
- * @var \Test\Util\User\Dummy&MockObject $backend1
- */
$backend1 = $this->createMock(\Test\Util\User\Dummy::class);
$backend1->expects($this->once())
->method('getUsers')
@@ -310,9 +270,6 @@ public function testSearchTwoBackendLimitOffset(): void {
$backend1->expects($this->never())
->method('loginName2UserName');
- /**
- * @var \Test\Util\User\Dummy&MockObject $backend2
- */
$backend2 = $this->createMock(\Test\Util\User\Dummy::class);
$backend2->expects($this->once())
->method('getUsers')
@@ -321,7 +278,7 @@ public function testSearchTwoBackendLimitOffset(): void {
$backend2->expects($this->never())
->method('loginName2UserName');
- $manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
+ $manager = new Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
$manager->registerBackend($backend1);
$manager->registerBackend($backend2);
@@ -366,7 +323,6 @@ public static function dataCreateUserInvalid(): array {
#[\PHPUnit\Framework\Attributes\DataProvider('dataCreateUserInvalid')]
public function testCreateUserInvalid($uid, $password, $exception): void {
- /** @var \Test\Util\User\Dummy&MockObject $backend */
$backend = $this->createMock(\Test\Util\User\Dummy::class);
$backend->expects($this->once())
->method('implementsActions')
@@ -374,7 +330,7 @@ public function testCreateUserInvalid($uid, $password, $exception): void {
->willReturn(true);
- $manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
+ $manager = new Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
$manager->registerBackend($backend);
$this->expectException(\InvalidArgumentException::class, $exception);
@@ -382,9 +338,6 @@ public function testCreateUserInvalid($uid, $password, $exception): void {
}
public function testCreateUserSingleBackendNotExists(): void {
- /**
- * @var \Test\Util\User\Dummy&MockObject $backend
- */
$backend = $this->createMock(\Test\Util\User\Dummy::class);
$backend->expects($this->any())
->method('implementsActions')
@@ -401,7 +354,7 @@ public function testCreateUserSingleBackendNotExists(): void {
$backend->expects($this->never())
->method('loginName2UserName');
- $manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
+ $manager = new Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
$manager->registerBackend($backend);
$user = $manager->createUser('foo', 'bar');
@@ -412,9 +365,6 @@ public function testCreateUserSingleBackendNotExists(): void {
public function testCreateUserSingleBackendExists(): void {
$this->expectException(\Exception::class);
- /**
- * @var \Test\Util\User\Dummy&MockObject $backend
- */
$backend = $this->createMock(\Test\Util\User\Dummy::class);
$backend->expects($this->any())
->method('implementsActions')
@@ -428,16 +378,13 @@ public function testCreateUserSingleBackendExists(): void {
->with($this->equalTo('foo'))
->willReturn(true);
- $manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
+ $manager = new Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
$manager->registerBackend($backend);
$manager->createUser('foo', 'bar');
}
public function testCreateUserSingleBackendNotSupported(): void {
- /**
- * @var \Test\Util\User\Dummy&MockObject $backend
- */
$backend = $this->createMock(\Test\Util\User\Dummy::class);
$backend->expects($this->any())
->method('implementsActions')
@@ -449,14 +396,14 @@ public function testCreateUserSingleBackendNotSupported(): void {
$backend->expects($this->never())
->method('userExists');
- $manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
+ $manager = new Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
$manager->registerBackend($backend);
$this->assertFalse($manager->createUser('foo', 'bar'));
}
public function testCreateUserNoBackends(): void {
- $manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
+ $manager = new Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
$this->assertFalse($manager->createUser('foo', 'bar'));
}
@@ -482,9 +429,6 @@ public function testCreateUserFromBackendWithBackendError(): void {
public function testCreateUserTwoBackendExists(): void {
$this->expectException(\Exception::class);
- /**
- * @var \Test\Util\User\Dummy&MockObject $backend1
- */
$backend1 = $this->createMock(\Test\Util\User\Dummy::class);
$backend1->expects($this->any())
->method('implementsActions')
@@ -498,9 +442,6 @@ public function testCreateUserTwoBackendExists(): void {
->with($this->equalTo('foo'))
->willReturn(false);
- /**
- * @var \Test\Util\User\Dummy&MockObject $backend2
- */
$backend2 = $this->createMock(\Test\Util\User\Dummy::class);
$backend2->expects($this->any())
->method('implementsActions')
@@ -514,7 +455,7 @@ public function testCreateUserTwoBackendExists(): void {
->with($this->equalTo('foo'))
->willReturn(true);
- $manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
+ $manager = new Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
$manager->registerBackend($backend1);
$manager->registerBackend($backend2);
@@ -522,7 +463,7 @@ public function testCreateUserTwoBackendExists(): void {
}
public function testCountUsersNoBackend(): void {
- $manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
+ $manager = new Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
$result = $manager->countUsers();
$this->assertTrue(is_array($result));
@@ -530,9 +471,6 @@ public function testCountUsersNoBackend(): void {
}
public function testCountUsersOneBackend(): void {
- /**
- * @var \Test\Util\User\Dummy&MockObject $backend
- */
$backend = $this->createMock(\Test\Util\User\Dummy::class);
$backend->expects($this->once())
->method('countUsers')
@@ -547,7 +485,7 @@ public function testCountUsersOneBackend(): void {
->method('getBackendName')
->willReturn('Mock_Test_Util_User_Dummy');
- $manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
+ $manager = new Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
$manager->registerBackend($backend);
$result = $manager->countUsers();
@@ -588,7 +526,7 @@ public function testCountUsersTwoBackends(): void {
->method('getBackendName')
->willReturn('Mock_Test_Util_User_Dummy');
- $manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
+ $manager = new Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
$manager->registerBackend($backend1);
$manager->registerBackend($backend2);
@@ -760,7 +698,7 @@ public function testDeleteUser(): void {
->method('getAppValue')
->willReturnArgument(2);
- $manager = new \OC\User\Manager($config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
+ $manager = new Manager($config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
$backend = new \Test\Util\User\Dummy();
$manager->registerBackend($backend);
@@ -771,27 +709,31 @@ public function testDeleteUser(): void {
}
public function testGetByEmail(): void {
- /** @var AllConfig&MockObject */
- $config = $this->getMockBuilder(AllConfig::class)
- ->disableOriginalConstructor()
- ->getMock();
- $config
- ->expects($this->once())
- ->method('getUsersForUserValueCaseInsensitive')
+ $userConfig = $this->createMock(IUserConfig::class);
+ $userConfig->expects($this->once())
+ ->method('searchUsersByValueString')
->with('settings', 'email', 'test@example.com')
- ->willReturn(['uid1', 'uid99', 'uid2']);
-
- $backend = $this->createMock(\Test\Util\User\Dummy::class);
- $backend->expects($this->exactly(3))
- ->method('userExists')
- ->willReturnMap([
- ['uid1', true],
- ['uid99', false],
- ['uid2', true]
- ]);
+ ->willReturnCallback(function () {
+ yield 'uid1';
+ yield 'uid99';
+ yield 'uid2';
+ });
- $manager = new \OC\User\Manager($config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
- $manager->registerBackend($backend);
+ $manager = $this->getMockBuilder(Manager::class)
+ ->setConstructorArgs([$this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger])
+ ->onlyMethods(['getUserConfig', 'get'])
+ ->getMock();
+ $manager->method('getUserConfig')->willReturn($userConfig);
+ $manager->expects($this->exactly(3))
+ ->method('get')
+ ->willReturnCallback(function (string $uid): ?IUser {
+ if ($uid === 'uid99') {
+ return null;
+ }
+ $user = $this->createMock(IUser::class);
+ $user->method('getUID')->willReturn($uid);
+ return $user;
+ });
$users = $manager->getByEmail('test@example.com');
$this->assertCount(2, $users);