Skip to content

Commit 582bb11

Browse files
authored
Merge pull request #55631 from nextcloud/carl/deprecate-config-user-correctly
refactor: Deprecated user config from IConfig correctly
2 parents b15e294 + 1661855 commit 582bb11

38 files changed

+848
-784
lines changed

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;
@@ -41,12 +42,13 @@ class IMipService {
4142

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

10111013
if (isset($vevent->ORGANIZER)) {
1012-
/** @var Property | Property\ICalendar\CalAddress $organizer */
1014+
/** @var Property&Property\ICalendar\CalAddress $organizer */
10131015
$organizer = $vevent->ORGANIZER;
10141016
$organizerEmail = substr($organizer->getNormalizedValue(), 7);
10151017
/** @var string|null $organizerName */
@@ -1039,8 +1041,14 @@ public function addAttendees(IEMailTemplate $template, VEvent $vevent) {
10391041
$attendeesHTML = [];
10401042
$attendeesText = [];
10411043
foreach ($attendees as $attendee) {
1044+
/** @var Property&Property\ICalendar\CalAddress $attendee */
10421045
$attendeeEmail = substr($attendee->getNormalizedValue(), 7);
1043-
$attendeeName = isset($attendee['CN']) ? $attendee['CN']->getValue() : null;
1046+
$attendeeName = null;
1047+
if (isset($attendee['CN'])) {
1048+
/** @var Parameter $cn */
1049+
$cn = $attendee['CN'];
1050+
$attendeeName = $cn->getValue();
1051+
}
10441052
$attendeeHTML = sprintf('<a href="%s">%s</a>',
10451053
htmlspecialchars($attendee->getNormalizedValue()),
10461054
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/dav/tests/unit/CalDAV/Schedule/IMipPluginCharsetTest.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
use OCA\DAV\CalDAV\Schedule\IMipPlugin;
1515
use OCA\DAV\CalDAV\Schedule\IMipService;
1616
use OCP\AppFramework\Utility\ITimeFactory;
17+
use OCP\Config\IUserConfig;
1718
use OCP\Defaults;
1819
use OCP\IAppConfig;
19-
use OCP\IConfig;
2020
use OCP\IDBConnection;
2121
use OCP\IURLGenerator;
2222
use OCP\IUser;
@@ -46,7 +46,7 @@ class IMipPluginCharsetTest extends TestCase {
4646
// Dependencies
4747
private Defaults&MockObject $defaults;
4848
private IAppConfig&MockObject $appConfig;
49-
private IConfig&MockObject $config;
49+
private IUserConfig&MockObject $userConfig;
5050
private IDBConnection&MockObject $db;
5151
private IFactory $l10nFactory;
5252
private IManager&MockObject $mailManager;
@@ -77,7 +77,8 @@ protected function setUp(): void {
7777

7878
// IMipService
7979
$this->urlGenerator = $this->createMock(URLGenerator::class);
80-
$this->config = $this->createMock(IConfig::class);
80+
$this->userConfig = $this->createMock(IUserConfig::class);
81+
$this->appConfig = $this->createMock(IAppConfig::class);
8182
$this->db = $this->createMock(IDBConnection::class);
8283
$this->random = $this->createMock(ISecureRandom::class);
8384
$l10n = $this->createMock(L10N::class);
@@ -92,19 +93,19 @@ protected function setUp(): void {
9293
$this->userManager->method('getByEmail')->willReturn([]);
9394
$this->imipService = new IMipService(
9495
$this->urlGenerator,
95-
$this->config,
9696
$this->db,
9797
$this->random,
9898
$this->l10nFactory,
9999
$this->timeFactory,
100-
$this->userManager
100+
$this->userManager,
101+
$this->userConfig,
102+
$this->appConfig,
101103
);
102104

103105
// EventComparisonService
104106
$this->eventComparisonService = new EventComparisonService();
105107

106108
// IMipPlugin
107-
$this->appConfig = $this->createMock(IAppConfig::class);
108109
$message = new \OC\Mail\Message(new Email(), false);
109110
$this->mailer = $this->createMock(IMailer::class);
110111
$this->mailer->method('createMessage')
@@ -177,8 +178,13 @@ public function testCharsetMailer(): void {
177178
public function testCharsetMailProvider(): void {
178179
// Arrange
179180
$this->appConfig->method('getValueBool')
180-
->with('core', 'mail_providers_enabled', true)
181-
->willReturn(true);
181+
->willReturnCallback(function ($app, $key, $default) {
182+
if ($app === 'core') {
183+
$this->assertEquals($key, 'mail_providers_enabled');
184+
return true;
185+
}
186+
return $default;
187+
});
182188
$mailMessage = new MailProviderMessage();
183189
$mailService = $this->createMockForIntersectionOfInterfaces([IService::class, IMessageSend::class]);
184190
$mailService->method('initiateMessage')

apps/dav/tests/unit/CalDAV/Schedule/IMipServiceTest.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
use OCA\DAV\CalDAV\EventReader;
1414
use OCA\DAV\CalDAV\Schedule\IMipService;
1515
use OCP\AppFramework\Utility\ITimeFactory;
16-
use OCP\IConfig;
16+
use OCP\Config\IUserConfig;
17+
use OCP\IAppConfig;
1718
use OCP\IDBConnection;
1819
use OCP\IL10N;
1920
use OCP\IUserManager;
@@ -26,7 +27,8 @@
2627

2728
class IMipServiceTest extends TestCase {
2829
private URLGenerator&MockObject $urlGenerator;
29-
private IConfig&MockObject $config;
30+
private IUserConfig&MockObject $userConfig;
31+
private IAppConfig&MockObject $appConfig;
3032
private IDBConnection&MockObject $db;
3133
private ISecureRandom&MockObject $random;
3234
private IFactory&MockObject $l10nFactory;
@@ -47,7 +49,8 @@ protected function setUp(): void {
4749
parent::setUp();
4850

4951
$this->urlGenerator = $this->createMock(URLGenerator::class);
50-
$this->config = $this->createMock(IConfig::class);
52+
$this->userConfig = $this->createMock(IUserConfig::class);
53+
$this->appConfig = $this->createMock(IAppConfig::class);
5154
$this->db = $this->createMock(IDBConnection::class);
5255
$this->random = $this->createMock(ISecureRandom::class);
5356
$this->l10nFactory = $this->createMock(IFactory::class);
@@ -63,12 +66,13 @@ protected function setUp(): void {
6366
->willReturn($this->l10n);
6467
$this->service = new IMipService(
6568
$this->urlGenerator,
66-
$this->config,
6769
$this->db,
6870
$this->random,
6971
$this->l10nFactory,
7072
$this->timeFactory,
71-
$this->userManager
73+
$this->userManager,
74+
$this->userConfig,
75+
$this->appConfig,
7276
);
7377

7478
// construct calendar with a 1 hour event and same start/end time zones

apps/dav/tests/unit/CalDAV/TimezoneServiceTest.php

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,22 @@
99
namespace OCA\DAV\Tests\unit\CalDAV;
1010

1111
use DateTimeZone;
12+
use OCA\DAV\CalDAV\CalDavBackend;
1213
use OCA\DAV\CalDAV\CalendarImpl;
1314
use OCA\DAV\CalDAV\TimezoneService;
1415
use OCA\DAV\Db\Property;
1516
use OCA\DAV\Db\PropertyMapper;
1617
use OCP\Calendar\ICalendar;
1718
use OCP\Calendar\IManager;
19+
use OCP\Config\IUserConfig;
1820
use OCP\IConfig;
1921
use PHPUnit\Framework\MockObject\MockObject;
2022
use Sabre\VObject\Component\VTimeZone;
2123
use Test\TestCase;
2224

2325
class TimezoneServiceTest extends TestCase {
2426
private IConfig&MockObject $config;
27+
private IUserConfig&MockObject $userConfig;
2528
private PropertyMapper&MockObject $propertyMapper;
2629
private IManager&MockObject $calendarManager;
2730
private TimezoneService $service;
@@ -30,19 +33,21 @@ protected function setUp(): void {
3033
parent::setUp();
3134

3235
$this->config = $this->createMock(IConfig::class);
36+
$this->userConfig = $this->createMock(IUserConfig::class);
3337
$this->propertyMapper = $this->createMock(PropertyMapper::class);
3438
$this->calendarManager = $this->createMock(IManager::class);
3539

3640
$this->service = new TimezoneService(
3741
$this->config,
42+
$this->userConfig,
3843
$this->propertyMapper,
3944
$this->calendarManager,
4045
);
4146
}
4247

4348
public function testGetUserTimezoneFromSettings(): void {
44-
$this->config->expects(self::once())
45-
->method('getUserValue')
49+
$this->userConfig->expects(self::once())
50+
->method('getValueString')
4651
->with('test123', 'core', 'timezone', '')
4752
->willReturn('Europe/Warsaw');
4853

@@ -52,8 +57,8 @@ public function testGetUserTimezoneFromSettings(): void {
5257
}
5358

5459
public function testGetUserTimezoneFromAvailability(): void {
55-
$this->config->expects(self::once())
56-
->method('getUserValue')
60+
$this->userConfig->expects(self::once())
61+
->method('getValueString')
5762
->with('test123', 'core', 'timezone', '')
5863
->willReturn('');
5964
$property = new Property();
@@ -76,11 +81,11 @@ public function testGetUserTimezoneFromAvailability(): void {
7681
}
7782

7883
public function testGetUserTimezoneFromPersonalCalendar(): void {
79-
$this->config->expects(self::exactly(2))
80-
->method('getUserValue')
84+
$this->userConfig->expects(self::exactly(2))
85+
->method('getValueString')
8186
->willReturnMap([
82-
['test123', 'core', 'timezone', '', ''],
83-
['test123', 'dav', 'defaultCalendar', '', 'personal-1'],
87+
['test123', 'core', 'timezone', '', false, ''],
88+
['test123', 'dav', 'defaultCalendar', CalDavBackend::PERSONAL_CALENDAR_URI, false, 'personal-1'],
8489
]);
8590
$other = $this->createMock(ICalendar::class);
8691
$other->method('getUri')->willReturn('other');
@@ -105,11 +110,11 @@ public function testGetUserTimezoneFromPersonalCalendar(): void {
105110
}
106111

107112
public function testGetUserTimezoneFromAny(): void {
108-
$this->config->expects(self::exactly(2))
109-
->method('getUserValue')
113+
$this->userConfig->expects(self::exactly(2))
114+
->method('getValueString')
110115
->willReturnMap([
111-
['test123', 'core', 'timezone', '', ''],
112-
['test123', 'dav', 'defaultCalendar', '', 'personal-1'],
116+
['test123', 'core', 'timezone', '', false, ''],
117+
['test123', 'dav', 'defaultCalendar', CalDavBackend::PERSONAL_CALENDAR_URI, false, 'personal-1'],
113118
]);
114119
$other = $this->createMock(ICalendar::class);
115120
$other->method('getUri')->willReturn('other');

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
}

0 commit comments

Comments
 (0)