Merge branch 'zarnifoulette-devel' into devel

Fix: Activity user messed up when creating a card using the REST-API.
Thanks to zarnifoulette ! Closes #1045
This commit is contained in:
Lauri Ojansivu 2017-07-19 21:35:50 +03:00
commit 3140067330
3 changed files with 209 additions and 153 deletions

View file

@ -4,7 +4,11 @@ This release adds the following new features:
* [Export and import attachments as base64 encoded files](https://github.com/wekan/wekan/pull/1134);
Thanks to GitHub user GhassenRjab for contributions.
and fixes the following bugs:
* [Activity user messed up when creating a card using the REST-API](https://github.com/wekan/wekan/pull/1116);
Thanks to GitHub users GhassenRjab and zarnifoulette for their contributions.
# v0.28 2017-07-15 Wekan release

View file

@ -56,6 +56,16 @@ CardComments.helpers({
CardComments.hookOptions.after.update = { fetchPrevious: false };
function commentCreation(userId, doc){
Activities.insert({
userId,
activityType: 'addComment',
boardId: doc.boardId,
cardId: doc.cardId,
commentId: doc._id,
});
}
if (Meteor.isServer) {
// Comments are often fetched within a card, so we create an index to make these
// queries more efficient.
@ -64,13 +74,7 @@ if (Meteor.isServer) {
});
CardComments.after.insert((userId, doc) => {
Activities.insert({
userId,
activityType: 'addComment',
boardId: doc.boardId,
cardId: doc.cardId,
commentId: doc._id,
});
commentCreation(userId, doc);
});
CardComments.after.remove((userId, doc) => {
@ -114,12 +118,16 @@ if (Meteor.isServer) {
Authentication.checkUserId( req.userId);
const paramBoardId = req.params.boardId;
const paramCardId = req.params.cardId;
const id = CardComments.insert({
const id = CardComments.direct.insert({
userId: req.body.authorId,
text: req.body.comment,
cardId: paramCardId,
boardId: paramBoardId,
});
const cardComment = CardComments.findOne({_id: id, cardId:paramCardId, boardId: paramBoardId });
commentCreation(req.body.authorId, cardComment);
JsonRoutes.sendResult(res, {
code: 200,
data: {

View file

@ -263,25 +263,23 @@ Cards.mutations({
},
});
if (Meteor.isServer) {
// Cards are often fetched within a board, so we create an index to make these
// queries more efficient.
Meteor.startup(() => {
Cards._collection._ensureIndex({ boardId: 1, createdAt: -1 });
});
Cards.after.insert((userId, doc) => {
//FUNCTIONS FOR creation of Activities
function cardMove(userId, doc, fieldNames, oldListId) {
if (_.contains(fieldNames, 'listId') && doc.listId !== oldListId) {
Activities.insert({
userId,
activityType: 'createCard',
boardId: doc.boardId,
oldListId,
activityType: 'moveCard',
listId: doc.listId,
boardId: doc.boardId,
cardId: doc._id,
});
});
}
}
// New activity for card (un)archivage
Cards.after.update((userId, doc, fieldNames) => {
function cardState(userId, doc, fieldNames) {
if (_.contains(fieldNames, 'archived')) {
if (doc.archived) {
Activities.insert({
@ -301,25 +299,9 @@ if (Meteor.isServer) {
});
}
}
});
// New activity for card moves
Cards.after.update(function (userId, doc, fieldNames) {
const oldListId = this.previous.listId;
if (_.contains(fieldNames, 'listId') && doc.listId !== oldListId) {
Activities.insert({
userId,
oldListId,
activityType: 'moveCard',
listId: doc.listId,
boardId: doc.boardId,
cardId: doc._id,
});
}
});
// Add a new activity if we add or remove a member to the card
Cards.before.update((userId, doc, fieldNames, modifier) => {
function cardMembers(userId, doc, fieldNames, modifier) {
if (!_.contains(fieldNames, 'members'))
return;
let memberId;
@ -351,11 +333,19 @@ if (Meteor.isServer) {
});
}
}
});
}
// Remove all activities associated with a card if we remove the card
// Remove also card_comments / checklists / attachments
Cards.after.remove((userId, doc) => {
function cardCreation(userId, doc) {
Activities.insert({
userId,
activityType: 'createCard',
boardId: doc.boardId,
listId: doc.listId,
cardId: doc._id,
});
}
function cardRemover(userId, doc) {
Activities.remove({
cardId: doc._id,
});
@ -368,6 +358,40 @@ if (Meteor.isServer) {
Attachments.remove({
cardId: doc._id,
});
}
if (Meteor.isServer) {
// Cards are often fetched within a board, so we create an index to make these
// queries more efficient.
Meteor.startup(() => {
Cards._collection._ensureIndex({boardId: 1, createdAt: -1});
});
Cards.after.insert((userId, doc) => {
cardCreation(userId, doc);
});
// New activity for card (un)archivage
Cards.after.update((userId, doc, fieldNames) => {
cardState(userId, doc, fieldNames);
});
//New activity for card moves
Cards.after.update(function (userId, doc, fieldNames) {
const oldListId = this.previous.listId;
cardMove(userId, doc, fieldNames, oldListId);
});
// Add a new activity if we add or remove a member to the card
Cards.before.update((userId, doc, fieldNames, modifier) => {
cardMembers(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) => {
cardRemover(userId, doc);
});
}
//LISTS REST API
@ -403,7 +427,9 @@ if (Meteor.isServer) {
Authentication.checkUserId(req.userId);
const paramBoardId = req.params.boardId;
const paramListId = req.params.listId;
const id = Cards.insert({
const check = Users.findOne({_id: req.body.authorId});
if (typeof check !== 'undefined') {
const id = Cards.direct.insert({
title: req.body.title,
boardId: paramBoardId,
listId: paramListId,
@ -418,6 +444,15 @@ if (Meteor.isServer) {
_id: id,
},
});
const card = Cards.findOne({_id:id});
cardCreation(req.body.authorId, card);
} else {
JsonRoutes.sendResult(res, {
code: 401,
});
}
});
JsonRoutes.add('PUT', '/api/boards/:boardId/lists/:listId/cards/:cardId', function (req, res, next) {
@ -425,19 +460,24 @@ if (Meteor.isServer) {
const paramBoardId = req.params.boardId;
const paramCardId = req.params.cardId;
const paramListId = req.params.listId;
if (req.body.hasOwnProperty('title')) {
const newTitle = req.body.title;
Cards.update({ _id: paramCardId, listId: paramListId, boardId: paramBoardId, archived: false },
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.update({ _id: paramCardId, listId: paramListId, boardId: paramBoardId, archived: false },
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);
}
if (req.body.hasOwnProperty('description')) {
const newDescription = req.body.description;
Cards.update({ _id: paramCardId, listId: paramListId, boardId: paramBoardId, archived: false },
Cards.direct.update({_id: paramCardId, listId: paramListId, boardId: paramBoardId, archived: false},
{$set: {description: newDescription}});
}
JsonRoutes.sendResult(res, {
@ -454,12 +494,16 @@ if (Meteor.isServer) {
const paramBoardId = req.params.boardId;
const paramListId = req.params.listId;
const paramCardId = req.params.cardId;
Cards.remove({ _id: paramCardId, listId: paramListId, boardId: paramBoardId });
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,
data: {
_id: paramCardId,
},
});
});
}