Use the new method everywhere

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2020-06-23 08:45:01 +02:00
parent b997edad10
commit db8267db26
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
12 changed files with 106 additions and 200 deletions

View File

@ -54,7 +54,7 @@ abstract class AbstractProvider implements INotificationProvider {
protected $logger; protected $logger;
/** @var L10NFactory */ /** @var L10NFactory */
private $l10nFactory; protected $l10nFactory;
/** @var IL10N[] */ /** @var IL10N[] */
private $l10ns; private $l10ns;

View File

@ -35,7 +35,6 @@ use OCP\IConfig;
use OCP\IL10N; use OCP\IL10N;
use OCP\ILogger; use OCP\ILogger;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use OCP\IUser;
use OCP\L10N\IFactory as L10NFactory; use OCP\L10N\IFactory as L10NFactory;
use OCP\Mail\IEMailTemplate; use OCP\Mail\IEMailTemplate;
use OCP\Mail\IMailer; use OCP\Mail\IMailer;
@ -349,7 +348,7 @@ class EmailProvider extends AbstractProvider {
foreach ($users as $user) { foreach ($users as $user) {
$emailAddress = $user->getEMailAddress(); $emailAddress = $user->getEMailAddress();
if ($emailAddress) { if ($emailAddress) {
$lang = $this->getLangForUser($user); $lang = $this->l10nFactory->getUserLanguage($user);
if ($lang) { if ($lang) {
$emailAddresses[$emailAddress] = [ $emailAddresses[$emailAddress] = [
'LANG' => $lang, 'LANG' => $lang,
@ -363,14 +362,6 @@ class EmailProvider extends AbstractProvider {
return $emailAddresses; return $emailAddresses;
} }
/**
* @param IUser $user
* @return string
*/
private function getLangForUser(IUser $user): ?string {
return $this->config->getUserValue($user->getUID(), 'core', 'lang', null);
}
/** /**
* @param IL10N $l10n * @param IL10N $l10n
* @param VEvent $vevent * @param VEvent $vevent

View File

@ -40,27 +40,28 @@ use OCP\L10N\IFactory as L10NFactory;
use OCP\Mail\IEMailTemplate; use OCP\Mail\IEMailTemplate;
use OCP\Mail\IMailer; use OCP\Mail\IMailer;
use OCP\Mail\IMessage; use OCP\Mail\IMessage;
use PHPUnit\Framework\MockObject\MockObject;
use Sabre\VObject\Component\VCalendar; use Sabre\VObject\Component\VCalendar;
class EmailProviderTest extends AbstractNotificationProviderTest { class EmailProviderTest extends AbstractNotificationProviderTest {
public const USER_EMAIL = 'frodo@hobb.it'; public const USER_EMAIL = 'frodo@hobb.it';
/** @var ILogger|\PHPUnit\Framework\MockObject\MockObject */ /** @var ILogger|MockObject */
protected $logger; protected $logger;
/** @var L10NFactory|\PHPUnit\Framework\MockObject\MockObject */ /** @var L10NFactory|MockObject */
protected $l10nFactory; protected $l10nFactory;
/** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */ /** @var IL10N|MockObject */
protected $l10n; protected $l10n;
/** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */ /** @var IURLGenerator|MockObject */
protected $urlGenerator; protected $urlGenerator;
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */ /** @var IConfig|MockObject */
protected $config; protected $config;
/** @var IMailer|\PHPUnit\Framework\MockObject\MockObject */ /** @var IMailer|MockObject */
private $mailer; private $mailer;
protected function setUp(): void { protected function setUp(): void {
@ -101,19 +102,6 @@ class EmailProviderTest extends AbstractNotificationProviderTest {
$users = [$user1, $user2, $user3, $user4]; $users = [$user1, $user2, $user3, $user4];
$this->config->expects($this->at(0))
->method('getUserValue')
->with('uid1', 'core', 'lang', null)
->willReturn(null);
$this->config->expects($this->at(1))
->method('getUserValue')
->with('uid2', 'core', 'lang', null)
->willReturn('de');
$this->config->expects($this->at(2))
->method('getUserValue')
->with('uid3', 'core', 'lang', null)
->willReturn('de');
$enL10N = $this->createMock(IL10N::class); $enL10N = $this->createMock(IL10N::class);
$enL10N->method('t') $enL10N->method('t')
->willReturnArgument(0); ->willReturnArgument(0);
@ -126,30 +114,31 @@ class EmailProviderTest extends AbstractNotificationProviderTest {
$deL10N->method('l') $deL10N->method('l')
->willReturnArgument(0); ->willReturnArgument(0);
$this->l10nFactory->expects($this->at(0)) $this->l10nFactory
->method('getUserLanguage')
->willReturnMap([
[$user1, 'en'],
[$user2, 'de'],
[$user3, 'de'],
]);
$this->l10nFactory
->method('findLanguage') ->method('findLanguage')
->with()
->willReturn('en'); ->willReturn('en');
$this->l10nFactory->expects($this->at(1)) $this->l10nFactory
->method('languageExists') ->method('languageExists')
->with('dav', 'en') ->willReturnMap([
->willReturn(true); ['dav', 'en', true],
['dav', 'de', true],
]);
$this->l10nFactory->expects($this->at(2)) $this->l10nFactory
->method('get') ->method('get')
->with('dav', 'en') ->willReturnMap([
->willReturn($enL10N); ['dav', 'en', null, $enL10N],
['dav', 'de', null, $deL10N],
$this->l10nFactory->expects($this->at(3)) ]);
->method('languageExists')
->with('dav', 'de')
->willReturn(true);
$this->l10nFactory->expects($this->at(4))
->method('get')
->with('dav', 'de')
->willReturn($deL10N);
$template1 = $this->getTemplateMock(); $template1 = $this->getTemplateMock();
$message11 = $this->getMessageMock('uid1@example.com', $template1); $message11 = $this->getMessageMock('uid1@example.com', $template1);
@ -223,19 +212,6 @@ class EmailProviderTest extends AbstractNotificationProviderTest {
$users = [$user1, $user2, $user3, $user4]; $users = [$user1, $user2, $user3, $user4];
$this->config->expects($this->at(0))
->method('getUserValue')
->with('uid1', 'core', 'lang', null)
->willReturn(null);
$this->config->expects($this->at(1))
->method('getUserValue')
->with('uid2', 'core', 'lang', null)
->willReturn('de');
$this->config->expects($this->at(2))
->method('getUserValue')
->with('uid3', 'core', 'lang', null)
->willReturn('de');
$enL10N = $this->createMock(IL10N::class); $enL10N = $this->createMock(IL10N::class);
$enL10N->method('t') $enL10N->method('t')
->willReturnArgument(0); ->willReturnArgument(0);
@ -248,30 +224,31 @@ class EmailProviderTest extends AbstractNotificationProviderTest {
$deL10N->method('l') $deL10N->method('l')
->willReturnArgument(0); ->willReturnArgument(0);
$this->l10nFactory->expects($this->at(0)) $this->l10nFactory
->method('getUserLanguage')
->willReturnMap([
[$user1, 'en'],
[$user2, 'de'],
[$user3, 'de'],
]);
$this->l10nFactory
->method('findLanguage') ->method('findLanguage')
->with()
->willReturn('en'); ->willReturn('en');
$this->l10nFactory->expects($this->at(1)) $this->l10nFactory
->method('languageExists') ->method('languageExists')
->with('dav', 'de') ->willReturnMap([
->willReturn(true); ['dav', 'en', true],
['dav', 'de', true],
]);
$this->l10nFactory->expects($this->at(2)) $this->l10nFactory
->method('get') ->method('get')
->with('dav', 'de') ->willReturnMap([
->willReturn($enL10N); ['dav', 'en', null, $enL10N],
['dav', 'de', null, $deL10N],
$this->l10nFactory->expects($this->at(3)) ]);
->method('languageExists')
->with('dav', 'en')
->willReturn(true);
$this->l10nFactory->expects($this->at(4))
->method('get')
->with('dav', 'en')
->willReturn($deL10N);
$template1 = $this->getTemplateMock(); $template1 = $this->getTemplateMock();
$message11 = $this->getMessageMock('foo1@example.org', $template1); $message11 = $this->getMessageMock('foo1@example.org', $template1);

View File

@ -44,6 +44,7 @@ use OCP\IGroupManager;
use OCP\IRequest; use OCP\IRequest;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\IUserSession; use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\User\Backend\ISetDisplayNameBackend; use OCP\User\Backend\ISetDisplayNameBackend;
use OCP\User\Backend\ISetPasswordBackend; use OCP\User\Backend\ISetPasswordBackend;
@ -59,23 +60,17 @@ abstract class AUserData extends OCSController {
protected $userSession; protected $userSession;
/** @var AccountManager */ /** @var AccountManager */
protected $accountManager; protected $accountManager;
/** @var IFactory */
protected $l10nFactory;
/**
* @param string $appName
* @param IRequest $request
* @param IUserManager $userManager
* @param IConfig $config
* @param IGroupManager $groupManager
* @param IUserSession $userSession
* @param AccountManager $accountManager
*/
public function __construct(string $appName, public function __construct(string $appName,
IRequest $request, IRequest $request,
IUserManager $userManager, IUserManager $userManager,
IConfig $config, IConfig $config,
IGroupManager $groupManager, IGroupManager $groupManager,
IUserSession $userSession, IUserSession $userSession,
AccountManager $accountManager) { AccountManager $accountManager,
IFactory $l10nFactory) {
parent::__construct($appName, $request); parent::__construct($appName, $request);
$this->userManager = $userManager; $this->userManager = $userManager;
@ -83,6 +78,7 @@ abstract class AUserData extends OCSController {
$this->groupManager = $groupManager; $this->groupManager = $groupManager;
$this->userSession = $userSession; $this->userSession = $userSession;
$this->accountManager = $accountManager; $this->accountManager = $accountManager;
$this->l10nFactory = $l10nFactory;
} }
/** /**
@ -146,7 +142,7 @@ abstract class AUserData extends OCSController {
$data[AccountManager::PROPERTY_WEBSITE] = $userAccount[AccountManager::PROPERTY_WEBSITE]['value']; $data[AccountManager::PROPERTY_WEBSITE] = $userAccount[AccountManager::PROPERTY_WEBSITE]['value'];
$data[AccountManager::PROPERTY_TWITTER] = $userAccount[AccountManager::PROPERTY_TWITTER]['value']; $data[AccountManager::PROPERTY_TWITTER] = $userAccount[AccountManager::PROPERTY_TWITTER]['value'];
$data['groups'] = $gids; $data['groups'] = $gids;
$data['language'] = $this->config->getSystemValue('force_language', $this->config->getUserValue($targetUserObject->getUID(), 'core', 'lang')); $data['language'] = $this->l10nFactory->getUserLanguage($targetUserObject);
$data['locale'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'locale'); $data['locale'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'locale');
$backend = $targetUserObject->getBackend(); $backend = $targetUserObject->getBackend();

View File

@ -47,23 +47,13 @@ use OCP\IRequest;
use OCP\IUser; use OCP\IUser;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\IUserSession; use OCP\IUserSession;
use OCP\L10N\IFactory;
class GroupsController extends AUserData { class GroupsController extends AUserData {
/** @var ILogger */ /** @var ILogger */
private $logger; private $logger;
/**
* @param string $appName
* @param IRequest $request
* @param IUserManager $userManager
* @param IConfig $config
* @param IGroupManager $groupManager
* @param IUserSession $userSession
* @param AccountManager $accountManager
* @param ILogger $logger
* @param UsersController $userController
*/
public function __construct(string $appName, public function __construct(string $appName,
IRequest $request, IRequest $request,
IUserManager $userManager, IUserManager $userManager,
@ -71,6 +61,7 @@ class GroupsController extends AUserData {
IGroupManager $groupManager, IGroupManager $groupManager,
IUserSession $userSession, IUserSession $userSession,
AccountManager $accountManager, AccountManager $accountManager,
IFactory $l10nFactory,
ILogger $logger) { ILogger $logger) {
parent::__construct($appName, parent::__construct($appName,
$request, $request,
@ -78,7 +69,9 @@ class GroupsController extends AUserData {
$config, $config,
$groupManager, $groupManager,
$userSession, $userSession,
$accountManager); $accountManager,
$l10nFactory
);
$this->logger = $logger; $this->logger = $logger;
} }

View File

@ -67,7 +67,7 @@ class UsersController extends AUserData {
/** @var ILogger */ /** @var ILogger */
private $logger; private $logger;
/** @var IFactory */ /** @var IFactory */
private $l10nFactory; protected $l10nFactory;
/** @var NewUserMailHelper */ /** @var NewUserMailHelper */
private $newUserMailHelper; private $newUserMailHelper;
/** @var FederatedFileSharingFactory */ /** @var FederatedFileSharingFactory */
@ -77,21 +77,6 @@ class UsersController extends AUserData {
/** @var RemoteWipe */ /** @var RemoteWipe */
private $remoteWipe; private $remoteWipe;
/**
* @param string $appName
* @param IRequest $request
* @param IUserManager $userManager
* @param IConfig $config
* @param IAppManager $appManager
* @param IGroupManager $groupManager
* @param IUserSession $userSession
* @param AccountManager $accountManager
* @param ILogger $logger
* @param IFactory $l10nFactory
* @param NewUserMailHelper $newUserMailHelper
* @param FederatedFileSharingFactory $federatedFileSharingFactory
* @param ISecureRandom $secureRandom
*/
public function __construct(string $appName, public function __construct(string $appName,
IRequest $request, IRequest $request,
IUserManager $userManager, IUserManager $userManager,
@ -112,7 +97,8 @@ class UsersController extends AUserData {
$config, $config,
$groupManager, $groupManager,
$userSession, $userSession,
$accountManager); $accountManager,
$l10nFactory);
$this->appManager = $appManager; $this->appManager = $appManager;
$this->logger = $logger; $this->logger = $logger;

View File

@ -41,6 +41,7 @@ use OCP\IRequest;
use OCP\IUser; use OCP\IUser;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\IUserSession; use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\UserInterface; use OCP\UserInterface;
class GroupsControllerTest extends \Test\TestCase { class GroupsControllerTest extends \Test\TestCase {
@ -75,6 +76,7 @@ class GroupsControllerTest extends \Test\TestCase {
$this->groupManager = $this->createMock(Manager::class); $this->groupManager = $this->createMock(Manager::class);
$this->userSession = $this->createMock(IUserSession::class); $this->userSession = $this->createMock(IUserSession::class);
$this->accountManager = $this->createMock(AccountManager::class); $this->accountManager = $this->createMock(AccountManager::class);
$this->l10nFactory = $this->createMock(IFactory::class);
$this->logger = $this->createMock(ILogger::class); $this->logger = $this->createMock(ILogger::class);
$this->subAdminManager = $this->createMock(SubAdmin::class); $this->subAdminManager = $this->createMock(SubAdmin::class);
@ -92,6 +94,7 @@ class GroupsControllerTest extends \Test\TestCase {
$this->groupManager, $this->groupManager,
$this->userSession, $this->userSession,
$this->accountManager, $this->accountManager,
$this->l10nFactory,
$this->logger $this->logger
]) ])
->setMethods(['fillStorageInfo']) ->setMethods(['fillStorageInfo'])

View File

@ -953,16 +953,6 @@ class UsersControllerTest extends TestCase {
->method('getUserValue') ->method('getUserValue')
->with('UID', 'core', 'enabled', 'true') ->with('UID', 'core', 'enabled', 'true')
->willReturn('true'); ->willReturn('true');
$this->config
->expects($this->at(1))
->method('getUserValue')
->with('UID', 'core', 'lang')
->willReturn('de');
$this->config
->expects($this->once())
->method('getSystemValue')
->with('force_language', 'de')
->willReturn('de');
$this->api $this->api
->expects($this->once()) ->expects($this->once())
->method('fillStorageInfo') ->method('fillStorageInfo')
@ -995,10 +985,15 @@ class UsersControllerTest extends TestCase {
->method('getBackend') ->method('getBackend')
->willReturn($backend); ->willReturn($backend);
$targetUser $targetUser
->expects($this->exactly(6))
->method('getUID') ->method('getUID')
->willReturn('UID'); ->willReturn('UID');
$this->l10nFactory
->expects($this->once())
->method('getUserLanguage')
->with($targetUser)
->willReturn('de');
$expected = [ $expected = [
'id' => 'UID', 'id' => 'UID',
'enabled' => true, 'enabled' => true,
@ -1078,16 +1073,6 @@ class UsersControllerTest extends TestCase {
->method('getUserValue') ->method('getUserValue')
->with('UID', 'core', 'enabled', 'true') ->with('UID', 'core', 'enabled', 'true')
->willReturn('true'); ->willReturn('true');
$this->config
->expects($this->once())
->method('getSystemValue')
->with('force_language', 'da')
->willReturn('da');
$this->config
->expects($this->at(1))
->method('getUserValue')
->with('UID', 'core', 'lang')
->willReturn('da');
$this->api $this->api
->expects($this->once()) ->expects($this->once())
->method('fillStorageInfo') ->method('fillStorageInfo')
@ -1120,7 +1105,6 @@ class UsersControllerTest extends TestCase {
->method('getBackend') ->method('getBackend')
->willReturn($backend); ->willReturn($backend);
$targetUser $targetUser
->expects($this->exactly(6))
->method('getUID') ->method('getUID')
->willReturn('UID'); ->willReturn('UID');
$this->accountManager->expects($this->any())->method('getUser') $this->accountManager->expects($this->any())->method('getUser')
@ -1134,6 +1118,12 @@ class UsersControllerTest extends TestCase {
] ]
); );
$this->l10nFactory
->expects($this->once())
->method('getUserLanguage')
->with($targetUser)
->willReturn('da');
$expected = [ $expected = [
'id' => 'UID', 'id' => 'UID',
'enabled' => true, 'enabled' => true,
@ -1255,11 +1245,6 @@ class UsersControllerTest extends TestCase {
->method('fillStorageInfo') ->method('fillStorageInfo')
->with('UID') ->with('UID')
->willReturn(['DummyValue']); ->willReturn(['DummyValue']);
$this->config
->expects($this->once())
->method('getSystemValue')
->with('force_language', 'ru')
->willReturn('ru');
$backend = $this->createMock(UserInterface::class); $backend = $this->createMock(UserInterface::class);
$backend->expects($this->atLeastOnce()) $backend->expects($this->atLeastOnce())
@ -1275,7 +1260,6 @@ class UsersControllerTest extends TestCase {
->method('getEMailAddress') ->method('getEMailAddress')
->willReturn('subadmin@nextcloud.com'); ->willReturn('subadmin@nextcloud.com');
$targetUser $targetUser
->expects($this->exactly(6))
->method('getUID') ->method('getUID')
->willReturn('UID'); ->willReturn('UID');
$targetUser $targetUser
@ -1294,11 +1278,6 @@ class UsersControllerTest extends TestCase {
->expects($this->once()) ->expects($this->once())
->method('getBackend') ->method('getBackend')
->willReturn($backend); ->willReturn($backend);
$this->config
->expects($this->at(0))
->method('getUserValue')
->with('UID', 'core', 'lang')
->willReturn('ru');
$this->accountManager->expects($this->any())->method('getUser') $this->accountManager->expects($this->any())->method('getUser')
->with($targetUser) ->with($targetUser)
->willReturn( ->willReturn(
@ -1310,6 +1289,12 @@ class UsersControllerTest extends TestCase {
] ]
); );
$this->l10nFactory
->expects($this->once())
->method('getUserLanguage')
->with($targetUser)
->willReturn('ru');
$expected = [ $expected = [
'id' => 'UID', 'id' => 'UID',
'storageLocation' => '/var/www/newtcloud/data/UID', 'storageLocation' => '/var/www/newtcloud/data/UID',
@ -2911,8 +2896,7 @@ class UsersControllerTest extends TestCase {
$subAdminManager $subAdminManager
->expects($this->once()) ->expects($this->once())
->method('createSubAdmin') ->method('createSubAdmin')
->with($targetUser, $targetGroup) ->with($targetUser, $targetGroup);
->willReturn(true);
$this->groupManager $this->groupManager
->expects($this->once()) ->expects($this->once())
->method('getSubAdmin') ->method('getSubAdmin')
@ -3014,8 +2998,7 @@ class UsersControllerTest extends TestCase {
$subAdminManager $subAdminManager
->expects($this->once()) ->expects($this->once())
->method('deleteSubAdmin') ->method('deleteSubAdmin')
->with($targetUser, $targetGroup) ->with($targetUser, $targetGroup);
->willReturn(true);
$this->groupManager $this->groupManager
->expects($this->once()) ->expects($this->once())
->method('getSubAdmin') ->method('getSubAdmin')

View File

@ -34,7 +34,6 @@ use OCP\Activity\IManager as IActivityManager;
use OCP\IConfig; use OCP\IConfig;
use OCP\IGroup; use OCP\IGroup;
use OCP\IGroupManager; use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use OCP\IUser; use OCP\IUser;
use OCP\IUserManager; use OCP\IUserManager;
@ -60,8 +59,6 @@ class Hooks {
protected $config; protected $config;
/** @var IFactory */ /** @var IFactory */
protected $languageFactory; protected $languageFactory;
/** @var IL10N */
protected $l;
public function __construct(IActivityManager $activityManager, public function __construct(IActivityManager $activityManager,
IGroupManager $groupManager, IGroupManager $groupManager,
@ -70,8 +67,7 @@ class Hooks {
IURLGenerator $urlGenerator, IURLGenerator $urlGenerator,
IMailer $mailer, IMailer $mailer,
IConfig $config, IConfig $config,
IFactory $languageFactory, IFactory $languageFactory) {
IL10N $l) {
$this->activityManager = $activityManager; $this->activityManager = $activityManager;
$this->groupManager = $groupManager; $this->groupManager = $groupManager;
$this->userManager = $userManager; $this->userManager = $userManager;
@ -80,7 +76,6 @@ class Hooks {
$this->mailer = $mailer; $this->mailer = $mailer;
$this->config = $config; $this->config = $config;
$this->languageFactory = $languageFactory; $this->languageFactory = $languageFactory;
$this->l = $l;
} }
/** /**
@ -103,36 +98,30 @@ class Hooks {
->setAffectedUser($user->getUID()); ->setAffectedUser($user->getUID());
$instanceUrl = $this->urlGenerator->getAbsoluteURL('/'); $instanceUrl = $this->urlGenerator->getAbsoluteURL('/');
$language = $this->languageFactory->getUserLanguage($user);
$l = $this->languageFactory->get('settings', $language);
$actor = $this->userSession->getUser(); $actor = $this->userSession->getUser();
if ($actor instanceof IUser) { if ($actor instanceof IUser) {
if ($actor->getUID() !== $user->getUID()) { if ($actor->getUID() !== $user->getUID()) {
// Admin changed the password through the user panel // Admin changed the password through the user panel
$this->l = $this->languageFactory->get( $text = $l->t('%1$s changed your password on %2$s.', [$actor->getDisplayName(), $instanceUrl]);
'settings',
$this->config->getUserValue(
$user->getUID(), 'core', 'lang',
$this->config->getSystemValue('default_language', 'en')
)
);
$text = $this->l->t('%1$s changed your password on %2$s.', [$actor->getDisplayName(), $instanceUrl]);
$event->setAuthor($actor->getUID()) $event->setAuthor($actor->getUID())
->setSubject(Provider::PASSWORD_CHANGED_BY, [$actor->getUID()]); ->setSubject(Provider::PASSWORD_CHANGED_BY, [$actor->getUID()]);
} else { } else {
// User changed their password themselves through settings // User changed their password themselves through settings
$text = $this->l->t('Your password on %s was changed.', [$instanceUrl]); $text = $l->t('Your password on %s was changed.', [$instanceUrl]);
$event->setAuthor($actor->getUID()) $event->setAuthor($actor->getUID())
->setSubject(Provider::PASSWORD_CHANGED_SELF); ->setSubject(Provider::PASSWORD_CHANGED_SELF);
} }
} else { } else {
if (\OC::$CLI) { if (\OC::$CLI) {
// Admin used occ to reset the password // Admin used occ to reset the password
$text = $this->l->t('Your password on %s was reset by an administrator.', [$instanceUrl]); $text = $l->t('Your password on %s was reset by an administrator.', [$instanceUrl]);
$event->setSubject(Provider::PASSWORD_RESET); $event->setSubject(Provider::PASSWORD_RESET);
} else { } else {
// User reset their password from Lost page // User reset their password from Lost page
$text = $this->l->t('Your password on %s was reset.', [$instanceUrl]); $text = $l->t('Your password on %s was reset.', [$instanceUrl]);
$event->setSubject(Provider::PASSWORD_RESET_SELF); $event->setSubject(Provider::PASSWORD_RESET_SELF);
} }
} }
@ -146,10 +135,10 @@ class Hooks {
'instanceUrl' => $instanceUrl, 'instanceUrl' => $instanceUrl,
]); ]);
$template->setSubject($this->l->t('Password for %1$s changed on %2$s', [$user->getDisplayName(), $instanceUrl])); $template->setSubject($l->t('Password for %1$s changed on %2$s', [$user->getDisplayName(), $instanceUrl]));
$template->addHeader(); $template->addHeader();
$template->addHeading($this->l->t('Password changed for %s', [$user->getDisplayName()]), false); $template->addHeading($l->t('Password changed for %s', [$user->getDisplayName()]), false);
$template->addBodyText($text . ' ' . $this->l->t('If you did not request this, please contact an administrator.')); $template->addBodyText($text . ' ' . $l->t('If you did not request this, please contact an administrator.'));
$template->addFooter(); $template->addFooter();
@ -180,25 +169,20 @@ class Hooks {
->setAffectedUser($user->getUID()); ->setAffectedUser($user->getUID());
$instanceUrl = $this->urlGenerator->getAbsoluteURL('/'); $instanceUrl = $this->urlGenerator->getAbsoluteURL('/');
$language = $this->languageFactory->getUserLanguage($user);
$l = $this->languageFactory->get('settings', $language);
$actor = $this->userSession->getUser(); $actor = $this->userSession->getUser();
if ($actor instanceof IUser) { if ($actor instanceof IUser) {
$subject = Provider::EMAIL_CHANGED_SELF; $subject = Provider::EMAIL_CHANGED_SELF;
if ($actor->getUID() !== $user->getUID()) { if ($actor->getUID() !== $user->getUID()) {
$this->l = $this->languageFactory->get(
'settings',
$this->config->getUserValue(
$user->getUID(), 'core', 'lang',
$this->config->getSystemValue('default_language', 'en')
)
);
$subject = Provider::EMAIL_CHANGED; $subject = Provider::EMAIL_CHANGED;
} }
$text = $this->l->t('Your email address on %s was changed.', [$instanceUrl]); $text = $l->t('Your email address on %s was changed.', [$instanceUrl]);
$event->setAuthor($actor->getUID()) $event->setAuthor($actor->getUID())
->setSubject($subject); ->setSubject($subject);
} else { } else {
$text = $this->l->t('Your email address on %s was changed by an administrator.', [$instanceUrl]); $text = $l->t('Your email address on %s was changed by an administrator.', [$instanceUrl]);
$event->setSubject(Provider::EMAIL_CHANGED); $event->setSubject(Provider::EMAIL_CHANGED);
} }
$this->activityManager->publish($event); $this->activityManager->publish($event);
@ -212,12 +196,12 @@ class Hooks {
'instanceUrl' => $instanceUrl, 'instanceUrl' => $instanceUrl,
]); ]);
$template->setSubject($this->l->t('Email address for %1$s changed on %2$s', [$user->getDisplayName(), $instanceUrl])); $template->setSubject($l->t('Email address for %1$s changed on %2$s', [$user->getDisplayName(), $instanceUrl]));
$template->addHeader(); $template->addHeader();
$template->addHeading($this->l->t('Email address changed for %s', [$user->getDisplayName()]), false); $template->addHeading($l->t('Email address changed for %s', [$user->getDisplayName()]), false);
$template->addBodyText($text . ' ' . $this->l->t('If you did not request this, please contact an administrator.')); $template->addBodyText($text . ' ' . $l->t('If you did not request this, please contact an administrator.'));
if ($user->getEMailAddress()) { if ($user->getEMailAddress()) {
$template->addBodyText($this->l->t('The new email address is %s', [$user->getEMailAddress()])); $template->addBodyText($l->t('The new email address is %s', [$user->getEMailAddress()]));
} }
$template->addFooter(); $template->addFooter();

View File

@ -99,11 +99,7 @@ class NewUserMailHelper {
*/ */
public function generateTemplate(IUser $user, $generatePasswordResetToken = false) { public function generateTemplate(IUser $user, $generatePasswordResetToken = false) {
$userId = $user->getUID(); $userId = $user->getUID();
$lang = $this->config->getUserValue($userId, 'core', 'lang', 'en'); $lang = $this->l10nFactory->getUserLanguage($user);
if (!$this->l10nFactory->languageExists('settings', $lang)) {
$lang = 'en';
}
$l10n = $this->l10nFactory->get('settings', $lang); $l10n = $this->l10nFactory->get('settings', $lang);
if ($generatePasswordResetToken) { if ($generatePasswordResetToken) {

View File

@ -1401,10 +1401,7 @@ class DefaultShareProvider implements IShareProvider {
/** @var IUser $recipient */ /** @var IUser $recipient */
$email = $recipient->getEMailAddress(); $email = $recipient->getEMailAddress();
if ($email) { if ($email) {
$language = $this->config->getSystemValue('force_language', false); $language = $this->l10nFactory->getUserLanguage($recipient);
$language = \is_string($language) ? $language : $this->config->getUserValue($recipient->getUID(), 'core', 'lang', null);
$language = $language ?? $this->config->getSystemValue('default_language', 'en');
if (!isset($toListByLanguage[$language])) { if (!isset($toListByLanguage[$language])) {
$toListByLanguage[$language] = []; $toListByLanguage[$language] = [];
} }

View File

@ -805,7 +805,7 @@ class Manager implements IManager {
if ($user !== null) { if ($user !== null) {
$emailAddress = $user->getEMailAddress(); $emailAddress = $user->getEMailAddress();
if ($emailAddress !== null && $emailAddress !== '') { if ($emailAddress !== null && $emailAddress !== '') {
$userLang = $this->config->getUserValue($share->getSharedWith(), 'core', 'lang', null); $userLang = $this->l10nFactory->getUserLanguage($user);
$l = $this->l10nFactory->get('lib', $userLang); $l = $this->l10nFactory->get('lib', $userLang);
$this->sendMailNotification( $this->sendMailNotification(
$l, $l,