Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/polls.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRené Gieling <github@dartcafe.de>2020-01-12 23:11:17 +0300
committerGitHub <noreply@github.com>2020-01-12 23:11:17 +0300
commit317dc3652349e452f3080f5990c42b0a3ebde726 (patch)
treefeb90fd9be8c943f16afe607da73239c45fdb380
parent7f00840cd48c08001f732aceb2e09aa8ba001d91 (diff)
parente7bc9067f89a87033ea31e42fe5c13a8dcb919cf (diff)
Merge pull request #735 from nextcloud/enhanceInvitationMailsv1.0-rc1
Enhance invitation mails
-rw-r--r--lib/Controller/ShareController.php4
-rw-r--r--lib/Controller/SystemController.php4
-rw-r--r--lib/Service/MailService.php48
-rw-r--r--src/js/components/Comments/CommentAdd.vue4
-rw-r--r--src/js/components/SideBar/SideBarTabShare.vue7
-rw-r--r--src/js/store/modules/shares.js29
6 files changed, 63 insertions, 33 deletions
diff --git a/lib/Controller/ShareController.php b/lib/Controller/ShareController.php
index 5cbb6baa..0904123f 100644
--- a/lib/Controller/ShareController.php
+++ b/lib/Controller/ShareController.php
@@ -163,11 +163,11 @@ class ShareController extends Controller {
try {
$newShare = $this->mapper->insert($newShare);
- $sentMail = $this->mailService->sendInvitationMail($newShare->getToken());
+ $sendResult = $this->mailService->sendInvitationMail($newShare->getToken());
return new DataResponse([
'share' => $newShare,
- 'mailSent' => $sentMail
+ 'sendResult' => $sendResult
], Http::STATUS_OK);
} catch (\Exception $e) {
diff --git a/lib/Controller/SystemController.php b/lib/Controller/SystemController.php
index be3948d2..933b925f 100644
--- a/lib/Controller/SystemController.php
+++ b/lib/Controller/SystemController.php
@@ -38,7 +38,6 @@ use OCA\Polls\Db\Vote;
use OCA\Polls\Db\VoteMapper;
use OCP\ILogger;
-
class SystemController extends Controller {
private $userId;
@@ -49,6 +48,7 @@ class SystemController extends Controller {
private $voteMapper;
private $shareMapper;
+
/**
* PageController constructor.
* @param string $appName
@@ -170,7 +170,7 @@ class SystemController extends Controller {
'type' => 'contact',
'icon' => 'icon-mail',
'avatarURL' => '',
- 'avatar' => isset($contact['PHOTO']) ? $contact['PHOTO'] : '',
+ 'avatar' => isset($contact['PHOTO']) ? $contact['PHOTO'] : '',
'lastLogin' => '',
'cloudId' => ''
];
diff --git a/lib/Service/MailService.php b/lib/Service/MailService.php
index f5b3dc39..64f51a46 100644
--- a/lib/Service/MailService.php
+++ b/lib/Service/MailService.php
@@ -112,7 +112,7 @@ class MailService {
* @param String $toUserId
* @param String $toEmail
* @param String $toDisplayName
- * @return Bool
+ * @return String
*/
private function sendMail($emailTemplate, $toUserId = '', $toEmail = '', $toDisplayName = '') {
@@ -131,6 +131,9 @@ class MailService {
$message->setTo([$toEmail => $toDisplayName]);
$message->useTemplate($emailTemplate);
$this->mailer->send($message);
+
+ return null;
+
} catch (\Exception $e) {
$this->logger->logException($e, ['app' => 'polls']);
throw $e;
@@ -152,7 +155,7 @@ class MailService {
$recipients[] = array(
'userId' => $share->getUserId(),
- 'email' => null,
+ 'eMailAddress' => null,
'displayName' => null,
'language' => $this->config->getUserValue($share->getUserId(), 'core', 'lang'),
'link' => $this->urlGenerator->getAbsoluteURL(
@@ -169,7 +172,7 @@ class MailService {
$recipients[] = array(
'userId' => $share->getUserId(),
- 'email' => $contact['EMAIL'][0],
+ 'eMailAddress' => $contact['EMAIL'][0],
'displayName' => $contact['FN'],
'language' => $defaultLang,
'link' => $this->urlGenerator->getAbsoluteURL(
@@ -186,7 +189,7 @@ class MailService {
$recipients[] = array(
'userId' => $share->getUserId(),
- 'email' => $share->getUserEmail(),
+ 'eMailAddress' => $share->getUserEmail(),
'displayName' => $share->getUserId(),
'language' => $defaultLang,
'link' => $this->urlGenerator->getAbsoluteURL(
@@ -207,7 +210,7 @@ class MailService {
$recipients[] = array(
'userId' => $member,
- 'email' => null,
+ 'eMailAddress' => null,
'displayName' => null,
'language' => $this->config->getUserValue($share->getUserId(), 'core', 'lang'),
'link' => $this->urlGenerator->getAbsoluteURL(
@@ -227,18 +230,19 @@ class MailService {
* @param string $token
*/
public function sendInvitationMail($token) {
+
$share = $this->shareMapper->findByToken($token);
$poll = $this->pollMapper->find($share->getPollId());
$owner = $this->userManager->get($poll->getOwner());
+ $sentMails = [];
+ $abortedMails = [];
$recipients = $this->getRecipientsByShare(
$this->shareMapper->findByToken($token),
$this->config->getUserValue($poll->getOwner(), 'core', 'lang'),
$poll->getOwner()
);
-
foreach ($recipients as $recipient) {
-
$trans = $this->transFactory->get('polls', $recipient['language']);
$emailTemplate = $this->mailer->createEMailTemplate('polls.Invitation', [
@@ -268,15 +272,16 @@ class MailService {
$this->sendMail(
$emailTemplate,
$recipient['userId'],
- $recipient['email'],
+ $recipient['eMailAddress'],
$recipient['displayName']
);
- return true;
+ $sentMails[] = $recipient;
} catch (Exception $e) {
- return false;
+ $abortedMails[] = $recipient;
+ $this->logger->alert('Error sending Mail to ' . json_encode($recipient));
}
-
}
+ return ['sentMails' => $sentMails, 'abortedMails' => $abortedMails];
}
public function sendNotifications() {
@@ -327,27 +332,32 @@ class MailService {
} elseif ($logItem->getMessageId() === 'setVote') {
$emailTemplate->addBodyText($trans->t(
'- %s voted.',
- array($this->userManager->get($logItem->getUserId())->getDisplayName()))
- );
+ array($logItem->getUserId()))
+ // array($this->userManager->get($logItem->getUserId())->getDisplayName()))
+ );
} elseif ($logItem->getMessageId() === 'updatePoll') {
$emailTemplate->addBodyText($trans->t(
'- %s updated the poll configuration. Please check your votes.',
- array($this->userManager->get($logItem->getUserId())->getDisplayName()))
+ array($logItem->getUserId()))
+ // array($this->userManager->get($logItem->getUserId())->getDisplayName()))
);
} elseif ($logItem->getMessageId() === 'deletePoll') {
$emailTemplate->addBodyText($trans->t(
'- %s deleted the poll.',
- array($this->userManager->get($logItem->getUserId())->getDisplayName()))
+ array($logItem->getUserId()))
+ // array($this->userManager->get($logItem->getUserId())->getDisplayName()))
);
} elseif ($logItem->getMessageId() === 'restorePoll') {
$emailTemplate->addBodyText($trans->t(
'- %s restored the poll.',
- array($this->userManager->get($logItem->getUserId())->getDisplayName()))
+ array($logItem->getUserId()))
+ // array($this->userManager->get($logItem->getUserId())->getDisplayName()))
);
} elseif ($logItem->getMessageId() === 'expirePoll') {
$emailTemplate->addBodyText($trans->t(
'- The poll expired.',
- array($this->userManager->get($logItem->getUserId())->getDisplayName()))
+ array($logItem->getUserId()))
+ // array($this->userManager->get($logItem->getUserId())->getDisplayName()))
);
}
@@ -367,8 +377,8 @@ class MailService {
try {
$this->sendMail($emailTemplate, $subscription->getUserId());
} catch (Exception $e) {
- // todo alert Owner
- // Notification to $subscription->getUserId() could not be sent
+ $this->logger->alert('Error sending Mail to ' . $subscription->getUserId());
+ // TODO: alert Owner
}
}
}
diff --git a/src/js/components/Comments/CommentAdd.vue b/src/js/components/Comments/CommentAdd.vue
index 56ac5790..984cb978 100644
--- a/src/js/components/Comments/CommentAdd.vue
+++ b/src/js/components/Comments/CommentAdd.vue
@@ -25,8 +25,8 @@
<user-div :user-id="currentUser" />
<form class="commentAdd" name="send-comment" @submit="writeComment">
- <input v-model="comment" class="message" data-placeholder="New Comment ..."/>
- <button v-show="!isLoading" type="submit" class="submit-comment icon-confirm"></button>
+ <input v-model="comment" class="message" data-placeholder="New Comment ...">
+ <button v-show="!isLoading" type="submit" class="submit-comment icon-confirm" />
<span v-show="isLoading" class="icon-loading-small" style="float:right;" />
</form>
</div>
diff --git a/src/js/components/SideBar/SideBarTabShare.vue b/src/js/components/SideBar/SideBarTabShare.vue
index 5420f6aa..5a959393 100644
--- a/src/js/components/SideBar/SideBarTabShare.vue
+++ b/src/js/components/SideBar/SideBarTabShare.vue
@@ -195,13 +195,6 @@ export default {
token: ''
}
})
- .then((response) => {
- if (response) {
- OC.Notification.showTemporary(t('polls', 'Invitation mail sent to %n.', 1, payload.user), { type: 'success' })
- } else {
- OC.Notification.showTemporary(t('polls', 'Error while sending invitation mail sent to %n.', 1, payload.user), { type: 'error' })
- }
- })
.catch(error => {
console.error('Error while adding share comment - Error: ', error)
OC.Notification.showTemporary(t('polls', 'Error while adding share'), { type: 'error' })
diff --git a/src/js/store/modules/shares.js b/src/js/store/modules/shares.js
index 34e71d70..e0b653a3 100644
--- a/src/js/store/modules/shares.js
+++ b/src/js/store/modules/shares.js
@@ -129,7 +129,34 @@ const actions = {
return axios.post(OC.generateUrl(endPoint), { pollId: context.rootState.poll.id, share: payload.share })
.then((response) => {
context.commit('addShare', response.data.share)
- return response.data.mailSent
+
+ if (response.data.sendResult.sentMails.length > 0) {
+ const sendList = response.data.sendResult.sentMails.map(element => {
+
+ if (element.displayName) {
+ return element.displayName
+ } else if (element.userId) {
+ return element.userId
+ } else if (element.eMailAddress) {
+ return element.eMailAddress
+ }
+ })
+ OC.Notification.showTemporary(t('polls', 'Invitation mail sent to %n.', 1, sendList.join(', ')), { type: 'success' })
+ }
+
+ if (response.data.sendResult.abortedMails.length > 0) {
+ const errorList = response.data.sendResult.abortedMails.map(element => {
+ if (element.displayName) {
+ return element.displayName
+ } else if (element.userId) {
+ return element.userId
+ } else if (element.eMailAddress) {
+ return element.eMailAddress
+ }
+ })
+ OC.Notification.showTemporary(t('polls', 'Error sending invitation mail to %n.', 1, errorList.join(', ')), { type: 'error' })
+ }
+ return response.data
}, (error) => {
console.error('Error writing share', { error: error.response }, { payload: payload })
throw error