From 4ad4c6ea2274919ced917e541120ad50c7512b80 Mon Sep 17 00:00:00 2001 From: Ghassen Rjab Date: Thu, 31 Aug 2017 22:14:57 +0100 Subject: Assign user to attachment before inserting --- models/wekanCreator.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'models/wekanCreator.js') diff --git a/models/wekanCreator.js b/models/wekanCreator.js index 1a02339a..d96ad2ca 100644 --- a/models/wekanCreator.js +++ b/models/wekanCreator.js @@ -312,6 +312,7 @@ export class WekanCreator { file.attachData(att.url, function (error) { file.boardId = boardId; file.cardId = cardId; + file.userId = this._user(att.userId); if (error) { throw(error); } else { @@ -330,6 +331,7 @@ export class WekanCreator { file.name(att.name); file.boardId = boardId; file.cardId = cardId; + file.userId = this._user(att.userId); if (error) { throw(error); } else { -- cgit v1.2.3-1-g7c22 From 6ff0cf91e2fe6fd0e777225eb7afb3b37ac313e7 Mon Sep 17 00:00:00 2001 From: Ghassen Rjab Date: Sat, 2 Sep 2017 07:17:42 +0100 Subject: Add source field to imported attachments We use this field to prevent adding attachments' related activities automatically only. Then this field will be removed. --- models/wekanCreator.js | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'models/wekanCreator.js') diff --git a/models/wekanCreator.js b/models/wekanCreator.js index d96ad2ca..3d0a2397 100644 --- a/models/wekanCreator.js +++ b/models/wekanCreator.js @@ -313,6 +313,9 @@ export class WekanCreator { file.boardId = boardId; file.cardId = cardId; file.userId = this._user(att.userId); + // The field source will only be used to prevent adding + // attachments' related activities automatically + file.source = 'import'; if (error) { throw(error); } else { @@ -332,6 +335,9 @@ export class WekanCreator { file.boardId = boardId; file.cardId = cardId; file.userId = this._user(att.userId); + // The field source will only be used to prevent adding + // attachments' related activities automatically + file.source = 'import'; if (error) { throw(error); } else { -- cgit v1.2.3-1-g7c22 From 255df20da068a203589dba15a5ad249183cd50f5 Mon Sep 17 00:00:00 2001 From: Ghassen Rjab Date: Sat, 2 Sep 2017 13:18:29 +0100 Subject: Put 'this' in 'self' variable For some reason, TrelloCreator didn't keep 'this' reference --- models/wekanCreator.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'models/wekanCreator.js') diff --git a/models/wekanCreator.js b/models/wekanCreator.js index 3d0a2397..7e320817 100644 --- a/models/wekanCreator.js +++ b/models/wekanCreator.js @@ -307,12 +307,13 @@ export class WekanCreator { // - HEAD returns null, which causes exception down the line // - the template then tries to display the url to the attachment which causes other errors // so we make it server only, and let UI catch up once it is done, forget about latency comp. + const self = this; if(Meteor.isServer) { if (att.url) { file.attachData(att.url, function (error) { file.boardId = boardId; file.cardId = cardId; - file.userId = this._user(att.userId); + file.userId = self._user(att.userId); // The field source will only be used to prevent adding // attachments' related activities automatically file.source = 'import'; @@ -322,7 +323,7 @@ export class WekanCreator { const wekanAtt = Attachments.insert(file, () => { // we do nothing }); - this.attachmentIds[att._id] = wekanAtt._id; + self.attachmentIds[att._id] = wekanAtt._id; // if(wekanCoverId === att._id) { Cards.direct.update(cardId, { $set: {coverId: wekanAtt._id}}); @@ -334,7 +335,7 @@ export class WekanCreator { file.name(att.name); file.boardId = boardId; file.cardId = cardId; - file.userId = this._user(att.userId); + file.userId = self._user(att.userId); // The field source will only be used to prevent adding // attachments' related activities automatically file.source = 'import'; -- cgit v1.2.3-1-g7c22 From 2e845a51343fccf6f8b6a2b9e1142d771f2cf40d Mon Sep 17 00:00:00 2001 From: Ghassen Rjab Date: Sat, 2 Sep 2017 13:19:31 +0100 Subject: Uncomment code about adding attachments' related activities --- models/wekanCreator.js | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) (limited to 'models/wekanCreator.js') diff --git a/models/wekanCreator.js b/models/wekanCreator.js index 7e320817..9c7f50ec 100644 --- a/models/wekanCreator.js +++ b/models/wekanCreator.js @@ -550,24 +550,18 @@ export class WekanCreator { break; } // Attachment related activities - // TODO: We can't add activities related to adding attachments - // because when we import an attachment, an activity is - // autmatically created. We need to directly insert the attachment - // without calling the "Attachments.files.after.insert" hook first, - // then we can uncomment the code below - // case 'addAttachment': { - // console.log(this.attachmentIds); - // Activities.direct.insert({ - // userId: this._user(activity.userId), - // type: 'card', - // activityType: activity.activityType, - // attachmentId: this.attachmentIds[activity.attachmentId], - // cardId: this.cards[activity.cardId], - // boardId, - // createdAt: this._now(activity.createdAt), - // }); - // break; - // } + case 'addAttachment': { + Activities.direct.insert({ + userId: this._user(activity.userId), + type: 'card', + activityType: activity.activityType, + attachmentId: this.attachmentIds[activity.attachmentId], + cardId: this.cards[activity.cardId], + boardId, + createdAt: this._now(activity.createdAt), + }); + break; + } // Checklist related activities case 'addChecklist': { Activities.direct.insert({ -- cgit v1.2.3-1-g7c22