Pārlūkot izejas kodu

Add source field to imported attachments

We use this field to prevent adding attachments' related activities automatically only. Then this field will be removed.
Ghassen Rjab 7 gadi atpakaļ
vecāks
revīzija
6ff0cf91e2
3 mainītis faili ar 26 papildinājumiem un 8 dzēšanām
  1. 17 8
      models/attachments.js
  2. 3 0
      models/trelloCreator.js
  3. 6 0
      models/wekanCreator.js

+ 17 - 8
models/attachments.js

@@ -55,14 +55,23 @@ if (Meteor.isServer) {
 
 if (Meteor.isServer) {
   Attachments.files.after.insert((userId, doc) => {
-    Activities.insert({
-      userId,
-      type: 'card',
-      activityType: 'addAttachment',
-      attachmentId: doc._id,
-      boardId: doc.boardId,
-      cardId: doc.cardId,
-    });
+    // If the attachment doesn't have a source field
+    // or its source is different than import
+    if (!doc.source || doc.source !== 'import') {
+      // Add activity about adding the attachment
+      Activities.insert({
+        userId,
+        type: 'card',
+        activityType: 'addAttachment',
+        attachmentId: doc._id,
+        boardId: doc.boardId,
+        cardId: doc.cardId,
+      });
+    } else {
+      // Don't add activity about adding the attachment as the activity
+      // be imported and delete source field
+      Attachments.update( {_id: doc._id} , {$unset: { source : "" } } );
+    }
   });
 
   Attachments.files.after.remove((userId, doc) => {

+ 3 - 0
models/trelloCreator.js

@@ -323,6 +323,9 @@ export class TrelloCreator {
               file.boardId = boardId;
               file.cardId = cardId;
               file.userId = this._user(att.idMemberCreator);
+              // The field source will only be used to prevent adding
+              // attachments' related activities automatically
+              file.source = 'import';
               if (error) {
                 throw(error);
               } else {

+ 6 - 0
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 {