mirror of
https://github.com/wekan/wekan.git
synced 2025-12-23 02:40:14 +01:00
Export/Import done for rules
This commit is contained in:
parent
a57806b054
commit
8cb132f492
2 changed files with 351 additions and 192 deletions
|
|
@ -29,7 +29,10 @@ if (Meteor.isServer) {
|
|||
|
||||
const exporter = new Exporter(boardId);
|
||||
if (exporter.canExport(user)) {
|
||||
JsonRoutes.sendResult(res, { code: 200, data: exporter.build() });
|
||||
JsonRoutes.sendResult(res, {
|
||||
code: 200,
|
||||
data: exporter.build()
|
||||
});
|
||||
} else {
|
||||
// we could send an explicit error message, but on the other hand the only
|
||||
// way to get there is by hacking the UI so let's keep it raw.
|
||||
|
|
@ -44,25 +47,52 @@ class Exporter {
|
|||
}
|
||||
|
||||
build() {
|
||||
const byBoard = { boardId: this._boardId };
|
||||
const byBoard = {
|
||||
boardId: this._boardId
|
||||
};
|
||||
// we do not want to retrieve boardId in related elements
|
||||
const noBoardId = { fields: { boardId: 0 } };
|
||||
const noBoardId = {
|
||||
fields: {
|
||||
boardId: 0
|
||||
}
|
||||
};
|
||||
const result = {
|
||||
_format: 'wekan-board-1.0.0',
|
||||
};
|
||||
_.extend(result, Boards.findOne(this._boardId, { fields: { stars: 0 } }));
|
||||
_.extend(result, Boards.findOne(this._boardId, {
|
||||
fields: {
|
||||
stars: 0
|
||||
}
|
||||
}));
|
||||
result.lists = Lists.find(byBoard, noBoardId).fetch();
|
||||
result.cards = Cards.find(byBoard, noBoardId).fetch();
|
||||
result.swimlanes = Swimlanes.find(byBoard, noBoardId).fetch();
|
||||
result.comments = CardComments.find(byBoard, noBoardId).fetch();
|
||||
result.activities = Activities.find(byBoard, noBoardId).fetch();
|
||||
result.rules = Rules.find(byBoard, noBoardId).fetch();
|
||||
result.checklists = [];
|
||||
result.checklistItems = [];
|
||||
result.subtaskItems = [];
|
||||
result.triggers = [];
|
||||
result.actions = [];
|
||||
result.cards.forEach((card) => {
|
||||
result.checklists.push(...Checklists.find({ cardId: card._id }).fetch());
|
||||
result.checklistItems.push(...ChecklistItems.find({ cardId: card._id }).fetch());
|
||||
result.subtaskItems.push(...Cards.find({ parentid: card._id }).fetch());
|
||||
result.checklists.push(...Checklists.find({
|
||||
cardId: card._id
|
||||
}).fetch());
|
||||
result.checklistItems.push(...ChecklistItems.find({
|
||||
cardId: card._id
|
||||
}).fetch());
|
||||
result.subtaskItems.push(...Cards.find({
|
||||
parentid: card._id
|
||||
}).fetch());
|
||||
});
|
||||
result.rules.forEach((rule) => {
|
||||
result.triggers.push(...Triggers.find({
|
||||
_id: rule.triggerId
|
||||
}, noBoardId).fetch());
|
||||
result.actions.push(...Actions.find({
|
||||
_id: rule.actionId
|
||||
}, noBoardId).fetch());
|
||||
});
|
||||
|
||||
// [Old] for attachments we only export IDs and absolute url to original doc
|
||||
|
|
@ -99,18 +129,34 @@ class Exporter {
|
|||
// 1- only exports users that are linked somehow to that board
|
||||
// 2- do not export any sensitive information
|
||||
const users = {};
|
||||
result.members.forEach((member) => { users[member.userId] = true; });
|
||||
result.lists.forEach((list) => { users[list.userId] = true; });
|
||||
result.members.forEach((member) => {
|
||||
users[member.userId] = true;
|
||||
});
|
||||
result.lists.forEach((list) => {
|
||||
users[list.userId] = true;
|
||||
});
|
||||
result.cards.forEach((card) => {
|
||||
users[card.userId] = true;
|
||||
if (card.members) {
|
||||
card.members.forEach((memberId) => { users[memberId] = true; });
|
||||
card.members.forEach((memberId) => {
|
||||
users[memberId] = true;
|
||||
});
|
||||
}
|
||||
});
|
||||
result.comments.forEach((comment) => { users[comment.userId] = true; });
|
||||
result.activities.forEach((activity) => { users[activity.userId] = true; });
|
||||
result.checklists.forEach((checklist) => { users[checklist.userId] = true; });
|
||||
const byUserIds = { _id: { $in: Object.getOwnPropertyNames(users) } };
|
||||
result.comments.forEach((comment) => {
|
||||
users[comment.userId] = true;
|
||||
});
|
||||
result.activities.forEach((activity) => {
|
||||
users[activity.userId] = true;
|
||||
});
|
||||
result.checklists.forEach((checklist) => {
|
||||
users[checklist.userId] = true;
|
||||
});
|
||||
const byUserIds = {
|
||||
_id: {
|
||||
$in: Object.getOwnPropertyNames(users)
|
||||
}
|
||||
};
|
||||
// we use whitelist to be sure we do not expose inadvertently
|
||||
// some secret fields that gets added to User later.
|
||||
const userFields = {
|
||||
|
|
|
|||
|
|
@ -42,6 +42,10 @@ export class WekanCreator {
|
|||
this.comments = {};
|
||||
// the members, indexed by Wekan member id => Wekan user ID
|
||||
this.members = data.membersMapping ? data.membersMapping : {};
|
||||
// Map of triggers Wekan ID => Wekan ID
|
||||
this.triggers = {};
|
||||
// Map of actions Wekan ID => Wekan ID
|
||||
this.actions = {};
|
||||
|
||||
// maps a wekanCardId to an array of wekanAttachments
|
||||
this.attachments = {};
|
||||
|
|
@ -147,6 +151,30 @@ export class WekanCreator {
|
|||
})]);
|
||||
}
|
||||
|
||||
checkRules(wekanRules) {
|
||||
check(wekanRules, [Match.ObjectIncluding({
|
||||
triggerId: String,
|
||||
actionId: String,
|
||||
title: String,
|
||||
})]);
|
||||
}
|
||||
|
||||
checkTriggers(wekanTriggers) {
|
||||
// XXX More check based on trigger type
|
||||
check(wekanTriggers, [Match.ObjectIncluding({
|
||||
activityType: String,
|
||||
desc: String,
|
||||
})]);
|
||||
}
|
||||
|
||||
checkActions(wekanActions) {
|
||||
// XXX More check based on action type
|
||||
check(wekanActions, [Match.ObjectIncluding({
|
||||
actionType: String,
|
||||
desc: String,
|
||||
})]);
|
||||
}
|
||||
|
||||
// You must call parseActions before calling this one.
|
||||
createBoardAndLabels(boardToImport) {
|
||||
const boardToCreate = {
|
||||
|
|
@ -193,7 +221,11 @@ export class WekanCreator {
|
|||
boardToCreate.labels.push(labelToCreate);
|
||||
});
|
||||
const boardId = Boards.direct.insert(boardToCreate);
|
||||
Boards.direct.update(boardId, {$set: {modifiedAt: this._now()}});
|
||||
Boards.direct.update(boardId, {
|
||||
$set: {
|
||||
modifiedAt: this._now()
|
||||
}
|
||||
});
|
||||
// log activity
|
||||
Activities.direct.insert({
|
||||
activityType: 'importBoard',
|
||||
|
|
@ -338,12 +370,18 @@ export class WekanCreator {
|
|||
self.attachmentIds[att._id] = wekanAtt._id;
|
||||
//
|
||||
if (wekanCoverId === att._id) {
|
||||
Cards.direct.update(cardId, { $set: {coverId: wekanAtt._id}});
|
||||
Cards.direct.update(cardId, {
|
||||
$set: {
|
||||
coverId: wekanAtt._id
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
} else if (att.file) {
|
||||
file.attachData(new Buffer(att.file, 'base64'), {type: att.type}, (error) => {
|
||||
file.attachData(new Buffer(att.file, 'base64'), {
|
||||
type: att.type
|
||||
}, (error) => {
|
||||
file.name(att.name);
|
||||
file.boardId = boardId;
|
||||
file.cardId = cardId;
|
||||
|
|
@ -360,7 +398,11 @@ export class WekanCreator {
|
|||
this.attachmentIds[att._id] = wekanAtt._id;
|
||||
//
|
||||
if (wekanCoverId === att._id) {
|
||||
Cards.direct.update(cardId, { $set: {coverId: wekanAtt._id}});
|
||||
Cards.direct.update(cardId, {
|
||||
$set: {
|
||||
coverId: wekanAtt._id
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -403,7 +445,11 @@ export class WekanCreator {
|
|||
sort: list.sort ? list.sort : listIndex,
|
||||
};
|
||||
const listId = Lists.direct.insert(listToCreate);
|
||||
Lists.direct.update(listId, {$set: {'updatedAt': this._now()}});
|
||||
Lists.direct.update(listId, {
|
||||
$set: {
|
||||
'updatedAt': this._now()
|
||||
}
|
||||
});
|
||||
this.lists[list._id] = listId;
|
||||
// // log activity
|
||||
// Activities.direct.insert({
|
||||
|
|
@ -436,7 +482,11 @@ export class WekanCreator {
|
|||
sort: swimlane.sort ? swimlane.sort : swimlaneIndex,
|
||||
};
|
||||
const swimlaneId = Swimlanes.direct.insert(swimlaneToCreate);
|
||||
Swimlanes.direct.update(swimlaneId, {$set: {'updatedAt': this._now()}});
|
||||
Swimlanes.direct.update(swimlaneId, {
|
||||
$set: {
|
||||
'updatedAt': this._now()
|
||||
}
|
||||
});
|
||||
this.swimlanes[swimlane._id] = swimlaneId;
|
||||
});
|
||||
}
|
||||
|
|
@ -458,6 +508,47 @@ export class WekanCreator {
|
|||
return result;
|
||||
}
|
||||
|
||||
createTriggers(wekanTriggers, boardId) {
|
||||
wekanTriggers.forEach((trigger, ruleIndex) => {
|
||||
if (trigger.hasOwnProperty('labelId')) {
|
||||
trigger['labelId'] = this.labels[trigger['labelId']]
|
||||
}
|
||||
if (trigger.hasOwnProperty('memberId')) {
|
||||
trigger['memberId'] = this.members[trigger['memberId']]
|
||||
}
|
||||
trigger['boardId'] = boardId;
|
||||
const oldId = trigger['_id'];
|
||||
delete trigger._id;
|
||||
this.triggers[oldId] = Triggers.direct.insert(trigger);
|
||||
});
|
||||
}
|
||||
|
||||
createActions(wekanActions, boardId) {
|
||||
wekanActions.forEach((action, ruleIndex) => {
|
||||
if (action.hasOwnProperty('labelId')) {
|
||||
action['labelId'] = this.labels[action['labelId']]
|
||||
}
|
||||
if (action.hasOwnProperty('memberId')) {
|
||||
action['memberId'] = this.members[action['memberId']]
|
||||
}
|
||||
action['boardId'] = boardId;
|
||||
const oldId = action['_id'];
|
||||
delete action._id;
|
||||
this.actions[oldId] = Actions.direct.insert(action);
|
||||
});
|
||||
}
|
||||
|
||||
createRules(wekanRules, boardId) {
|
||||
wekanRules.forEach((rule, ruleIndex) => {
|
||||
// Create the rule
|
||||
rule['boardId'] = boardId;
|
||||
rule['triggerId'] = this.triggers[rule['triggerId']];
|
||||
rule['actionId'] = this.actions[rule['actionId']];
|
||||
delete rule._id;
|
||||
Rules.direct.insert(rule);
|
||||
});
|
||||
}
|
||||
|
||||
createChecklistItems(wekanChecklistItems) {
|
||||
wekanChecklistItems.forEach((checklistitem, checklistitemIndex) => {
|
||||
// Create the checklistItem
|
||||
|
|
@ -476,7 +567,8 @@ export class WekanCreator {
|
|||
parseActivities(wekanBoard) {
|
||||
wekanBoard.activities.forEach((activity) => {
|
||||
switch (activity.activityType) {
|
||||
case 'addAttachment': {
|
||||
case 'addAttachment':
|
||||
{
|
||||
// We have to be cautious, because the attachment could have been removed later.
|
||||
// In that case Wekan still reports its addition, but removes its 'url' field.
|
||||
// So we test for that
|
||||
|
|
@ -497,7 +589,8 @@ export class WekanCreator {
|
|||
}
|
||||
break;
|
||||
}
|
||||
case 'addComment': {
|
||||
case 'addComment':
|
||||
{
|
||||
const wekanComment = wekanBoard.comments.filter((comment) => {
|
||||
return comment._id === activity.commentId;
|
||||
})[0];
|
||||
|
|
@ -508,26 +601,31 @@ export class WekanCreator {
|
|||
this.comments[id].push(wekanComment);
|
||||
break;
|
||||
}
|
||||
case 'createBoard': {
|
||||
case 'createBoard':
|
||||
{
|
||||
this.createdAt.board = activity.createdAt;
|
||||
break;
|
||||
}
|
||||
case 'createCard': {
|
||||
case 'createCard':
|
||||
{
|
||||
const cardId = activity.cardId;
|
||||
this.createdAt.cards[cardId] = activity.createdAt;
|
||||
this.createdBy.cards[cardId] = activity.userId;
|
||||
break;
|
||||
}
|
||||
case 'createList': {
|
||||
case 'createList':
|
||||
{
|
||||
const listId = activity.listId;
|
||||
this.createdAt.lists[listId] = activity.createdAt;
|
||||
break;
|
||||
}
|
||||
case 'createSwimlane': {
|
||||
case 'createSwimlane':
|
||||
{
|
||||
const swimlaneId = activity.swimlaneId;
|
||||
this.createdAt.swimlanes[swimlaneId] = activity.createdAt;
|
||||
break;
|
||||
}}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -536,7 +634,8 @@ export class WekanCreator {
|
|||
switch (activity.activityType) {
|
||||
// Board related activities
|
||||
// TODO: addBoardMember, removeBoardMember
|
||||
case 'createBoard': {
|
||||
case 'createBoard':
|
||||
{
|
||||
Activities.direct.insert({
|
||||
userId: this._user(activity.userId),
|
||||
type: 'board',
|
||||
|
|
@ -549,7 +648,8 @@ export class WekanCreator {
|
|||
}
|
||||
// List related activities
|
||||
// TODO: removeList, archivedList
|
||||
case 'createList': {
|
||||
case 'createList':
|
||||
{
|
||||
Activities.direct.insert({
|
||||
userId: this._user(activity.userId),
|
||||
type: 'list',
|
||||
|
|
@ -562,7 +662,8 @@ export class WekanCreator {
|
|||
}
|
||||
// Card related activities
|
||||
// TODO: archivedCard, restoredCard, joinMember, unjoinMember
|
||||
case 'createCard': {
|
||||
case 'createCard':
|
||||
{
|
||||
Activities.direct.insert({
|
||||
userId: this._user(activity.userId),
|
||||
activityType: activity.activityType,
|
||||
|
|
@ -573,7 +674,8 @@ export class WekanCreator {
|
|||
});
|
||||
break;
|
||||
}
|
||||
case 'moveCard': {
|
||||
case 'moveCard':
|
||||
{
|
||||
Activities.direct.insert({
|
||||
userId: this._user(activity.userId),
|
||||
oldListId: this.lists[activity.oldListId],
|
||||
|
|
@ -586,7 +688,8 @@ export class WekanCreator {
|
|||
break;
|
||||
}
|
||||
// Comment related activities
|
||||
case 'addComment': {
|
||||
case 'addComment':
|
||||
{
|
||||
Activities.direct.insert({
|
||||
userId: this._user(activity.userId),
|
||||
activityType: activity.activityType,
|
||||
|
|
@ -598,7 +701,8 @@ export class WekanCreator {
|
|||
break;
|
||||
}
|
||||
// Attachment related activities
|
||||
case 'addAttachment': {
|
||||
case 'addAttachment':
|
||||
{
|
||||
Activities.direct.insert({
|
||||
userId: this._user(activity.userId),
|
||||
type: 'card',
|
||||
|
|
@ -611,7 +715,8 @@ export class WekanCreator {
|
|||
break;
|
||||
}
|
||||
// Checklist related activities
|
||||
case 'addChecklist': {
|
||||
case 'addChecklist':
|
||||
{
|
||||
Activities.direct.insert({
|
||||
userId: this._user(activity.userId),
|
||||
activityType: activity.activityType,
|
||||
|
|
@ -622,7 +727,8 @@ export class WekanCreator {
|
|||
});
|
||||
break;
|
||||
}
|
||||
case 'addChecklistItem': {
|
||||
case 'addChecklistItem':
|
||||
{
|
||||
Activities.direct.insert({
|
||||
userId: this._user(activity.userId),
|
||||
activityType: activity.activityType,
|
||||
|
|
@ -635,7 +741,8 @@ export class WekanCreator {
|
|||
createdAt: this._now(activity.createdAt),
|
||||
});
|
||||
break;
|
||||
}}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -651,6 +758,9 @@ export class WekanCreator {
|
|||
this.checkSwimlanes(board.swimlanes);
|
||||
this.checkCards(board.cards);
|
||||
this.checkChecklists(board.checklists);
|
||||
this.checkRules(board.rules);
|
||||
this.checkActions(board.actions);
|
||||
this.checkTriggers(board.triggers);
|
||||
this.checkChecklistItems(board.checklistItems);
|
||||
} catch (e) {
|
||||
throw new Meteor.Error('error-json-schema');
|
||||
|
|
@ -673,6 +783,9 @@ export class WekanCreator {
|
|||
this.createChecklists(board.checklists);
|
||||
this.createChecklistItems(board.checklistItems);
|
||||
this.importActivities(board.activities, boardId);
|
||||
this.createTriggers(board.triggers, boardId);
|
||||
this.createActions(board.actions, boardId);
|
||||
this.createRules(board.rules, boardId);
|
||||
// XXX add members
|
||||
return boardId;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue