diff options
Diffstat (limited to 'models')
-rw-r--r-- | models/attachments.js | 121 | ||||
-rw-r--r-- | models/cards.js | 11 | ||||
-rw-r--r-- | models/export.js | 2 | ||||
-rw-r--r-- | models/trelloCreator.js | 1 | ||||
-rw-r--r-- | models/wekanCreator.js | 2 |
5 files changed, 44 insertions, 93 deletions
diff --git a/models/attachments.js b/models/attachments.js index 9b8ec04f..c35d3d4c 100644 --- a/models/attachments.js +++ b/models/attachments.js @@ -1,5 +1,35 @@ +import { FilesCollection } from 'meteor/ostrio:files'; + +Attachments = new FilesCollection({ + storagePath: storagePath(), + debug: false, // FIXME: Remove debug mode + collectionName: 'attachments2', + allowClientCode: true, // FIXME: Permissions + onAfterUpload: (fileRef) => { + Attachments.update({_id:fileRef._id}, {$set: {"meta.uploaded": true}}); + } +}); + +if (Meteor.isServer) { + Meteor.startup(() => { + Attachments.collection._ensureIndex({ cardId: 1 }); + }); + + // TODO: Permission related + // TODO: Add Activity update + // TODO: publish and subscribe + + Meteor.publish('attachments2', function() { + return Attachments.find().cursor; + }); +} else { + Meteor.subscribe('attachments2'); +} + +// ---------- Deprecated fallback ---------- // + const localFSStore = process.env.ATTACHMENTS_STORE_PATH; -const storeName = 'attachments'; +const storeName = 'attachments2'; const defaultStoreOptions = { beforeWrite: fileObj => { if (!fileObj.isImage()) { @@ -171,93 +201,10 @@ if (localFSStore) { ...defaultStoreOptions, }); } -Attachments = new FS.Collection('attachments', { - stores: [store], -}); - -if (Meteor.isServer) { - Meteor.startup(() => { - Attachments.files._ensureIndex({ cardId: 1 }); - }); - - Attachments.allow({ - insert(userId, doc) { - return allowIsBoardMember(userId, Boards.findOne(doc.boardId)); - }, - update(userId, doc) { - return allowIsBoardMember(userId, Boards.findOne(doc.boardId)); - }, - remove(userId, doc) { - return allowIsBoardMember(userId, Boards.findOne(doc.boardId)); - }, - // We authorize the attachment download either: - // - if the board is public, everyone (even unconnected) can download it - // - if the board is private, only board members can download it - download(userId, doc) { - const board = Boards.findOne(doc.boardId); - if (board.isPublic()) { - return true; - } else { - return board.hasMember(userId); - } - }, - - fetch: ['boardId'], - }); -} -// XXX Enforce a schema for the Attachments CollectionFS - -if (Meteor.isServer) { - Attachments.files.after.insert((userId, doc) => { - // 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, - listId: doc.listId, - swimlaneId: doc.swimlaneId, - }); - } 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.before.remove((userId, doc) => { - Activities.insert({ - userId, - type: 'card', - activityType: 'deleteAttachment', - attachmentId: doc._id, - boardId: doc.boardId, - cardId: doc.cardId, - listId: doc.listId, - swimlaneId: doc.swimlaneId, - }); - }); - - Attachments.files.after.remove((userId, doc) => { - Activities.remove({ - attachmentId: doc._id, - }); - }); +function storagePath(defaultPath) { + const storePath = process.env.ATTACHMENTS_STORE_PATH; + return storePath ? storePath : defaultPath; } export default Attachments; diff --git a/models/cards.js b/models/cards.js index eed1b958..fac8922c 100644 --- a/models/cards.js +++ b/models/cards.js @@ -367,7 +367,7 @@ Cards.helpers({ // Copy attachments oldCard.attachments().forEach(att => { - att.cardId = _id; + att.meta.cardId = _id; delete att._id; return Attachments.insert(att); }); @@ -457,14 +457,15 @@ Cards.helpers({ attachments() { if (this.isLinkedCard()) { return Attachments.find( - { cardId: this.linkedId }, + { 'meta.cardId': this.linkedId }, { sort: { uploadedAt: -1 } }, ); } else { - return Attachments.find( - { cardId: this._id }, + let ret = Attachments.find( + { 'meta.cardId': this._id }, { sort: { uploadedAt: -1 } }, ); + return ret; } }, @@ -472,7 +473,7 @@ Cards.helpers({ const cover = Attachments.findOne(this.coverId); // if we return a cover before it is fully stored, we will get errors when we try to display it // todo XXX we could return a default "upload pending" image in the meantime? - return cover && cover.url() && cover; + return cover && cover.link(); }, checklists() { diff --git a/models/export.js b/models/export.js index 339123c8..35e55804 100644 --- a/models/export.js +++ b/models/export.js @@ -165,7 +165,7 @@ export class Exporter { readStream.pipe(tmpWriteable); }; const getBase64DataSync = Meteor.wrapAsync(getBase64Data); - result.attachments = Attachments.find(byBoard) + result.attachments = Attachments.find({ 'meta.boardId': byBoard.boardId }) .fetch() .map(attachment => { let filebase64 = null; diff --git a/models/trelloCreator.js b/models/trelloCreator.js index cb1a6a67..b38e4652 100644 --- a/models/trelloCreator.js +++ b/models/trelloCreator.js @@ -345,6 +345,7 @@ export class TrelloCreator { // 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) { + // FIXME: Change to new model file.attachData(att.url, function(error) { file.boardId = boardId; file.cardId = cardId; diff --git a/models/wekanCreator.js b/models/wekanCreator.js index 9914f817..c5591a0b 100644 --- a/models/wekanCreator.js +++ b/models/wekanCreator.js @@ -415,6 +415,7 @@ export class WekanCreator { const self = this; if (Meteor.isServer) { if (att.url) { + // FIXME: Change to new file library file.attachData(att.url, function(error) { file.boardId = boardId; file.cardId = cardId; @@ -440,6 +441,7 @@ export class WekanCreator { } }); } else if (att.file) { + // FIXME: Change to new file library file.attachData( Buffer.from(att.file, 'base64'), { |