mirror of
https://github.com/wekan/wekan.git
synced 2026-01-06 01:28:49 +01:00
Start writing migration
This commit is contained in:
parent
617fdaeb74
commit
b34ed58289
3 changed files with 272 additions and 97 deletions
|
|
@ -19,17 +19,17 @@ if (Meteor.isServer) {
|
|||
// TODO: Add Activity update
|
||||
// TODO: publish and subscribe
|
||||
|
||||
Meteor.publish('attachments', function() {
|
||||
Meteor.publish('attachments2', function() {
|
||||
return Attachments.find().cursor;
|
||||
});
|
||||
} else {
|
||||
Meteor.subscribe('attachments');
|
||||
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()) {
|
||||
|
|
@ -201,102 +201,8 @@ if (localFSStore) {
|
|||
...defaultStoreOptions,
|
||||
});
|
||||
}
|
||||
DeprecatedAttachs = new FS.Collection('attachments', {
|
||||
stores: [store],
|
||||
});
|
||||
|
||||
if (Meteor.isServer) {
|
||||
Meteor.startup(() => {
|
||||
DeprecatedAttachs.files._ensureIndex({ cardId: 1 });
|
||||
});
|
||||
|
||||
DeprecatedAttachs.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 DeprecatedAttachs CollectionFS
|
||||
|
||||
if (Meteor.isServer) {
|
||||
DeprecatedAttachs.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
|
||||
DeprecatedAttachs.update(
|
||||
{
|
||||
_id: doc._id,
|
||||
},
|
||||
{
|
||||
$unset: {
|
||||
source: '',
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
DeprecatedAttachs.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,
|
||||
});
|
||||
});
|
||||
|
||||
DeprecatedAttachs.files.after.remove((userId, doc) => {
|
||||
Activities.remove({
|
||||
attachmentId: doc._id,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function storagePath(defaultPath) {
|
||||
/*
|
||||
console.log('path', process.env.ATTACHMENTS_STORE_PATH);
|
||||
console.log('env', process.env);
|
||||
// FIXME
|
||||
return '/var/attachments';
|
||||
*/
|
||||
const storePath = process.env.ATTACHMENTS_STORE_PATH;
|
||||
return storePath ? storePath : defaultPath;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue