ReplyTo option for sharebymail Issue #24139
Signed-off-by: Nicolas SIMIDE <2083596+dems54@users.noreply.github.com>
This commit is contained in:
parent
5fa935d6d6
commit
4ac636d252
|
@ -35,4 +35,12 @@ $(function() {
|
||||||
OCP.AppConfig.setValue('sharebymail', 'enforcePasswordProtection', status);
|
OCP.AppConfig.setValue('sharebymail', 'enforcePasswordProtection', status);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#replyToInitiator').on('change', function() {
|
||||||
|
var status = 'no';
|
||||||
|
if ($(this).is(':checked')) {
|
||||||
|
status = 'yes';
|
||||||
|
}
|
||||||
|
OCP.AppConfig.setValue('sharebymail', 'replyToInitiator', status);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -41,7 +41,8 @@ class Admin implements ISettings {
|
||||||
public function getForm() {
|
public function getForm() {
|
||||||
$parameters = [
|
$parameters = [
|
||||||
'sendPasswordMail' => $this->settingsManager->sendPasswordByMail(),
|
'sendPasswordMail' => $this->settingsManager->sendPasswordByMail(),
|
||||||
'enforcePasswordProtection' => $this->settingsManager->enforcePasswordProtection()
|
'enforcePasswordProtection' => $this->settingsManager->enforcePasswordProtection(),
|
||||||
|
'replyToInitiator' => $this->settingsManager->replyToInitiator()
|
||||||
];
|
];
|
||||||
|
|
||||||
return new TemplateResponse('sharebymail', 'settings-admin', $parameters, '');
|
return new TemplateResponse('sharebymail', 'settings-admin', $parameters, '');
|
||||||
|
|
|
@ -38,6 +38,8 @@ class SettingsManager {
|
||||||
|
|
||||||
private $enforcePasswordProtectionDefault = 'no';
|
private $enforcePasswordProtectionDefault = 'no';
|
||||||
|
|
||||||
|
private $replyToInitiator = 'yes';
|
||||||
|
|
||||||
public function __construct(IConfig $config) {
|
public function __construct(IConfig $config) {
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
}
|
}
|
||||||
|
@ -61,4 +63,14 @@ class SettingsManager {
|
||||||
$enforcePassword = $this->config->getAppValue('sharebymail', 'enforcePasswordProtection', $this->enforcePasswordProtectionDefault);
|
$enforcePassword = $this->config->getAppValue('sharebymail', 'enforcePasswordProtection', $this->enforcePasswordProtectionDefault);
|
||||||
return $enforcePassword === 'yes';
|
return $enforcePassword === 'yes';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* should add reply to with initiator mail
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function replyToInitiator(): bool {
|
||||||
|
$replyToInitiator = $this->config->getAppValue('sharebymail', 'replyToInitiator', $this->replyToInitiator);
|
||||||
|
return $replyToInitiator === 'yes';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -399,19 +399,22 @@ class ShareByMailProvider implements IShareProvider {
|
||||||
|
|
||||||
// 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 = $instanceName;
|
||||||
'%1$s via %2$s',
|
if ($this->settingsManager->replyToInitiator()) {
|
||||||
[
|
$senderName = $this->l->t(
|
||||||
$initiatorDisplayName,
|
'%1$s via %2$s',
|
||||||
$instanceName
|
[
|
||||||
]
|
$initiatorDisplayName,
|
||||||
);
|
$instanceName
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
$message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]);
|
$message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]);
|
||||||
|
|
||||||
// The "Reply-To" is set to the sharer if an mail address is configured
|
// The "Reply-To" is set to the sharer if an mail address is configured
|
||||||
// also the default footer contains a "Do not reply" which needs to be adjusted.
|
// also the default footer contains a "Do not reply" which needs to be adjusted.
|
||||||
$initiatorEmail = $initiatorUser->getEMailAddress();
|
$initiatorEmail = $initiatorUser->getEMailAddress();
|
||||||
if ($initiatorEmail !== null) {
|
if ($this->settingsManager->replyToInitiator() && $initiatorEmail !== null) {
|
||||||
$message->setReplyTo([$initiatorEmail => $initiatorDisplayName]);
|
$message->setReplyTo([$initiatorEmail => $initiatorDisplayName]);
|
||||||
$emailTemplate->addFooter($instanceName . ($this->defaults->getSlogan() !== '' ? ' - ' . $this->defaults->getSlogan() : ''));
|
$emailTemplate->addFooter($instanceName . ($this->defaults->getSlogan() !== '' ? ' - ' . $this->defaults->getSlogan() : ''));
|
||||||
} else {
|
} else {
|
||||||
|
@ -464,15 +467,18 @@ class ShareByMailProvider implements IShareProvider {
|
||||||
|
|
||||||
// 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 = $instanceName;
|
||||||
'%1$s via %2$s',
|
if ($this->settingsManager->replyToInitiator()) {
|
||||||
[
|
$senderName = $this->l->t(
|
||||||
$initiatorDisplayName,
|
'%1$s via %2$s',
|
||||||
$instanceName
|
[
|
||||||
]
|
$initiatorDisplayName,
|
||||||
);
|
$instanceName
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
$message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]);
|
$message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]);
|
||||||
if ($initiatorEmailAddress !== null) {
|
if ($this->settingsManager->replyToInitiator() && $initiatorEmailAddress !== null) {
|
||||||
$message->setReplyTo([$initiatorEmailAddress => $initiatorDisplayName]);
|
$message->setReplyTo([$initiatorEmailAddress => $initiatorDisplayName]);
|
||||||
$emailTemplate->addFooter($instanceName . ' - ' . $this->defaults->getSlogan());
|
$emailTemplate->addFooter($instanceName . ' - ' . $this->defaults->getSlogan());
|
||||||
} else {
|
} else {
|
||||||
|
@ -521,15 +527,18 @@ class ShareByMailProvider implements IShareProvider {
|
||||||
|
|
||||||
// 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 = $instanceName;
|
||||||
'%1$s via %2$s',
|
if ($this->settingsManager->replyToInitiator()) {
|
||||||
[
|
$senderName = $this->l->t(
|
||||||
$initiatorDisplayName,
|
'%1$s via %2$s',
|
||||||
$instanceName
|
[
|
||||||
]
|
$initiatorDisplayName,
|
||||||
);
|
$instanceName
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
$message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]);
|
$message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]);
|
||||||
if ($initiatorEmailAddress !== null) {
|
if ($this->settingsManager->replyToInitiator() && $initiatorEmailAddress !== null) {
|
||||||
$message->setReplyTo([$initiatorEmailAddress => $initiatorDisplayName]);
|
$message->setReplyTo([$initiatorEmailAddress => $initiatorDisplayName]);
|
||||||
$emailTemplate->addFooter($instanceName . ' - ' . $this->defaults->getSlogan());
|
$emailTemplate->addFooter($instanceName . ' - ' . $this->defaults->getSlogan());
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -17,7 +17,11 @@ style('sharebymail', 'settings-admin');
|
||||||
<input id="enforcePasswordProtection" type="checkbox" class="checkbox" <?php if ($_['enforcePasswordProtection']) {
|
<input id="enforcePasswordProtection" type="checkbox" class="checkbox" <?php if ($_['enforcePasswordProtection']) {
|
||||||
p('checked');
|
p('checked');
|
||||||
} ?> />
|
} ?> />
|
||||||
<label for="enforcePasswordProtection"><?php p($l->t('Enforce password protection')); ?></label>
|
<label for="enforcePasswordProtection"><?php p($l->t('Enforce password protection')); ?></label><br/>
|
||||||
|
<input id="replyToInitiator" type="checkbox" class="checkbox" <?php if ($_['replyToInitiator']) {
|
||||||
|
p('checked');
|
||||||
|
} ?> />
|
||||||
|
<label for="replyToInitiator"><?php p($l->t('Reply to initiator')); ?></label>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1077,6 +1077,7 @@ class ShareByMailProviderTest extends TestCase {
|
||||||
public function testSendMailNotificationWithSameUserAndUserEmail() {
|
public function testSendMailNotificationWithSameUserAndUserEmail() {
|
||||||
$provider = $this->getInstance();
|
$provider = $this->getInstance();
|
||||||
$user = $this->createMock(IUser::class);
|
$user = $this->createMock(IUser::class);
|
||||||
|
$this->settingsManager->expects($this->any())->method('replyToInitiator')->willReturn(true);
|
||||||
$this->userManager
|
$this->userManager
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('get')
|
->method('get')
|
||||||
|
@ -1175,6 +1176,7 @@ class ShareByMailProviderTest extends TestCase {
|
||||||
public function testSendMailNotificationWithDifferentUserAndNoUserEmail() {
|
public function testSendMailNotificationWithDifferentUserAndNoUserEmail() {
|
||||||
$provider = $this->getInstance();
|
$provider = $this->getInstance();
|
||||||
$initiatorUser = $this->createMock(IUser::class);
|
$initiatorUser = $this->createMock(IUser::class);
|
||||||
|
$this->settingsManager->expects($this->any())->method('replyToInitiator')->willReturn(true);
|
||||||
$this->userManager
|
$this->userManager
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('get')
|
->method('get')
|
||||||
|
@ -1260,4 +1262,188 @@ class ShareByMailProviderTest extends TestCase {
|
||||||
null,
|
null,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSendMailNotificationWithSameUserAndUserEmailAndReplyToDesactivate() {
|
||||||
|
$provider = $this->getInstance();
|
||||||
|
$user = $this->createMock(IUser::class);
|
||||||
|
$this->settingsManager->expects($this->any())->method('replyToInitiator')->willReturn(false);
|
||||||
|
$this->userManager
|
||||||
|
->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with('OwnerUser')
|
||||||
|
->willReturn($user);
|
||||||
|
$user
|
||||||
|
->expects($this->once())
|
||||||
|
->method('getDisplayName')
|
||||||
|
->willReturn('Mrs. Owner User');
|
||||||
|
$message = $this->createMock(Message::class);
|
||||||
|
$this->mailer
|
||||||
|
->expects($this->once())
|
||||||
|
->method('createMessage')
|
||||||
|
->willReturn($message);
|
||||||
|
$template = $this->createMock(IEMailTemplate::class);
|
||||||
|
$this->mailer
|
||||||
|
->expects($this->once())
|
||||||
|
->method('createEMailTemplate')
|
||||||
|
->willReturn($template);
|
||||||
|
$template
|
||||||
|
->expects($this->once())
|
||||||
|
->method('addHeader');
|
||||||
|
$template
|
||||||
|
->expects($this->once())
|
||||||
|
->method('addHeading')
|
||||||
|
->with('Mrs. Owner User shared »file.txt« with you');
|
||||||
|
$template
|
||||||
|
->expects($this->once())
|
||||||
|
->method('addBodyText')
|
||||||
|
->with(
|
||||||
|
'Mrs. Owner User shared »file.txt« with you. Click the button below to open it.',
|
||||||
|
'Mrs. Owner User shared »file.txt« with you.'
|
||||||
|
);
|
||||||
|
$template
|
||||||
|
->expects($this->once())
|
||||||
|
->method('addBodyButton')
|
||||||
|
->with(
|
||||||
|
'Open »file.txt«',
|
||||||
|
'https://example.com/file.txt'
|
||||||
|
);
|
||||||
|
$message
|
||||||
|
->expects($this->once())
|
||||||
|
->method('setTo')
|
||||||
|
->with(['john@doe.com']);
|
||||||
|
$this->defaults
|
||||||
|
->expects($this->once())
|
||||||
|
->method('getName')
|
||||||
|
->willReturn('UnitTestCloud');
|
||||||
|
$message
|
||||||
|
->expects($this->once())
|
||||||
|
->method('setFrom')
|
||||||
|
->with([
|
||||||
|
\OCP\Util::getDefaultEmailAddress('UnitTestCloud') => 'UnitTestCloud'
|
||||||
|
]);
|
||||||
|
$user
|
||||||
|
->expects($this->once())
|
||||||
|
->method('getEMailAddress')
|
||||||
|
->willReturn('owner@example.com');
|
||||||
|
$message
|
||||||
|
->expects($this->never())
|
||||||
|
->method('setReplyTo');
|
||||||
|
$template
|
||||||
|
->expects($this->once())
|
||||||
|
->method('addFooter')
|
||||||
|
->with('');
|
||||||
|
$template
|
||||||
|
->expects($this->once())
|
||||||
|
->method('setSubject')
|
||||||
|
->with('Mrs. Owner User shared »file.txt« with you');
|
||||||
|
$message
|
||||||
|
->expects($this->once())
|
||||||
|
->method('useTemplate')
|
||||||
|
->with($template);
|
||||||
|
$this->mailer
|
||||||
|
->expects($this->once())
|
||||||
|
->method('send')
|
||||||
|
->with($message);
|
||||||
|
|
||||||
|
self::invokePrivate(
|
||||||
|
$provider,
|
||||||
|
'sendMailNotification',
|
||||||
|
[
|
||||||
|
'file.txt',
|
||||||
|
'https://example.com/file.txt',
|
||||||
|
'OwnerUser',
|
||||||
|
'john@doe.com',
|
||||||
|
null,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSendMailNotificationWithDifferentUserAndNoUserEmailAndReplyToDesactivate() {
|
||||||
|
$provider = $this->getInstance();
|
||||||
|
$initiatorUser = $this->createMock(IUser::class);
|
||||||
|
$this->settingsManager->expects($this->any())->method('replyToInitiator')->willReturn(false);
|
||||||
|
$this->userManager
|
||||||
|
->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with('InitiatorUser')
|
||||||
|
->willReturn($initiatorUser);
|
||||||
|
$initiatorUser
|
||||||
|
->expects($this->once())
|
||||||
|
->method('getDisplayName')
|
||||||
|
->willReturn('Mr. Initiator User');
|
||||||
|
$message = $this->createMock(Message::class);
|
||||||
|
$this->mailer
|
||||||
|
->expects($this->once())
|
||||||
|
->method('createMessage')
|
||||||
|
->willReturn($message);
|
||||||
|
$template = $this->createMock(IEMailTemplate::class);
|
||||||
|
$this->mailer
|
||||||
|
->expects($this->once())
|
||||||
|
->method('createEMailTemplate')
|
||||||
|
->willReturn($template);
|
||||||
|
$template
|
||||||
|
->expects($this->once())
|
||||||
|
->method('addHeader');
|
||||||
|
$template
|
||||||
|
->expects($this->once())
|
||||||
|
->method('addHeading')
|
||||||
|
->with('Mr. Initiator User shared »file.txt« with you');
|
||||||
|
$template
|
||||||
|
->expects($this->once())
|
||||||
|
->method('addBodyText')
|
||||||
|
->with(
|
||||||
|
'Mr. Initiator User shared »file.txt« with you. Click the button below to open it.',
|
||||||
|
'Mr. Initiator User shared »file.txt« with you.'
|
||||||
|
);
|
||||||
|
$template
|
||||||
|
->expects($this->once())
|
||||||
|
->method('addBodyButton')
|
||||||
|
->with(
|
||||||
|
'Open »file.txt«',
|
||||||
|
'https://example.com/file.txt'
|
||||||
|
);
|
||||||
|
$message
|
||||||
|
->expects($this->once())
|
||||||
|
->method('setTo')
|
||||||
|
->with(['john@doe.com']);
|
||||||
|
$this->defaults
|
||||||
|
->expects($this->once())
|
||||||
|
->method('getName')
|
||||||
|
->willReturn('UnitTestCloud');
|
||||||
|
$message
|
||||||
|
->expects($this->once())
|
||||||
|
->method('setFrom')
|
||||||
|
->with([
|
||||||
|
\OCP\Util::getDefaultEmailAddress('UnitTestCloud') => 'UnitTestCloud'
|
||||||
|
]);
|
||||||
|
$message
|
||||||
|
->expects($this->never())
|
||||||
|
->method('setReplyTo');
|
||||||
|
$template
|
||||||
|
->expects($this->once())
|
||||||
|
->method('addFooter')
|
||||||
|
->with('');
|
||||||
|
$template
|
||||||
|
->expects($this->once())
|
||||||
|
->method('setSubject')
|
||||||
|
->with('Mr. Initiator User shared »file.txt« with you');
|
||||||
|
$message
|
||||||
|
->expects($this->once())
|
||||||
|
->method('useTemplate')
|
||||||
|
->with($template);
|
||||||
|
$this->mailer
|
||||||
|
->expects($this->once())
|
||||||
|
->method('send')
|
||||||
|
->with($message);
|
||||||
|
|
||||||
|
self::invokePrivate(
|
||||||
|
$provider,
|
||||||
|
'sendMailNotification',
|
||||||
|
[
|
||||||
|
'file.txt',
|
||||||
|
'https://example.com/file.txt',
|
||||||
|
'InitiatorUser',
|
||||||
|
'john@doe.com',
|
||||||
|
null,
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue