Merge pull request #21550 from nextcloud/backport/21535/stable19
[stable19] Fix language in share notes email for users
This commit is contained in:
commit
41587bd8fb
|
@ -43,13 +43,14 @@ use OCP\Defaults;
|
||||||
use OCP\Files\Folder;
|
use OCP\Files\Folder;
|
||||||
use OCP\Files\IRootFolder;
|
use OCP\Files\IRootFolder;
|
||||||
use OCP\Files\Node;
|
use OCP\Files\Node;
|
||||||
|
use OCP\IConfig;
|
||||||
use OCP\IDBConnection;
|
use OCP\IDBConnection;
|
||||||
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;
|
||||||
|
use OCP\L10N\IFactory;
|
||||||
use OCP\Mail\IMailer;
|
use OCP\Mail\IMailer;
|
||||||
use OCP\Share\Exceptions\ShareNotFound;
|
use OCP\Share\Exceptions\ShareNotFound;
|
||||||
use OCP\Share\IShare;
|
use OCP\Share\IShare;
|
||||||
|
@ -83,24 +84,15 @@ class DefaultShareProvider implements IShareProvider {
|
||||||
/** @var Defaults */
|
/** @var Defaults */
|
||||||
private $defaults;
|
private $defaults;
|
||||||
|
|
||||||
/** @var IL10N */
|
/** @var IFactory */
|
||||||
private $l;
|
private $l10nFactory;
|
||||||
|
|
||||||
/** @var IURLGenerator */
|
/** @var IURLGenerator */
|
||||||
private $urlGenerator;
|
private $urlGenerator;
|
||||||
|
|
||||||
/**
|
/** @var IConfig */
|
||||||
* DefaultShareProvider constructor.
|
private $config;
|
||||||
*
|
|
||||||
* @param IDBConnection $connection
|
|
||||||
* @param IUserManager $userManager
|
|
||||||
* @param IGroupManager $groupManager
|
|
||||||
* @param IRootFolder $rootFolder
|
|
||||||
* @param IMailer $mailer ;
|
|
||||||
* @param Defaults $defaults
|
|
||||||
* @param IL10N $l
|
|
||||||
* @param IURLGenerator $urlGenerator
|
|
||||||
*/
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
IDBConnection $connection,
|
IDBConnection $connection,
|
||||||
IUserManager $userManager,
|
IUserManager $userManager,
|
||||||
|
@ -108,16 +100,18 @@ class DefaultShareProvider implements IShareProvider {
|
||||||
IRootFolder $rootFolder,
|
IRootFolder $rootFolder,
|
||||||
IMailer $mailer,
|
IMailer $mailer,
|
||||||
Defaults $defaults,
|
Defaults $defaults,
|
||||||
IL10N $l,
|
IFactory $l10nFactory,
|
||||||
IURLGenerator $urlGenerator) {
|
IURLGenerator $urlGenerator,
|
||||||
|
IConfig $config) {
|
||||||
$this->dbConn = $connection;
|
$this->dbConn = $connection;
|
||||||
$this->userManager = $userManager;
|
$this->userManager = $userManager;
|
||||||
$this->groupManager = $groupManager;
|
$this->groupManager = $groupManager;
|
||||||
$this->rootFolder = $rootFolder;
|
$this->rootFolder = $rootFolder;
|
||||||
$this->mailer = $mailer;
|
$this->mailer = $mailer;
|
||||||
$this->defaults = $defaults;
|
$this->defaults = $defaults;
|
||||||
$this->l = $l;
|
$this->l10nFactory = $l10nFactory;
|
||||||
$this->urlGenerator = $urlGenerator;
|
$this->urlGenerator = $urlGenerator;
|
||||||
|
$this->config = $config;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1407,45 +1401,58 @@ class DefaultShareProvider implements IShareProvider {
|
||||||
* @throws \OCP\Files\NotFoundException
|
* @throws \OCP\Files\NotFoundException
|
||||||
*/
|
*/
|
||||||
private function sendNote(array $recipients, IShare $share) {
|
private function sendNote(array $recipients, IShare $share) {
|
||||||
$toList = [];
|
$toListByLanguage = [];
|
||||||
|
|
||||||
foreach ($recipients as $recipient) {
|
foreach ($recipients as $recipient) {
|
||||||
/** @var IUser $recipient */
|
/** @var IUser $recipient */
|
||||||
$email = $recipient->getEMailAddress();
|
$email = $recipient->getEMailAddress();
|
||||||
if ($email) {
|
if ($email) {
|
||||||
$toList[$email] = $recipient->getDisplayName();
|
$language = $this->config->getSystemValue('force_language', false);
|
||||||
|
$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])) {
|
||||||
|
$toListByLanguage[$language] = [];
|
||||||
|
}
|
||||||
|
$toListByLanguage[$language][$email] = $recipient->getDisplayName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($toList)) {
|
if (empty($toListByLanguage)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($toListByLanguage as $l10n => $toList) {
|
||||||
$filename = $share->getNode()->getName();
|
$filename = $share->getNode()->getName();
|
||||||
$initiator = $share->getSharedBy();
|
$initiator = $share->getSharedBy();
|
||||||
$note = $share->getNote();
|
$note = $share->getNote();
|
||||||
|
|
||||||
|
$l = $this->l10nFactory->get('lib', $l10n);
|
||||||
|
|
||||||
$initiatorUser = $this->userManager->get($initiator);
|
$initiatorUser = $this->userManager->get($initiator);
|
||||||
$initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator;
|
$initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator;
|
||||||
$initiatorEmailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null;
|
$initiatorEmailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null;
|
||||||
$plainHeading = $this->l->t('%1$s shared »%2$s« with you and wants to add:', [$initiatorDisplayName, $filename]);
|
$plainHeading = $l->t('%1$s shared »%2$s« with you and wants to add:', [$initiatorDisplayName, $filename]);
|
||||||
$htmlHeading = $this->l->t('%1$s shared »%2$s« with you and wants to add', [$initiatorDisplayName, $filename]);
|
$htmlHeading = $l->t('%1$s shared »%2$s« with you and wants to add', [$initiatorDisplayName, $filename]);
|
||||||
$message = $this->mailer->createMessage();
|
$message = $this->mailer->createMessage();
|
||||||
|
|
||||||
$emailTemplate = $this->mailer->createEMailTemplate('defaultShareProvider.sendNote');
|
$emailTemplate = $this->mailer->createEMailTemplate('defaultShareProvider.sendNote');
|
||||||
|
|
||||||
$emailTemplate->setSubject($this->l->t('»%s« added a note to a file shared with you', [$initiatorDisplayName]));
|
$emailTemplate->setSubject($l->t('»%s« added a note to a file shared with you', [$initiatorDisplayName]));
|
||||||
$emailTemplate->addHeader();
|
$emailTemplate->addHeader();
|
||||||
$emailTemplate->addHeading($htmlHeading, $plainHeading);
|
$emailTemplate->addHeading($htmlHeading, $plainHeading);
|
||||||
$emailTemplate->addBodyText(htmlspecialchars($note), $note);
|
$emailTemplate->addBodyText(htmlspecialchars($note), $note);
|
||||||
|
|
||||||
$link = $this->urlGenerator->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $share->getNode()->getId()]);
|
$link = $this->urlGenerator->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $share->getNode()->getId()]);
|
||||||
$emailTemplate->addBodyButton(
|
$emailTemplate->addBodyButton(
|
||||||
$this->l->t('Open »%s«', [$filename]),
|
$l->t('Open »%s«', [$filename]),
|
||||||
$link
|
$link
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
// The "From" contains the sharers name
|
// The "From" contains the sharers name
|
||||||
$instanceName = $this->defaults->getName();
|
$instanceName = $this->defaults->getName();
|
||||||
$senderName = $this->l->t(
|
$senderName = $l->t(
|
||||||
'%1$s via %2$s',
|
'%1$s via %2$s',
|
||||||
[
|
[
|
||||||
$initiatorDisplayName,
|
$initiatorDisplayName,
|
||||||
|
|
|
@ -87,8 +87,9 @@ class ProviderFactory implements IProviderFactory {
|
||||||
$this->serverContainer->getLazyRootFolder(),
|
$this->serverContainer->getLazyRootFolder(),
|
||||||
$this->serverContainer->getMailer(),
|
$this->serverContainer->getMailer(),
|
||||||
$this->serverContainer->query(Defaults::class),
|
$this->serverContainer->query(Defaults::class),
|
||||||
$this->serverContainer->getL10N('sharing'),
|
$this->serverContainer->getL10NFactory(),
|
||||||
$this->serverContainer->getURLGenerator()
|
$this->serverContainer->getURLGenerator(),
|
||||||
|
$this->serverContainer->getConfig()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ use OCP\Defaults;
|
||||||
use OCP\Files\File;
|
use OCP\Files\File;
|
||||||
use OCP\Files\Folder;
|
use OCP\Files\Folder;
|
||||||
use OCP\Files\IRootFolder;
|
use OCP\Files\IRootFolder;
|
||||||
|
use OCP\IConfig;
|
||||||
use OCP\IDBConnection;
|
use OCP\IDBConnection;
|
||||||
use OCP\IGroup;
|
use OCP\IGroup;
|
||||||
use OCP\IGroupManager;
|
use OCP\IGroupManager;
|
||||||
|
@ -35,8 +36,10 @@ use OCP\IL10N;
|
||||||
use OCP\IURLGenerator;
|
use OCP\IURLGenerator;
|
||||||
use OCP\IUser;
|
use OCP\IUser;
|
||||||
use OCP\IUserManager;
|
use OCP\IUserManager;
|
||||||
|
use OCP\L10N\IFactory;
|
||||||
use OCP\Mail\IMailer;
|
use OCP\Mail\IMailer;
|
||||||
use OCP\Share\IShare;
|
use OCP\Share\IShare;
|
||||||
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class DefaultShareProviderTest
|
* Class DefaultShareProviderTest
|
||||||
|
@ -64,6 +67,9 @@ class DefaultShareProviderTest extends \Test\TestCase {
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject|IMailer */
|
/** @var \PHPUnit_Framework_MockObject_MockObject|IMailer */
|
||||||
protected $mailer;
|
protected $mailer;
|
||||||
|
|
||||||
|
/** @var IFactory|MockObject */
|
||||||
|
protected $l10nFactory;
|
||||||
|
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject|IL10N */
|
/** @var \PHPUnit_Framework_MockObject_MockObject|IL10N */
|
||||||
protected $l10n;
|
protected $l10n;
|
||||||
|
|
||||||
|
@ -73,15 +79,20 @@ class DefaultShareProviderTest extends \Test\TestCase {
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject|IURLGenerator */
|
/** @var \PHPUnit_Framework_MockObject_MockObject|IURLGenerator */
|
||||||
protected $urlGenerator;
|
protected $urlGenerator;
|
||||||
|
|
||||||
|
/** @var IConfig|MockObject */
|
||||||
|
protected $config;
|
||||||
|
|
||||||
protected function setUp(): void {
|
protected function setUp(): void {
|
||||||
$this->dbConn = \OC::$server->getDatabaseConnection();
|
$this->dbConn = \OC::$server->getDatabaseConnection();
|
||||||
$this->userManager = $this->createMock(IUserManager::class);
|
$this->userManager = $this->createMock(IUserManager::class);
|
||||||
$this->groupManager = $this->createMock(IGroupManager::class);
|
$this->groupManager = $this->createMock(IGroupManager::class);
|
||||||
$this->rootFolder = $this->createMock(IRootFolder::class);
|
$this->rootFolder = $this->createMock(IRootFolder::class);
|
||||||
$this->mailer = $this->createMock(IMailer::class);
|
$this->mailer = $this->createMock(IMailer::class);
|
||||||
|
$this->l10nFactory = $this->createMock(IFactory::class);
|
||||||
$this->l10n = $this->createMock(IL10N::class);
|
$this->l10n = $this->createMock(IL10N::class);
|
||||||
$this->defaults = $this->getMockBuilder(Defaults::class)->disableOriginalConstructor()->getMock();
|
$this->defaults = $this->getMockBuilder(Defaults::class)->disableOriginalConstructor()->getMock();
|
||||||
$this->urlGenerator = $this->createMock(IURLGenerator::class);
|
$this->urlGenerator = $this->createMock(IURLGenerator::class);
|
||||||
|
$this->config = $this->createMock(IConfig::class);
|
||||||
|
|
||||||
$this->userManager->expects($this->any())->method('userExists')->willReturn(true);
|
$this->userManager->expects($this->any())->method('userExists')->willReturn(true);
|
||||||
|
|
||||||
|
@ -95,8 +106,9 @@ class DefaultShareProviderTest extends \Test\TestCase {
|
||||||
$this->rootFolder,
|
$this->rootFolder,
|
||||||
$this->mailer,
|
$this->mailer,
|
||||||
$this->defaults,
|
$this->defaults,
|
||||||
$this->l10n,
|
$this->l10nFactory,
|
||||||
$this->urlGenerator
|
$this->urlGenerator,
|
||||||
|
$this->config
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -454,8 +466,9 @@ class DefaultShareProviderTest extends \Test\TestCase {
|
||||||
$this->rootFolder,
|
$this->rootFolder,
|
||||||
$this->mailer,
|
$this->mailer,
|
||||||
$this->defaults,
|
$this->defaults,
|
||||||
$this->l10n,
|
$this->l10nFactory,
|
||||||
$this->urlGenerator
|
$this->urlGenerator,
|
||||||
|
$this->config
|
||||||
])
|
])
|
||||||
->setMethods(['getShareById'])
|
->setMethods(['getShareById'])
|
||||||
->getMock();
|
->getMock();
|
||||||
|
@ -548,8 +561,9 @@ class DefaultShareProviderTest extends \Test\TestCase {
|
||||||
$this->rootFolder,
|
$this->rootFolder,
|
||||||
$this->mailer,
|
$this->mailer,
|
||||||
$this->defaults,
|
$this->defaults,
|
||||||
$this->l10n,
|
$this->l10nFactory,
|
||||||
$this->urlGenerator
|
$this->urlGenerator,
|
||||||
|
$this->config
|
||||||
])
|
])
|
||||||
->setMethods(['getShareById'])
|
->setMethods(['getShareById'])
|
||||||
->getMock();
|
->getMock();
|
||||||
|
@ -2491,8 +2505,9 @@ class DefaultShareProviderTest extends \Test\TestCase {
|
||||||
$rootFolder,
|
$rootFolder,
|
||||||
$this->mailer,
|
$this->mailer,
|
||||||
$this->defaults,
|
$this->defaults,
|
||||||
$this->l10n,
|
$this->l10nFactory,
|
||||||
$this->urlGenerator
|
$this->urlGenerator,
|
||||||
|
$this->config
|
||||||
);
|
);
|
||||||
|
|
||||||
$password = md5(time());
|
$password = md5(time());
|
||||||
|
@ -2588,8 +2603,9 @@ class DefaultShareProviderTest extends \Test\TestCase {
|
||||||
$rootFolder,
|
$rootFolder,
|
||||||
$this->mailer,
|
$this->mailer,
|
||||||
$this->defaults,
|
$this->defaults,
|
||||||
$this->l10n,
|
$this->l10nFactory,
|
||||||
$this->urlGenerator
|
$this->urlGenerator,
|
||||||
|
$this->config
|
||||||
);
|
);
|
||||||
|
|
||||||
$u1 = $userManager->createUser('testShare1', 'test');
|
$u1 = $userManager->createUser('testShare1', 'test');
|
||||||
|
@ -2683,8 +2699,9 @@ class DefaultShareProviderTest extends \Test\TestCase {
|
||||||
$rootFolder,
|
$rootFolder,
|
||||||
$this->mailer,
|
$this->mailer,
|
||||||
$this->defaults,
|
$this->defaults,
|
||||||
$this->l10n,
|
$this->l10nFactory,
|
||||||
$this->urlGenerator
|
$this->urlGenerator,
|
||||||
|
$this->config
|
||||||
);
|
);
|
||||||
|
|
||||||
$u1 = $userManager->createUser('testShare1', 'test');
|
$u1 = $userManager->createUser('testShare1', 'test');
|
||||||
|
|
Loading…
Reference in New Issue