direct hook to bypass the checking step with API request

This commit is contained in:
zago 2017-07-19 10:27:23 +02:00
parent cbcf10a02b
commit e2ee005a5f
2 changed files with 186 additions and 141 deletions

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
@ -405,7 +429,7 @@ if (Meteor.isServer) {
const paramListId = req.params.listId;
const check = Users.findOne({_id: req.body.authorId});
if (typeof check !== 'undefined') {
const id = Cards.insert({
const id = Cards.direct.insert({
title: req.body.title,
boardId: paramBoardId,
listId: paramListId,
@ -420,6 +444,10 @@ if (Meteor.isServer) {
_id: id,
},
});
const card = Cards.findOne({_id:id});
cardCreation(req.body.authorId, card);
} else {
JsonRoutes.sendResult(res, {
code: 401,
@ -432,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, {
@ -461,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,
},
});
});
}