Merge pull request #55631 from nextcloud/carl/deprecate-config-user-correctly

refactor: Deprecated user config from IConfig correctly
This commit is contained in:
Stephan Orbaugh 2025-12-15 17:30:52 +01:00 committed by GitHub
commit 582bb11eae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
38 changed files with 848 additions and 784 deletions

View file

@ -11,7 +11,8 @@ namespace OCA\DAV\CalDAV\Schedule;
use OC\URLGenerator;
use OCA\DAV\CalDAV\EventReader;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IConfig;
use OCP\Config\IUserConfig;
use OCP\IAppConfig;
use OCP\IDBConnection;
use OCP\IL10N;
use OCP\IUserManager;
@ -41,12 +42,13 @@ class IMipService {
public function __construct(
private URLGenerator $urlGenerator,
private IConfig $config,
private IDBConnection $db,
private ISecureRandom $random,
private L10NFactory $l10nFactory,
private ITimeFactory $timeFactory,
private readonly IUserManager $userManager,
private readonly IUserConfig $userConfig,
private readonly IAppConfig $appConfig,
) {
$language = $this->l10nFactory->findGenericLanguage();
$locale = $this->l10nFactory->findLocale($language);
@ -887,8 +889,8 @@ class IMipService {
$users = $this->userManager->getByEmail($userAddress);
if ($users !== []) {
$user = array_shift($users);
$language = $this->config->getUserValue($user->getUID(), 'core', 'lang', null);
$locale = $this->config->getUserValue($user->getUID(), 'core', 'locale', null);
$language = $this->userConfig->getValueString($user->getUID(), 'core', 'lang', '') ?: null;
$locale = $this->userConfig->getValueString($user->getUID(), 'core', 'locale', '') ?: null;
}
// fallback to attendee LANGUAGE parameter if language not set
if ($language === null && isset($attendee['LANGUAGE']) && $attendee['LANGUAGE'] instanceof Parameter) {
@ -996,7 +998,7 @@ class IMipService {
* The default is 'no', which matches old behavior, and is privacy preserving.
*
* To enable including attendees in invitation emails:
* % php occ config:app:set dav invitation_list_attendees --value yes
* % php occ config:app:set dav invitation_list_attendees --value yes --type bool
*
* @param IEMailTemplate $template
* @param IL10N $this->l10n
@ -1004,12 +1006,12 @@ class IMipService {
* @author brad2014 on github.com
*/
public function addAttendees(IEMailTemplate $template, VEvent $vevent) {
if ($this->config->getAppValue('dav', 'invitation_list_attendees', 'no') === 'no') {
if (!$this->appConfig->getValueBool('dav', 'invitation_list_attendees')) {
return;
}
if (isset($vevent->ORGANIZER)) {
/** @var Property | Property\ICalendar\CalAddress $organizer */
/** @var Property&Property\ICalendar\CalAddress $organizer */
$organizer = $vevent->ORGANIZER;
$organizerEmail = substr($organizer->getNormalizedValue(), 7);
/** @var string|null $organizerName */
@ -1039,8 +1041,14 @@ class IMipService {
$attendeesHTML = [];
$attendeesText = [];
foreach ($attendees as $attendee) {
/** @var Property&Property\ICalendar\CalAddress $attendee */
$attendeeEmail = substr($attendee->getNormalizedValue(), 7);
$attendeeName = isset($attendee['CN']) ? $attendee['CN']->getValue() : null;
$attendeeName = null;
if (isset($attendee['CN'])) {
/** @var Parameter $cn */
$cn = $attendee['CN'];
$attendeeName = $cn->getValue();
}
$attendeeHTML = sprintf('<a href="%s">%s</a>',
htmlspecialchars($attendee->getNormalizedValue()),
htmlspecialchars($attendeeName ?: $attendeeEmail));

View file

@ -12,6 +12,7 @@ namespace OCA\DAV\CalDAV;
use OCA\DAV\Db\PropertyMapper;
use OCP\Calendar\ICalendar;
use OCP\Calendar\IManager;
use OCP\Config\IUserConfig;
use OCP\IConfig;
use Sabre\VObject\Component\VCalendar;
use Sabre\VObject\Component\VTimeZone;
@ -22,13 +23,14 @@ class TimezoneService {
public function __construct(
private IConfig $config,
private IUserConfig $userConfig,
private PropertyMapper $propertyMapper,
private IManager $calendarManager,
) {
}
public function getUserTimezone(string $userId): ?string {
$fromConfig = $this->config->getUserValue(
$fromConfig = $this->userConfig->getValueString(
$userId,
'core',
'timezone',
@ -51,7 +53,7 @@ class TimezoneService {
}
$principal = 'principals/users/' . $userId;
$uri = $this->config->getUserValue($userId, 'dav', 'defaultCalendar', CalDavBackend::PERSONAL_CALENDAR_URI);
$uri = $this->userConfig->getValueString($userId, 'dav', 'defaultCalendar', CalDavBackend::PERSONAL_CALENDAR_URI);
$calendars = $this->calendarManager->getCalendarsForPrincipal($principal);
/** @var ?VTimeZone $personalCalendarTimezone */

View file

@ -14,9 +14,9 @@ use OCA\DAV\CalDAV\EventComparisonService;
use OCA\DAV\CalDAV\Schedule\IMipPlugin;
use OCA\DAV\CalDAV\Schedule\IMipService;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Config\IUserConfig;
use OCP\Defaults;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IURLGenerator;
use OCP\IUser;
@ -46,7 +46,7 @@ class IMipPluginCharsetTest extends TestCase {
// Dependencies
private Defaults&MockObject $defaults;
private IAppConfig&MockObject $appConfig;
private IConfig&MockObject $config;
private IUserConfig&MockObject $userConfig;
private IDBConnection&MockObject $db;
private IFactory $l10nFactory;
private IManager&MockObject $mailManager;
@ -77,7 +77,8 @@ class IMipPluginCharsetTest extends TestCase {
// IMipService
$this->urlGenerator = $this->createMock(URLGenerator::class);
$this->config = $this->createMock(IConfig::class);
$this->userConfig = $this->createMock(IUserConfig::class);
$this->appConfig = $this->createMock(IAppConfig::class);
$this->db = $this->createMock(IDBConnection::class);
$this->random = $this->createMock(ISecureRandom::class);
$l10n = $this->createMock(L10N::class);
@ -92,19 +93,19 @@ class IMipPluginCharsetTest extends TestCase {
$this->userManager->method('getByEmail')->willReturn([]);
$this->imipService = new IMipService(
$this->urlGenerator,
$this->config,
$this->db,
$this->random,
$this->l10nFactory,
$this->timeFactory,
$this->userManager
$this->userManager,
$this->userConfig,
$this->appConfig,
);
// EventComparisonService
$this->eventComparisonService = new EventComparisonService();
// IMipPlugin
$this->appConfig = $this->createMock(IAppConfig::class);
$message = new \OC\Mail\Message(new Email(), false);
$this->mailer = $this->createMock(IMailer::class);
$this->mailer->method('createMessage')
@ -177,8 +178,13 @@ class IMipPluginCharsetTest extends TestCase {
public function testCharsetMailProvider(): void {
// Arrange
$this->appConfig->method('getValueBool')
->with('core', 'mail_providers_enabled', true)
->willReturn(true);
->willReturnCallback(function ($app, $key, $default) {
if ($app === 'core') {
$this->assertEquals($key, 'mail_providers_enabled');
return true;
}
return $default;
});
$mailMessage = new MailProviderMessage();
$mailService = $this->createMockForIntersectionOfInterfaces([IService::class, IMessageSend::class]);
$mailService->method('initiateMessage')

View file

@ -13,7 +13,8 @@ use OC\URLGenerator;
use OCA\DAV\CalDAV\EventReader;
use OCA\DAV\CalDAV\Schedule\IMipService;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IConfig;
use OCP\Config\IUserConfig;
use OCP\IAppConfig;
use OCP\IDBConnection;
use OCP\IL10N;
use OCP\IUserManager;
@ -26,7 +27,8 @@ use Test\TestCase;
class IMipServiceTest extends TestCase {
private URLGenerator&MockObject $urlGenerator;
private IConfig&MockObject $config;
private IUserConfig&MockObject $userConfig;
private IAppConfig&MockObject $appConfig;
private IDBConnection&MockObject $db;
private ISecureRandom&MockObject $random;
private IFactory&MockObject $l10nFactory;
@ -47,7 +49,8 @@ class IMipServiceTest extends TestCase {
parent::setUp();
$this->urlGenerator = $this->createMock(URLGenerator::class);
$this->config = $this->createMock(IConfig::class);
$this->userConfig = $this->createMock(IUserConfig::class);
$this->appConfig = $this->createMock(IAppConfig::class);
$this->db = $this->createMock(IDBConnection::class);
$this->random = $this->createMock(ISecureRandom::class);
$this->l10nFactory = $this->createMock(IFactory::class);
@ -63,12 +66,13 @@ class IMipServiceTest extends TestCase {
->willReturn($this->l10n);
$this->service = new IMipService(
$this->urlGenerator,
$this->config,
$this->db,
$this->random,
$this->l10nFactory,
$this->timeFactory,
$this->userManager
$this->userManager,
$this->userConfig,
$this->appConfig,
);
// construct calendar with a 1 hour event and same start/end time zones

View file

@ -9,12 +9,14 @@ declare(strict_types=1);
namespace OCA\DAV\Tests\unit\CalDAV;
use DateTimeZone;
use OCA\DAV\CalDAV\CalDavBackend;
use OCA\DAV\CalDAV\CalendarImpl;
use OCA\DAV\CalDAV\TimezoneService;
use OCA\DAV\Db\Property;
use OCA\DAV\Db\PropertyMapper;
use OCP\Calendar\ICalendar;
use OCP\Calendar\IManager;
use OCP\Config\IUserConfig;
use OCP\IConfig;
use PHPUnit\Framework\MockObject\MockObject;
use Sabre\VObject\Component\VTimeZone;
@ -22,6 +24,7 @@ use Test\TestCase;
class TimezoneServiceTest extends TestCase {
private IConfig&MockObject $config;
private IUserConfig&MockObject $userConfig;
private PropertyMapper&MockObject $propertyMapper;
private IManager&MockObject $calendarManager;
private TimezoneService $service;
@ -30,19 +33,21 @@ class TimezoneServiceTest extends TestCase {
parent::setUp();
$this->config = $this->createMock(IConfig::class);
$this->userConfig = $this->createMock(IUserConfig::class);
$this->propertyMapper = $this->createMock(PropertyMapper::class);
$this->calendarManager = $this->createMock(IManager::class);
$this->service = new TimezoneService(
$this->config,
$this->userConfig,
$this->propertyMapper,
$this->calendarManager,
);
}
public function testGetUserTimezoneFromSettings(): void {
$this->config->expects(self::once())
->method('getUserValue')
$this->userConfig->expects(self::once())
->method('getValueString')
->with('test123', 'core', 'timezone', '')
->willReturn('Europe/Warsaw');
@ -52,8 +57,8 @@ class TimezoneServiceTest extends TestCase {
}
public function testGetUserTimezoneFromAvailability(): void {
$this->config->expects(self::once())
->method('getUserValue')
$this->userConfig->expects(self::once())
->method('getValueString')
->with('test123', 'core', 'timezone', '')
->willReturn('');
$property = new Property();
@ -76,11 +81,11 @@ END:VCALENDAR');
}
public function testGetUserTimezoneFromPersonalCalendar(): void {
$this->config->expects(self::exactly(2))
->method('getUserValue')
$this->userConfig->expects(self::exactly(2))
->method('getValueString')
->willReturnMap([
['test123', 'core', 'timezone', '', ''],
['test123', 'dav', 'defaultCalendar', '', 'personal-1'],
['test123', 'core', 'timezone', '', false, ''],
['test123', 'dav', 'defaultCalendar', CalDavBackend::PERSONAL_CALENDAR_URI, false, 'personal-1'],
]);
$other = $this->createMock(ICalendar::class);
$other->method('getUri')->willReturn('other');
@ -105,11 +110,11 @@ END:VCALENDAR');
}
public function testGetUserTimezoneFromAny(): void {
$this->config->expects(self::exactly(2))
->method('getUserValue')
$this->userConfig->expects(self::exactly(2))
->method('getValueString')
->willReturnMap([
['test123', 'core', 'timezone', '', ''],
['test123', 'dav', 'defaultCalendar', '', 'personal-1'],
['test123', 'core', 'timezone', '', false, ''],
['test123', 'dav', 'defaultCalendar', CalDavBackend::PERSONAL_CALENDAR_URI, false, 'personal-1'],
]);
$other = $this->createMock(ICalendar::class);
$other->method('getUri')->willReturn('other');

View file

@ -24,6 +24,7 @@ use OCA\Files_Versions\Storage;
use OCP\App\IAppManager;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Command\IBus;
use OCP\Config\IUserConfig;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\EventDispatcher\IEventListener;
@ -38,6 +39,7 @@ use OCP\Files\NotPermittedException;
use OCP\Files\Storage\ILockingStorage;
use OCP\Files\Storage\IStorage;
use OCP\FilesMetadata\IFilesMetadataManager;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IRequest;
@ -368,12 +370,14 @@ class Trashbin implements IEventListener {
}
private static function getConfiguredTrashbinSize(string $user): int|float {
$config = Server::get(IConfig::class);
$userTrashbinSize = $config->getUserValue($user, 'files_trashbin', 'trashbin_size', '-1');
$userConfig = Server::get(IUserConfig::class);
$userTrashbinSize = $userConfig->getValueString($user, 'files_trashbin', 'trashbin_size', '-1');
if (is_numeric($userTrashbinSize) && ($userTrashbinSize > -1)) {
return Util::numericToNumber($userTrashbinSize);
}
$systemTrashbinSize = $config->getAppValue('files_trashbin', 'trashbin_size', '-1');
$appConfig = Server::get(IAppConfig::class);
$systemTrashbinSize = $appConfig->getValueString('files_trashbin', 'trashbin_size', '-1');
if (is_numeric($systemTrashbinSize)) {
return Util::numericToNumber($systemTrashbinSize);
}

View file

@ -11,10 +11,10 @@ use OCA\Theming\Service\BackgroundService;
use OCP\App\AppPathNotFoundException;
use OCP\App\IAppManager;
use OCP\AppFramework\Services\IAppConfig;
use OCP\Config\IUserConfig;
use OCP\Files\NotFoundException;
use OCP\Files\SimpleFS\ISimpleFile;
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IL10N;
use OCP\INavigationManager;
use OCP\IURLGenerator;
@ -40,17 +40,17 @@ class ThemingDefaults extends \OC_Defaults {
* ThemingDefaults constructor.
*/
public function __construct(
private IConfig $config,
private IAppConfig $appConfig,
private IL10N $l,
private IUserSession $userSession,
private IURLGenerator $urlGenerator,
private ICacheFactory $cacheFactory,
private Util $util,
private ImageManager $imageManager,
private IAppManager $appManager,
private INavigationManager $navigationManager,
private BackgroundService $backgroundService,
private readonly IAppConfig $appConfig,
private readonly IUserConfig $userConfig,
private readonly IL10N $l,
private readonly IUserSession $userSession,
private readonly IURLGenerator $urlGenerator,
private readonly ICacheFactory $cacheFactory,
private readonly Util $util,
private readonly ImageManager $imageManager,
private readonly IAppManager $appManager,
private readonly INavigationManager $navigationManager,
private readonly BackgroundService $backgroundService,
) {
parent::__construct();
@ -183,7 +183,7 @@ class ThemingDefaults extends \OC_Defaults {
// user-defined primary color
if (!empty($user)) {
$userPrimaryColor = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'primary_color', '');
$userPrimaryColor = $this->userConfig->getValueString($user->getUID(), Application::APP_ID, 'primary_color');
if (preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $userPrimaryColor)) {
return $userPrimaryColor;
}
@ -209,7 +209,7 @@ class ThemingDefaults extends \OC_Defaults {
// user-defined background color
if (!empty($user)) {
$userBackgroundColor = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'background_color', '');
$userBackgroundColor = $this->userConfig->getValueString($user->getUID(), Application::APP_ID, 'background_color');
if (preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $userBackgroundColor)) {
return $userBackgroundColor;
}

View file

@ -14,10 +14,10 @@ use OCA\Theming\ThemingDefaults;
use OCA\Theming\Util;
use OCP\App\IAppManager;
use OCP\AppFramework\Services\IAppConfig;
use OCP\Config\IUserConfig;
use OCP\Files\NotFoundException;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IL10N;
use OCP\INavigationManager;
use OCP\IURLGenerator;
@ -28,7 +28,7 @@ use Test\TestCase;
class ThemingDefaultsTest extends TestCase {
private IAppConfig&MockObject $appConfig;
private IConfig&MockObject $config;
private IUserConfig&MockObject $userConfig;
private IL10N&MockObject $l10n;
private IUserSession&MockObject $userSession;
private IURLGenerator&MockObject $urlGenerator;
@ -46,7 +46,7 @@ class ThemingDefaultsTest extends TestCase {
protected function setUp(): void {
parent::setUp();
$this->appConfig = $this->createMock(IAppConfig::class);
$this->config = $this->createMock(IConfig::class);
$this->userConfig = $this->createMock(IUserConfig::class);
$this->l10n = $this->createMock(IL10N::class);
$this->userSession = $this->createMock(IUserSession::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
@ -63,8 +63,8 @@ class ThemingDefaultsTest extends TestCase {
->method('getBaseUrl')
->willReturn('');
$this->template = new ThemingDefaults(
$this->config,
$this->appConfig,
$this->userConfig,
$this->l10n,
$this->userSession,
$this->urlGenerator,
@ -468,9 +468,9 @@ class ThemingDefaultsTest extends TestCase {
->method('getAppValueString')
->with('primary_color', '')
->willReturn($primaryColor);
$this->config
$this->userConfig
->expects($this->any())
->method('getUserValue')
->method('getValueString')
->with('user', 'theming', 'primary_color', '')
->willReturn($userPrimaryColor);

View file

@ -18,7 +18,6 @@ use OCA\User_LDAP\User\OfflineUser;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\HintException;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IUserManager;
use OCP\Server;
@ -55,7 +54,6 @@ class Access extends LDAPUtility {
public Connection $connection,
public Manager $userManager,
private Helper $helper,
private IConfig $config,
private IUserManager $ncUserManager,
private LoggerInterface $logger,
private IAppConfig $appConfig,
@ -1572,14 +1570,12 @@ class Access extends LDAPUtility {
* a *
*/
private function prepareSearchTerm(string $term): string {
$config = Server::get(IConfig::class);
$allowEnum = $config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes');
$allowEnum = $this->appConfig->getValueBool('core', 'shareapi_allow_share_dialog_user_enumeration', true);
$result = $term;
if ($term === '') {
$result = '*';
} elseif ($allowEnum !== 'no') {
} elseif ($allowEnum) {
$result = $term . '*';
}
return $result;

View file

@ -9,7 +9,6 @@ namespace OCA\User_LDAP;
use OCA\User_LDAP\User\Manager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IUserManager;
use OCP\Server;
use Psr\Log\LoggerInterface;
@ -19,7 +18,6 @@ class AccessFactory {
public function __construct(
private ILDAPWrapper $ldap,
private Helper $helper,
private IConfig $config,
private IAppConfig $appConfig,
private IUserManager $ncUserManager,
private LoggerInterface $logger,
@ -34,7 +32,6 @@ class AccessFactory {
$connection,
Server::get(Manager::class),
$this->helper,
$this->config,
$this->ncUserManager,
$this->logger,
$this->appConfig,

View file

@ -29,13 +29,16 @@ use OCP\AppFramework\Bootstrap\IBootContext;
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 @@ class Application extends App implements IBootstrap {
/**
* Controller
*/
$container->registerService('RenewPasswordController', function (IAppContainer $appContainer) {
/** @var IServerContainer $server */
$server = $appContainer->get(IServerContainer::class);
$container->registerService('RenewPasswordController', function (ContainerInterface $appContainer) {
return new RenewPasswordController(
$appContainer->get('AppName'),
$server->getRequest(),
$appContainer->get('UserManager'),
$server->getConfig(),
$appContainer->get(IRequest::class),
$appContainer->get(IUserManager::class),
$appContainer->get(IConfig::class),
$appContainer->get(IUserConfig::class),
$appContainer->get(IL10N::class),
$appContainer->get('Session'),
$server->getURLGenerator()
$appContainer->get(IURLGenerator::class),
);
});
$container->registerService(ILDAPWrapper::class, function (IAppContainer $appContainer) {
/** @var IServerContainer $server */
$server = $appContainer->get(IServerContainer::class);
$container->registerService(ILDAPWrapper::class, function (ContainerInterface $appContainer) {
return new LDAP(
$server->getConfig()->getSystemValueString('ldap_log_file')
$appContainer->get(IConfig::class)->getSystemValueString('ldap_log_file')
);
});
}
@ -87,6 +85,8 @@ class Application extends App implements IBootstrap {
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),

View file

@ -13,6 +13,7 @@ use OCP\AppFramework\Http\Attribute\PublicPage;
use OCP\AppFramework\Http\Attribute\UseSession;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\Config\IUserConfig;
use OCP\HintException;
use OCP\IConfig;
use OCP\IL10N;
@ -24,18 +25,12 @@ use OCP\IUserManager;
#[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
class RenewPasswordController extends Controller {
/**
* @param string $appName
* @param IRequest $request
* @param IUserManager $userManager
* @param IConfig $config
* @param IURLGenerator $urlGenerator
*/
public function __construct(
$appName,
string $appName,
IRequest $request,
private IUserManager $userManager,
private IConfig $config,
private IUserConfig $userConfig,
protected IL10N $l10n,
private ISession $session,
private IURLGenerator $urlGenerator,
@ -43,25 +38,17 @@ class RenewPasswordController extends Controller {
parent::__construct($appName, $request);
}
/**
* @return RedirectResponse
*/
#[PublicPage]
#[NoCSRFRequired]
public function cancel() {
public function cancel(): RedirectResponse {
return new RedirectResponse($this->urlGenerator->linkToRouteAbsolute('core.login.showLoginForm'));
}
/**
* @param string $user
*
* @return TemplateResponse|RedirectResponse
*/
#[PublicPage]
#[NoCSRFRequired]
#[UseSession]
public function showRenewPasswordForm($user) {
if ($this->config->getUserValue($user, 'user_ldap', 'needsPasswordReset') !== 'true') {
public function showRenewPasswordForm(string $user): TemplateResponse|RedirectResponse {
if (!$this->userConfig->getValueBool($user, 'user_ldap', 'needsPasswordReset')) {
return new RedirectResponse($this->urlGenerator->linkToRouteAbsolute('core.login.showLoginForm'));
}
$parameters = [];
@ -94,17 +81,10 @@ class RenewPasswordController extends Controller {
);
}
/**
* @param string $user
* @param string $oldPassword
* @param string $newPassword
*
* @return RedirectResponse
*/
#[PublicPage]
#[UseSession]
public function tryRenewPassword($user, $oldPassword, $newPassword) {
if ($this->config->getUserValue($user, 'user_ldap', 'needsPasswordReset') !== 'true') {
public function tryRenewPassword(?string $user, string $oldPassword, ?string $newPassword): RedirectResponse {
if ($user !== null && !$this->userConfig->getValueBool($user, 'user_ldap', 'needsPasswordReset')) {
return new RedirectResponse($this->urlGenerator->linkToRouteAbsolute('core.login.showLoginForm'));
}
$args = !is_null($user) ? ['user' => $user] : [];
@ -121,7 +101,7 @@ class RenewPasswordController extends Controller {
$this->session->set('loginMessages', [
[], [$this->l10n->t('Please login with the new password')]
]);
$this->config->setUserValue($user, 'user_ldap', 'needsPasswordReset', 'false');
$this->userConfig->setValueBool($user, 'user_ldap', 'needsPasswordReset', false);
return new RedirectResponse($this->urlGenerator->linkToRoute('core.login.showLoginForm', $args));
} else {
$this->session->set('renewPasswordMessages', [
@ -137,13 +117,10 @@ class RenewPasswordController extends Controller {
return new RedirectResponse($this->urlGenerator->linkToRoute('user_ldap.renewPassword.showRenewPasswordForm', $args));
}
/**
* @return RedirectResponse
*/
#[PublicPage]
#[NoCSRFRequired]
#[UseSession]
public function showLoginFormInvalidPassword($user) {
public function showLoginFormInvalidPassword(?string $user): RedirectResponse {
$args = !is_null($user) ? ['user' => $user] : [];
$this->session->set('loginMessages', [
['invalidpassword'], []

View file

@ -11,16 +11,15 @@ use Exception;
use OC\ServerNotAvailableException;
use OCA\User_LDAP\User\OfflineUser;
use OCP\Cache\CappedMemoryCache;
use OCP\Config\IUserConfig;
use OCP\Group\Backend\ABackend;
use OCP\Group\Backend\IDeleteGroupBackend;
use OCP\Group\Backend\IGetDisplayNameBackend;
use OCP\Group\Backend\IIsAdminBackend;
use OCP\GroupInterface;
use OCP\IConfig;
use OCP\IUserManager;
use OCP\Server;
use Psr\Log\LoggerInterface;
use function json_decode;
class Group_LDAP extends ABackend implements GroupInterface, IGroupLDAP, IGetDisplayNameBackend, IDeleteGroupBackend, IIsAdminBackend {
protected bool $enabled = false;
@ -41,7 +40,7 @@ class Group_LDAP extends ABackend implements GroupInterface, IGroupLDAP, IGetDis
public function __construct(
protected Access $access,
protected GroupPluginManager $groupPluginManager,
private IConfig $config,
private IUserConfig $userConfig,
private IUserManager $ncUserManager,
) {
$filter = $this->access->connection->ldapGroupFilter;
@ -643,8 +642,9 @@ class Group_LDAP extends ABackend implements GroupInterface, IGroupLDAP, IGetDis
* @return list<string>
*/
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<string> $cache */
$cache = $this->userConfig->getValueArray($uid, 'user_ldap', 'cached-group-memberships-' . $this->access->connection->getConfigPrefix());
return $cache;
}
/**
@ -800,8 +800,7 @@ class Group_LDAP extends ABackend implements GroupInterface, IGroupLDAP, IGetDis
$groups = array_values(array_unique($groups, SORT_LOCALE_STRING));
$this->access->connection->writeToCache($cacheKey, $groups);
$groupStr = \json_encode($groups);
$this->config->setUserValue($ncUid, 'user_ldap', 'cached-group-memberships-' . $this->access->connection->getConfigPrefix(), $groupStr);
$this->userConfig->setValueArray($ncUid, 'user_ldap', 'cached-group-memberships-' . $this->access->connection->getConfigPrefix(), $groups);
return $groups;
}

View file

@ -8,6 +8,7 @@
namespace OCA\User_LDAP;
use OC\ServerNotAvailableException;
use OCP\Config\IUserConfig;
use OCP\Group\Backend\IBatchMethodsBackend;
use OCP\Group\Backend\IDeleteGroupBackend;
use OCP\Group\Backend\IGetDisplayNameBackend;
@ -15,7 +16,6 @@ use OCP\Group\Backend\IGroupDetailsBackend;
use OCP\Group\Backend\IIsAdminBackend;
use OCP\Group\Backend\INamedBackend;
use OCP\GroupInterface;
use OCP\IConfig;
use OCP\IUserManager;
/**
@ -23,11 +23,11 @@ use OCP\IUserManager;
*/
class Group_Proxy extends Proxy implements GroupInterface, IGroupLDAP, IGetDisplayNameBackend, INamedBackend, IDeleteGroupBackend, IBatchMethodsBackend, IIsAdminBackend {
public function __construct(
private Helper $helper,
Helper $helper,
ILDAPWrapper $ldap,
AccessFactory $accessFactory,
private GroupPluginManager $groupPluginManager,
private IConfig $config,
private IUserConfig $userConfig,
private IUserManager $ncUserManager,
) {
parent::__construct($helper, $ldap, $accessFactory);
@ -35,7 +35,7 @@ class Group_Proxy extends Proxy implements GroupInterface, IGroupLDAP, IGetDispl
protected function newInstance(string $configPrefix): Group_LDAP {
return new Group_LDAP($this->getAccess($configPrefix), $this->groupPluginManager, $this->config, $this->ncUserManager);
return new Group_LDAP($this->getAccess($configPrefix), $this->groupPluginManager, $this->userConfig, $this->ncUserManager);
}
/**

View file

@ -14,15 +14,10 @@ use OCA\User_LDAP\ConnectionFactory;
use OCA\User_LDAP\Helper;
use OCA\User_LDAP\LDAP;
use OCA\User_LDAP\Mapping\UserMapping;
use OCP\AppFramework\Services\IAppConfig;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IAvatarManager;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IUserManager;
use OCP\Notification\IManager;
use Psr\Log\LoggerInterface;
class Sync extends TimedJob {
public const MAX_INTERVAL = 12 * 60 * 60; // 12h
@ -32,13 +27,9 @@ class Sync extends TimedJob {
public function __construct(
ITimeFactory $timeFactory,
private IEventDispatcher $dispatcher,
private IConfig $config,
private IDBConnection $dbc,
private IAvatarManager $avatarManager,
private IUserManager $ncUserManager,
private LoggerInterface $logger,
private IManager $notificationManager,
private IAppConfig $appConfig,
private \OCP\IAppConfig $globalAppConfig,
private UserMapping $mapper,
private Helper $ldapHelper,
private ConnectionFactory $connectionFactory,
@ -46,10 +37,9 @@ class Sync extends TimedJob {
) {
parent::__construct($timeFactory);
$this->setInterval(
(int)$this->config->getAppValue(
'user_ldap',
$this->appConfig->getAppValueInt(
'background_sync_interval',
(string)self::MIN_INTERVAL
self::MIN_INTERVAL
)
);
$this->ldap = new LDAP($this->config->getSystemValueString('ldap_log_file'));
@ -71,31 +61,31 @@ class Sync extends TimedJob {
$interval = floor(24 * 60 * 60 / $runsPerDay);
$interval = min(max($interval, self::MIN_INTERVAL), self::MAX_INTERVAL);
$this->config->setAppValue('user_ldap', 'background_sync_interval', (string)$interval);
$this->appConfig->setAppValueInt('background_sync_interval', (int)$interval);
}
/**
* returns the smallest configured paging size
*/
protected function getMinPagingSize(): int {
$configKeys = $this->config->getAppKeys('user_ldap');
$configKeys = $this->appConfig->getAppKeys();
$configKeys = array_filter($configKeys, function ($key) {
return str_contains($key, 'ldap_paging_size');
});
$minPagingSize = null;
$minPagingSize = 0;
foreach ($configKeys as $configKey) {
$pagingSize = $this->config->getAppValue('user_ldap', $configKey, $minPagingSize);
$minPagingSize = $minPagingSize === null ? $pagingSize : min($minPagingSize, $pagingSize);
$pagingSize = $this->appConfig->getAppValueInt($configKey, $minPagingSize);
$minPagingSize = $minPagingSize === 0 ? $pagingSize : min($minPagingSize, $pagingSize);
}
return (int)$minPagingSize;
return $minPagingSize;
}
/**
* @param array $argument
*/
public function run($argument) {
$isBackgroundJobModeAjax = $this->config
->getAppValue('core', 'backgroundjobs_mode', 'ajax') === 'ajax';
$isBackgroundJobModeAjax = $this->globalAppConfig
->getValueString('core', 'backgroundjobs_mode', 'ajax') === 'ajax';
if ($isBackgroundJobModeAjax) {
return;
}
@ -158,6 +148,7 @@ class Sync extends TimedJob {
/**
* Returns the info about the current cycle that should be run, if any,
* otherwise null
* @return ?array{prefix: string, offset: int}
*/
public function getCycle(): ?array {
$prefixes = $this->ldapHelper->getServerConfigurationPrefixes(true);
@ -166,8 +157,8 @@ class Sync extends TimedJob {
}
$cycleData = [
'prefix' => $this->config->getAppValue('user_ldap', 'background_sync_prefix', 'none'),
'offset' => (int)$this->config->getAppValue('user_ldap', 'background_sync_offset', '0'),
'prefix' => $this->appConfig->getAppValueString('background_sync_prefix', 'none'),
'offset' => $this->appConfig->getAppValueInt('background_sync_offset'),
];
if (
@ -186,8 +177,8 @@ class Sync extends TimedJob {
* @param array{prefix: ?string, offset: int} $cycleData
*/
public function setCycle(array $cycleData): void {
$this->config->setAppValue('user_ldap', 'background_sync_prefix', $cycleData['prefix']);
$this->config->setAppValue('user_ldap', 'background_sync_offset', (string)$cycleData['offset']);
$this->appConfig->setAppValueString('background_sync_prefix', $cycleData['prefix'] ?? '');
$this->appConfig->setAppValueInt('background_sync_offset', $cycleData['offset']);
}
/**
@ -220,10 +211,10 @@ class Sync extends TimedJob {
* Checks whether the provided cycle should be run. Currently, only the
* last configuration change goes into account (at least one hour).
*
* @param array{prefix: string} $cycleData
* @param array{prefix: string, offset: int} $cycleData
*/
public function qualifiesToRun(array $cycleData): bool {
$lastChange = (int)$this->config->getAppValue('user_ldap', $cycleData['prefix'] . '_lastChange', '0');
$lastChange = $this->appConfig->getAppValueInt($cycleData['prefix'] . '_lastChange');
if ((time() - $lastChange) > 60 * 30) {
return true;
}

View file

@ -10,21 +10,21 @@ declare(strict_types=1);
namespace OCA\User_LDAP\Jobs;
use OCA\User_LDAP\Service\UpdateGroupsService;
use OCP\AppFramework\Services\IAppConfig;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;
use OCP\DB\Exception;
use OCP\IConfig;
use Psr\Log\LoggerInterface;
class UpdateGroups extends TimedJob {
public function __construct(
private UpdateGroupsService $service,
private LoggerInterface $logger,
IConfig $config,
IAppConfig $appConfig,
ITimeFactory $timeFactory,
) {
parent::__construct($timeFactory);
$this->interval = (int)$config->getAppValue('user_ldap', 'bgjRefreshInterval', '3600');
$this->interval = $appConfig->getAppValueInt('bgjRefreshInterval', 3600);
}
/**

View file

@ -8,41 +8,27 @@ namespace OCA\User_LDAP\Migration;
use OCA\User_LDAP\Mapping\GroupMapping;
use OCA\User_LDAP\Mapping\UserMapping;
use OCP\AppFramework\Services\IAppConfig;
use OCP\BackgroundJob\IJobList;
use OCP\IConfig;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
class UUIDFixInsert implements IRepairStep {
public function __construct(
protected IConfig $config,
protected IAppConfig $appConfig,
protected UserMapping $userMapper,
protected GroupMapping $groupMapper,
protected IJobList $jobList,
) {
}
/**
* Returns the step's name
*
* @return string
* @since 9.1.0
*/
public function getName() {
public function getName(): string {
return 'Insert UUIDFix background job for user and group in batches';
}
/**
* Run repair step.
* Must throw exception on error.
*
* @param IOutput $output
* @throws \Exception in case of failure
* @since 9.1.0
*/
public function run(IOutput $output) {
$installedVersion = $this->config->getAppValue('user_ldap', 'installed_version', '1.2.1');
public function run(IOutput $output): void {
$installedVersion = $this->appConfig->getAppValueString('installed_version', '1.2.1');
if (version_compare($installedVersion, '1.2.1') !== -1) {
return;
}

View file

@ -7,7 +7,7 @@
namespace OCA\User_LDAP\User;
use OCA\User_LDAP\Mapping\UserMapping;
use OCP\IConfig;
use OCP\Config\IUserConfig;
use OCP\PreConditionNotMetException;
use OCP\Share\IManager;
@ -19,22 +19,23 @@ class DeletedUsersIndex {
protected ?array $deletedUsers = null;
public function __construct(
protected IConfig $config,
protected IUserConfig $userConfig,
protected UserMapping $mapping,
private IManager $shareManager,
) {
}
/**
* reads LDAP users marked as deleted from the database
* Reads LDAP users marked as deleted from the database.
*
* @return OfflineUser[]
*/
private function fetchDeletedUsers(): array {
$deletedUsers = $this->config->getUsersForUserValue('user_ldap', 'isDeleted', '1');
$deletedUsers = $this->userConfig->searchUsersByValueBool('user_ldap', 'isDeleted', true);
$userObjects = [];
foreach ($deletedUsers as $user) {
$userObject = new OfflineUser($user, $this->config, $this->mapping, $this->shareManager);
$userObject = new OfflineUser($user, $this->userConfig, $this->mapping, $this->shareManager);
if ($userObject->getLastLogin() > $userObject->getDetectedOn()) {
$userObject->unmark();
} else {
@ -47,7 +48,8 @@ class DeletedUsersIndex {
}
/**
* returns all LDAP users that are marked as deleted
* Returns all LDAP users that are marked as deleted.
*
* @return OfflineUser[]
*/
public function getUsers(): array {
@ -58,7 +60,7 @@ class DeletedUsersIndex {
}
/**
* whether at least one user was detected as deleted
* Whether at least one user was detected as deleted.
*/
public function hasUsers(): bool {
if (!is_array($this->deletedUsers)) {
@ -68,7 +70,7 @@ class DeletedUsersIndex {
}
/**
* marks a user as deleted
* Marks a user as deleted.
*
* @throws PreConditionNotMetException
*/
@ -77,12 +79,12 @@ class DeletedUsersIndex {
// the user is already marked, do not write to DB again
return;
}
$this->config->setUserValue($ocName, 'user_ldap', 'isDeleted', '1');
$this->config->setUserValue($ocName, 'user_ldap', 'foundDeleted', (string)time());
$this->userConfig->setValueBool($ocName, 'user_ldap', 'isDeleted', true);
$this->userConfig->setValueInt($ocName, 'user_ldap', 'foundDeleted', time());
$this->deletedUsers = null;
}
public function isUserMarked(string $ocName): bool {
return ($this->config->getUserValue($ocName, 'user_ldap', 'isDeleted', '0') === '1');
return $this->userConfig->getValueBool($ocName, 'user_ldap', 'isDeleted');
}
}

View file

@ -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 @@ class Manager {
*/
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 @@ class Manager {
}
/**
* Checks whether the specified user is marked as deleted
* @param string $id the Nextcloud user name
* @return bool
* Checks whether the specified user is marked as deleted.
* @param string $id the Nextcloud username
*/
public function isDeletedUser($id) {
$isDeleted = $this->ocConfig->getUserValue(
$id, 'user_ldap', 'isDeleted', 0);
return (int)$isDeleted === 1;
public function isDeletedUser(string $id): bool {
return $this->userConfig->getValueBool(
$id, 'user_ldap', 'isDeleted');
}
/**
* creates and returns an instance of OfflineUser for the specified user
* @param string $id
* @return OfflineUser
* Creates and returns an instance of OfflineUser for the specified user.
*/
public function getDeletedUser($id) {
public function getDeletedUser(string $id): OfflineUser {
return new OfflineUser(
$id,
$this->ocConfig,
$this->userConfig,
$this->access->getUserMapper(),
$this->shareManager
);

View file

@ -7,75 +7,45 @@
*/
namespace OCA\User_LDAP\User;
use OCA\User_LDAP\Mapping\UserMapping;
use OCP\IConfig;
use OCP\IDBConnection;
use OCA\User_LDAP\Mapping\AbstractMapping;
use OCP\Config\IUserConfig;
use OCP\Share\IManager;
use OCP\Share\IShare;
class OfflineUser {
/**
* @var string $dn
*/
protected $dn;
/**
* @var string $uid the UID as provided by LDAP
*/
protected $uid;
/**
* @var string $displayName
*/
protected $displayName;
/**
* @var string $homePath
*/
protected $homePath;
/**
* @var string $lastLogin the timestamp of the last login
*/
protected $lastLogin;
/**
* @var string $foundDeleted the timestamp when the user was detected as unavailable
*/
protected $foundDeleted;
protected ?string $dn = null;
/** @var ?string $uid the UID as provided by LDAP */
protected ?string $uid = null;
protected ?string $displayName = null;
protected ?string $homePath = null;
/** @var ?int $lastLogin the timestamp of the last login */
protected ?int $lastLogin = null;
/** @var ?int $foundDeleted the timestamp when the user was detected as unavailable */
protected ?int $foundDeleted = null;
protected ?string $extStorageHome = null;
/**
* @var string $email
*/
protected $email;
/**
* @var bool $hasActiveShares
*/
protected $hasActiveShares;
/**
* @var IDBConnection $db
*/
protected $db;
protected ?string $email = null;
protected ?bool $hasActiveShares = null;
/**
* @param string $ocName
*/
public function __construct(
protected $ocName,
protected IConfig $config,
protected UserMapping $mapping,
protected string $ocName,
protected IUserConfig $userConfig,
protected AbstractMapping $mapping,
private IManager $shareManager,
) {
}
/**
* remove the Delete-flag from the user.
* Remove the Delete-flag from the user.
*/
public function unmark() {
$this->config->deleteUserValue($this->ocName, 'user_ldap', 'isDeleted');
$this->config->deleteUserValue($this->ocName, 'user_ldap', 'foundDeleted');
public function unmark(): void {
$this->userConfig->deleteUserConfig($this->ocName, 'user_ldap', 'isDeleted');
$this->userConfig->deleteUserConfig($this->ocName, 'user_ldap', 'foundDeleted');
}
/**
* exports the user details in an assoc array
* @return array
* Exports the user details in an assoc array.
*/
public function export() {
public function export(): array {
$data = [];
$data['ocName'] = $this->getOCName();
$data['dn'] = $this->getDN();
@ -90,29 +60,26 @@ class OfflineUser {
}
/**
* getter for Nextcloud internal name
* @return string
* Getter for Nextcloud internal name.
*/
public function getOCName() {
public function getOCName(): string {
return $this->ocName;
}
/**
* getter for LDAP uid
* @return string
* Getter for LDAP uid.
*/
public function getUID() {
public function getUID(): string {
if ($this->uid === null) {
$this->fetchDetails();
}
return $this->uid;
return $this->uid ?? '';
}
/**
* getter for LDAP DN
* @return string
* Getter for LDAP DN.
*/
public function getDN() {
public function getDN(): string {
if ($this->dn === null) {
$dn = $this->mapping->getDNByName($this->ocName);
$this->dn = ($dn !== false) ? $dn : '';
@ -121,101 +88,90 @@ class OfflineUser {
}
/**
* getter for display name
* @return string
* Getter for display name.
*/
public function getDisplayName() {
public function getDisplayName(): string {
if ($this->displayName === null) {
$this->fetchDetails();
}
return $this->displayName;
return $this->displayName ?? '';
}
/**
* getter for email
* @return string
* Getter for email.
*/
public function getEmail() {
public function getEmail(): string {
if ($this->email === null) {
$this->fetchDetails();
}
return $this->email;
return $this->email ?? '';
}
/**
* getter for home directory path
* @return string
* Getter for home directory path.
*/
public function getHomePath() {
public function getHomePath(): string {
if ($this->homePath === null) {
$this->fetchDetails();
}
return $this->homePath;
return $this->homePath ?? '';
}
/**
* getter for the last login timestamp
* @return int
* Getter for the last login timestamp.
*/
public function getLastLogin() {
public function getLastLogin(): int {
if ($this->lastLogin === null) {
$this->fetchDetails();
}
return (int)$this->lastLogin;
return $this->lastLogin ?? -1;
}
/**
* getter for the detection timestamp
* @return int
* Getter for the detection timestamp.
*/
public function getDetectedOn() {
public function getDetectedOn(): int {
if ($this->foundDeleted === null) {
$this->fetchDetails();
}
return (int)$this->foundDeleted;
return $this->foundDeleted ?? -1;
}
public function getExtStorageHome(): string {
if ($this->extStorageHome === null) {
$this->fetchDetails();
}
return (string)$this->extStorageHome;
return $this->extStorageHome ?? '';
}
/**
* getter for having active shares
* @return bool
* Getter for having active shares.
*/
public function getHasActiveShares() {
public function getHasActiveShares(): bool {
if ($this->hasActiveShares === null) {
$this->determineShares();
}
return $this->hasActiveShares;
return $this->hasActiveShares ?? false;
}
/**
* reads the user details
* Reads the user details.
*/
protected function fetchDetails() {
$properties = [
'displayName' => 'user_ldap',
'uid' => 'user_ldap',
'homePath' => 'user_ldap',
'foundDeleted' => 'user_ldap',
'extStorageHome' => 'user_ldap',
'email' => 'settings',
'lastLogin' => 'login',
];
foreach ($properties as $property => $app) {
$this->$property = $this->config->getUserValue($this->ocName, $app, $property, '');
}
protected function fetchDetails(): void {
$this->displayName = $this->userConfig->getValueString($this->ocName, 'user_ldap', 'displayName');
$this->uid = $this->userConfig->getValueString($this->ocName, 'user_ldap', 'uid');
$this->homePath = $this->userConfig->getValueString($this->ocName, 'user_ldap', 'homePath');
$this->foundDeleted = $this->userConfig->getValueInt($this->ocName, 'user_ldap', 'foundDeleted');
$this->extStorageHome = $this->userConfig->getValueString($this->ocName, 'user_ldap', 'extStorageHome');
$this->email = $this->userConfig->getValueString($this->ocName, 'user_ldap', 'email');
$this->lastLogin = $this->userConfig->getValueInt($this->ocName, 'user_ldap', 'email');
}
/**
* finds out whether the user has active shares. The result is stored in
* $this->hasActiveShares
* Finds out whether the user has active shares. The result is stored in
* $this->hasActiveShares.
*/
protected function determineShares() {
protected function determineShares(): void {
$shareInterface = new \ReflectionClass(IShare::class);
$shareConstants = $shareInterface->getConstants();

View file

@ -15,6 +15,8 @@ use OCA\User_LDAP\Exceptions\AttributeNotSet;
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 @@ class User {
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 @@ class User {
* @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 @@ class User {
$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 @@ class User {
}
//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 @@ class User {
* @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 @@ class User {
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 @@ class User {
// 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 @@ class User {
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 @@ class User {
* @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 @@ class User {
}
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 @@ class User {
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 @@ class User {
}
//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();

View file

@ -20,6 +20,7 @@ use OCA\User_LDAP\Mapping\UserMapping;
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 @@ class AccessTest extends TestCase {
->getMock();
$this->userManager = $this->createMock(Manager::class);
$this->helper = $this->createMock(Helper::class);
$this->config = $this->createMock(IConfig::class);
$this->userMapper = $this->createMock(UserMapping::class);
$this->groupMapper = $this->createMock(GroupMapping::class);
$this->ncUserManager = $this->createMock(IUserManager::class);
@ -77,7 +76,6 @@ class AccessTest extends TestCase {
$this->connection,
$this->userManager,
$this->helper,
$this->config,
$this->ncUserManager,
$this->logger,
$this->appConfig,
@ -102,6 +100,8 @@ class AccessTest extends TestCase {
$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 @@ class AccessTest extends TestCase {
#[\PHPUnit\Framework\Attributes\DataProvider('dnInputDataProvider')]
public function testStringResemblesDN(string $input, array|bool $interResult, bool $expectedResult): void {
[$lw, $con, $um, $helper] = $this->getConnectorAndLdapMock();
/** @var IConfig&MockObject $config */
$config = $this->createMock(IConfig::class);
$access = new Access($lw, $con, $um, $helper, $config, $this->ncUserManager, $this->logger, $this->appConfig, $this->dispatcher);
$access = new Access($lw, $con, $um, $helper, $this->ncUserManager, $this->logger, $this->appConfig, $this->dispatcher);
$lw->expects($this->exactly(1))
->method('explodeDN')
@ -241,10 +239,8 @@ class AccessTest extends TestCase {
#[\PHPUnit\Framework\Attributes\DataProvider('dnInputDataProvider')]
public function testStringResemblesDNLDAPmod(string $input, array|bool $interResult, bool $expectedResult): void {
[, $con, $um, $helper] = $this->getConnectorAndLdapMock();
/** @var IConfig&MockObject $config */
$config = $this->createMock(IConfig::class);
$lw = new LDAP();
$access = new Access($lw, $con, $um, $helper, $config, $this->ncUserManager, $this->logger, $this->appConfig, $this->dispatcher);
$access = new Access($lw, $con, $um, $helper, $this->ncUserManager, $this->logger, $this->appConfig, $this->dispatcher);
if (!function_exists('ldap_explode_dn')) {
$this->markTestSkipped('LDAP Module not available');
@ -413,9 +409,6 @@ class AccessTest extends TestCase {
#[\PHPUnit\Framework\Attributes\DataProvider('dNAttributeProvider')]
public function testSanitizeDN(string $attribute): void {
[$lw, $con, $um, $helper] = $this->getConnectorAndLdapMock();
/** @var IConfig&MockObject $config */
$config = $this->createMock(IConfig::class);
$dnFromServer = 'cn=Mixed Cases,ou=Are Sufficient To,ou=Test,dc=example,dc=org';
$lw->expects($this->any())
@ -427,7 +420,7 @@ class AccessTest extends TestCase {
$attribute => ['count' => 1, $dnFromServer]
]);
$access = new Access($lw, $con, $um, $helper, $config, $this->ncUserManager, $this->logger, $this->appConfig, $this->dispatcher);
$access = new Access($lw, $con, $um, $helper, $this->ncUserManager, $this->logger, $this->appConfig, $this->dispatcher);
$values = $access->readAttribute('uid=whoever,dc=example,dc=org', $attribute);
$this->assertSame($values[0], strtolower($dnFromServer));
}

View file

@ -18,8 +18,8 @@ use OCA\User_LDAP\User\Manager;
use OCA\User_LDAP\User\OfflineUser;
use OCA\User_LDAP\User\User;
use OCA\User_LDAP\User_Proxy;
use OCP\Config\IUserConfig;
use OCP\GroupInterface;
use OCP\IConfig;
use OCP\IUser;
use OCP\IUserManager;
use OCP\Security\ISecureRandom;
@ -37,7 +37,7 @@ use Test\TestCase;
class Group_LDAPTest extends TestCase {
private Access&MockObject $access;
private GroupPluginManager&MockObject $pluginManager;
private IConfig&MockObject $config;
private IUserConfig&MockObject $userConfig;
private IUserManager&MockObject $ncUserManager;
private GroupLDAP $groupBackend;
@ -46,12 +46,12 @@ class Group_LDAPTest extends TestCase {
$this->access = $this->getAccessMock();
$this->pluginManager = $this->createMock(GroupPluginManager::class);
$this->config = $this->createMock(IConfig::class);
$this->userConfig = $this->createMock(IUserConfig::class);
$this->ncUserManager = $this->createMock(IUserManager::class);
}
public function initBackend(): void {
$this->groupBackend = new GroupLDAP($this->access, $this->pluginManager, $this->config, $this->ncUserManager);
$this->groupBackend = new GroupLDAP($this->access, $this->pluginManager, $this->userConfig, $this->ncUserManager);
}
public function testCountEmptySearchString(): void {
@ -772,9 +772,9 @@ class Group_LDAPTest extends TestCase {
->method('isDNPartOfBase')
->willReturn(true);
$this->config->expects($this->once())
->method('setUserValue')
->with('userX', 'user_ldap', 'cached-group-memberships-', \json_encode($expectedGroups));
$this->userConfig->expects($this->once())
->method('setValueArray')
->with('userX', 'user_ldap', 'cached-group-memberships-', $expectedGroups);
$this->initBackend();
$groups = $this->groupBackend->getUserGroups('userX');
@ -810,9 +810,9 @@ class Group_LDAPTest extends TestCase {
->willReturn([]);
// empty group result should not be oer
$this->config->expects($this->once())
->method('setUserValue')
->with('userX', 'user_ldap', 'cached-group-memberships-', '[]');
$this->userConfig->expects($this->once())
->method('setValueArray')
->with('userX', 'user_ldap', 'cached-group-memberships-', []);
$ldapUser = $this->createMock(User::class);
@ -846,10 +846,10 @@ class Group_LDAPTest extends TestCase {
$offlineUser = $this->createMock(OfflineUser::class);
$this->config->expects($this->any())
->method('getUserValue')
$this->userConfig->expects($this->any())
->method('getValueArray')
->with('userX', 'user_ldap', 'cached-group-memberships-', $this->anything())
->willReturn(\json_encode(['groupB', 'groupF']));
->willReturn(['groupB', 'groupF']);
$this->access->userManager->expects($this->any())
->method('get')
@ -872,11 +872,11 @@ class Group_LDAPTest extends TestCase {
$offlineUser = $this->createMock(OfflineUser::class);
$this->config->expects($this->any())
->method('getUserValue')
$this->userConfig->expects($this->any())
->method('getValueArray')
->with('userX', 'user_ldap', 'cached-group-memberships-', $this->anything())
// results in a json object: {"0":"groupB","2":"groupF"}
->willReturn(\json_encode([0 => 'groupB', 2 => 'groupF']));
->willReturn([0 => 'groupB', 2 => 'groupF']);
$this->access->userManager->expects($this->any())
->method('get')
@ -907,10 +907,10 @@ class Group_LDAPTest extends TestCase {
->method('getBackend')
->willReturn($userBackend);
$this->config->expects($this->atLeastOnce())
->method('getUserValue')
$this->userConfig->expects($this->atLeastOnce())
->method('getValueArray')
->with('userX', 'user_ldap', 'cached-group-memberships-', $this->anything())
->willReturn(\json_encode(['groupB', 'groupF']));
->willReturn(['groupB', 'groupF']);
$this->access->expects($this->any())
->method('username2dn')

View file

@ -15,16 +15,16 @@ use OCA\User_LDAP\Jobs\Sync;
use OCA\User_LDAP\LDAP;
use OCA\User_LDAP\Mapping\UserMapping;
use OCA\User_LDAP\User\Manager;
use OCP\AppFramework\Services\IAppConfig;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IAvatarManager;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IUserManager;
use OCP\Notification\IManager;
use OCP\Server;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Test\TestCase;
#[\PHPUnit\Framework\Attributes\Group('DB')]
@ -34,6 +34,8 @@ class SyncTest extends TestCase {
protected Manager&MockObject $userManager;
protected UserMapping&MockObject $mapper;
protected IConfig&MockObject $config;
protected IAppConfig&MockObject $appConfig;
protected \OCP\IAppConfig&MockObject $globalAppConfig;
protected IAvatarManager&MockObject $avatarManager;
protected IDBConnection&MockObject $dbc;
protected IUserManager&MockObject $ncUserManager;
@ -51,6 +53,8 @@ class SyncTest extends TestCase {
$this->userManager = $this->createMock(Manager::class);
$this->mapper = $this->createMock(UserMapping::class);
$this->config = $this->createMock(IConfig::class);
$this->appConfig = $this->createMock(IAppConfig::class);
$this->globalAppConfig = $this->createMock(\OCP\IAppConfig::class);
$this->avatarManager = $this->createMock(IAvatarManager::class);
$this->dbc = $this->createMock(IDBConnection::class);
$this->ncUserManager = $this->createMock(IUserManager::class);
@ -64,13 +68,9 @@ class SyncTest extends TestCase {
$this->sync = new Sync(
Server::get(ITimeFactory::class),
Server::get(IEventDispatcher::class),
$this->config,
$this->dbc,
$this->avatarManager,
$this->ncUserManager,
Server::get(LoggerInterface::class),
$this->notificationManager,
$this->appConfig,
$this->globalAppConfig,
$this->mapper,
$this->helper,
$this->connectionFactory,
@ -100,17 +100,17 @@ class SyncTest extends TestCase {
];
}
#[\PHPUnit\Framework\Attributes\DataProvider('intervalDataProvider')]
#[DataProvider('intervalDataProvider')]
public function testUpdateInterval(int $userCount, int $pagingSize1, int $pagingSize2): void {
$this->config->expects($this->once())
->method('setAppValue')
->with('user_ldap', 'background_sync_interval', $this->anything())
->willReturnCallback(function ($a, $k, $interval) {
$this->appConfig->expects($this->once())
->method('setAppValueInt')
->with('background_sync_interval', $this->anything())
->willReturnCallback(function ($key, $interval) {
$this->assertTrue($interval >= SYNC::MIN_INTERVAL);
$this->assertTrue($interval <= SYNC::MAX_INTERVAL);
return true;
});
$this->config->expects($this->atLeastOnce())
$this->appConfig->expects($this->atLeastOnce())
->method('getAppKeys')
->willReturn([
'blabla',
@ -119,8 +119,8 @@ class SyncTest extends TestCase {
'installed',
's07ldap_paging_size'
]);
$this->config->expects($this->exactly(2))
->method('getAppValue')
$this->appConfig->expects($this->exactly(2))
->method('getAppValueInt')
->willReturnOnConsecutiveCalls($pagingSize1, $pagingSize2);
$this->mapper->expects($this->atLeastOnce())
@ -141,7 +141,7 @@ class SyncTest extends TestCase {
];
}
#[\PHPUnit\Framework\Attributes\DataProvider('moreResultsProvider')]
#[DataProvider('moreResultsProvider')]
public function testMoreResults($pagingSize, $results, $expected): void {
$connection = $this->getMockBuilder(Connection::class)
->setConstructorArgs([
@ -198,7 +198,7 @@ class SyncTest extends TestCase {
];
}
#[\PHPUnit\Framework\Attributes\DataProvider('cycleDataProvider')]
#[DataProvider('cycleDataProvider')]
public function testDetermineNextCycle(?array $cycleData, array $prefixes, ?array $expectedCycle): void {
$this->helper->expects($this->any())
->method('getServerConfigurationPrefixes')
@ -206,19 +206,18 @@ class SyncTest extends TestCase {
->willReturn($prefixes);
if (is_array($expectedCycle)) {
$calls = [
['user_ldap', 'background_sync_prefix', $expectedCycle['prefix']],
['user_ldap', 'background_sync_offset', $expectedCycle['offset']],
];
$this->config->expects($this->exactly(2))
->method('setAppValue')
->willReturnCallback(function () use (&$calls): void {
$expected = array_shift($calls);
$this->assertEquals($expected, func_get_args());
});
$this->appConfig->expects($this->once())
->method('setAppValueInt')
->with('background_sync_offset', $expectedCycle['offset']);
$this->appConfig->expects($this->once())
->method('setAppValueString')
->with('background_sync_prefix', $expectedCycle['prefix']);
} else {
$this->config->expects($this->never())
->method('setAppValue');
$this->appConfig->expects($this->never())
->method('setAppValueString');
$this->appConfig->expects($this->never())
->method('setAppValueInt');
}
$this->sync->setArgument($this->arguments);
@ -235,8 +234,8 @@ class SyncTest extends TestCase {
public function testQualifiesToRun(): void {
$cycleData = ['prefix' => 's01'];
$this->config->expects($this->exactly(2))
->method('getAppValue')
$this->appConfig->expects($this->exactly(2))
->method('getAppValueInt')
->willReturnOnConsecutiveCalls(time() - 60 * 40, time() - 60 * 20);
$this->sync->setArgument($this->arguments);
@ -249,76 +248,94 @@ class SyncTest extends TestCase {
#0 - one LDAP server, reset
[[
'prefixes' => [''],
'scheduledCycle' => ['prefix' => '', 'offset' => '4500'],
'scheduledCycle' => ['prefix' => '', 'offset' => 4500],
'pagingSize' => 500,
'usersThisCycle' => 0,
'expectedNextCycle' => ['prefix' => '', 'offset' => '0'],
'expectedNextCycle' => ['prefix' => '', 'offset' => 0],
'mappedUsers' => 123,
]],
#1 - 2 LDAP servers, next prefix
[[
'prefixes' => ['', 's01'],
'scheduledCycle' => ['prefix' => '', 'offset' => '4500'],
'scheduledCycle' => ['prefix' => '', 'offset' => 4500],
'pagingSize' => 500,
'usersThisCycle' => 0,
'expectedNextCycle' => ['prefix' => 's01', 'offset' => '0'],
'expectedNextCycle' => ['prefix' => 's01', 'offset' => 0],
'mappedUsers' => 123,
]],
#2 - 2 LDAP servers, rotate prefix
[[
'prefixes' => ['', 's01'],
'scheduledCycle' => ['prefix' => 's01', 'offset' => '4500'],
'scheduledCycle' => ['prefix' => 's01', 'offset' => 4500],
'pagingSize' => 500,
'usersThisCycle' => 0,
'expectedNextCycle' => ['prefix' => '', 'offset' => '0'],
'expectedNextCycle' => ['prefix' => '', 'offset' => 0],
'mappedUsers' => 123,
]],
];
}
#[\PHPUnit\Framework\Attributes\DataProvider('runDataProvider')]
#[DataProvider('runDataProvider')]
public function testRun(array $runData): void {
$this->config->expects($this->any())
->method('getAppValue')
->willReturnCallback(function ($app, $key, $default) use ($runData) {
$this->globalAppConfig->expects($this->any())
->method('getValueString')
->willReturnCallback(function (string $app, string $key, $default) use ($runData) {
if ($app === 'core' && $key === 'backgroundjobs_mode') {
return 'cron';
}
if ($app = 'user_ldap') {
// for getCycle()
if ($key === 'background_sync_prefix') {
return $runData['scheduledCycle']['prefix'];
}
if ($key === 'background_sync_offset') {
return $runData['scheduledCycle']['offset'];
}
// for qualifiesToRun()
if ($key === $runData['scheduledCycle']['prefix'] . '_lastChange') {
return time() - 60 * 40;
}
// for getMinPagingSize
if ($key === $runData['scheduledCycle']['prefix'] . 'ldap_paging_size') {
return $runData['pagingSize'];
}
return $default;
});
$this->appConfig->expects($this->any())
->method('getAppValueInt')
->willReturnCallback(function (string $key, int $default) use ($runData): int {
if ($key === 'background_sync_offset') {
return $runData['scheduledCycle']['offset'];
}
// for getMinPagingSize
if ($key === $runData['scheduledCycle']['prefix'] . 'ldap_paging_size') {
return $runData['pagingSize'];
}
// for qualifiesToRun()
if ($key === $runData['scheduledCycle']['prefix'] . '_lastChange') {
return time() - 60 * 40;
}
return $default;
});
$this->appConfig->expects($this->any())
->method('getAppValueString')
->willReturnCallback(function (string $key, string $default) use ($runData): string {
// for getCycle()
if ($key === 'background_sync_prefix') {
return $runData['scheduledCycle']['prefix'];
}
return $default;
});
$calls = [
['user_ldap', 'background_sync_prefix', $runData['expectedNextCycle']['prefix']],
['user_ldap', 'background_sync_offset', $runData['expectedNextCycle']['offset']],
['user_ldap', 'background_sync_interval', '43200'],
['background_sync_prefix', $runData['expectedNextCycle']['prefix'], false, false],
['background_sync_offset', $runData['expectedNextCycle']['offset'], false, false],
['background_sync_interval', 43200, false, false],
];
$this->config->expects($this->exactly(3))
->method('setAppValue')
->willReturnCallback(function () use (&$calls): void {
$this->appConfig->expects($this->once())
->method('setAppValueString')
->willReturnCallback(function () use (&$calls): bool {
$expected = array_shift($calls);
$this->assertEquals($expected, func_get_args());
return true;
});
$this->config->expects($this->any())
$this->appConfig->expects($this->exactly(2))
->method('setAppValueInt')
->willReturnCallback(function () use (&$calls): bool {
$expected = array_shift($calls);
$this->assertEquals($expected, func_get_args());
return true;
});
$this->appConfig->expects($this->any())
->method('getAppKeys')
->with('user_ldap')
->willReturn([$runData['scheduledCycle']['prefix'] . 'ldap_paging_size']);
$this->helper->expects($this->any())

View file

@ -10,14 +10,14 @@ namespace OCA\User_LDAP\Tests\Migration;
use OCA\User_LDAP\Mapping\GroupMapping;
use OCA\User_LDAP\Mapping\UserMapping;
use OCA\User_LDAP\Migration\UUIDFixInsert;
use OCP\AppFramework\Services\IAppConfig;
use OCP\BackgroundJob\IJobList;
use OCP\IConfig;
use OCP\Migration\IOutput;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class UUIDFixInsertTest extends TestCase {
protected IConfig&MockObject $config;
protected IAppConfig&MockObject $appConfig;
protected UserMapping&MockObject $userMapper;
protected GroupMapping&MockObject $groupMapper;
protected IJobList&MockObject $jobList;
@ -27,11 +27,11 @@ class UUIDFixInsertTest extends TestCase {
parent::setUp();
$this->jobList = $this->createMock(IJobList::class);
$this->config = $this->createMock(IConfig::class);
$this->appConfig = $this->createMock(IAppConfig::class);
$this->userMapper = $this->createMock(UserMapping::class);
$this->groupMapper = $this->createMock(GroupMapping::class);
$this->job = new UUIDFixInsert(
$this->config,
$this->appConfig,
$this->userMapper,
$this->groupMapper,
$this->jobList
@ -88,9 +88,9 @@ class UUIDFixInsertTest extends TestCase {
#[\PHPUnit\Framework\Attributes\DataProvider('recordProvider')]
public function testRun(array $userBatches, array $groupBatches): void {
$this->config->expects($this->once())
->method('getAppValue')
->with('user_ldap', 'installed_version', '1.2.1')
$this->appConfig->expects($this->once())
->method('getAppValueString')
->with('installed_version', '1.2.1')
->willReturn('1.2.0');
$this->userMapper->expects($this->exactly(3))
@ -116,9 +116,9 @@ class UUIDFixInsertTest extends TestCase {
#[\PHPUnit\Framework\Attributes\DataProvider('recordProviderTooLongAndNone')]
public function testRunWithManyAndNone(array $userBatches, array $groupBatches): void {
$this->config->expects($this->once())
->method('getAppValue')
->with('user_ldap', 'installed_version', '1.2.1')
$this->appConfig->expects($this->once())
->method('getAppValueString')
->with('installed_version', '1.2.1')
->willReturn('1.2.0');
$this->userMapper->expects($this->exactly(5))
@ -152,9 +152,9 @@ class UUIDFixInsertTest extends TestCase {
}
public function testDonNotRun(): void {
$this->config->expects($this->once())
->method('getAppValue')
->with('user_ldap', 'installed_version', '1.2.1')
$this->appConfig->expects($this->once())
->method('getAppValueString')
->with('installed_version', '1.2.1')
->willReturn('1.2.1');
$this->userMapper->expects($this->never())
->method('getList');

View file

@ -9,7 +9,7 @@ namespace OCA\User_LDAP\Tests\User;
use OCA\User_LDAP\Mapping\UserMapping;
use OCA\User_LDAP\User\DeletedUsersIndex;
use OCP\IConfig;
use OCP\Config\IUserConfig;
use OCP\IDBConnection;
use OCP\Server;
use OCP\Share\IManager;
@ -24,7 +24,7 @@ use PHPUnit\Framework\MockObject\MockObject;
#[\PHPUnit\Framework\Attributes\Group('DB')]
class DeletedUsersIndexTest extends \Test\TestCase {
protected DeletedUsersIndex $dui;
protected IConfig $config;
protected IUserConfig $userConfig;
protected IDBConnection $db;
protected UserMapping&MockObject $mapping;
protected IManager&MockObject $shareManager;
@ -33,20 +33,20 @@ class DeletedUsersIndexTest extends \Test\TestCase {
parent::setUp();
// no mocks for those as tests go against DB
$this->config = Server::get(IConfig::class);
$this->userConfig = Server::get(IUserConfig::class);
$this->db = Server::get(IDBConnection::class);
// ensure a clean database
$this->config->deleteAppFromAllUsers('user_ldap');
$this->userConfig->deleteApp('user_ldap');
$this->mapping = $this->createMock(UserMapping::class);
$this->shareManager = $this->createMock(IManager::class);
$this->dui = new DeletedUsersIndex($this->config, $this->mapping, $this->shareManager);
$this->dui = new DeletedUsersIndex($this->userConfig, $this->mapping, $this->shareManager);
}
protected function tearDown(): void {
$this->config->deleteAppFromAllUsers('user_ldap');
$this->userConfig->deleteApp('user_ldap');
parent::tearDown();
}

View file

@ -13,6 +13,8 @@ use OCA\User_LDAP\Connection;
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 @@ use Psr\Log\LoggerInterface;
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 @@ class ManagerTest extends \Test\TestCase {
$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 @@ class ManagerTest extends \Test\TestCase {
/** @noinspection PhpUnhandledExceptionInspection */
$this->manager = new Manager(
$this->config,
$this->userConfig,
$this->appConfig,
$this->logger,
$this->avatarManager,
$this->image,

View file

@ -10,7 +10,7 @@ namespace OCA\User_LDAP\Tests\User;
use OCA\User_LDAP\Mapping\UserMapping;
use OCA\User_LDAP\User\OfflineUser;
use OCP\IConfig;
use OCP\Config\IUserConfig;
use OCP\Share\IManager;
use OCP\Share\IShare;
use PHPUnit\Framework\MockObject\MockObject;
@ -19,19 +19,19 @@ use Test\TestCase;
class OfflineUserTest extends TestCase {
protected UserMapping&MockObject $mapping;
protected string $uid;
protected IConfig&MockObject $config;
protected IUserConfig&MockObject $userConfig;
protected IManager&MockObject $shareManager;
protected OfflineUser $offlineUser;
public function setUp(): void {
$this->uid = 'deborah';
$this->config = $this->createMock(IConfig::class);
$this->userConfig = $this->createMock(IUserConfig::class);
$this->mapping = $this->createMock(UserMapping::class);
$this->shareManager = $this->createMock(IManager::class);
$this->offlineUser = new OfflineUser(
$this->uid,
$this->config,
$this->userConfig,
$this->mapping,
$this->shareManager
);

View file

@ -12,6 +12,8 @@ use OCA\User_LDAP\Access;
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 @@ class UserTest extends \Test\TestCase {
->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 @@ class UserTest extends \Test\TestCase {
$this->dn,
$this->access,
$this->config,
$this->userConfig,
$this->appConfig,
$this->image,
$this->logger,
$this->avatarManager,
@ -118,8 +126,8 @@ class UserTest extends \Test\TestCase {
$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 @@ class UserTest extends \Test\TestCase {
$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 @@ class UserTest extends \Test\TestCase {
->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 @@ class UserTest extends \Test\TestCase {
$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 @@ class UserTest extends \Test\TestCase {
->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 @@ class UserTest extends \Test\TestCase {
->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 @@ class UserTest extends \Test\TestCase {
->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 @@ class UserTest extends \Test\TestCase {
$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 @@ class UserTest extends \Test\TestCase {
->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 @@ class UserTest extends \Test\TestCase {
$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 @@ class UserTest extends \Test\TestCase {
}
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 @@ class UserTest extends \Test\TestCase {
}
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 @@ class UserTest extends \Test\TestCase {
$this->dn,
$this->access,
$this->config,
$this->userConfig,
$this->appConfig,
$this->image,
$this->logger,
$this->avatarManager,
@ -944,8 +954,8 @@ class UserTest extends \Test\TestCase {
$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 @@ class UserTest extends \Test\TestCase {
->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 @@ class UserTest extends \Test\TestCase {
->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 @@ class UserTest extends \Test\TestCase {
#[\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 @@ class UserTest extends \Test\TestCase {
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())

View file

@ -13,11 +13,11 @@ use OCA\WeatherStatus\ResponseDefinitions;
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 @@ class WeatherStatusService {
* @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 @@ class WeatherStatusService {
* @return list<string>
*/
public function getFavorites(): array {
$favoritesJson = $this->config->getUserValue($this->userId, Application::APP_ID, 'favorites', '');
return json_decode($favoritesJson, true) ?: [];
/** @var list<string> $favorites */
$favorites = $this->userConfig->getValueArray($this->userId, Application::APP_ID, 'favorites', []);
return $favorites;
}
/**
@ -83,7 +84,7 @@ class WeatherStatusService {
* @return WeatherStatusSuccess success state
*/
public function setFavorites(array $favorites): array {
$this->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 @@ class WeatherStatusService {
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 @@ class WeatherStatusService {
$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 @@ class WeatherStatusService {
* @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 @@ class WeatherStatusService {
* @return list<WeatherStatusForecast>|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];
}

View file

@ -63,6 +63,25 @@
<code><![CDATA[CommentsEvent::EVENT_PRE_UPDATE]]></code>
</DeprecatedConstant>
</file>
<file src="apps/dashboard/lib/Controller/DashboardApiController.php">
<DeprecatedMethod>
<code><![CDATA[getUserValue]]></code>
<code><![CDATA[setUserValue]]></code>
<code><![CDATA[setUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/dashboard/lib/Controller/DashboardController.php">
<DeprecatedMethod>
<code><![CDATA[getUserValue]]></code>
<code><![CDATA[setUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/dashboard/lib/Service/DashboardService.php">
<DeprecatedMethod>
<code><![CDATA[getUserValue]]></code>
<code><![CDATA[getUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/dav/appinfo/v1/caldav.php">
<DeprecatedMethod>
<code><![CDATA[exec]]></code>
@ -161,6 +180,7 @@
<file src="apps/dav/lib/BackgroundJob/GenerateBirthdayCalendarBackgroundJob.php">
<DeprecatedMethod>
<code><![CDATA[getAppValue]]></code>
<code><![CDATA[getUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/dav/lib/BackgroundJob/PruneOutdatedSyncTokensJob.php">
@ -174,9 +194,21 @@
<code><![CDATA[getAppValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/dav/lib/BackgroundJob/UserStatusAutomation.php">
<DeprecatedMethod>
<code><![CDATA[getUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/dav/lib/CalDAV/BirthdayCalendar/EnablePlugin.php">
<DeprecatedMethod>
<code><![CDATA[setUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/dav/lib/CalDAV/BirthdayService.php">
<DeprecatedMethod>
<code><![CDATA[getAppValue]]></code>
<code><![CDATA[getUserValue]]></code>
<code><![CDATA[getUserValue]]></code>
</DeprecatedMethod>
<UndefinedMethod>
<code><![CDATA[setDateTime]]></code>
@ -221,6 +253,11 @@
<code><![CDATA[null]]></code>
</NullableReturnStatement>
</file>
<file src="apps/dav/lib/CalDAV/Calendar.php">
<DeprecatedMethod>
<code><![CDATA[setUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/dav/lib/CalDAV/CalendarHome.php">
<DeprecatedMethod>
<code><![CDATA[getL10N]]></code>
@ -373,18 +410,10 @@
<code><![CDATA[is_array($modified['old'])]]></code>
</RedundantCondition>
</file>
<file src="apps/dav/lib/CalDAV/Schedule/IMipService.php">
<DeprecatedMethod>
<code><![CDATA[getAppValue]]></code>
</DeprecatedMethod>
<UndefinedMethod>
<code><![CDATA[getNormalizedValue]]></code>
<code><![CDATA[getNormalizedValue]]></code>
</UndefinedMethod>
</file>
<file src="apps/dav/lib/CalDAV/Schedule/Plugin.php">
<DeprecatedMethod>
<code><![CDATA[getPropertiesForPath]]></code>
<code><![CDATA[getUserValue]]></code>
</DeprecatedMethod>
<InvalidArgument>
<code><![CDATA[[$aclPlugin, 'propFind']]]></code>
@ -512,6 +541,9 @@
<file src="apps/dav/lib/Command/SyncBirthdayCalendar.php">
<DeprecatedMethod>
<code><![CDATA[getAppValue]]></code>
<code><![CDATA[getUserValue]]></code>
<code><![CDATA[getUserValue]]></code>
<code><![CDATA[setUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/dav/lib/Command/SyncSystemAddressBook.php">
@ -847,6 +879,17 @@
<code><![CDATA[getUserFolder]]></code>
</DeprecatedMethod>
</file>
<file src="apps/dav/lib/Listener/CalendarDeletionDefaultUpdaterListener.php">
<DeprecatedMethod>
<code><![CDATA[deleteUserValue]]></code>
<code><![CDATA[getUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/dav/lib/Listener/OutOfOfficeListener.php">
<DeprecatedMethod>
<code><![CDATA[getUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/dav/lib/Migration/BuildCalendarSearchIndex.php">
<DeprecatedMethod>
<code><![CDATA[getAppValue]]></code>
@ -943,6 +986,11 @@
<code><![CDATA[getUserFolder]]></code>
</DeprecatedMethod>
</file>
<file src="apps/dav/lib/Settings/AvailabilitySettings.php">
<DeprecatedMethod>
<code><![CDATA[getUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/dav/lib/Settings/CalDAVSettings.php">
<DeprecatedMethod>
<code><![CDATA[getAppValue]]></code>
@ -1158,8 +1206,10 @@
<file src="apps/encryption/lib/Recovery.php">
<DeprecatedMethod>
<code><![CDATA[getAppValue]]></code>
<code><![CDATA[getUserValue]]></code>
<code><![CDATA[setAppValue]]></code>
<code><![CDATA[setAppValue]]></code>
<code><![CDATA[setUserValue]]></code>
</DeprecatedMethod>
<InternalMethod>
<code><![CDATA[getDirectoryContent]]></code>
@ -1188,7 +1238,9 @@
<DeprecatedMethod>
<code><![CDATA[getAppValue]]></code>
<code><![CDATA[getAppValue]]></code>
<code><![CDATA[getUserValue]]></code>
<code><![CDATA[setAppValue]]></code>
<code><![CDATA[setUserValue]]></code>
</DeprecatedMethod>
<InternalMethod>
<code><![CDATA[file_exists]]></code>
@ -1335,6 +1387,14 @@
<code><![CDATA[\OC_Util::tearDownFS()]]></code>
</DeprecatedMethod>
</file>
<file src="apps/files/lib/Command/Object/Multi/Users.php">
<DeprecatedMethod>
<code><![CDATA[getUsersForUserValue]]></code>
<code><![CDATA[getUsersForUserValue]]></code>
<code><![CDATA[getUsersForUserValue]]></code>
<code><![CDATA[getUsersForUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/files/lib/Command/Scan.php">
<DeprecatedMethod>
<code><![CDATA[listen]]></code>
@ -1358,6 +1418,14 @@
<code><![CDATA[null]]></code>
</NullArgument>
</file>
<file src="apps/files/lib/Controller/ApiController.php">
<DeprecatedMethod>
<code><![CDATA[getUserValue]]></code>
<code><![CDATA[setUserValue]]></code>
<code><![CDATA[setUserValue]]></code>
<code><![CDATA[setUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/files/lib/Controller/DirectEditingController.php">
<InvalidArgument>
<code><![CDATA[$templateId]]></code>
@ -1367,6 +1435,11 @@
<code><![CDATA[open]]></code>
</UndefinedInterfaceMethod>
</file>
<file src="apps/files/lib/Controller/ViewController.php">
<DeprecatedMethod>
<code><![CDATA[getUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/files/lib/Helper.php">
<UndefinedInterfaceMethod>
<code><![CDATA[$i]]></code>
@ -1417,6 +1490,19 @@
<code><![CDATA[isReadyForUser]]></code>
</UndefinedInterfaceMethod>
</file>
<file src="apps/files/lib/Service/UserConfig.php">
<DeprecatedMethod>
<code><![CDATA[getUserValue]]></code>
<code><![CDATA[setUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/files/lib/Service/ViewConfig.php">
<DeprecatedMethod>
<code><![CDATA[getUserValue]]></code>
<code><![CDATA[getUserValue]]></code>
<code><![CDATA[setUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/files_external/lib/Command/Notify.php">
<DeprecatedClass>
<code><![CDATA[\OC_Util::normalizeUnicode($parent)]]></code>
@ -1549,6 +1635,13 @@
<code><![CDATA[new View('/' . \OC_User::getUser() . '/files/')]]></code>
</InternalMethod>
</file>
<file src="apps/files_sharing/lib/Controller/SettingsController.php">
<DeprecatedMethod>
<code><![CDATA[deleteUserValue]]></code>
<code><![CDATA[setUserValue]]></code>
<code><![CDATA[setUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/files_sharing/lib/Controller/ShareAPIController.php">
<DeprecatedClass>
<code><![CDATA[new QueryException()]]></code>
@ -1627,6 +1720,7 @@
<code><![CDATA[Util::connectHook('OC_Filesystem', 'post_delete', '\OCA\Files_Sharing\Hooks', 'unshareChildren')]]></code>
<code><![CDATA[Util::connectHook('OC_Filesystem', 'post_rename', '\OCA\Files_Sharing\Updater', 'renameHook')]]></code>
<code><![CDATA[Util::connectHook('OC_User', 'post_deleteUser', '\OCA\Files_Sharing\Hooks', 'deleteUser')]]></code>
<code><![CDATA[getUserValue]]></code>
</DeprecatedMethod>
<InternalMethod>
<code><![CDATA[file_exists]]></code>
@ -1645,6 +1739,16 @@
<code><![CDATA[unlink]]></code>
</InternalMethod>
</file>
<file src="apps/files_sharing/lib/Listener/UserAddedToGroupListener.php">
<DeprecatedMethod>
<code><![CDATA[getUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/files_sharing/lib/Listener/UserShareAcceptanceListener.php">
<DeprecatedMethod>
<code><![CDATA[getUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/files_sharing/lib/Middleware/SharingCheckMiddleware.php">
<DeprecatedInterface>
<code><![CDATA[protected]]></code>
@ -1687,6 +1791,11 @@
<code><![CDATA[Scanner]]></code>
</DeprecatedInterface>
</file>
<file src="apps/files_sharing/lib/Settings/Personal.php">
<DeprecatedMethod>
<code><![CDATA[getUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/files_sharing/lib/ShareBackend/File.php">
<InternalClass>
<code><![CDATA[new View('/' . $shareWith . '/files')]]></code>
@ -1819,7 +1928,10 @@
</DeprecatedInterface>
<DeprecatedMethod>
<code><![CDATA[getAppValue]]></code>
<code><![CDATA[getUserValue]]></code>
<code><![CDATA[getUserValueForUsers]]></code>
<code><![CDATA[setAppValue]]></code>
<code><![CDATA[setUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/files_trashbin/lib/Helper.php">
@ -1894,7 +2006,6 @@
<code><![CDATA[Util::emitHook('\OCA\Files_Trashbin\Trashbin', 'post_moveToTrash', ['filePath' => Filesystem::normalizePath($file_path),
'trashPath' => Filesystem::normalizePath(static::getTrashFilename($filename, $timestamp))])]]></code>
<code><![CDATA[Util::emitHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', ['filePath' => $targetPath, 'trashPath' => $sourcePath])]]></code>
<code><![CDATA[getAppValue]]></code>
<code><![CDATA[getUserFolder]]></code>
<code><![CDATA[getUserFolder]]></code>
<code><![CDATA[getUserFolder]]></code>
@ -2187,6 +2298,19 @@
<code><![CDATA[IAccountManager::PROPERTY_TWITTER]]></code>
<code><![CDATA[IAccountManager::PROPERTY_TWITTER]]></code>
</DeprecatedConstant>
<DeprecatedMethod>
<code><![CDATA[deleteUserValue]]></code>
<code><![CDATA[getUserValue]]></code>
<code><![CDATA[getUserValue]]></code>
<code><![CDATA[setUserValue]]></code>
<code><![CDATA[setUserValue]]></code>
<code><![CDATA[setUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/lookup_server_connector/lib/UpdateLookupServer.php">
<DeprecatedMethod>
<code><![CDATA[deleteUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/oauth2/lib/Controller/OauthApiController.php">
<NoInterfaceProperties>
@ -2204,10 +2328,21 @@
</DeprecatedConstant>
<DeprecatedMethod>
<code><![CDATA[\OC_Util::tearDownFS()]]></code>
<code><![CDATA[getUserValue]]></code>
<code><![CDATA[getUserValue]]></code>
<code><![CDATA[getUserValue]]></code>
<code><![CDATA[implementsActions]]></code>
<code><![CDATA[implementsActions]]></code>
</DeprecatedMethod>
</file>
<file src="apps/provisioning_api/lib/Controller/PreferencesController.php">
<DeprecatedMethod>
<code><![CDATA[deleteUserValue]]></code>
<code><![CDATA[deleteUserValue]]></code>
<code><![CDATA[setUserValue]]></code>
<code><![CDATA[setUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/provisioning_api/lib/Controller/UsersController.php">
<DeprecatedConstant>
<code><![CDATA[IAccountManager::PROPERTY_TWITTER]]></code>
@ -2218,16 +2353,22 @@
<code><![CDATA[IAccountManager::PROPERTY_TWITTER]]></code>
</DeprecatedConstant>
<DeprecatedMethod>
<code><![CDATA[deleteUserValue]]></code>
<code><![CDATA[getAppValue]]></code>
<code><![CDATA[getAppValue]]></code>
<code><![CDATA[getAppValue]]></code>
<code><![CDATA[getAppValue]]></code>
<code><![CDATA[getAppValue]]></code>
<code><![CDATA[getUserValue]]></code>
<code><![CDATA[implementsActions]]></code>
<code><![CDATA[implementsActions]]></code>
<code><![CDATA[implementsActions]]></code>
<code><![CDATA[search]]></code>
<code><![CDATA[search]]></code>
<code><![CDATA[setUserValue]]></code>
<code><![CDATA[setUserValue]]></code>
<code><![CDATA[setUserValue]]></code>
<code><![CDATA[setUserValue]]></code>
</DeprecatedMethod>
<TypeDoesNotContainNull>
<code><![CDATA[$groupid === null]]></code>
@ -2274,8 +2415,6 @@
<code><![CDATA[query]]></code>
<code><![CDATA[query]]></code>
<code><![CDATA[query]]></code>
<code><![CDATA[query]]></code>
<code><![CDATA[query]]></code>
</DeprecatedMethod>
<UndefinedInterfaceMethod>
<code><![CDATA[getSettingsManager]]></code>
@ -2294,6 +2433,7 @@
</file>
<file src="apps/settings/lib/Controller/MailSettingsController.php">
<DeprecatedMethod>
<code><![CDATA[getUserValue]]></code>
<code><![CDATA[setAppValue]]></code>
<code><![CDATA[setAppValue]]></code>
<code><![CDATA[setAppValue]]></code>
@ -2337,6 +2477,11 @@
<code><![CDATA[[$user->getEMailAddress() => $user->getDisplayName()]]]></code>
</InvalidArrayOffset>
</file>
<file src="apps/settings/lib/Mailer/NewUserMailHelper.php">
<DeprecatedMethod>
<code><![CDATA[setUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/settings/lib/Settings/Admin/ArtificialIntelligence.php">
<DeprecatedInterface>
<code><![CDATA[$taskProcessingSettings]]></code>
@ -2387,6 +2532,13 @@
<code><![CDATA[IAccountManager::PROPERTY_TWITTER]]></code>
<code><![CDATA[IAccountManager::PROPERTY_TWITTER]]></code>
</DeprecatedConstant>
<DeprecatedMethod>
<code><![CDATA[getUserValue]]></code>
<code><![CDATA[getUserValue]]></code>
<code><![CDATA[getUserValue]]></code>
<code><![CDATA[getUserValue]]></code>
<code><![CDATA[getUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/settings/lib/Settings/Personal/Security/Authtokens.php">
<DeprecatedClass>
@ -2455,6 +2607,10 @@
<code><![CDATA[MapperEvent::EVENT_UNASSIGN]]></code>
<code><![CDATA[MapperEvent::EVENT_UNASSIGN]]></code>
</DeprecatedConstant>
<DeprecatedMethod>
<code><![CDATA[getUserValue]]></code>
<code><![CDATA[setUserValue]]></code>
</DeprecatedMethod>
<InvalidArgument>
<code><![CDATA[$event->getObjectId()]]></code>
<code><![CDATA[$event->getObjectId()]]></code>
@ -2473,6 +2629,11 @@
<code><![CDATA[query]]></code>
</DeprecatedMethod>
</file>
<file src="apps/systemtags/lib/Controller/LastUsedController.php">
<DeprecatedMethod>
<code><![CDATA[getUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/testing/lib/AlternativeHomeUserBackend.php">
<DeprecatedInterface>
<code><![CDATA[AlternativeHomeUserBackend]]></code>
@ -2504,6 +2665,16 @@
<code><![CDATA[setAppValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/testing/lib/Listener/GetDeclarativeSettingsValueListener.php">
<DeprecatedMethod>
<code><![CDATA[getUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/testing/lib/Listener/SetDeclarativeSettingsValueListener.php">
<DeprecatedMethod>
<code><![CDATA[setUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/testing/lib/Provider/FakeText2ImageProvider.php">
<DeprecatedInterface>
<code><![CDATA[FakeText2ImageProvider]]></code>
@ -2542,6 +2713,7 @@
<file src="apps/theming/lib/Capabilities.php">
<DeprecatedMethod>
<code><![CDATA[getAppValue]]></code>
<code><![CDATA[getUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/theming/lib/Command/UpdateConfig.php">
@ -2558,6 +2730,14 @@
<code><![CDATA[getAppValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/theming/lib/Controller/UserThemeController.php">
<DeprecatedMethod>
<code><![CDATA[getUserValue]]></code>
<code><![CDATA[getUserValue]]></code>
<code><![CDATA[getUserValue]]></code>
<code><![CDATA[setUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/theming/lib/ImageManager.php">
<DeprecatedMethod>
<code><![CDATA[deleteAppValue]]></code>
@ -2573,6 +2753,39 @@
<code><![CDATA[setAppValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/theming/lib/Jobs/RestoreBackgroundImageColor.php">
<DeprecatedMethod>
<code><![CDATA[getUserValue]]></code>
<code><![CDATA[getUserValue]]></code>
<code><![CDATA[getUserValue]]></code>
<code><![CDATA[setUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/theming/lib/Listener/BeforeTemplateRenderedListener.php">
<DeprecatedMethod>
<code><![CDATA[getUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/theming/lib/Service/BackgroundService.php">
<DeprecatedMethod>
<code><![CDATA[deleteUserValue]]></code>
<code><![CDATA[deleteUserValue]]></code>
<code><![CDATA[deleteUserValue]]></code>
<code><![CDATA[getUserValue]]></code>
<code><![CDATA[setUserValue]]></code>
<code><![CDATA[setUserValue]]></code>
<code><![CDATA[setUserValue]]></code>
<code><![CDATA[setUserValue]]></code>
<code><![CDATA[setUserValue]]></code>
<code><![CDATA[setUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/theming/lib/Service/ThemesService.php">
<DeprecatedMethod>
<code><![CDATA[getUserValue]]></code>
<code><![CDATA[setUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/theming/lib/Settings/Admin.php">
<DeprecatedMethod>
<code><![CDATA[getAppValue]]></code>
@ -2584,11 +2797,22 @@
<file src="apps/theming/lib/Settings/Personal.php">
<DeprecatedMethod>
<code><![CDATA[getAppValue]]></code>
<code><![CDATA[getUserValue]]></code>
<code><![CDATA[getUserValue]]></code>
<code><![CDATA[getUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/theming/lib/Themes/CommonThemeTrait.php">
<DeprecatedMethod>
<code><![CDATA[getAppValue]]></code>
<code><![CDATA[getUserValue]]></code>
<code><![CDATA[getUserValue]]></code>
<code><![CDATA[getUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/theming/lib/Themes/DefaultTheme.php">
<DeprecatedMethod>
<code><![CDATA[getUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/theming/lib/Util.php">
@ -2596,6 +2820,7 @@
<code><![CDATA[getAppValue]]></code>
<code><![CDATA[getAppValue]]></code>
<code><![CDATA[getAppValue]]></code>
<code><![CDATA[getUserValue]]></code>
</DeprecatedMethod>
<InvalidReturnStatement>
<code><![CDATA[array_values($color->getRgb())]]></code>
@ -2612,7 +2837,6 @@
<file src="apps/user_ldap/lib/Access.php">
<DeprecatedMethod>
<code><![CDATA[emit]]></code>
<code><![CDATA[getAppValue]]></code>
</DeprecatedMethod>
<InvalidReturnStatement>
<code><![CDATA[$uuid]]></code>
@ -2627,10 +2851,6 @@
</file>
<file src="apps/user_ldap/lib/AppInfo/Application.php">
<DeprecatedInterface>
<code><![CDATA[$server]]></code>
<code><![CDATA[$server]]></code>
<code><![CDATA[IAppContainer]]></code>
<code><![CDATA[IAppContainer]]></code>
<code><![CDATA[IAppContainer]]></code>
<code><![CDATA[IAppContainer]]></code>
</DeprecatedInterface>
@ -2642,10 +2862,6 @@
'loginName2UserName'
)]]></code>
<code><![CDATA[dispatch]]></code>
<code><![CDATA[getConfig]]></code>
<code><![CDATA[getConfig]]></code>
<code><![CDATA[getRequest]]></code>
<code><![CDATA[getURLGenerator]]></code>
<code><![CDATA[registerService]]></code>
<code><![CDATA[registerService]]></code>
</DeprecatedMethod>
@ -2684,27 +2900,10 @@
</DeprecatedMethod>
</file>
<file src="apps/user_ldap/lib/Jobs/Sync.php">
<DeprecatedMethod>
<code><![CDATA[getAppKeys]]></code>
<code><![CDATA[getAppValue]]></code>
<code><![CDATA[getAppValue]]></code>
<code><![CDATA[getAppValue]]></code>
<code><![CDATA[getAppValue]]></code>
<code><![CDATA[getAppValue]]></code>
<code><![CDATA[getAppValue]]></code>
<code><![CDATA[setAppValue]]></code>
<code><![CDATA[setAppValue]]></code>
<code><![CDATA[setAppValue]]></code>
</DeprecatedMethod>
<InvalidOperand>
<code><![CDATA[$i]]></code>
</InvalidOperand>
</file>
<file src="apps/user_ldap/lib/Jobs/UpdateGroups.php">
<DeprecatedMethod>
<code><![CDATA[getAppValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/user_ldap/lib/LDAPProvider.php">
<DeprecatedInterface>
<code><![CDATA[IServerContainer]]></code>
@ -2736,11 +2935,6 @@
<code><![CDATA[deleteAppValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/user_ldap/lib/Migration/UUIDFixInsert.php">
<DeprecatedMethod>
<code><![CDATA[getAppValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/user_ldap/lib/Migration/Version1120Date20210917155206.php">
<DeprecatedMethod>
<code><![CDATA[emit]]></code>
@ -2763,7 +2957,6 @@
</DeprecatedConstant>
<DeprecatedMethod>
<code><![CDATA[Util::connectHook('OC_User', 'post_login', $this, 'handlePasswordExpiry')]]></code>
<code><![CDATA[getAppValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/user_ldap/lib/User_LDAP.php">
@ -2870,6 +3063,12 @@
<code><![CDATA[setAppValue]]></code>
</DeprecatedMethod>
</file>
<file src="core/BackgroundJobs/LookupServerSendCheckBackgroundJob.php">
<DeprecatedMethod>
<code><![CDATA[getUserValue]]></code>
<code><![CDATA[setUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="core/Command/App/ListApps.php">
<LessSpecificImplementedReturnType>
<code><![CDATA[array]]></code>
@ -3050,10 +3249,19 @@
<code><![CDATA[search]]></code>
</DeprecatedMethod>
</file>
<file src="core/Command/User/Report.php">
<DeprecatedMethod>
<code><![CDATA[getUsersForUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="core/Command/User/Setting.php">
<DeprecatedMethod>
<code><![CDATA[deleteUserValue]]></code>
<code><![CDATA[getAllUserValues]]></code>
<code><![CDATA[getUserValue]]></code>
<code><![CDATA[search]]></code>
<code><![CDATA[setEMailAddress]]></code>
<code><![CDATA[setUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="core/Controller/AppPasswordController.php">
@ -3090,6 +3298,7 @@
</file>
<file src="core/Controller/LoginController.php">
<DeprecatedMethod>
<code><![CDATA[deleteUserValue]]></code>
<code><![CDATA[getDelay]]></code>
</DeprecatedMethod>
</file>
@ -3100,6 +3309,7 @@
'preLoginNameUsedAsUserName',
['uid' => &$user]
)]]></code>
<code><![CDATA[deleteUserValue]]></code>
</DeprecatedMethod>
<RedundantCast>
<code><![CDATA[(int)$e->getCode()]]></code>
@ -3110,6 +3320,11 @@
<code><![CDATA[IInitialStateService]]></code>
</DeprecatedInterface>
</file>
<file src="core/Controller/ProfileApiController.php">
<DeprecatedMethod>
<code><![CDATA[getUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="core/Controller/RecommendedAppsController.php">
<DeprecatedInterface>
<code><![CDATA[private]]></code>
@ -3176,6 +3391,12 @@
)]]></code>
</DeprecatedMethod>
</file>
<file src="core/Controller/WhatsNewController.php">
<DeprecatedMethod>
<code><![CDATA[getUserValue]]></code>
<code><![CDATA[setUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="core/Middleware/TwoFactorMiddleware.php">
<DeprecatedInterface>
<code><![CDATA[private]]></code>
@ -4169,7 +4390,6 @@
</InvalidArgument>
<UndefinedInterfaceMethod>
<code><![CDATA[createUser]]></code>
<code><![CDATA[getUsersForUserValueCaseInsensitive]]></code>
</UndefinedInterfaceMethod>
</file>
<file src="lib/private/User/Session.php">

View file

@ -447,14 +447,14 @@ class OC {
}
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);
}
/**

View file

@ -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 @@ class AllConfig implements IConfig {
}
/**
* 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 @@ class AllConfig implements IConfig {
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<string> 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<string> $result */
$result = iterator_to_array(\OCP\Server::get(IUserConfig::class)->searchUsersByValueString($appName, $key, $value, true));
return $result;
}
public function getSystemConfig() {
return $this->systemConfig;
}

View file

@ -1034,12 +1034,12 @@ class Server extends ServerContainer implements IServerContainer {
$backgroundService,
);
return new ThemingDefaults(
$c->get(\OCP\IConfig::class),
new AppConfig(
$c->get(\OCP\IConfig::class),
$c->get(\OCP\IAppConfig::class),
'theming',
),
$c->get(IUserConfig::class),
$c->get(IFactory::class)->get('theming'),
$c->get(IUserSession::class),
$c->get(IURLGenerator::class),

View file

@ -9,6 +9,7 @@ namespace OC\User;
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 @@ class Manager extends PublicEmitter implements IUserManager {
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;
}
/**

View file

@ -164,6 +164,7 @@ interface IConfig {
* @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 @@ interface IConfig {
* @param mixed $default the default value to be returned if the value isn't set
* @return string
* @since 6.0.0 - parameter $default was added in 7.0.0
* @deprecated 33.0.0 - use {@see IUserConfig} directly
*/
public function getUserValue($userId, $appName, $key, $default = '');
@ -186,6 +188,7 @@ interface IConfig {
* @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 @@ interface IConfig {
* @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 @@ interface IConfig {
* [ $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 @@ interface IConfig {
* @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 @@ interface IConfig {
*
* @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 @@ interface IConfig {
*
* @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 @@ interface IConfig {
* @param string $key the key to get the user for
* @param string $value the value to get the user for
* @return list<string> of user IDs
* @since 31.0.0 return type of `list<string>`
* @since 33.0.0 return type of `list<string>`
* @since 8.0.0
* @deprecated 33.0.0 - use {@see IUserConfig::searchUsersByValueString} directly
*/
public function getUsersForUserValue($appName, $key, $value);
}

View file

@ -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 @@ class AllConfigTest extends \Test\TestCase {
// 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);
}
}

View file

@ -13,6 +13,7 @@ use OC\USER\BACKEND;
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 @@ class ManagerTest extends TestCase {
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 @@ class ManagerTest extends TestCase {
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 @@ class ManagerTest extends TestCase {
}
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 @@ class ManagerTest extends TestCase {
}
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 @@ class ManagerTest extends TestCase {
}
});
$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 @@ class ManagerTest extends TestCase {
}
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 @@ class ManagerTest extends TestCase {
->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 @@ class ManagerTest extends TestCase {
$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 @@ class ManagerTest extends TestCase {
$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 @@ class ManagerTest extends TestCase {
$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 @@ class ManagerTest extends TestCase {
}
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 @@ class ManagerTest extends TestCase {
$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 @@ class ManagerTest extends TestCase {
$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 @@ class ManagerTest extends TestCase {
#[\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 @@ class ManagerTest extends TestCase {
->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 @@ class ManagerTest extends TestCase {
}
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 @@ class ManagerTest extends TestCase {
$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 @@ class ManagerTest extends TestCase {
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 @@ class ManagerTest extends TestCase {
->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 @@ class ManagerTest extends TestCase {
$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 @@ class ManagerTest extends TestCase {
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 @@ class ManagerTest extends TestCase {
->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 @@ class ManagerTest extends TestCase {
->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 @@ class ManagerTest extends TestCase {
}
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 @@ class ManagerTest extends TestCase {
}
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 @@ class ManagerTest extends TestCase {
->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 @@ class ManagerTest extends TestCase {
->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 @@ class ManagerTest extends TestCase {
->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 @@ class ManagerTest extends TestCase {
}
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']);
->willReturnCallback(function () {
yield 'uid1';
yield 'uid99';
yield 'uid2';
});
$backend = $this->createMock(\Test\Util\User\Dummy::class);
$backend->expects($this->exactly(3))
->method('userExists')
->willReturnMap([
['uid1', true],
['uid99', false],
['uid2', true]
]);
$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);