Skip to content

Commit ea9ee80

Browse files
committed
refactor(user_ldap): Port most of the remaining deprecated IConfig usage
Signed-off-by: Carl Schwan <carl.schwan@nextcloud.com>
1 parent f6fcace commit ea9ee80

28 files changed

Lines changed: 320 additions & 475 deletions

apps/dav/lib/CalDAV/Schedule/IMipService.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
use OC\URLGenerator;
1212
use OCA\DAV\CalDAV\EventReader;
1313
use OCP\AppFramework\Utility\ITimeFactory;
14-
use OCP\IConfig;
14+
use OCP\Config\IUserConfig;
15+
use OCP\IAppConfig;
1516
use OCP\IDBConnection;
1617
use OCP\IL10N;
1718
use OCP\IUserManager;
@@ -40,12 +41,13 @@ class IMipService {
4041

4142
public function __construct(
4243
private URLGenerator $urlGenerator,
43-
private IConfig $config,
4444
private IDBConnection $db,
4545
private ISecureRandom $random,
4646
private L10NFactory $l10nFactory,
4747
private ITimeFactory $timeFactory,
4848
private readonly IUserManager $userManager,
49+
private readonly IUserConfig $userConfig,
50+
private readonly IAppConfig $appConfig,
4951
) {
5052
$language = $this->l10nFactory->findGenericLanguage();
5153
$locale = $this->l10nFactory->findLocale($language);
@@ -885,8 +887,8 @@ public function setL10nFromAttendee(Property $attendee) {
885887
$users = $this->userManager->getByEmail($userAddress);
886888
if ($users !== []) {
887889
$user = array_shift($users);
888-
$language = $this->config->getUserValue($user->getUID(), 'core', 'lang', null);
889-
$locale = $this->config->getUserValue($user->getUID(), 'core', 'locale', null);
890+
$language = $this->userConfig->getValueString($user->getUID(), 'core', 'lang', '') ?: null;
891+
$locale = $this->userConfig->getValueString($user->getUID(), 'core', 'locale', '') ?: null;
890892
}
891893
// fallback to attendee LANGUAGE parameter if language not set
892894
if ($language === null && isset($attendee['LANGUAGE']) && $attendee['LANGUAGE'] instanceof Parameter) {
@@ -994,20 +996,20 @@ public function getAbsoluteImagePath($path): string {
994996
* The default is 'no', which matches old behavior, and is privacy preserving.
995997
*
996998
* To enable including attendees in invitation emails:
997-
* % php occ config:app:set dav invitation_list_attendees --value yes
999+
* % php occ config:app:set dav invitation_list_attendees --value yes --type bool
9981000
*
9991001
* @param IEMailTemplate $template
10001002
* @param IL10N $this->l10n
10011003
* @param VEvent $vevent
10021004
* @author brad2014 on github.com
10031005
*/
10041006
public function addAttendees(IEMailTemplate $template, VEvent $vevent) {
1005-
if ($this->config->getAppValue('dav', 'invitation_list_attendees', 'no') === 'no') {
1007+
if (!$this->appConfig->getValueBool('dav', 'invitation_list_attendees')) {
10061008
return;
10071009
}
10081010

10091011
if (isset($vevent->ORGANIZER)) {
1010-
/** @var Property | Property\ICalendar\CalAddress $organizer */
1012+
/** @var Property&Property\ICalendar\CalAddress $organizer */
10111013
$organizer = $vevent->ORGANIZER;
10121014
$organizerEmail = substr($organizer->getNormalizedValue(), 7);
10131015
/** @var string|null $organizerName */
@@ -1037,8 +1039,14 @@ public function addAttendees(IEMailTemplate $template, VEvent $vevent) {
10371039
$attendeesHTML = [];
10381040
$attendeesText = [];
10391041
foreach ($attendees as $attendee) {
1042+
/** @var Property&Property\ICalendar\CalAddress $attendee */
10401043
$attendeeEmail = substr($attendee->getNormalizedValue(), 7);
1041-
$attendeeName = isset($attendee['CN']) ? $attendee['CN']->getValue() : null;
1044+
$attendeeName = null;
1045+
if (isset($attendee['CN'])) {
1046+
/** @var Parameter $cn */
1047+
$cn = $attendee['CN'];
1048+
$attendeeName = $cn->getValue();
1049+
}
10421050
$attendeeHTML = sprintf('<a href="%s">%s</a>',
10431051
htmlspecialchars($attendee->getNormalizedValue()),
10441052
htmlspecialchars($attendeeName ?: $attendeeEmail));

apps/dav/lib/CalDAV/TimezoneService.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use OCA\DAV\Db\PropertyMapper;
1313
use OCP\Calendar\ICalendar;
1414
use OCP\Calendar\IManager;
15+
use OCP\Config\IUserConfig;
1516
use OCP\IConfig;
1617
use Sabre\VObject\Component\VCalendar;
1718
use Sabre\VObject\Component\VTimeZone;
@@ -22,13 +23,14 @@ class TimezoneService {
2223

2324
public function __construct(
2425
private IConfig $config,
26+
private IUserConfig $userConfig,
2527
private PropertyMapper $propertyMapper,
2628
private IManager $calendarManager,
2729
) {
2830
}
2931

3032
public function getUserTimezone(string $userId): ?string {
31-
$fromConfig = $this->config->getUserValue(
33+
$fromConfig = $this->userConfig->getValueString(
3234
$userId,
3335
'core',
3436
'timezone',
@@ -51,7 +53,7 @@ public function getUserTimezone(string $userId): ?string {
5153
}
5254

5355
$principal = 'principals/users/' . $userId;
54-
$uri = $this->config->getUserValue($userId, 'dav', 'defaultCalendar', CalDavBackend::PERSONAL_CALENDAR_URI);
56+
$uri = $this->userConfig->getValueString($userId, 'dav', 'defaultCalendar', CalDavBackend::PERSONAL_CALENDAR_URI);
5557
$calendars = $this->calendarManager->getCalendarsForPrincipal($principal);
5658

5759
/** @var ?VTimeZone $personalCalendarTimezone */

apps/files_trashbin/lib/Trashbin.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use OCP\App\IAppManager;
2525
use OCP\AppFramework\Utility\ITimeFactory;
2626
use OCP\Command\IBus;
27+
use OCP\Config\IUserConfig;
2728
use OCP\EventDispatcher\Event;
2829
use OCP\EventDispatcher\IEventDispatcher;
2930
use OCP\EventDispatcher\IEventListener;
@@ -38,6 +39,7 @@
3839
use OCP\Files\Storage\ILockingStorage;
3940
use OCP\Files\Storage\IStorage;
4041
use OCP\FilesMetadata\IFilesMetadataManager;
42+
use OCP\IAppConfig;
4143
use OCP\IConfig;
4244
use OCP\IDBConnection;
4345
use OCP\IRequest;
@@ -368,12 +370,14 @@ public static function move2trash($file_path, $ownerOnly = false) {
368370
}
369371

370372
private static function getConfiguredTrashbinSize(string $user): int|float {
371-
$config = Server::get(IConfig::class);
372-
$userTrashbinSize = $config->getUserValue($user, 'files_trashbin', 'trashbin_size', '-1');
373+
$userConfig = Server::get(IUserConfig::class);
374+
$userTrashbinSize = $userConfig->getValueString($user, 'files_trashbin', 'trashbin_size', '-1');
373375
if (is_numeric($userTrashbinSize) && ($userTrashbinSize > -1)) {
374376
return Util::numericToNumber($userTrashbinSize);
375377
}
376-
$systemTrashbinSize = $config->getAppValue('files_trashbin', 'trashbin_size', '-1');
378+
379+
$appConfig = Server::get(IAppConfig::class);
380+
$systemTrashbinSize = $appConfig->getValueString('files_trashbin', 'trashbin_size', '-1');
377381
if (is_numeric($systemTrashbinSize)) {
378382
return Util::numericToNumber($systemTrashbinSize);
379383
}

apps/theming/lib/ThemingDefaults.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
use OCP\App\AppPathNotFoundException;
1212
use OCP\App\IAppManager;
1313
use OCP\AppFramework\Services\IAppConfig;
14+
use OCP\Config\IUserConfig;
1415
use OCP\Files\NotFoundException;
1516
use OCP\Files\SimpleFS\ISimpleFile;
1617
use OCP\ICacheFactory;
17-
use OCP\IConfig;
1818
use OCP\IL10N;
1919
use OCP\INavigationManager;
2020
use OCP\IURLGenerator;
@@ -40,17 +40,17 @@ class ThemingDefaults extends \OC_Defaults {
4040
* ThemingDefaults constructor.
4141
*/
4242
public function __construct(
43-
private IConfig $config,
44-
private IAppConfig $appConfig,
45-
private IL10N $l,
46-
private IUserSession $userSession,
47-
private IURLGenerator $urlGenerator,
48-
private ICacheFactory $cacheFactory,
49-
private Util $util,
50-
private ImageManager $imageManager,
51-
private IAppManager $appManager,
52-
private INavigationManager $navigationManager,
53-
private BackgroundService $backgroundService,
43+
private readonly IAppConfig $appConfig,
44+
private readonly IUserConfig $userConfig,
45+
private readonly IL10N $l,
46+
private readonly IUserSession $userSession,
47+
private readonly IURLGenerator $urlGenerator,
48+
private readonly ICacheFactory $cacheFactory,
49+
private readonly Util $util,
50+
private readonly ImageManager $imageManager,
51+
private readonly IAppManager $appManager,
52+
private readonly INavigationManager $navigationManager,
53+
private readonly BackgroundService $backgroundService,
5454
) {
5555
parent::__construct();
5656

@@ -183,7 +183,7 @@ public function getColorPrimary(): string {
183183

184184
// user-defined primary color
185185
if (!empty($user)) {
186-
$userPrimaryColor = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'primary_color', '');
186+
$userPrimaryColor = $this->userConfig->getValueString($user->getUID(), Application::APP_ID, 'primary_color');
187187
if (preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $userPrimaryColor)) {
188188
return $userPrimaryColor;
189189
}
@@ -209,7 +209,7 @@ public function getColorBackground(): string {
209209

210210
// user-defined background color
211211
if (!empty($user)) {
212-
$userBackgroundColor = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'background_color', '');
212+
$userBackgroundColor = $this->userConfig->getValueString($user->getUID(), Application::APP_ID, 'background_color');
213213
if (preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $userBackgroundColor)) {
214214
return $userBackgroundColor;
215215
}

apps/theming/tests/ThemingDefaultsTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use OCP\Files\NotFoundException;
1818
use OCP\ICache;
1919
use OCP\ICacheFactory;
20-
use OCP\IConfig;
2120
use OCP\IL10N;
2221
use OCP\INavigationManager;
2322
use OCP\IURLGenerator;
@@ -28,7 +27,7 @@
2827

2928
class ThemingDefaultsTest extends TestCase {
3029
private IAppConfig&MockObject $appConfig;
31-
private IConfig&MockObject $config;
30+
private IUserConfig&MockObject $userConfig;
3231
private IL10N&MockObject $l10n;
3332
private IUserSession&MockObject $userSession;
3433
private IURLGenerator&MockObject $urlGenerator;
@@ -46,7 +45,7 @@ class ThemingDefaultsTest extends TestCase {
4645
protected function setUp(): void {
4746
parent::setUp();
4847
$this->appConfig = $this->createMock(IAppConfig::class);
49-
$this->config = $this->createMock(IConfig::class);
48+
$this->userConfig = $this->createMock(IUserConfig::class);
5049
$this->l10n = $this->createMock(IL10N::class);
5150
$this->userSession = $this->createMock(IUserSession::class);
5251
$this->urlGenerator = $this->createMock(IURLGenerator::class);
@@ -63,8 +62,8 @@ protected function setUp(): void {
6362
->method('getBaseUrl')
6463
->willReturn('');
6564
$this->template = new ThemingDefaults(
66-
$this->config,
6765
$this->appConfig,
66+
$this->userConfig,
6867
$this->l10n,
6968
$this->userSession,
7069
$this->urlGenerator,

apps/user_ldap/lib/Access.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use OCP\EventDispatcher\IEventDispatcher;
1919
use OCP\HintException;
2020
use OCP\IAppConfig;
21-
use OCP\IConfig;
2221
use OCP\IGroupManager;
2322
use OCP\IUserManager;
2423
use OCP\Server;
@@ -55,7 +54,6 @@ public function __construct(
5554
public Connection $connection,
5655
public Manager $userManager,
5756
private Helper $helper,
58-
private IConfig $config,
5957
private IUserManager $ncUserManager,
6058
private LoggerInterface $logger,
6159
private IAppConfig $appConfig,
@@ -1572,14 +1570,12 @@ private function getFilterPartForSearch(string $search, $searchAttributes, strin
15721570
* a *
15731571
*/
15741572
private function prepareSearchTerm(string $term): string {
1575-
$config = Server::get(IConfig::class);
1576-
1577-
$allowEnum = $config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes');
1573+
$allowEnum = $this->appConfig->getValueBool('core', 'shareapi_allow_share_dialog_user_enumeration', true);
15781574

15791575
$result = $term;
15801576
if ($term === '') {
15811577
$result = '*';
1582-
} elseif ($allowEnum !== 'no') {
1578+
} elseif ($allowEnum) {
15831579
$result = $term . '*';
15841580
}
15851581
return $result;

apps/user_ldap/lib/AccessFactory.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use OCA\User_LDAP\User\Manager;
1010
use OCP\EventDispatcher\IEventDispatcher;
1111
use OCP\IAppConfig;
12-
use OCP\IConfig;
1312
use OCP\IUserManager;
1413
use OCP\Server;
1514
use Psr\Log\LoggerInterface;
@@ -19,7 +18,6 @@ class AccessFactory {
1918
public function __construct(
2019
private ILDAPWrapper $ldap,
2120
private Helper $helper,
22-
private IConfig $config,
2321
private IAppConfig $appConfig,
2422
private IUserManager $ncUserManager,
2523
private LoggerInterface $logger,
@@ -34,7 +32,6 @@ public function get(Connection $connection): Access {
3432
$connection,
3533
Server::get(Manager::class),
3634
$this->helper,
37-
$this->config,
3835
$this->ncUserManager,
3936
$this->logger,
4037
$this->appConfig,

apps/user_ldap/lib/AppInfo/Application.php

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
use OCP\IGroupManager;
3838
use OCP\IL10N;
3939
use OCP\Image;
40-
use OCP\IServerContainer;
40+
use OCP\IRequest;
41+
use OCP\IURLGenerator;
4142
use OCP\IUserManager;
4243
use OCP\Notification\IManager as INotificationManager;
4344
use OCP\Share\IManager as IShareManager;
@@ -56,27 +57,22 @@ public function __construct() {
5657
/**
5758
* Controller
5859
*/
59-
$container->registerService('RenewPasswordController', function (IAppContainer $appContainer) {
60-
/** @var IServerContainer $server */
61-
$server = $appContainer->get(IServerContainer::class);
62-
60+
$container->registerService('RenewPasswordController', function (ContainerInterface $appContainer) {
6361
return new RenewPasswordController(
6462
$appContainer->get('AppName'),
65-
$server->getRequest(),
66-
$appContainer->get('UserManager'),
67-
$server->getConfig(),
63+
$appContainer->get(IRequest::class),
64+
$appContainer->get(IUserManager::class),
65+
$appContainer->get(IConfig::class),
66+
$appContainer->get(IUserConfig::class),
6867
$appContainer->get(IL10N::class),
6968
$appContainer->get('Session'),
70-
$server->getURLGenerator()
69+
$appContainer->get(IURLGenerator::class),
7170
);
7271
});
7372

74-
$container->registerService(ILDAPWrapper::class, function (IAppContainer $appContainer) {
75-
/** @var IServerContainer $server */
76-
$server = $appContainer->get(IServerContainer::class);
77-
73+
$container->registerService(ILDAPWrapper::class, function (ContainerInterface $appContainer) {
7874
return new LDAP(
79-
$server->getConfig()->getSystemValueString('ldap_log_file')
75+
$appContainer->get(IConfig::class)->getSystemValueString('ldap_log_file')
8076
);
8177
});
8278
}

0 commit comments

Comments
 (0)