mirror of
https://github.com/wekan/wekan.git
synced 2025-12-16 23:40:13 +01:00
Import single card: check user authorized
This commit is contained in:
parent
81bd551137
commit
4b99ce2aa2
1 changed files with 16 additions and 10 deletions
|
|
@ -3,13 +3,11 @@ Meteor.methods({
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
importTrelloCard(trelloCard, listId, sortIndex) {
|
importTrelloCard(trelloCard, listId, sortIndex) {
|
||||||
|
// 1. check parameters are ok from a syntax point of view
|
||||||
DateString = Match.Where(function (dateAsString) {
|
DateString = Match.Where(function (dateAsString) {
|
||||||
check(dateAsString, String);
|
check(dateAsString, String);
|
||||||
//const date = new Date(dateAsString);
|
|
||||||
//return (date.toString() !== 'Invalid Date') && !isNan(date);
|
|
||||||
return moment(dateAsString, moment.ISO_8601).isValid();
|
return moment(dateAsString, moment.ISO_8601).isValid();
|
||||||
});
|
});
|
||||||
|
|
||||||
check(trelloCard, Match.ObjectIncluding({
|
check(trelloCard, Match.ObjectIncluding({
|
||||||
name: String,
|
name: String,
|
||||||
desc: String,
|
desc: String,
|
||||||
|
|
@ -29,14 +27,18 @@ Meteor.methods({
|
||||||
check(listId, String);
|
check(listId, String);
|
||||||
check(sortIndex, Number);
|
check(sortIndex, Number);
|
||||||
|
|
||||||
|
// 2. check parameters are ok from a business point of view (exist & authorized)
|
||||||
const list = Lists.findOne(listId);
|
const list = Lists.findOne(listId);
|
||||||
if(!list) {
|
if(!list) {
|
||||||
throw 'exception-list-doesNotExist';
|
throw 'exception-list-doesNotExist';
|
||||||
}
|
}
|
||||||
|
if(Meteor.isServer) {
|
||||||
|
if (!allowIsBoardMember(Meteor.userId(), Boards.findOne(list.boardId))) {
|
||||||
|
throw 'exception-board-notAMember';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// XXX check we are allowed to run method
|
// 3. map all fields for the card to create
|
||||||
|
|
||||||
// 1. map all fields for the card to create
|
|
||||||
const dateOfImport = new Date();
|
const dateOfImport = new Date();
|
||||||
const cardToCreate = {
|
const cardToCreate = {
|
||||||
title: trelloCard.name,
|
title: trelloCard.name,
|
||||||
|
|
@ -50,12 +52,14 @@ Meteor.methods({
|
||||||
createdAt: dateOfImport,
|
createdAt: dateOfImport,
|
||||||
dateLastActivity: dateOfImport,
|
dateLastActivity: dateOfImport,
|
||||||
};
|
};
|
||||||
// find actual creation date
|
|
||||||
|
// 4. find actual creation date
|
||||||
const creationAction = trelloCard.actions.find((action) => {return action.type === 'createCard';});
|
const creationAction = trelloCard.actions.find((action) => {return action.type === 'createCard';});
|
||||||
if(creationAction) {
|
if(creationAction) {
|
||||||
cardToCreate.createdAt = creationAction.date;
|
cardToCreate.createdAt = creationAction.date;
|
||||||
}
|
}
|
||||||
// 2. map labels
|
|
||||||
|
// 5. map labels - create missing ones
|
||||||
trelloCard.labels.forEach((currentLabel) => {
|
trelloCard.labels.forEach((currentLabel) => {
|
||||||
const color = currentLabel.color;
|
const color = currentLabel.color;
|
||||||
const name = currentLabel.name;
|
const name = currentLabel.name;
|
||||||
|
|
@ -77,10 +81,12 @@ Meteor.methods({
|
||||||
cardToCreate.labelIds.push(labelId);
|
cardToCreate.labelIds.push(labelId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// 3. insert new card into list
|
|
||||||
|
// 6. insert new card into list
|
||||||
const cardId = Cards.direct.insert(cardToCreate);
|
const cardId = Cards.direct.insert(cardToCreate);
|
||||||
// XXX then add import activity
|
// XXX then add import activity
|
||||||
// 4. parse actions and add comments
|
|
||||||
|
// 7. parse actions and add comments
|
||||||
trelloCard.actions.forEach((currentAction) => {
|
trelloCard.actions.forEach((currentAction) => {
|
||||||
if(currentAction.type === 'commentCard') {
|
if(currentAction.type === 'commentCard') {
|
||||||
const commentToCreate = {
|
const commentToCreate = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue