Skip to content

Commit

Permalink
Merge pull request #2327 from nextcloud/enh/add-mail-addresses-to-export
Browse files Browse the repository at this point in the history
add email addresses to poll export for owner
  • Loading branch information
dartcafe committed Mar 23, 2022
2 parents bddb12e + da96a69 commit 0ec00ec
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/Model/Mail/MailBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ protected function getRichDescription() : string {
return $this->getParsedMarkDown($this->poll->getDescription());
}

protected function getParsedMarkDown($source) : string {
protected function getParsedMarkDown(string $source) : string {
$config = [
'renderer' => [
'soft_break' => "<br />",
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/MailService.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function resolveEmailAddress(int $pollId, string $userId): string {
} catch (\Exception $e) {
// catch silently
}
return $userId;
return '';
}

public function resendInvitation(string $token): Share {
Expand Down
11 changes: 7 additions & 4 deletions lib/Service/PollService.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,9 @@ public function clone(int $pollId): Poll {
/**
* Collect email addresses from particitipants
*
* @return string[]
* @return string[][]
*
* @psalm-return array<int, string>
* @psalm-return list<array{displayName: string, emailAddress: string, combined: string}>
*/
public function getParticipantsEmailAddresses(int $pollId): array {
$this->acl->setPollId($pollId, Acl::PERMISSION_POLL_EDIT);
Expand All @@ -359,9 +359,12 @@ public function getParticipantsEmailAddresses(int $pollId): array {
$votes = $this->voteMapper->findParticipantsByPoll($this->poll->getId());
$list = [];
foreach ($votes as $vote) {
$list[] = $vote->getDisplayName() . ' <' . $this->mailService->resolveEmailAddress($this->poll->getId(), $vote->getUserId()) . '>';
$list[] = [
'displayName' => $vote->getDisplayName(),
'emailAddress' => $this->mailService->resolveEmailAddress($this->poll->getId(), $vote->getUserId()),
'combined' => $vote->getDisplayName() . ' <' . $this->mailService->resolveEmailAddress($this->poll->getId(), $vote->getUserId()) . '>'];
}
return array_unique($list);
return $list;
}

/**
Expand Down
46 changes: 38 additions & 8 deletions src/js/components/Export/ExportPoll.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export default {
return {
workBook: [],
sheetData: [],
emailAddresses: [],
}
},
Expand All @@ -90,11 +91,15 @@ export default {
poll: (state) => state.poll,
options: (state) => state.options,
votes: (state) => state.votes,
isOwner: (state) => state.poll.acl.allowEdit,
}),
},
methods: {
exportFile(type) {
async exportFile(type) {
const participantsHeader = [t('polls', 'Participants')]
const fromHeader = [t('polls', 'From')]
const toHeader = [t('polls', 'To')]
this.workBook = xlsxUtils.book_new()
this.workBook.SheetNames.push(this.poll.title.slice(0, 31))
this.sheetData = []
Expand All @@ -106,18 +111,41 @@ export default {
)
}
if (this.isOwner) {
participantsHeader.push(t('polls', 'Email address'))
fromHeader.push('')
toHeader.push('')
const response = await this.$store.dispatch('poll/getParticipantsEmailAddresses')
this.emailAddresses = response.data
}
if (this.poll.type === 'textPoll') {
this.sheetData.push(['', ...this.options.list.map((item) => item.text)])
this.sheetData.push([
...participantsHeader,
...this.options.list.map((item) => item.text),
])
} else if (['csv'].includes(type)) {
this.sheetData.push([t('polls', 'Participants'), ...this.options.list.map((option) => this.explodeDates(option).iso)])
this.sheetData.push([
...participantsHeader,
...this.options.list.map((option) => this.explodeDates(option).iso),
])
} else if (['html'].includes(type)) {
this.sheetData.push([t('polls', 'Participants'), ...this.options.list.map((option) => this.explodeDates(option).raw)])
this.sheetData.push([
...participantsHeader,
...this.options.list.map((option) => this.explodeDates(option).raw),
])
} else {
this.sheetData.push([t('polls', 'From'), ...this.options.list.map((option) => this.explodeDates(option).from.dateTime)])
this.sheetData.push([t('polls', 'To'), ...this.options.list.map((option) => this.explodeDates(option).to.dateTime)])
this.sheetData.push([
...fromHeader,
...this.options.list.map((option) => this.explodeDates(option).from.dateTime),
])
this.sheetData.push([
...toHeader,
...this.options.list.map((option) => this.explodeDates(option).to.dateTime),
])
}
if (['html', 'ods', 'xlsx'].includes(type)) {
Expand All @@ -127,14 +155,16 @@ export default {
} else {
this.addVotesArray()
}
const workBookOutput = xlsxWrite(this.workBook, { bookType: type, type: 'binary' })
saveAs(new Blob([this.s2ab(workBookOutput)], { type: 'application/octet-stream' }), `poll.${type}`)
},
addVotesArray(style) {
this.participants.forEach((participant) => {
const votesLine = [participant.displayName]
if (this.isOwner) {
votesLine.push(this.emailAddresses.find((item) => item.displayName === participant.displayName).emailAddress)
}
this.options.list.forEach((option, i) => {
if (style === 'symbols') {
Expand All @@ -150,7 +180,7 @@ export default {
})
const workSheet = xlsxUtils.aoa_to_sheet(this.sheetData)
this.workBook.Sheets[this.poll.title] = workSheet
this.workBook.Sheets[this.poll.title.slice(0, 31)] = workSheet
},
s2ab(s) {
Expand Down
3 changes: 2 additions & 1 deletion src/js/components/User/UserMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,11 @@ export default {
showError(t('polls', 'Error while copying link to clipboard'))
}
},
async getAddresses() {
try {
const response = await this.$store.dispatch('poll/getParticipantsEmailAddresses')
await this.$copyText(response.data)
await this.$copyText(response.data.map((item) => item.combined))
showSuccess(t('polls', 'Link copied to clipboard'))
} catch {
showError(t('polls', 'Error while copying link to clipboard'))
Expand Down

0 comments on commit 0ec00ec

Please sign in to comment.