Skip to content

Commit 44f33ea

Browse files
committed
Use the new method everywhere
Signed-off-by: Joas Schilling <coding@schilljs.com>
1 parent b997eda commit 44f33ea

9 files changed

Lines changed: 53 additions & 120 deletions

File tree

apps/dav/lib/CalDAV/Reminder/NotificationProvider/AbstractProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ abstract class AbstractProvider implements INotificationProvider {
5454
protected $logger;
5555

5656
/** @var L10NFactory */
57-
private $l10nFactory;
57+
protected $l10nFactory;
5858

5959
/** @var IL10N[] */
6060
private $l10ns;

apps/dav/lib/CalDAV/Reminder/NotificationProvider/EmailProvider.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
use OCP\IL10N;
3636
use OCP\ILogger;
3737
use OCP\IURLGenerator;
38-
use OCP\IUser;
3938
use OCP\L10N\IFactory as L10NFactory;
4039
use OCP\Mail\IEMailTemplate;
4140
use OCP\Mail\IMailer;
@@ -349,7 +348,7 @@ private function getEMailAddressesOfAllUsersWithWriteAccessToCalendar(array $use
349348
foreach ($users as $user) {
350349
$emailAddress = $user->getEMailAddress();
351350
if ($emailAddress) {
352-
$lang = $this->getLangForUser($user);
351+
$lang = $this->l10nFactory->getUserLanguage($user);
353352
if ($lang) {
354353
$emailAddresses[$emailAddress] = [
355354
'LANG' => $lang,
@@ -363,14 +362,6 @@ private function getEMailAddressesOfAllUsersWithWriteAccessToCalendar(array $use
363362
return $emailAddresses;
364363
}
365364

366-
/**
367-
* @param IUser $user
368-
* @return string
369-
*/
370-
private function getLangForUser(IUser $user): ?string {
371-
return $this->config->getUserValue($user->getUID(), 'core', 'lang', null);
372-
}
373-
374365
/**
375366
* @param IL10N $l10n
376367
* @param VEvent $vevent

apps/provisioning_api/lib/Controller/AUserData.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
use OCP\IRequest;
4545
use OCP\IUserManager;
4646
use OCP\IUserSession;
47+
use OCP\L10N\IFactory;
4748
use OCP\User\Backend\ISetDisplayNameBackend;
4849
use OCP\User\Backend\ISetPasswordBackend;
4950

@@ -59,30 +60,25 @@ abstract class AUserData extends OCSController {
5960
protected $userSession;
6061
/** @var AccountManager */
6162
protected $accountManager;
63+
/** @var IFactory */
64+
protected $l10nFactory;
6265

63-
/**
64-
* @param string $appName
65-
* @param IRequest $request
66-
* @param IUserManager $userManager
67-
* @param IConfig $config
68-
* @param IGroupManager $groupManager
69-
* @param IUserSession $userSession
70-
* @param AccountManager $accountManager
71-
*/
7266
public function __construct(string $appName,
7367
IRequest $request,
7468
IUserManager $userManager,
7569
IConfig $config,
7670
IGroupManager $groupManager,
7771
IUserSession $userSession,
78-
AccountManager $accountManager) {
72+
AccountManager $accountManager,
73+
IFactory $l10nFactory) {
7974
parent::__construct($appName, $request);
8075

8176
$this->userManager = $userManager;
8277
$this->config = $config;
8378
$this->groupManager = $groupManager;
8479
$this->userSession = $userSession;
8580
$this->accountManager = $accountManager;
81+
$this->l10nFactory = $l10nFactory;
8682
}
8783

8884
/**
@@ -146,7 +142,7 @@ protected function getUserData(string $userId): array {
146142
$data[AccountManager::PROPERTY_WEBSITE] = $userAccount[AccountManager::PROPERTY_WEBSITE]['value'];
147143
$data[AccountManager::PROPERTY_TWITTER] = $userAccount[AccountManager::PROPERTY_TWITTER]['value'];
148144
$data['groups'] = $gids;
149-
$data['language'] = $this->config->getSystemValue('force_language', $this->config->getUserValue($targetUserObject->getUID(), 'core', 'lang'));
145+
$data['language'] = $this->l10nFactory->getUserLanguage($targetUserObject);
150146
$data['locale'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'locale');
151147

152148
$backend = $targetUserObject->getBackend();

apps/provisioning_api/lib/Controller/UsersController.php

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class UsersController extends AUserData {
6767
/** @var ILogger */
6868
private $logger;
6969
/** @var IFactory */
70-
private $l10nFactory;
70+
protected $l10nFactory;
7171
/** @var NewUserMailHelper */
7272
private $newUserMailHelper;
7373
/** @var FederatedFileSharingFactory */
@@ -77,21 +77,6 @@ class UsersController extends AUserData {
7777
/** @var RemoteWipe */
7878
private $remoteWipe;
7979

80-
/**
81-
* @param string $appName
82-
* @param IRequest $request
83-
* @param IUserManager $userManager
84-
* @param IConfig $config
85-
* @param IAppManager $appManager
86-
* @param IGroupManager $groupManager
87-
* @param IUserSession $userSession
88-
* @param AccountManager $accountManager
89-
* @param ILogger $logger
90-
* @param IFactory $l10nFactory
91-
* @param NewUserMailHelper $newUserMailHelper
92-
* @param FederatedFileSharingFactory $federatedFileSharingFactory
93-
* @param ISecureRandom $secureRandom
94-
*/
9580
public function __construct(string $appName,
9681
IRequest $request,
9782
IUserManager $userManager,
@@ -112,7 +97,8 @@ public function __construct(string $appName,
11297
$config,
11398
$groupManager,
11499
$userSession,
115-
$accountManager);
100+
$accountManager,
101+
$l10nFactory);
116102

117103
$this->appManager = $appManager;
118104
$this->logger = $logger;

apps/provisioning_api/tests/Controller/UsersControllerTest.php

Lines changed: 20 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -953,16 +953,6 @@ public function testGetUserDataAsAdmin() {
953953
->method('getUserValue')
954954
->with('UID', 'core', 'enabled', 'true')
955955
->willReturn('true');
956-
$this->config
957-
->expects($this->at(1))
958-
->method('getUserValue')
959-
->with('UID', 'core', 'lang')
960-
->willReturn('de');
961-
$this->config
962-
->expects($this->once())
963-
->method('getSystemValue')
964-
->with('force_language', 'de')
965-
->willReturn('de');
966956
$this->api
967957
->expects($this->once())
968958
->method('fillStorageInfo')
@@ -995,10 +985,15 @@ public function testGetUserDataAsAdmin() {
995985
->method('getBackend')
996986
->willReturn($backend);
997987
$targetUser
998-
->expects($this->exactly(6))
999988
->method('getUID')
1000989
->willReturn('UID');
1001990

991+
$this->l10nFactory
992+
->expects($this->once())
993+
->method('getUserLanguage')
994+
->with($targetUser)
995+
->willReturn('de');
996+
1002997
$expected = [
1003998
'id' => 'UID',
1004999
'enabled' => true,
@@ -1078,16 +1073,6 @@ public function testGetUserDataAsSubAdminAndUserIsAccessible() {
10781073
->method('getUserValue')
10791074
->with('UID', 'core', 'enabled', 'true')
10801075
->willReturn('true');
1081-
$this->config
1082-
->expects($this->once())
1083-
->method('getSystemValue')
1084-
->with('force_language', 'da')
1085-
->willReturn('da');
1086-
$this->config
1087-
->expects($this->at(1))
1088-
->method('getUserValue')
1089-
->with('UID', 'core', 'lang')
1090-
->willReturn('da');
10911076
$this->api
10921077
->expects($this->once())
10931078
->method('fillStorageInfo')
@@ -1120,7 +1105,6 @@ public function testGetUserDataAsSubAdminAndUserIsAccessible() {
11201105
->method('getBackend')
11211106
->willReturn($backend);
11221107
$targetUser
1123-
->expects($this->exactly(6))
11241108
->method('getUID')
11251109
->willReturn('UID');
11261110
$this->accountManager->expects($this->any())->method('getUser')
@@ -1134,6 +1118,12 @@ public function testGetUserDataAsSubAdminAndUserIsAccessible() {
11341118
]
11351119
);
11361120

1121+
$this->l10nFactory
1122+
->expects($this->once())
1123+
->method('getUserLanguage')
1124+
->with($targetUser)
1125+
->willReturn('da');
1126+
11371127
$expected = [
11381128
'id' => 'UID',
11391129
'enabled' => true,
@@ -1255,11 +1245,6 @@ public function testGetUserDataAsSubAdminSelfLookup() {
12551245
->method('fillStorageInfo')
12561246
->with('UID')
12571247
->willReturn(['DummyValue']);
1258-
$this->config
1259-
->expects($this->once())
1260-
->method('getSystemValue')
1261-
->with('force_language', 'ru')
1262-
->willReturn('ru');
12631248

12641249
$backend = $this->createMock(UserInterface::class);
12651250
$backend->expects($this->atLeastOnce())
@@ -1275,7 +1260,6 @@ public function testGetUserDataAsSubAdminSelfLookup() {
12751260
->method('getEMailAddress')
12761261
->willReturn('subadmin@nextcloud.com');
12771262
$targetUser
1278-
->expects($this->exactly(6))
12791263
->method('getUID')
12801264
->willReturn('UID');
12811265
$targetUser
@@ -1294,11 +1278,6 @@ public function testGetUserDataAsSubAdminSelfLookup() {
12941278
->expects($this->once())
12951279
->method('getBackend')
12961280
->willReturn($backend);
1297-
$this->config
1298-
->expects($this->at(0))
1299-
->method('getUserValue')
1300-
->with('UID', 'core', 'lang')
1301-
->willReturn('ru');
13021281
$this->accountManager->expects($this->any())->method('getUser')
13031282
->with($targetUser)
13041283
->willReturn(
@@ -1310,6 +1289,12 @@ public function testGetUserDataAsSubAdminSelfLookup() {
13101289
]
13111290
);
13121291

1292+
$this->l10nFactory
1293+
->expects($this->once())
1294+
->method('getUserLanguage')
1295+
->with($targetUser)
1296+
->willReturn('ru');
1297+
13131298
$expected = [
13141299
'id' => 'UID',
13151300
'storageLocation' => '/var/www/newtcloud/data/UID',
@@ -2911,8 +2896,7 @@ public function testAddSubAdminSuccessful() {
29112896
$subAdminManager
29122897
->expects($this->once())
29132898
->method('createSubAdmin')
2914-
->with($targetUser, $targetGroup)
2915-
->willReturn(true);
2899+
->with($targetUser, $targetGroup);
29162900
$this->groupManager
29172901
->expects($this->once())
29182902
->method('getSubAdmin')
@@ -3014,8 +2998,7 @@ public function testRemoveSubAdminSuccessful() {
30142998
$subAdminManager
30152999
->expects($this->once())
30163000
->method('deleteSubAdmin')
3017-
->with($targetUser, $targetGroup)
3018-
->willReturn(true);
3001+
->with($targetUser, $targetGroup);
30193002
$this->groupManager
30203003
->expects($this->once())
30213004
->method('getSubAdmin')

0 commit comments

Comments
 (0)