From a661f655f535aeb4787797df9531d4420cc69798 Mon Sep 17 00:00:00 2001 From: GretaD Date: Wed, 29 Apr 2020 14:42:07 +0200 Subject: [PATCH] Fix languages empty array Signed-off-by: GretaD --- .../lib/Controller/AUserData.php | 2 +- .../tests/Controller/UsersControllerTest.php | 107 ++++++++++-------- .../lib/Controller/UsersController.php | 1 + lib/private/L10N/Factory.php | 13 ++- 4 files changed, 74 insertions(+), 49 deletions(-) diff --git a/apps/provisioning_api/lib/Controller/AUserData.php b/apps/provisioning_api/lib/Controller/AUserData.php index 2bc81e9dcf9da..fb3dcd05953d4 100644 --- a/apps/provisioning_api/lib/Controller/AUserData.php +++ b/apps/provisioning_api/lib/Controller/AUserData.php @@ -145,7 +145,7 @@ protected function getUserData(string $userId): array { $data[AccountManager::PROPERTY_WEBSITE] = $userAccount[AccountManager::PROPERTY_WEBSITE]['value']; $data[AccountManager::PROPERTY_TWITTER] = $userAccount[AccountManager::PROPERTY_TWITTER]['value']; $data['groups'] = $gids; - $data['language'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'lang'); + $data['language'] = $this->config->getSystemValue('force_language', $this->config->getUserValue($targetUserObject->getUID(), 'core', 'lang')); $data['locale'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'locale'); $backend = $targetUserObject->getBackend(); diff --git a/apps/provisioning_api/tests/Controller/UsersControllerTest.php b/apps/provisioning_api/tests/Controller/UsersControllerTest.php index ac2da91005e0c..58c03f984b2a4 100644 --- a/apps/provisioning_api/tests/Controller/UsersControllerTest.php +++ b/apps/provisioning_api/tests/Controller/UsersControllerTest.php @@ -225,7 +225,7 @@ public function testGetUsersAsSubAdmin() { $this->assertEquals($expected, $this->api->getUsers('MyCustomSearch')->getData()); } - + public function testAddUserAlreadyExisting() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionCode(102); @@ -259,7 +259,7 @@ public function testAddUserAlreadyExisting() { $this->api->addUser('AlreadyExistingUser', 'password', '', '', []); } - + public function testAddUserNonExistingGroup() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionMessage('group NonExistingGroup does not exist'); @@ -295,7 +295,7 @@ public function testAddUserNonExistingGroup() { $this->api->addUser('NewUser', 'pass', '', '', ['NonExistingGroup']); } - + public function testAddUserExistingGroupNonExistingGroup() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionMessage('group NonExistingGroup does not exist'); @@ -485,7 +485,7 @@ public function testAddUserSuccessfulGenerateUserID() { )); } - + public function testAddUserFailedToGenerateUserID() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionMessage('Could not create non-existing user id'); @@ -528,7 +528,7 @@ public function testAddUserFailedToGenerateUserID() { $this->api->addUser('', 'PasswordOfTheNewUser')->getData(); } - + public function testAddUserEmailRequired() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionMessage('Required email address was not provided'); @@ -635,7 +635,7 @@ public function testAddUserExistingGroup() { )); } - + public function testAddUserUnsuccessful() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionMessage('Bad request'); @@ -680,7 +680,7 @@ public function testAddUserUnsuccessful() { $this->api->addUser('NewUser', 'PasswordOfTheNewUser'); } - + public function testAddUserAsSubAdminNoGroup() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionMessage('no group specified (required for subadmins)'); @@ -713,7 +713,7 @@ public function testAddUserAsSubAdminNoGroup() { $this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', '', []); } - + public function testAddUserAsSubAdminValidGroupNotSubAdmin() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionMessage('insufficient privileges for group ExistingGroup'); @@ -856,7 +856,7 @@ public function testAddUserAsSubAdminExistingGroups() { )); } - + public function testGetUserTargetDoesNotExist() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionMessage('User does not exist'); @@ -956,6 +956,11 @@ public function testGetUserDataAsAdmin() { ->method('getUserValue') ->with('UID', 'core', 'lang') ->will($this->returnValue('de')); + $this->config + ->expects($this->once()) + ->method('getSystemValue') + ->with('force_language', 'de') + ->willRreturn('de'); $this->api ->expects($this->once()) ->method('fillStorageInfo') @@ -1071,6 +1076,11 @@ public function testGetUserDataAsSubAdminAndUserIsAccessible() { ->method('getUserValue') ->with('UID', 'core', 'enabled', 'true') ->will($this->returnValue('true')); + $this->config + ->expects($this->once()) + ->method('getSystemValue') + ->with('force_language', 'da') + ->willReturn('da'); $this->config ->expects($this->at(1)) ->method('getUserValue') @@ -1148,7 +1158,7 @@ public function testGetUserDataAsSubAdminAndUserIsAccessible() { } - + public function testGetUserDataAsSubAdminAndUserIsNotAccessible() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionCode(997); @@ -1243,6 +1253,11 @@ public function testGetUserDataAsSubAdminSelfLookup() { ->method('fillStorageInfo') ->with('UID') ->will($this->returnValue(['DummyValue'])); + $this->config + ->expects($this->once()) + ->method('getSystemValue') + ->with('force_language', 'ru') + ->willReturn('ru'); $backend = $this->createMock(UserInterface::class); $backend->expects($this->atLeastOnce()) @@ -1382,7 +1397,7 @@ public function testEditUserRegularUserSelfEditChangeEmailValid() { } - + public function testEditUserRegularUserSelfEditChangeEmailInvalid() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionCode(102); @@ -1451,7 +1466,7 @@ public function testEditUserRegularUserSelfEditChangePassword() { } - + public function testEditUserRegularUserSelfEditChangeQuota() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionCode(997); @@ -1516,7 +1531,7 @@ public function testEditUserAdminUserSelfEditChangeValidQuota() { } - + public function testEditUserAdminUserSelfEditChangeInvalidQuota() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionMessage('Invalid quota value ABC'); @@ -1809,7 +1824,7 @@ public function testEditUserSubadminUserAccessible() { $this->assertEquals([], $this->api->editUser('UserToEdit', 'quota', '3042824')->getData()); } - + public function testEditUserSubadminUserInaccessible() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionCode(997); @@ -1849,7 +1864,7 @@ public function testEditUserSubadminUserInaccessible() { $this->api->editUser('UserToEdit', 'quota', 'value'); } - + public function testDeleteUserNotExistingUser() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionCode(101); @@ -1872,7 +1887,7 @@ public function testDeleteUserNotExistingUser() { $this->api->deleteUser('UserToDelete'); } - + public function testDeleteUserSelf() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionCode(101); @@ -1933,7 +1948,7 @@ public function testDeleteSuccessfulUserAsAdmin() { $this->assertEquals([], $this->api->deleteUser('UserToDelete')->getData()); } - + public function testDeleteUnsuccessfulUserAsAdmin() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionCode(101); @@ -2014,7 +2029,7 @@ public function testDeleteSuccessfulUserAsSubadmin() { $this->assertEquals([], $this->api->deleteUser('UserToDelete')->getData()); } - + public function testDeleteUnsuccessfulUserAsSubadmin() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionCode(101); @@ -2062,7 +2077,7 @@ public function testDeleteUnsuccessfulUserAsSubadmin() { $this->api->deleteUser('UserToDelete'); } - + public function testDeleteUserAsSubAdminAndUserIsNotAccessible() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionCode(997); @@ -2106,7 +2121,7 @@ public function testDeleteUserAsSubAdminAndUserIsNotAccessible() { $this->api->deleteUser('UserToDelete'); } - + public function testGetUsersGroupsTargetUserNotExisting() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionCode(998); @@ -2243,7 +2258,7 @@ public function testGetUsersGroupsForSubAdminUserAndUserIsAccessible() { $this->assertEquals(['groups' => ['Group1']], $this->api->getUsersGroups('UserToLookup')->getData()); } - + public function testGetUsersGroupsForSubAdminUserAndUserIsInaccessible() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionCode(997); @@ -2292,7 +2307,7 @@ public function testGetUsersGroupsForSubAdminUserAndUserIsInaccessible() { $this->api->getUsersGroups('UserToLookup'); } - + public function testAddToGroupWithTargetGroupNotExisting() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionCode(102); @@ -2305,7 +2320,7 @@ public function testAddToGroupWithTargetGroupNotExisting() { $this->api->addToGroup('TargetUser', 'GroupToAddTo'); } - + public function testAddToGroupWithNoGroupSpecified() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionCode(101); @@ -2313,7 +2328,7 @@ public function testAddToGroupWithNoGroupSpecified() { $this->api->addToGroup('TargetUser'); } - + public function testAddToGroupWithTargetUserNotExisting() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionCode(103); @@ -2327,7 +2342,7 @@ public function testAddToGroupWithTargetUserNotExisting() { $this->api->addToGroup('TargetUser', 'GroupToAddTo'); } - + public function testAddToGroupNoSubadmin() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionCode(104); @@ -2461,7 +2476,7 @@ public function testAddToGroupSuccessAsAdmin() { $this->assertEquals(new DataResponse(), $this->api->addToGroup('TargetUser', 'GroupToAddTo')); } - + public function testRemoveFromGroupWithNoTargetGroup() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionCode(101); @@ -2475,7 +2490,7 @@ public function testRemoveFromGroupWithNoTargetGroup() { $this->api->removeFromGroup('TargetUser', ''); } - + public function testRemoveFromGroupWithEmptyTargetGroup() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionCode(101); @@ -2489,7 +2504,7 @@ public function testRemoveFromGroupWithEmptyTargetGroup() { $this->api->removeFromGroup('TargetUser', ''); } - + public function testRemoveFromGroupWithNotExistingTargetGroup() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionCode(102); @@ -2508,7 +2523,7 @@ public function testRemoveFromGroupWithNotExistingTargetGroup() { $this->api->removeFromGroup('TargetUser', 'TargetGroup'); } - + public function testRemoveFromGroupWithNotExistingTargetUser() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionCode(103); @@ -2533,7 +2548,7 @@ public function testRemoveFromGroupWithNotExistingTargetUser() { $this->api->removeFromGroup('TargetUser', 'TargetGroup'); } - + public function testRemoveFromGroupWithoutPermission() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionCode(104); @@ -2574,7 +2589,7 @@ public function testRemoveFromGroupWithoutPermission() { $this->api->removeFromGroup('TargetUser', 'TargetGroup'); } - + public function testRemoveFromGroupAsAdminFromAdmin() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionMessage('Cannot remove yourself from the admin group'); @@ -2624,7 +2639,7 @@ public function testRemoveFromGroupAsAdminFromAdmin() { $this->api->removeFromGroup('Admin', 'admin'); } - + public function testRemoveFromGroupAsSubAdminFromSubAdmin() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionMessage('Cannot remove yourself from this group as you are a SubAdmin'); @@ -2679,7 +2694,7 @@ public function testRemoveFromGroupAsSubAdminFromSubAdmin() { $this->api->removeFromGroup('SubAdmin', 'subadmin'); } - + public function testRemoveFromGroupAsSubAdminFromLastSubAdminGroup() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionMessage('Not viable to remove user from the last group you are SubAdmin of'); @@ -2782,7 +2797,7 @@ public function testRemoveFromGroupSuccessful() { $this->assertEquals([], $this->api->removeFromGroup('AnotherUser', 'admin')->getData()); } - + public function testAddSubAdminWithNotExistingTargetUser() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionMessage('User does not exist'); @@ -2797,7 +2812,7 @@ public function testAddSubAdminWithNotExistingTargetUser() { $this->api->addSubAdmin('NotExistingUser', ''); } - + public function testAddSubAdminWithNotExistingTargetGroup() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionMessage('Group does not exist'); @@ -2819,7 +2834,7 @@ public function testAddSubAdminWithNotExistingTargetGroup() { $this->api->addSubAdmin('ExistingUser', 'NotExistingGroup'); } - + public function testAddSubAdminToAdminGroup() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionMessage('Cannot create subadmins for admin group'); @@ -2906,7 +2921,7 @@ public function testAddSubAdminSuccessful() { $this->assertEquals([], $this->api->addSubAdmin('ExistingUser', 'TargetGroup')->getData()); } - + public function testRemoveSubAdminNotExistingTargetUser() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionMessage('User does not exist'); @@ -2921,7 +2936,7 @@ public function testRemoveSubAdminNotExistingTargetUser() { $this->api->removeSubAdmin('NotExistingUser', 'GroupToDeleteFrom'); } - + public function testRemoveSubAdminNotExistingTargetGroup() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionMessage('Group does not exist'); @@ -2943,7 +2958,7 @@ public function testRemoveSubAdminNotExistingTargetGroup() { } - + public function testRemoveSubAdminFromNotASubadmin() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionMessage('User is not a subadmin of this group'); @@ -3009,7 +3024,7 @@ public function testRemoveSubAdminSuccessful() { $this->assertEquals([], $this->api->removeSubAdmin('ExistingUser', 'GroupToDeleteFrom')->getData()); } - + public function testGetUserSubAdminGroupsNotExistingTargetUser() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionMessage('User does not exist'); @@ -3163,7 +3178,7 @@ public function testGetCurrentUserLoggedIn() { $this->assertSame($expected, $api->getCurrentUser()->getData()); } - + public function testGetCurrentUserNotLoggedIn() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); @@ -3216,7 +3231,7 @@ public function testGetUser() { $this->assertSame($expected, $api->getUser('uid')->getData()); } - + public function testResendWelcomeMessageWithNotExistingTargetUser() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionCode(998); @@ -3230,7 +3245,7 @@ public function testResendWelcomeMessageWithNotExistingTargetUser() { $this->api->resendWelcomeMessage('NotExistingUser'); } - + public function testResendWelcomeMessageAsSubAdminAndUserIsNotAccessible() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionCode(997); @@ -3275,7 +3290,7 @@ public function testResendWelcomeMessageAsSubAdminAndUserIsNotAccessible() { $this->api->resendWelcomeMessage('UserToGet'); } - + public function testResendWelcomeMessageNoEmail() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionMessage('Email address not available'); @@ -3316,7 +3331,7 @@ public function testResendWelcomeMessageNoEmail() { $this->api->resendWelcomeMessage('UserToGet'); } - + public function testResendWelcomeMessageNullEmail() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionMessage('Email address not available'); @@ -3456,7 +3471,7 @@ public function testResendWelcomeMessageSuccessWithFallbackLanguage() { $this->api->resendWelcomeMessage('UserToGet'); } - + public function testResendWelcomeMessageFailed() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); $this->expectExceptionMessage('Sending email failed'); diff --git a/apps/settings/lib/Controller/UsersController.php b/apps/settings/lib/Controller/UsersController.php index 107f047aa30ac..598841a9022c5 100644 --- a/apps/settings/lib/Controller/UsersController.php +++ b/apps/settings/lib/Controller/UsersController.php @@ -274,6 +274,7 @@ public function usersList() { $serverData['userCount'] = $userCount; $serverData['languages'] = $languages; $serverData['defaultLanguage'] = $this->config->getSystemValue('default_language', 'en'); + $serverData['forceLanguage'] = $this->config->getSystemValue('force_language', false); // Settings $serverData['defaultQuota'] = $defaultQuota; $serverData['canChangePassword'] = $canChangePassword; diff --git a/lib/private/L10N/Factory.php b/lib/private/L10N/Factory.php index bba5538588265..00e4bdcc60c5d 100644 --- a/lib/private/L10N/Factory.php +++ b/lib/private/L10N/Factory.php @@ -264,7 +264,7 @@ public function findLanguageFromLocale(string $app = 'core', string $locale = nu if ($this->languageExists($app, $locale)) { return $locale; } - + // Try to split e.g: fr_FR => fr $locale = explode('_', $locale)[0]; if ($this->languageExists($app, $locale)) { @@ -586,7 +586,16 @@ public function createPluralFunction($string) { public function getLanguages() { $forceLanguage = $this->config->getSystemValue('force_language', false); if ($forceLanguage !== false) { - return []; + $l = $this->get('lib', $forceLanguage); + $potentialName = (string) $l->t('__language_name__'); + + return [ + 'commonlanguages' => [[ + 'code' => $forceLanguage, + 'name' => $potentialName, + ]], + 'languages' => [], + ]; } $languageCodes = $this->findAvailableLanguages();