|
@@ -8,13 +8,19 @@ class TrelloCreator {
|
|
// we log current date, to use the same timestamp for all our actions.
|
|
// we log current date, to use the same timestamp for all our actions.
|
|
// this helps to retrieve all elements performed by the same import.
|
|
// this helps to retrieve all elements performed by the same import.
|
|
this._nowDate = new Date();
|
|
this._nowDate = new Date();
|
|
- // The object creation dates, indexed by Trello id (so we only parse actions
|
|
|
|
- // once!)
|
|
|
|
|
|
+ // The object creation dates, indexed by Trello id
|
|
|
|
+ // (so we only parse actions once!)
|
|
this.createdAt = {
|
|
this.createdAt = {
|
|
board: null,
|
|
board: null,
|
|
cards: {},
|
|
cards: {},
|
|
lists: {},
|
|
lists: {},
|
|
};
|
|
};
|
|
|
|
+ // The object creator Trello Id, indexed by the object Trello id
|
|
|
|
+ // (so we only parse actions once!)
|
|
|
|
+ this.createdBy = {
|
|
|
|
+ cards: {}, // only cards have a field for that
|
|
|
|
+ };
|
|
|
|
+
|
|
// Map of labels Trello ID => Wekan ID
|
|
// Map of labels Trello ID => Wekan ID
|
|
this.labels = {};
|
|
this.labels = {};
|
|
// Map of lists Trello ID => Wekan ID
|
|
// Map of lists Trello ID => Wekan ID
|
|
@@ -139,10 +145,16 @@ class TrelloCreator {
|
|
if(this.members[trelloId]) {
|
|
if(this.members[trelloId]) {
|
|
const wekanId = this.members[trelloId];
|
|
const wekanId = this.members[trelloId];
|
|
// do we already have it in our list?
|
|
// do we already have it in our list?
|
|
- if(!boardToCreate.members.find((wekanMember) => wekanMember.userId === wekanId)) {
|
|
|
|
|
|
+ const wekanMember = boardToCreate.members.find((wekanMember) => wekanMember.userId === wekanId);
|
|
|
|
+ if(wekanMember) {
|
|
|
|
+ // we're already mapped, but maybe with lower rights
|
|
|
|
+ if(!wekanMember.isAdmin) {
|
|
|
|
+ wekanMember.isAdmin = this.getAdmin(trelloMembership.memberType);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
boardToCreate.members.push({
|
|
boardToCreate.members.push({
|
|
userId: wekanId,
|
|
userId: wekanId,
|
|
- isAdmin: false,
|
|
|
|
|
|
+ isAdmin: this.getAdmin(trelloMembership.memberType),
|
|
isActive: true,
|
|
isActive: true,
|
|
});
|
|
});
|
|
}
|
|
}
|
|
@@ -172,9 +184,9 @@ class TrelloCreator {
|
|
system: 'Trello',
|
|
system: 'Trello',
|
|
url: trelloBoard.url,
|
|
url: trelloBoard.url,
|
|
},
|
|
},
|
|
- // We attribute the import to current user, not the one from the original
|
|
|
|
- // object.
|
|
|
|
- userId: Meteor.userId(),
|
|
|
|
|
|
+ // We attribute the import to current user,
|
|
|
|
+ // not the author from the original object.
|
|
|
|
+ userId: this._user(),
|
|
});
|
|
});
|
|
return boardId;
|
|
return boardId;
|
|
}
|
|
}
|
|
@@ -199,8 +211,8 @@ class TrelloCreator {
|
|
listId: this.lists[card.idList],
|
|
listId: this.lists[card.idList],
|
|
sort: card.pos,
|
|
sort: card.pos,
|
|
title: card.name,
|
|
title: card.name,
|
|
- // XXX use the original user?
|
|
|
|
- userId: Meteor.userId(),
|
|
|
|
|
|
+ // we attribute the card to its creator if available
|
|
|
|
+ userId: this._user(this.createdBy.cards[card.id]),
|
|
};
|
|
};
|
|
// add labels
|
|
// add labels
|
|
if (card.idLabels) {
|
|
if (card.idLabels) {
|
|
@@ -241,9 +253,9 @@ class TrelloCreator {
|
|
system: 'Trello',
|
|
system: 'Trello',
|
|
url: card.url,
|
|
url: card.url,
|
|
},
|
|
},
|
|
- // we attribute the import to current user, not the one from the
|
|
|
|
- // original card
|
|
|
|
- userId: Meteor.userId(),
|
|
|
|
|
|
+ // we attribute the import to current user,
|
|
|
|
+ // not the author of the original card
|
|
|
|
+ userId: this._user(),
|
|
});
|
|
});
|
|
// add comments
|
|
// add comments
|
|
const comments = this.comments[card.id];
|
|
const comments = this.comments[card.id];
|
|
@@ -254,7 +266,7 @@ class TrelloCreator {
|
|
cardId,
|
|
cardId,
|
|
createdAt: this._now(comment.date),
|
|
createdAt: this._now(comment.date),
|
|
text: comment.data.text,
|
|
text: comment.data.text,
|
|
- // map comment author, default to current user
|
|
|
|
|
|
+ // we attribute the comment to the original author, default to current user
|
|
userId: this._user(comment.memberCreator.id),
|
|
userId: this._user(comment.memberCreator.id),
|
|
};
|
|
};
|
|
// dateLastActivity will be set from activity insert, no need to
|
|
// dateLastActivity will be set from activity insert, no need to
|
|
@@ -266,6 +278,8 @@ class TrelloCreator {
|
|
cardId: commentToCreate.cardId,
|
|
cardId: commentToCreate.cardId,
|
|
commentId,
|
|
commentId,
|
|
createdAt: this._now(commentToCreate.createdAt),
|
|
createdAt: this._now(commentToCreate.createdAt),
|
|
|
|
+ // we attribute the addComment (not the import)
|
|
|
|
+ // to the original author - it is needed by some UI elements.
|
|
userId: commentToCreate.userId,
|
|
userId: commentToCreate.userId,
|
|
});
|
|
});
|
|
});
|
|
});
|
|
@@ -330,7 +344,6 @@ class TrelloCreator {
|
|
// we require.
|
|
// we require.
|
|
createdAt: this._now(this.createdAt.lists[list.id]),
|
|
createdAt: this._now(this.createdAt.lists[list.id]),
|
|
title: list.name,
|
|
title: list.name,
|
|
- userId: Meteor.userId(),
|
|
|
|
};
|
|
};
|
|
const listId = Lists.direct.insert(listToCreate);
|
|
const listId = Lists.direct.insert(listToCreate);
|
|
Lists.direct.update(listId, {$set: {'updatedAt': this._now()}});
|
|
Lists.direct.update(listId, {$set: {'updatedAt': this._now()}});
|
|
@@ -345,13 +358,19 @@ class TrelloCreator {
|
|
id: list.id,
|
|
id: list.id,
|
|
system: 'Trello',
|
|
system: 'Trello',
|
|
},
|
|
},
|
|
- // We attribute the import to current user, not the one from the
|
|
|
|
- // original object
|
|
|
|
- userId: Meteor.userId(),
|
|
|
|
|
|
+ // We attribute the import to current user,
|
|
|
|
+ // not the creator of the original object
|
|
|
|
+ userId: this._user(),
|
|
});
|
|
});
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ getAdmin(trelloMemberType) {
|
|
|
|
+ if (trelloMemberType === 'admin') {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
|
|
getColor(trelloColorCode) {
|
|
getColor(trelloColorCode) {
|
|
// trello color name => wekan color
|
|
// trello color name => wekan color
|
|
@@ -411,6 +430,7 @@ class TrelloCreator {
|
|
case 'createCard':
|
|
case 'createCard':
|
|
const cardId = action.data.card.id;
|
|
const cardId = action.data.card.id;
|
|
this.createdAt.cards[cardId] = action.date;
|
|
this.createdAt.cards[cardId] = action.date;
|
|
|
|
+ this.createdBy.cards[cardId] = action.idMemberCreator;
|
|
break;
|
|
break;
|
|
case 'createList':
|
|
case 'createList':
|
|
const listId = action.data.list.id;
|
|
const listId = action.data.list.id;
|