prevent ex-participants appearing in challenge export file - Fix #9844 (#9846)

* possible fix for 9844

* fix typo in challengeModal file

* remove lines for empty users
This commit is contained in:
Matteo Pagliazzi
2018-01-29 23:23:40 +01:00
committed by Sabe Jones
parent ae27ae0090
commit 1dc558ddba
2 changed files with 15 additions and 7 deletions

View File

@@ -53,8 +53,7 @@
input(type='number', :min='minPrize', :max='maxPrize', v-model="workingChallenge.prize")
.row.footer-wrap
.col-12.text-center.submit-button-wrapper
.alert.alert-warning(v-if='insufficientGemsForTavernChallenge')
You do not have enough gems to create a Tavern challenge
.alert.alert-warning(v-if='insufficientGemsForTavernChallenge') You do not have enough gems to create a Tavern challenge
// @TODO if buy gems button is added, add analytics tracking to it
// see https://github.com/HabitRPG/habitica/blob/develop/website/views/options/social/challenges.jade#L134
button.btn.btn-primary(v-if='creating && !cloning', @click='createChallenge()', :disabled='loading') {{$t('createChallengeAddTasks')}}

View File

@@ -592,13 +592,12 @@ api.exportChallengeCsv = {
let resArray = members.map(member => [member._id, member.profile.name]);
// We assume every user in the challenge as at least some data so we can say that members[0] tasks will be at tasks [0]
let lastUserId;
let index = -1;
tasks.forEach(task => {
if (task.userId !== lastUserId) {
lastUserId = task.userId;
while (task.userId !== lastUserId) {
index++;
lastUserId = resArray[index][0]; // resArray[index][0] is an user id
}
const streak = task.streak || 0;
@@ -611,8 +610,18 @@ api.exportChallengeCsv = {
return result.concat(array);
}, []).sort();
resArray.unshift(['UUID', 'name']);
_.times(challengeTasks.length, () => resArray[0].push('Task', 'Value', 'Notes', 'Streak'));
// Remove lines for users without tasks info
resArray = resArray.filter((line) => {
if (line.length === 2) { // only user data ([id, profile name]), no task data
return false;
}
return true;
});
res.set({
'Content-Type': 'text/csv',
'Content-disposition': `attachment; filename=${challengeId}.csv`,