소스 검색

Use a Meteor call to copy a board

The current method was to copy a board on the client side.  But
not all data was available for copying rules.  Moving the copy
function to the server side solves this problem.
John R. Supplee 4 년 전
부모
커밋
ff8a36653a
3개의 변경된 파일30개의 추가작업 그리고 6개의 파일을 삭제
  1. 13 6
      client/components/lists/listBody.js
  2. 1 0
      models/boards.js
  3. 16 0
      server/publications/boards.js

+ 13 - 6
client/components/lists/listBody.js

@@ -675,12 +675,19 @@ BlazeComponent.extendComponent({
             element.type = 'swimlane';
             _id = element.copy(this.boardId);
           } else if (this.isBoardTemplateSearch) {
-            board = Boards.findOne(element.linkedId);
-            board.sort = Boards.find({ archived: false }).count();
-            board.type = 'board';
-            board.title = element.title;
-            delete board.slug;
-            _id = board.copy();
+            Meteor.call(
+              'copyBoard',
+              element.linkedId,
+              {
+                sort: Boards.find({ archived: false }).count(),
+                type: 'board',
+                title: element.title,
+              },
+              (err, data) => {
+                _id = data;
+              },
+            );
+            // _id = board.copy();
           }
           Popup.close();
         },

+ 1 - 0
models/boards.js

@@ -508,6 +508,7 @@ Boards.helpers({
   copy() {
     const oldId = this._id;
     delete this._id;
+    delete this.slug;
     const _id = Boards.insert(this);
 
     // Copy all swimlanes in board

+ 16 - 0
server/publications/boards.js

@@ -209,3 +209,19 @@ Meteor.publishRelations('board', function(boardId, isArchived) {
 
   return this.ready();
 });
+
+Meteor.methods({
+  copyBoard(boardId, properties) {
+    check(boardId, String);
+    check(properties, Object);
+
+    const board = Boards.findOne(boardId);
+    if (board) {
+      for (const key in properties) {
+        board[key] = properties[key];
+      }
+      return board.copy();
+    }
+    return null;
+  },
+});