summaryrefslogtreecommitdiffstats
path: root/models/export.js
diff options
context:
space:
mode:
authorXavier Priour <xavier.priour@bubblyware.com>2015-12-17 11:58:55 +0100
committerXavier Priour <xavier.priour@bubblyware.com>2015-12-17 11:58:55 +0100
commit4cea6fca908b4f9acd8687293041ebee86284883 (patch)
tree10ee89e85ed938238b0b79dba5a726f8fa567042 /models/export.js
parent3a52d7d7af838037b6e933203ffb661ff2e13b5e (diff)
downloadwekan-4cea6fca908b4f9acd8687293041ebee86284883.tar.gz
wekan-4cea6fca908b4f9acd8687293041ebee86284883.tar.bz2
wekan-4cea6fca908b4f9acd8687293041ebee86284883.zip
Export: include attachments
Diffstat (limited to 'models/export.js')
-rw-r--r--models/export.js33
1 files changed, 17 insertions, 16 deletions
diff --git a/models/export.js b/models/export.js
index c20053ad..9fbcbcef 100644
--- a/models/export.js
+++ b/models/export.js
@@ -19,19 +19,6 @@ if(Meteor.isServer) {
});
}
-
-Meteor.methods({
- exportBoard(boardId) {
- check(boardId, String);
- const exporter = new Exporter(boardId);
- if(exporter.canExport(Meteor.user())) {
- return exporter.build();
- } else {
- throw new Meteor.Error('error-board-notAMember');
- }
- },
-});
-
class Exporter {
constructor(boardId) {
this._boardId = boardId;
@@ -41,12 +28,20 @@ class Exporter {
const byBoard = {boardId: this._boardId};
// we do not want to retrieve boardId in related elements
const noBoardId = {fields: {boardId: 0}};
- const result = Boards.findOne(this._boardId, {fields: {stars: 0}});
- result._format = 'wekan-board-1.0.0';
+ const result = {
+ _format: 'wekan-board-1.0.0',
+ };
+ _.extend(result, Boards.findOne(this._boardId, {fields: {stars: 0}}));
result.lists = Lists.find(byBoard, noBoardId).fetch();
result.cards = Cards.find(byBoard, noBoardId).fetch();
result.comments = CardComments.find(byBoard, noBoardId).fetch();
result.activities = Activities.find(byBoard, noBoardId).fetch();
+ // for attachments we only export IDs and absolute url to original doc
+ result.attachments = Attachments.find(byBoard).fetch().map((attachment) => { return {
+ _id: attachment._id,
+ cardId: attachment.cardId,
+ url: Meteor.absoluteUrl(Utils.stripLeadingSlash(attachment.url())),
+ };});
// we also have to export some user data - as the other elements only include id
// but we have to be careful:
@@ -73,7 +68,13 @@ class Exporter {
'profile.initials': 1,
'profile.avatarUrl': 1,
}};
- result.users = Users.find(byUserIds, userFields).fetch();
+ result.users = Users.find(byUserIds, userFields).fetch().map((user) => {
+ // user avatar is stored as a relative url, we export absolute
+ if(user.profile.avatarUrl) {
+ user.profile.avatarUrl = Meteor.absoluteUrl(Utils.stripLeadingSlash(user.profile.avatarUrl));
+ }
+ return user;
+ });
return result;
}