mirror of
https://github.com/wekan/wekan.git
synced 2026-01-06 17:48:49 +01:00
Merge branch 'feature-rules' of https://github.com/Angtrim/wekan into Angtrim-feature-rules
This commit is contained in:
commit
6673b79738
60 changed files with 3074 additions and 259 deletions
BIN
models/.DS_Store
vendored
Normal file
BIN
models/.DS_Store
vendored
Normal file
Binary file not shown.
19
models/actions.js
Normal file
19
models/actions.js
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
Actions = new Mongo.Collection('actions');
|
||||
|
||||
Actions.allow({
|
||||
insert(userId, doc) {
|
||||
return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId));
|
||||
},
|
||||
update(userId, doc) {
|
||||
return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId));
|
||||
},
|
||||
remove(userId, doc) {
|
||||
return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId));
|
||||
}
|
||||
});
|
||||
|
||||
Actions.helpers({
|
||||
description() {
|
||||
return this.desc;
|
||||
}
|
||||
});
|
||||
|
|
@ -56,6 +56,17 @@ Activities.before.insert((userId, doc) => {
|
|||
doc.createdAt = new Date();
|
||||
});
|
||||
|
||||
|
||||
|
||||
Activities.after.insert((userId, doc) => {
|
||||
const activity = Activities._transform(doc);
|
||||
RulesHelper.executeRules(activity);
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
if (Meteor.isServer) {
|
||||
// For efficiency create indexes on the date of creation, and on the date of
|
||||
// creation in conjunction with the card or board id, as corresponding views
|
||||
|
|
|
|||
|
|
@ -86,5 +86,12 @@ if (Meteor.isServer) {
|
|||
Activities.remove({
|
||||
attachmentId: doc._id,
|
||||
});
|
||||
Activities.insert({
|
||||
userId,
|
||||
type: 'card',
|
||||
activityType: 'deleteAttachment',
|
||||
boardId: doc.boardId,
|
||||
cardId: doc.cardId,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -280,6 +280,10 @@ Boards.helpers({
|
|||
return _.findWhere(this.labels, { name, color });
|
||||
},
|
||||
|
||||
getLabelById(labelId){
|
||||
return _.findWhere(this.labels, { _id: labelId });
|
||||
},
|
||||
|
||||
labelIndex(labelId) {
|
||||
return _.pluck(this.labels, '_id').indexOf(labelId);
|
||||
},
|
||||
|
|
|
|||
410
models/cards.js
410
models/cards.js
|
|
@ -276,14 +276,22 @@ Cards.helpers({
|
|||
return Cards.find({
|
||||
parentId: this._id,
|
||||
archived: false,
|
||||
}, {sort: { sort: 1 } });
|
||||
}, {
|
||||
sort: {
|
||||
sort: 1
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
allSubtasks() {
|
||||
return Cards.find({
|
||||
parentId: this._id,
|
||||
archived: false,
|
||||
}, {sort: { sort: 1 } });
|
||||
}, {
|
||||
sort: {
|
||||
sort: 1
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
subtasksCount() {
|
||||
|
|
@ -296,7 +304,8 @@ Cards.helpers({
|
|||
subtasksFinishedCount() {
|
||||
return Cards.find({
|
||||
parentId: this._id,
|
||||
archived: true}).count();
|
||||
archived: true
|
||||
}).count();
|
||||
},
|
||||
|
||||
subtasksFinished() {
|
||||
|
|
@ -328,12 +337,9 @@ Cards.helpers({
|
|||
});
|
||||
//search for "True Value" which is for DropDowns other then the Value (which is the id)
|
||||
let trueValue = customField.value;
|
||||
if (definition.settings.dropdownItems && definition.settings.dropdownItems.length > 0)
|
||||
{
|
||||
for (let i = 0; i < definition.settings.dropdownItems.length; i++)
|
||||
{
|
||||
if (definition.settings.dropdownItems[i]._id === customField.value)
|
||||
{
|
||||
if (definition.settings.dropdownItems && definition.settings.dropdownItems.length > 0) {
|
||||
for (let i = 0; i < definition.settings.dropdownItems.length; i++) {
|
||||
if (definition.settings.dropdownItems[i]._id === customField.value) {
|
||||
trueValue = definition.settings.dropdownItems[i].name;
|
||||
}
|
||||
}
|
||||
|
|
@ -358,8 +364,10 @@ Cards.helpers({
|
|||
},
|
||||
|
||||
canBeRestored() {
|
||||
const list = Lists.findOne({_id: this.listId});
|
||||
if(!list.getWipLimit('soft') && list.getWipLimit('enabled') && list.getWipLimit('value') === list.cards().count()){
|
||||
const list = Lists.findOne({
|
||||
_id: this.listId
|
||||
});
|
||||
if (!list.getWipLimit('soft') && list.getWipLimit('enabled') && list.getWipLimit('value') === list.cards().count()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
@ -424,7 +432,7 @@ Cards.helpers({
|
|||
},
|
||||
|
||||
parentString(sep) {
|
||||
return this.parentList().map(function(elem){
|
||||
return this.parentList().map(function(elem) {
|
||||
return elem.title;
|
||||
}).join(sep);
|
||||
},
|
||||
|
|
@ -826,19 +834,65 @@ Cards.helpers({
|
|||
|
||||
Cards.mutations({
|
||||
applyToChildren(funct) {
|
||||
Cards.find({ parentId: this._id }).forEach((card) => {
|
||||
Cards.find({
|
||||
parentId: this._id
|
||||
}).forEach((card) => {
|
||||
funct(card);
|
||||
});
|
||||
},
|
||||
|
||||
archive() {
|
||||
this.applyToChildren((card) => { return card.archive(); });
|
||||
return {$set: {archived: true}};
|
||||
this.applyToChildren((card) => {
|
||||
return card.archive();
|
||||
});
|
||||
return {
|
||||
$set: {
|
||||
archived: true
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
restore() {
|
||||
this.applyToChildren((card) => { return card.restore(); });
|
||||
return {$set: {archived: false}};
|
||||
this.applyToChildren((card) => {
|
||||
return card.restore();
|
||||
});
|
||||
return {
|
||||
$set: {
|
||||
archived: false
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
setTitle(title) {
|
||||
return {
|
||||
$set: {
|
||||
title
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
setDescription(description) {
|
||||
return {
|
||||
$set: {
|
||||
description
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
setRequestedBy(requestedBy) {
|
||||
return {
|
||||
$set: {
|
||||
requestedBy
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
setAssignedBy(assignedBy) {
|
||||
return {
|
||||
$set: {
|
||||
assignedBy
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
move(swimlaneId, listId, sortIndex) {
|
||||
|
|
@ -850,15 +904,25 @@ Cards.mutations({
|
|||
sort: sortIndex,
|
||||
};
|
||||
|
||||
return {$set: mutatedFields};
|
||||
return {
|
||||
$set: mutatedFields
|
||||
};
|
||||
},
|
||||
|
||||
addLabel(labelId) {
|
||||
return {$addToSet: {labelIds: labelId}};
|
||||
return {
|
||||
$addToSet: {
|
||||
labelIds: labelId
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
removeLabel(labelId) {
|
||||
return {$pull: {labelIds: labelId}};
|
||||
return {
|
||||
$pull: {
|
||||
labelIds: labelId
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
toggleLabel(labelId) {
|
||||
|
|
@ -869,12 +933,52 @@ Cards.mutations({
|
|||
}
|
||||
},
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
assignMember(memberId) {
|
||||
return {
|
||||
$addToSet: {
|
||||
members: memberId
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
unassignMember(memberId) {
|
||||
return {
|
||||
$pull: {
|
||||
members: memberId
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
toggleMember(memberId) {
|
||||
if (this.members && this.members.indexOf(memberId) > -1) {
|
||||
return this.unassignMember(memberId);
|
||||
} else {
|
||||
return this.assignMember(memberId);
|
||||
}
|
||||
},
|
||||
|
||||
>>>>>>> 36c04edb9f7cf16fb450b76598c4957968d4674b
|
||||
assignCustomField(customFieldId) {
|
||||
return {$addToSet: {customFields: {_id: customFieldId, value: null}}};
|
||||
return {
|
||||
$addToSet: {
|
||||
customFields: {
|
||||
_id: customFieldId,
|
||||
value: null
|
||||
}
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
unassignCustomField(customFieldId) {
|
||||
return {$pull: {customFields: {_id: customFieldId}}};
|
||||
return {
|
||||
$pull: {
|
||||
customFields: {
|
||||
_id: customFieldId
|
||||
}
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
toggleCustomField(customFieldId) {
|
||||
|
|
@ -889,7 +993,9 @@ Cards.mutations({
|
|||
// todo
|
||||
const index = this.customFieldIndex(customFieldId);
|
||||
if (index > -1) {
|
||||
const update = {$set: {}};
|
||||
const update = {
|
||||
$set: {}
|
||||
};
|
||||
update.$set[`customFields.${index}.value`] = value;
|
||||
return update;
|
||||
}
|
||||
|
|
@ -899,19 +1005,122 @@ Cards.mutations({
|
|||
},
|
||||
|
||||
setCover(coverId) {
|
||||
return {$set: {coverId}};
|
||||
return {
|
||||
$set: {
|
||||
coverId
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
unsetCover() {
|
||||
return {$unset: {coverId: ''}};
|
||||
return {
|
||||
$unset: {
|
||||
coverId: ''
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
setReceived(receivedAt) {
|
||||
return {
|
||||
$set: {
|
||||
receivedAt
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
unsetReceived() {
|
||||
return {
|
||||
$unset: {
|
||||
receivedAt: ''
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
setStart(startAt) {
|
||||
return {
|
||||
$set: {
|
||||
startAt
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
unsetStart() {
|
||||
return {
|
||||
$unset: {
|
||||
startAt: ''
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
setDue(dueAt) {
|
||||
return {
|
||||
$set: {
|
||||
dueAt
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
unsetDue() {
|
||||
return {
|
||||
$unset: {
|
||||
dueAt: ''
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
setEnd(endAt) {
|
||||
return {
|
||||
$set: {
|
||||
endAt
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
unsetEnd() {
|
||||
return {
|
||||
$unset: {
|
||||
endAt: ''
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
setOvertime(isOvertime) {
|
||||
return {
|
||||
$set: {
|
||||
isOvertime
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
setSpentTime(spentTime) {
|
||||
return {
|
||||
$set: {
|
||||
spentTime
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
unsetSpentTime() {
|
||||
return {
|
||||
$unset: {
|
||||
spentTime: '',
|
||||
isOvertime: false
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
>>>>>>> 36c04edb9f7cf16fb450b76598c4957968d4674b
|
||||
setParentId(parentId) {
|
||||
return {$set: {parentId}};
|
||||
return {
|
||||
$set: {
|
||||
parentId
|
||||
}
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
//FUNCTIONS FOR creation of Activities
|
||||
|
||||
function cardMove(userId, doc, fieldNames, oldListId, oldSwimlaneId) {
|
||||
|
|
@ -921,6 +1130,7 @@ function cardMove(userId, doc, fieldNames, oldListId, oldSwimlaneId) {
|
|||
userId,
|
||||
oldListId,
|
||||
activityType: 'moveCard',
|
||||
listName: Lists.findOne(doc.listId).title,
|
||||
listId: doc.listId,
|
||||
boardId: doc.boardId,
|
||||
cardId: doc._id,
|
||||
|
|
@ -936,6 +1146,7 @@ function cardState(userId, doc, fieldNames) {
|
|||
Activities.insert({
|
||||
userId,
|
||||
activityType: 'archivedCard',
|
||||
listName: Lists.findOne(doc.listId).title,
|
||||
boardId: doc.boardId,
|
||||
listId: doc.listId,
|
||||
cardId: doc._id,
|
||||
|
|
@ -945,6 +1156,7 @@ function cardState(userId, doc, fieldNames) {
|
|||
userId,
|
||||
activityType: 'restoredCard',
|
||||
boardId: doc.boardId,
|
||||
listName: Lists.findOne(doc.listId).title,
|
||||
listId: doc.listId,
|
||||
cardId: doc._id,
|
||||
});
|
||||
|
|
@ -986,11 +1198,47 @@ function cardMembers(userId, doc, fieldNames, modifier) {
|
|||
}
|
||||
}
|
||||
|
||||
function cardLabels(userId, doc, fieldNames, modifier) {
|
||||
if (!_.contains(fieldNames, 'labelIds'))
|
||||
return;
|
||||
let labelId;
|
||||
// Say hello to the new label
|
||||
if (modifier.$addToSet && modifier.$addToSet.labelIds) {
|
||||
labelId = modifier.$addToSet.labelIds;
|
||||
if (!_.contains(doc.labelIds, labelId)) {
|
||||
const act = {
|
||||
userId,
|
||||
labelId,
|
||||
activityType: 'addedLabel',
|
||||
boardId: doc.boardId,
|
||||
cardId: doc._id,
|
||||
}
|
||||
Activities.insert(act);
|
||||
}
|
||||
}
|
||||
|
||||
// Say goodbye to the label
|
||||
if (modifier.$pull && modifier.$pull.labelIds) {
|
||||
labelId = modifier.$pull.labelIds;
|
||||
// Check that the former member is member of the card
|
||||
if (_.contains(doc.labelIds, labelId)) {
|
||||
Activities.insert({
|
||||
userId,
|
||||
labelId,
|
||||
activityType: 'removedLabel',
|
||||
boardId: doc.boardId,
|
||||
cardId: doc._id,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function cardCreation(userId, doc) {
|
||||
Activities.insert({
|
||||
userId,
|
||||
activityType: 'createCard',
|
||||
boardId: doc.boardId,
|
||||
listName: Lists.findOne(doc.listId).title,
|
||||
listId: doc.listId,
|
||||
cardId: doc._id,
|
||||
swimlaneId: doc.swimlaneId,
|
||||
|
|
@ -1015,7 +1263,6 @@ function cardRemover(userId, doc) {
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
if (Meteor.isServer) {
|
||||
// Cards are often fetched within a board, so we create an index to make these
|
||||
// queries more efficient.
|
||||
|
|
@ -1039,7 +1286,7 @@ if (Meteor.isServer) {
|
|||
});
|
||||
|
||||
//New activity for card moves
|
||||
Cards.after.update(function (userId, doc, fieldNames) {
|
||||
Cards.after.update(function(userId, doc, fieldNames) {
|
||||
const oldListId = this.previous.listId;
|
||||
const oldSwimlaneId = this.previous.swimlaneId;
|
||||
cardMove(userId, doc, fieldNames, oldListId, oldSwimlaneId);
|
||||
|
|
@ -1050,6 +1297,11 @@ if (Meteor.isServer) {
|
|||
cardMembers(userId, doc, fieldNames, modifier);
|
||||
});
|
||||
|
||||
// Add a new activity if we add or remove a label to the card
|
||||
Cards.before.update((userId, doc, fieldNames, modifier) => {
|
||||
cardLabels(userId, doc, fieldNames, modifier);
|
||||
});
|
||||
|
||||
// Remove all activities associated with a card if we remove the card
|
||||
// Remove also card_comments / checklists / attachments
|
||||
Cards.after.remove((userId, doc) => {
|
||||
|
|
@ -1058,13 +1310,17 @@ if (Meteor.isServer) {
|
|||
}
|
||||
//LISTS REST API
|
||||
if (Meteor.isServer) {
|
||||
JsonRoutes.add('GET', '/api/boards/:boardId/lists/:listId/cards', function (req, res) {
|
||||
JsonRoutes.add('GET', '/api/boards/:boardId/lists/:listId/cards', function(req, res) {
|
||||
const paramBoardId = req.params.boardId;
|
||||
const paramListId = req.params.listId;
|
||||
Authentication.checkBoardAccess(req.userId, paramBoardId);
|
||||
JsonRoutes.sendResult(res, {
|
||||
code: 200,
|
||||
data: Cards.find({boardId: paramBoardId, listId: paramListId, archived: false}).map(function (doc) {
|
||||
data: Cards.find({
|
||||
boardId: paramBoardId,
|
||||
listId: paramListId,
|
||||
archived: false
|
||||
}).map(function(doc) {
|
||||
return {
|
||||
_id: doc._id,
|
||||
title: doc.title,
|
||||
|
|
@ -1074,24 +1330,31 @@ if (Meteor.isServer) {
|
|||
});
|
||||
});
|
||||
|
||||
JsonRoutes.add('GET', '/api/boards/:boardId/lists/:listId/cards/:cardId', function (req, res) {
|
||||
JsonRoutes.add('GET', '/api/boards/:boardId/lists/:listId/cards/:cardId', function(req, res) {
|
||||
const paramBoardId = req.params.boardId;
|
||||
const paramListId = req.params.listId;
|
||||
const paramCardId = req.params.cardId;
|
||||
Authentication.checkBoardAccess(req.userId, paramBoardId);
|
||||
JsonRoutes.sendResult(res, {
|
||||
code: 200,
|
||||
data: Cards.findOne({_id: paramCardId, listId: paramListId, boardId: paramBoardId, archived: false}),
|
||||
data: Cards.findOne({
|
||||
_id: paramCardId,
|
||||
listId: paramListId,
|
||||
boardId: paramBoardId,
|
||||
archived: false
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
JsonRoutes.add('POST', '/api/boards/:boardId/lists/:listId/cards', function (req, res) {
|
||||
JsonRoutes.add('POST', '/api/boards/:boardId/lists/:listId/cards', function(req, res) {
|
||||
Authentication.checkUserId(req.userId);
|
||||
const paramBoardId = req.params.boardId;
|
||||
const paramListId = req.params.listId;
|
||||
const check = Users.findOne({_id: req.body.authorId});
|
||||
const check = Users.findOne({
|
||||
_id: req.body.authorId
|
||||
});
|
||||
const members = req.body.members || [req.body.authorId];
|
||||
if (typeof check !== 'undefined') {
|
||||
if (typeof check !== 'undefined') {
|
||||
const id = Cards.direct.insert({
|
||||
title: req.body.title,
|
||||
boardId: paramBoardId,
|
||||
|
|
@ -1109,7 +1372,9 @@ if (Meteor.isServer) {
|
|||
},
|
||||
});
|
||||
|
||||
const card = Cards.findOne({_id:id});
|
||||
const card = Cards.findOne({
|
||||
_id: id
|
||||
});
|
||||
cardCreation(req.body.authorId, card);
|
||||
|
||||
} else {
|
||||
|
|
@ -1119,7 +1384,7 @@ if (Meteor.isServer) {
|
|||
}
|
||||
});
|
||||
|
||||
JsonRoutes.add('PUT', '/api/boards/:boardId/lists/:listId/cards/:cardId', function (req, res) {
|
||||
JsonRoutes.add('PUT', '/api/boards/:boardId/lists/:listId/cards/:cardId', function(req, res) {
|
||||
Authentication.checkUserId(req.userId);
|
||||
const paramBoardId = req.params.boardId;
|
||||
const paramCardId = req.params.cardId;
|
||||
|
|
@ -1127,27 +1392,63 @@ if (Meteor.isServer) {
|
|||
|
||||
if (req.body.hasOwnProperty('title')) {
|
||||
const newTitle = req.body.title;
|
||||
Cards.direct.update({_id: paramCardId, listId: paramListId, boardId: paramBoardId, archived: false},
|
||||
{$set: {title: newTitle}});
|
||||
Cards.direct.update({
|
||||
_id: paramCardId,
|
||||
listId: paramListId,
|
||||
boardId: paramBoardId,
|
||||
archived: false
|
||||
}, {
|
||||
$set: {
|
||||
title: newTitle
|
||||
}
|
||||
});
|
||||
}
|
||||
if (req.body.hasOwnProperty('listId')) {
|
||||
const newParamListId = req.body.listId;
|
||||
Cards.direct.update({_id: paramCardId, listId: paramListId, boardId: paramBoardId, archived: false},
|
||||
{$set: {listId: newParamListId}});
|
||||
Cards.direct.update({
|
||||
_id: paramCardId,
|
||||
listId: paramListId,
|
||||
boardId: paramBoardId,
|
||||
archived: false
|
||||
}, {
|
||||
$set: {
|
||||
listId: newParamListId
|
||||
}
|
||||
});
|
||||
|
||||
const card = Cards.findOne({_id: paramCardId} );
|
||||
cardMove(req.body.authorId, card, {fieldName: 'listId'}, paramListId);
|
||||
const card = Cards.findOne({
|
||||
_id: paramCardId
|
||||
});
|
||||
cardMove(req.body.authorId, card, {
|
||||
fieldName: 'listId'
|
||||
}, paramListId);
|
||||
|
||||
}
|
||||
if (req.body.hasOwnProperty('description')) {
|
||||
const newDescription = req.body.description;
|
||||
Cards.direct.update({_id: paramCardId, listId: paramListId, boardId: paramBoardId, archived: false},
|
||||
{$set: {description: newDescription}});
|
||||
Cards.direct.update({
|
||||
_id: paramCardId,
|
||||
listId: paramListId,
|
||||
boardId: paramBoardId,
|
||||
archived: false
|
||||
}, {
|
||||
$set: {
|
||||
description: newDescription
|
||||
}
|
||||
});
|
||||
}
|
||||
if (req.body.hasOwnProperty('labelIds')) {
|
||||
const newlabelIds = req.body.labelIds;
|
||||
Cards.direct.update({_id: paramCardId, listId: paramListId, boardId: paramBoardId, archived: false},
|
||||
{$set: {labelIds: newlabelIds}});
|
||||
Cards.direct.update({
|
||||
_id: paramCardId,
|
||||
listId: paramListId,
|
||||
boardId: paramBoardId,
|
||||
archived: false
|
||||
}, {
|
||||
$set: {
|
||||
labelIds: newlabelIds
|
||||
}
|
||||
});
|
||||
}
|
||||
if (req.body.hasOwnProperty('requestedBy')) {
|
||||
const newrequestedBy = req.body.requestedBy;
|
||||
|
|
@ -1202,15 +1503,20 @@ if (Meteor.isServer) {
|
|||
});
|
||||
});
|
||||
|
||||
|
||||
JsonRoutes.add('DELETE', '/api/boards/:boardId/lists/:listId/cards/:cardId', function (req, res) {
|
||||
JsonRoutes.add('DELETE', '/api/boards/:boardId/lists/:listId/cards/:cardId', function(req, res) {
|
||||
Authentication.checkUserId(req.userId);
|
||||
const paramBoardId = req.params.boardId;
|
||||
const paramListId = req.params.listId;
|
||||
const paramCardId = req.params.cardId;
|
||||
|
||||
Cards.direct.remove({_id: paramCardId, listId: paramListId, boardId: paramBoardId});
|
||||
const card = Cards.find({_id: paramCardId} );
|
||||
Cards.direct.remove({
|
||||
_id: paramCardId,
|
||||
listId: paramListId,
|
||||
boardId: paramBoardId
|
||||
});
|
||||
const card = Cards.find({
|
||||
_id: paramCardId
|
||||
});
|
||||
cardRemover(req.body.authorId, card);
|
||||
JsonRoutes.sendResult(res, {
|
||||
code: 200,
|
||||
|
|
|
|||
|
|
@ -44,6 +44,12 @@ ChecklistItems.mutations({
|
|||
setTitle(title) {
|
||||
return { $set: { title } };
|
||||
},
|
||||
check(){
|
||||
return { $set: { isFinished: true } };
|
||||
},
|
||||
uncheck(){
|
||||
return { $set: { isFinished: false } };
|
||||
},
|
||||
toggleItem() {
|
||||
return { $set: { isFinished: !this.isFinished } };
|
||||
},
|
||||
|
|
@ -70,21 +76,102 @@ function itemCreation(userId, doc) {
|
|||
boardId,
|
||||
checklistId: doc.checklistId,
|
||||
checklistItemId: doc._id,
|
||||
checklistItemName:doc.title
|
||||
});
|
||||
}
|
||||
|
||||
function itemRemover(userId, doc) {
|
||||
const card = Cards.findOne(doc.cardId);
|
||||
const boardId = card.boardId;
|
||||
Activities.insert({
|
||||
userId,
|
||||
activityType: 'removedChecklistItem',
|
||||
cardId: doc.cardId,
|
||||
boardId,
|
||||
checklistId: doc.checklistId,
|
||||
checklistItemId: doc._id,
|
||||
checklistItemName:doc.title
|
||||
});
|
||||
Activities.remove({
|
||||
checklistItemId: doc._id,
|
||||
});
|
||||
}
|
||||
|
||||
function publishCheckActivity(userId,doc){
|
||||
const card = Cards.findOne(doc.cardId);
|
||||
const boardId = card.boardId;
|
||||
let activityType;
|
||||
if(doc.isFinished){
|
||||
activityType = "checkedItem";
|
||||
}else{
|
||||
activityType = "uncheckedItem";
|
||||
}
|
||||
let act = {
|
||||
userId,
|
||||
activityType: activityType,
|
||||
cardId: doc.cardId,
|
||||
boardId,
|
||||
checklistId: doc.checklistId,
|
||||
checklistItemId: doc._id,
|
||||
checklistItemName:doc.title
|
||||
}
|
||||
console.log(act);
|
||||
Activities.insert(act);
|
||||
}
|
||||
|
||||
function publishChekListCompleted(userId,doc,fieldNames,modifier){
|
||||
const card = Cards.findOne(doc.cardId);
|
||||
const boardId = card.boardId;
|
||||
const checklistId = doc.checklistId;
|
||||
const checkList = Checklists.findOne({_id:checklistId});
|
||||
if(checkList.isFinished()){
|
||||
let act = {
|
||||
userId,
|
||||
activityType: "checklistCompleted",
|
||||
cardId: doc.cardId,
|
||||
boardId,
|
||||
checklistId: doc.checklistId,
|
||||
checklistName:doc.title
|
||||
}
|
||||
Activities.insert(act);
|
||||
}
|
||||
}
|
||||
|
||||
function publishChekListUncompleted(userId,doc,fieldNames,modifier){
|
||||
const card = Cards.findOne(doc.cardId);
|
||||
const boardId = card.boardId;
|
||||
const checklistId = doc.checklistId;
|
||||
const checkList = Checklists.findOne({_id:checklistId});
|
||||
if(checkList.isFinished()){
|
||||
let act = {
|
||||
userId,
|
||||
activityType: "checklistUncompleted",
|
||||
cardId: doc.cardId,
|
||||
boardId,
|
||||
checklistId: doc.checklistId,
|
||||
checklistName:doc.title
|
||||
}
|
||||
Activities.insert(act);
|
||||
}
|
||||
}
|
||||
|
||||
// Activities
|
||||
if (Meteor.isServer) {
|
||||
Meteor.startup(() => {
|
||||
ChecklistItems._collection._ensureIndex({ checklistId: 1 });
|
||||
});
|
||||
|
||||
ChecklistItems.after.update((userId, doc, fieldNames, modifier) => {
|
||||
publishCheckActivity(userId,doc);
|
||||
publishChekListCompleted(userId,doc,fieldNames,modifier)
|
||||
});
|
||||
|
||||
ChecklistItems.before.update((userId, doc, fieldNames, modifier) => {
|
||||
publishChekListUncompleted(userId,doc,fieldNames,modifier)
|
||||
});
|
||||
|
||||
|
||||
|
||||
ChecklistItems.after.insert((userId, doc) => {
|
||||
itemCreation(userId, doc);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -47,6 +47,18 @@ Checklists.helpers({
|
|||
isFinished() {
|
||||
return 0 !== this.itemCount() && this.itemCount() === this.finishedCount();
|
||||
},
|
||||
checkAllItems(){
|
||||
const checkItems = ChecklistItems.find({checklistId: this._id});
|
||||
checkItems.forEach(function(item){
|
||||
item.check();
|
||||
});
|
||||
},
|
||||
uncheckAllItems(){
|
||||
const checkItems = ChecklistItems.find({checklistId: this._id});
|
||||
checkItems.forEach(function(item){
|
||||
item.uncheck();
|
||||
});
|
||||
},
|
||||
itemIndex(itemId) {
|
||||
const items = self.findOne({_id : this._id}).items;
|
||||
return _.pluck(items, '_id').indexOf(itemId);
|
||||
|
|
@ -91,6 +103,7 @@ if (Meteor.isServer) {
|
|||
cardId: doc.cardId,
|
||||
boardId: Cards.findOne(doc.cardId).boardId,
|
||||
checklistId: doc._id,
|
||||
checklistName:doc.title
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -101,6 +114,16 @@ if (Meteor.isServer) {
|
|||
Activities.remove(activity._id);
|
||||
});
|
||||
}
|
||||
Activities.insert({
|
||||
userId,
|
||||
activityType: 'removeChecklist',
|
||||
cardId: doc.cardId,
|
||||
boardId: Cards.findOne(doc.cardId).boardId,
|
||||
checklistId: doc._id,
|
||||
checklistName:doc.title
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ if (Meteor.isServer) {
|
|||
* See https://blog.kayla.com.au/server-side-route-authentication-in-meteor/
|
||||
* for detailed explanations
|
||||
*/
|
||||
JsonRoutes.add('get', '/api/boards/:boardId/export', function (req, res) {
|
||||
JsonRoutes.add('get', '/api/boards/:boardId/export', function(req, res) {
|
||||
const boardId = req.params.boardId;
|
||||
let user = null;
|
||||
// todo XXX for real API, first look for token in Authentication: header
|
||||
|
|
@ -28,8 +28,11 @@ if (Meteor.isServer) {
|
|||
}
|
||||
|
||||
const exporter = new Exporter(boardId);
|
||||
if(exporter.canExport(user)) {
|
||||
JsonRoutes.sendResult(res, { code: 200, data: exporter.build() });
|
||||
if (exporter.canExport(user)) {
|
||||
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.
|
||||
|
|
@ -47,24 +50,49 @@ class Exporter {
|
|||
const byBoard = { boardId: this._boardId };
|
||||
const byBoardNoLinked = { boardId: this._boardId, linkedId: '' };
|
||||
// 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(byBoardNoLinked, noBoardId).fetch();
|
||||
result.swimlanes = Swimlanes.find(byBoard, noBoardId).fetch();
|
||||
result.customFields = CustomFields.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
|
||||
|
|
@ -101,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 = {
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ Lists.helpers({
|
|||
};
|
||||
if (swimlaneId)
|
||||
selector.swimlaneId = swimlaneId;
|
||||
return Cards.find(Filter.mongoSelector(selector),
|
||||
return Cards.find(selector,
|
||||
{ sort: ['sort'] });
|
||||
},
|
||||
|
||||
|
|
|
|||
49
models/rules.js
Normal file
49
models/rules.js
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
Rules = new Mongo.Collection('rules');
|
||||
|
||||
Rules.attachSchema(new SimpleSchema({
|
||||
title: {
|
||||
type: String,
|
||||
optional: false,
|
||||
},
|
||||
triggerId: {
|
||||
type: String,
|
||||
optional: false,
|
||||
},
|
||||
actionId: {
|
||||
type: String,
|
||||
optional: false,
|
||||
},
|
||||
boardId: {
|
||||
type: String,
|
||||
optional: false,
|
||||
},
|
||||
}));
|
||||
|
||||
Rules.mutations({
|
||||
rename(description) {
|
||||
return { $set: { description } };
|
||||
},
|
||||
});
|
||||
|
||||
Rules.helpers({
|
||||
getAction(){
|
||||
return Actions.findOne({_id:this.actionId});
|
||||
},
|
||||
getTrigger(){
|
||||
return Triggers.findOne({_id:this.triggerId});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
Rules.allow({
|
||||
insert(userId, doc) {
|
||||
return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId));
|
||||
},
|
||||
update(userId, doc) {
|
||||
return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId));
|
||||
},
|
||||
remove(userId, doc) {
|
||||
return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId));
|
||||
}
|
||||
});
|
||||
58
models/triggers.js
Normal file
58
models/triggers.js
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
Triggers = new Mongo.Collection('triggers');
|
||||
|
||||
Triggers.mutations({
|
||||
rename(description) {
|
||||
return {
|
||||
$set: {
|
||||
description
|
||||
}
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
Triggers.allow({
|
||||
insert(userId, doc) {
|
||||
return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId));
|
||||
},
|
||||
update(userId, doc) {
|
||||
return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId));
|
||||
},
|
||||
remove(userId, doc) {
|
||||
return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId));
|
||||
}
|
||||
});
|
||||
|
||||
Triggers.helpers({
|
||||
|
||||
description() {
|
||||
return this.desc;
|
||||
},
|
||||
|
||||
getRule() {
|
||||
return Rules.findOne({
|
||||
triggerId: this._id
|
||||
});
|
||||
},
|
||||
|
||||
fromList() {
|
||||
return Lists.findOne(this.fromId);
|
||||
},
|
||||
|
||||
toList() {
|
||||
return Lists.findOne(this.toId);
|
||||
},
|
||||
|
||||
findList(title) {
|
||||
return Lists.findOne({
|
||||
title: title
|
||||
});
|
||||
},
|
||||
|
||||
labels() {
|
||||
const boardLabels = this.board().labels;
|
||||
const cardLabels = _.filter(boardLabels, (label) => {
|
||||
return _.contains(this.labelIds, label._id);
|
||||
});
|
||||
return cardLabels;
|
||||
}
|
||||
});
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
const DateString = Match.Where(function (dateAsString) {
|
||||
const DateString = Match.Where(function(dateAsString) {
|
||||
check(dateAsString, String);
|
||||
return moment(dateAsString, moment.ISO_8601).isValid();
|
||||
});
|
||||
|
|
@ -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 = {};
|
||||
|
|
@ -57,10 +61,10 @@ export class WekanCreator {
|
|||
* @param {String} dateString a properly formatted Date
|
||||
*/
|
||||
_now(dateString) {
|
||||
if(dateString) {
|
||||
if (dateString) {
|
||||
return new Date(dateString);
|
||||
}
|
||||
if(!this._nowDate) {
|
||||
if (!this._nowDate) {
|
||||
this._nowDate = new Date();
|
||||
}
|
||||
return this._nowDate;
|
||||
|
|
@ -72,9 +76,9 @@ export class WekanCreator {
|
|||
* Otherwise return current logged user.
|
||||
* @param wekanUserId
|
||||
* @private
|
||||
*/
|
||||
*/
|
||||
_user(wekanUserId) {
|
||||
if(wekanUserId && this.members[wekanUserId]) {
|
||||
if (wekanUserId && this.members[wekanUserId]) {
|
||||
return this.members[wekanUserId];
|
||||
}
|
||||
return Meteor.userId();
|
||||
|
|
@ -96,7 +100,7 @@ export class WekanCreator {
|
|||
// allowed values (is it worth the maintenance?)
|
||||
color: String,
|
||||
permission: Match.Where((value) => {
|
||||
return ['private', 'public'].indexOf(value)>= 0;
|
||||
return ['private', 'public'].indexOf(value) >= 0;
|
||||
}),
|
||||
}));
|
||||
}
|
||||
|
|
@ -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 = {
|
||||
|
|
@ -172,12 +200,12 @@ export class WekanCreator {
|
|||
title: boardToImport.title,
|
||||
};
|
||||
// now add other members
|
||||
if(boardToImport.members) {
|
||||
if (boardToImport.members) {
|
||||
boardToImport.members.forEach((wekanMember) => {
|
||||
// do we already have it in our list?
|
||||
if(!boardToCreate.members.some((member) => member.wekanId === wekanMember.wekanId))
|
||||
if (!boardToCreate.members.some((member) => member.wekanId === wekanMember.wekanId))
|
||||
boardToCreate.members.push({
|
||||
... wekanMember,
|
||||
...wekanMember,
|
||||
userId: wekanMember.wekanId,
|
||||
});
|
||||
});
|
||||
|
|
@ -194,7 +222,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',
|
||||
|
|
@ -246,21 +278,21 @@ export class WekanCreator {
|
|||
});
|
||||
}
|
||||
// add members {
|
||||
if(card.members) {
|
||||
if (card.members) {
|
||||
const wekanMembers = [];
|
||||
// we can't just map, as some members may not have been mapped
|
||||
card.members.forEach((sourceMemberId) => {
|
||||
if(this.members[sourceMemberId]) {
|
||||
if (this.members[sourceMemberId]) {
|
||||
const wekanId = this.members[sourceMemberId];
|
||||
// we may map multiple Wekan members to the same wekan user
|
||||
// in which case we risk adding the same user multiple times
|
||||
if(!wekanMembers.find((wId) => wId === wekanId)){
|
||||
if (!wekanMembers.find((wId) => wId === wekanId)) {
|
||||
wekanMembers.push(wekanId);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
if(wekanMembers.length>0) {
|
||||
if (wekanMembers.length > 0) {
|
||||
cardToCreate.members = wekanMembers;
|
||||
}
|
||||
}
|
||||
|
|
@ -321,9 +353,9 @@ export class WekanCreator {
|
|||
// - the template then tries to display the url to the attachment which causes other errors
|
||||
// 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) {
|
||||
if (Meteor.isServer) {
|
||||
if (att.url) {
|
||||
file.attachData(att.url, function (error) {
|
||||
file.attachData(att.url, function(error) {
|
||||
file.boardId = boardId;
|
||||
file.cardId = cardId;
|
||||
file.userId = self._user(att.userId);
|
||||
|
|
@ -331,20 +363,26 @@ export class WekanCreator {
|
|||
// attachments' related activities automatically
|
||||
file.source = 'import';
|
||||
if (error) {
|
||||
throw(error);
|
||||
throw (error);
|
||||
} else {
|
||||
const wekanAtt = Attachments.insert(file, () => {
|
||||
// we do nothing
|
||||
});
|
||||
self.attachmentIds[att._id] = wekanAtt._id;
|
||||
//
|
||||
if(wekanCoverId === att._id) {
|
||||
Cards.direct.update(cardId, { $set: {coverId: wekanAtt._id}});
|
||||
if (wekanCoverId === att._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;
|
||||
|
|
@ -353,15 +391,19 @@ export class WekanCreator {
|
|||
// attachments' related activities automatically
|
||||
file.source = 'import';
|
||||
if (error) {
|
||||
throw(error);
|
||||
throw (error);
|
||||
} else {
|
||||
const wekanAtt = Attachments.insert(file, () => {
|
||||
// we do nothing
|
||||
});
|
||||
this.attachmentIds[att._id] = wekanAtt._id;
|
||||
//
|
||||
if(wekanCoverId === att._id) {
|
||||
Cards.direct.update(cardId, { $set: {coverId: wekanAtt._id}});
|
||||
if (wekanCoverId === att._id) {
|
||||
Cards.direct.update(cardId, {
|
||||
$set: {
|
||||
coverId: wekanAtt._id
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -404,7 +446,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({
|
||||
|
|
@ -437,7 +483,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;
|
||||
});
|
||||
}
|
||||
|
|
@ -459,6 +509,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
|
||||
|
|
@ -477,166 +568,182 @@ export class WekanCreator {
|
|||
parseActivities(wekanBoard) {
|
||||
wekanBoard.activities.forEach((activity) => {
|
||||
switch (activity.activityType) {
|
||||
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
|
||||
const wekanAttachment = wekanBoard.attachments.filter((attachment) => {
|
||||
return attachment._id === activity.attachmentId;
|
||||
})[0];
|
||||
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
|
||||
const wekanAttachment = wekanBoard.attachments.filter((attachment) => {
|
||||
return attachment._id === activity.attachmentId;
|
||||
})[0];
|
||||
|
||||
if ( typeof wekanAttachment !== 'undefined' && wekanAttachment ) {
|
||||
if(wekanAttachment.url || wekanAttachment.file) {
|
||||
// we cannot actually create the Wekan attachment, because we don't yet
|
||||
// have the cards to attach it to, so we store it in the instance variable.
|
||||
const wekanCardId = activity.cardId;
|
||||
if(!this.attachments[wekanCardId]) {
|
||||
this.attachments[wekanCardId] = [];
|
||||
if (typeof wekanAttachment !== 'undefined' && wekanAttachment) {
|
||||
if (wekanAttachment.url || wekanAttachment.file) {
|
||||
// we cannot actually create the Wekan attachment, because we don't yet
|
||||
// have the cards to attach it to, so we store it in the instance variable.
|
||||
const wekanCardId = activity.cardId;
|
||||
if (!this.attachments[wekanCardId]) {
|
||||
this.attachments[wekanCardId] = [];
|
||||
}
|
||||
this.attachments[wekanCardId].push(wekanAttachment);
|
||||
}
|
||||
}
|
||||
this.attachments[wekanCardId].push(wekanAttachment);
|
||||
break;
|
||||
}
|
||||
case 'addComment':
|
||||
{
|
||||
const wekanComment = wekanBoard.comments.filter((comment) => {
|
||||
return comment._id === activity.commentId;
|
||||
})[0];
|
||||
const id = activity.cardId;
|
||||
if (!this.comments[id]) {
|
||||
this.comments[id] = [];
|
||||
}
|
||||
this.comments[id].push(wekanComment);
|
||||
break;
|
||||
}
|
||||
case 'createBoard':
|
||||
{
|
||||
this.createdAt.board = activity.createdAt;
|
||||
break;
|
||||
}
|
||||
case 'createCard':
|
||||
{
|
||||
const cardId = activity.cardId;
|
||||
this.createdAt.cards[cardId] = activity.createdAt;
|
||||
this.createdBy.cards[cardId] = activity.userId;
|
||||
break;
|
||||
}
|
||||
case 'createList':
|
||||
{
|
||||
const listId = activity.listId;
|
||||
this.createdAt.lists[listId] = activity.createdAt;
|
||||
break;
|
||||
}
|
||||
case 'createSwimlane':
|
||||
{
|
||||
const swimlaneId = activity.swimlaneId;
|
||||
this.createdAt.swimlanes[swimlaneId] = activity.createdAt;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'addComment': {
|
||||
const wekanComment = wekanBoard.comments.filter((comment) => {
|
||||
return comment._id === activity.commentId;
|
||||
})[0];
|
||||
const id = activity.cardId;
|
||||
if (!this.comments[id]) {
|
||||
this.comments[id] = [];
|
||||
}
|
||||
this.comments[id].push(wekanComment);
|
||||
break;
|
||||
}
|
||||
case 'createBoard': {
|
||||
this.createdAt.board = activity.createdAt;
|
||||
break;
|
||||
}
|
||||
case 'createCard': {
|
||||
const cardId = activity.cardId;
|
||||
this.createdAt.cards[cardId] = activity.createdAt;
|
||||
this.createdBy.cards[cardId] = activity.userId;
|
||||
break;
|
||||
}
|
||||
case 'createList': {
|
||||
const listId = activity.listId;
|
||||
this.createdAt.lists[listId] = activity.createdAt;
|
||||
break;
|
||||
}
|
||||
case 'createSwimlane': {
|
||||
const swimlaneId = activity.swimlaneId;
|
||||
this.createdAt.swimlanes[swimlaneId] = activity.createdAt;
|
||||
break;
|
||||
}}
|
||||
});
|
||||
}
|
||||
|
||||
importActivities(activities, boardId) {
|
||||
activities.forEach((activity) => {
|
||||
switch (activity.activityType) {
|
||||
// Board related activities
|
||||
// TODO: addBoardMember, removeBoardMember
|
||||
case 'createBoard': {
|
||||
Activities.direct.insert({
|
||||
userId: this._user(activity.userId),
|
||||
type: 'board',
|
||||
activityTypeId: boardId,
|
||||
activityType: activity.activityType,
|
||||
boardId,
|
||||
createdAt: this._now(activity.createdAt),
|
||||
});
|
||||
break;
|
||||
// Board related activities
|
||||
// TODO: addBoardMember, removeBoardMember
|
||||
case 'createBoard':
|
||||
{
|
||||
Activities.direct.insert({
|
||||
userId: this._user(activity.userId),
|
||||
type: 'board',
|
||||
activityTypeId: boardId,
|
||||
activityType: activity.activityType,
|
||||
boardId,
|
||||
createdAt: this._now(activity.createdAt),
|
||||
});
|
||||
break;
|
||||
}
|
||||
// List related activities
|
||||
// TODO: removeList, archivedList
|
||||
case 'createList':
|
||||
{
|
||||
Activities.direct.insert({
|
||||
userId: this._user(activity.userId),
|
||||
type: 'list',
|
||||
activityType: activity.activityType,
|
||||
listId: this.lists[activity.listId],
|
||||
boardId,
|
||||
createdAt: this._now(activity.createdAt),
|
||||
});
|
||||
break;
|
||||
}
|
||||
// Card related activities
|
||||
// TODO: archivedCard, restoredCard, joinMember, unjoinMember
|
||||
case 'createCard':
|
||||
{
|
||||
Activities.direct.insert({
|
||||
userId: this._user(activity.userId),
|
||||
activityType: activity.activityType,
|
||||
listId: this.lists[activity.listId],
|
||||
cardId: this.cards[activity.cardId],
|
||||
boardId,
|
||||
createdAt: this._now(activity.createdAt),
|
||||
});
|
||||
break;
|
||||
}
|
||||
case 'moveCard':
|
||||
{
|
||||
Activities.direct.insert({
|
||||
userId: this._user(activity.userId),
|
||||
oldListId: this.lists[activity.oldListId],
|
||||
activityType: activity.activityType,
|
||||
listId: this.lists[activity.listId],
|
||||
cardId: this.cards[activity.cardId],
|
||||
boardId,
|
||||
createdAt: this._now(activity.createdAt),
|
||||
});
|
||||
break;
|
||||
}
|
||||
// Comment related activities
|
||||
case 'addComment':
|
||||
{
|
||||
Activities.direct.insert({
|
||||
userId: this._user(activity.userId),
|
||||
activityType: activity.activityType,
|
||||
cardId: this.cards[activity.cardId],
|
||||
commentId: this.commentIds[activity.commentId],
|
||||
boardId,
|
||||
createdAt: this._now(activity.createdAt),
|
||||
});
|
||||
break;
|
||||
}
|
||||
// Attachment related activities
|
||||
case 'addAttachment':
|
||||
{
|
||||
Activities.direct.insert({
|
||||
userId: this._user(activity.userId),
|
||||
type: 'card',
|
||||
activityType: activity.activityType,
|
||||
attachmentId: this.attachmentIds[activity.attachmentId],
|
||||
cardId: this.cards[activity.cardId],
|
||||
boardId,
|
||||
createdAt: this._now(activity.createdAt),
|
||||
});
|
||||
break;
|
||||
}
|
||||
// Checklist related activities
|
||||
case 'addChecklist':
|
||||
{
|
||||
Activities.direct.insert({
|
||||
userId: this._user(activity.userId),
|
||||
activityType: activity.activityType,
|
||||
cardId: this.cards[activity.cardId],
|
||||
checklistId: this.checklists[activity.checklistId],
|
||||
boardId,
|
||||
createdAt: this._now(activity.createdAt),
|
||||
});
|
||||
break;
|
||||
}
|
||||
case 'addChecklistItem':
|
||||
{
|
||||
Activities.direct.insert({
|
||||
userId: this._user(activity.userId),
|
||||
activityType: activity.activityType,
|
||||
cardId: this.cards[activity.cardId],
|
||||
checklistId: this.checklists[activity.checklistId],
|
||||
checklistItemId: activity.checklistItemId.replace(
|
||||
activity.checklistId,
|
||||
this.checklists[activity.checklistId]),
|
||||
boardId,
|
||||
createdAt: this._now(activity.createdAt),
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
// List related activities
|
||||
// TODO: removeList, archivedList
|
||||
case 'createList': {
|
||||
Activities.direct.insert({
|
||||
userId: this._user(activity.userId),
|
||||
type: 'list',
|
||||
activityType: activity.activityType,
|
||||
listId: this.lists[activity.listId],
|
||||
boardId,
|
||||
createdAt: this._now(activity.createdAt),
|
||||
});
|
||||
break;
|
||||
}
|
||||
// Card related activities
|
||||
// TODO: archivedCard, restoredCard, joinMember, unjoinMember
|
||||
case 'createCard': {
|
||||
Activities.direct.insert({
|
||||
userId: this._user(activity.userId),
|
||||
activityType: activity.activityType,
|
||||
listId: this.lists[activity.listId],
|
||||
cardId: this.cards[activity.cardId],
|
||||
boardId,
|
||||
createdAt: this._now(activity.createdAt),
|
||||
});
|
||||
break;
|
||||
}
|
||||
case 'moveCard': {
|
||||
Activities.direct.insert({
|
||||
userId: this._user(activity.userId),
|
||||
oldListId: this.lists[activity.oldListId],
|
||||
activityType: activity.activityType,
|
||||
listId: this.lists[activity.listId],
|
||||
cardId: this.cards[activity.cardId],
|
||||
boardId,
|
||||
createdAt: this._now(activity.createdAt),
|
||||
});
|
||||
break;
|
||||
}
|
||||
// Comment related activities
|
||||
case 'addComment': {
|
||||
Activities.direct.insert({
|
||||
userId: this._user(activity.userId),
|
||||
activityType: activity.activityType,
|
||||
cardId: this.cards[activity.cardId],
|
||||
commentId: this.commentIds[activity.commentId],
|
||||
boardId,
|
||||
createdAt: this._now(activity.createdAt),
|
||||
});
|
||||
break;
|
||||
}
|
||||
// Attachment related activities
|
||||
case 'addAttachment': {
|
||||
Activities.direct.insert({
|
||||
userId: this._user(activity.userId),
|
||||
type: 'card',
|
||||
activityType: activity.activityType,
|
||||
attachmentId: this.attachmentIds[activity.attachmentId],
|
||||
cardId: this.cards[activity.cardId],
|
||||
boardId,
|
||||
createdAt: this._now(activity.createdAt),
|
||||
});
|
||||
break;
|
||||
}
|
||||
// Checklist related activities
|
||||
case 'addChecklist': {
|
||||
Activities.direct.insert({
|
||||
userId: this._user(activity.userId),
|
||||
activityType: activity.activityType,
|
||||
cardId: this.cards[activity.cardId],
|
||||
checklistId: this.checklists[activity.checklistId],
|
||||
boardId,
|
||||
createdAt: this._now(activity.createdAt),
|
||||
});
|
||||
break;
|
||||
}
|
||||
case 'addChecklistItem': {
|
||||
Activities.direct.insert({
|
||||
userId: this._user(activity.userId),
|
||||
activityType: activity.activityType,
|
||||
cardId: this.cards[activity.cardId],
|
||||
checklistId: this.checklists[activity.checklistId],
|
||||
checklistItemId: activity.checklistItemId.replace(
|
||||
activity.checklistId,
|
||||
this.checklists[activity.checklistId]),
|
||||
boardId,
|
||||
createdAt: this._now(activity.createdAt),
|
||||
});
|
||||
break;
|
||||
}}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -652,6 +759,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');
|
||||
|
|
@ -674,7 +784,10 @@ 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