trelloCreator.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  1. const DateString = Match.Where(function(dateAsString) {
  2. check(dateAsString, String);
  3. return moment(dateAsString, moment.ISO_8601).isValid();
  4. });
  5. export class TrelloCreator {
  6. constructor(data) {
  7. // we log current date, to use the same timestamp for all our actions.
  8. // this helps to retrieve all elements performed by the same import.
  9. this._nowDate = new Date();
  10. // The object creation dates, indexed by Trello id
  11. // (so we only parse actions once!)
  12. this.createdAt = {
  13. board: null,
  14. cards: {},
  15. lists: {},
  16. };
  17. // The object creator Trello Id, indexed by the object Trello id
  18. // (so we only parse actions once!)
  19. this.createdBy = {
  20. cards: {}, // only cards have a field for that
  21. };
  22. // Map of labels Trello ID => Wekan ID
  23. this.labels = {};
  24. // Default swimlane
  25. this.swimlane = null;
  26. // Map of lists Trello ID => Wekan ID
  27. this.lists = {};
  28. // Map of cards Trello ID => Wekan ID
  29. this.cards = {};
  30. // Map of attachments Wekan ID => Wekan ID
  31. this.attachmentIds = {};
  32. // Map of checklists Wekan ID => Wekan ID
  33. this.checklists = {};
  34. // The comments, indexed by Trello card id (to map when importing cards)
  35. this.comments = {};
  36. // the members, indexed by Trello member id => Wekan user ID
  37. this.members = data.membersMapping ? data.membersMapping : {};
  38. // maps a trelloCardId to an array of trelloAttachments
  39. this.attachments = {};
  40. this.customFields = {};
  41. }
  42. /**
  43. * If dateString is provided,
  44. * return the Date it represents.
  45. * If not, will return the date when it was first called.
  46. * This is useful for us, as we want all import operations to
  47. * have the exact same date for easier later retrieval.
  48. *
  49. * @param {String} dateString a properly formatted Date
  50. */
  51. _now(dateString) {
  52. if (dateString) {
  53. return new Date(dateString);
  54. }
  55. if (!this._nowDate) {
  56. this._nowDate = new Date();
  57. }
  58. return this._nowDate;
  59. }
  60. /**
  61. * if trelloUserId is provided and we have a mapping,
  62. * return it.
  63. * Otherwise return current logged user.
  64. * @param trelloUserId
  65. * @private
  66. */
  67. _user(trelloUserId) {
  68. if (trelloUserId && this.members[trelloUserId]) {
  69. return this.members[trelloUserId];
  70. }
  71. return Meteor.userId();
  72. }
  73. checkActions(trelloActions) {
  74. check(trelloActions, [
  75. Match.ObjectIncluding({
  76. data: Object,
  77. date: DateString,
  78. type: String,
  79. }),
  80. ]);
  81. // XXX we could perform more thorough checks based on action type
  82. }
  83. checkBoard(trelloBoard) {
  84. check(
  85. trelloBoard,
  86. Match.ObjectIncluding({
  87. // closed: Boolean, // issue #3840, should import closed Trello boards
  88. name: String,
  89. prefs: Match.ObjectIncluding({
  90. // XXX refine control by validating 'background' against a list of
  91. // allowed values (is it worth the maintenance?)
  92. background: String,
  93. permissionLevel: Match.Where(value => {
  94. return ['org', 'private', 'public'].indexOf(value) >= 0;
  95. }),
  96. }),
  97. }),
  98. );
  99. }
  100. checkCards(trelloCards) {
  101. check(trelloCards, [
  102. Match.ObjectIncluding({
  103. closed: Boolean,
  104. dateLastActivity: DateString,
  105. desc: String,
  106. idLabels: [String],
  107. idMembers: [String],
  108. name: String,
  109. pos: Number,
  110. }),
  111. ]);
  112. }
  113. checkLabels(trelloLabels) {
  114. check(trelloLabels, [
  115. Match.ObjectIncluding({
  116. // XXX refine control by validating 'color' against a list of allowed
  117. // values (is it worth the maintenance?)
  118. name: String,
  119. }),
  120. ]);
  121. }
  122. checkLists(trelloLists) {
  123. check(trelloLists, [
  124. Match.ObjectIncluding({
  125. closed: Boolean,
  126. name: String,
  127. }),
  128. ]);
  129. }
  130. checkChecklists(trelloChecklists) {
  131. check(trelloChecklists, [
  132. Match.ObjectIncluding({
  133. idBoard: String,
  134. idCard: String,
  135. name: String,
  136. checkItems: [
  137. Match.ObjectIncluding({
  138. state: String,
  139. name: String,
  140. }),
  141. ],
  142. }),
  143. ]);
  144. }
  145. // You must call parseActions before calling this one.
  146. createBoardAndLabels(trelloBoard) {
  147. let color = 'blue';
  148. if (this.getColor(trelloBoard.prefs.background) !== undefined) {
  149. color = this.getColor(trelloBoard.prefs.background);
  150. }
  151. const boardToCreate = {
  152. archived: trelloBoard.closed,
  153. color: color,
  154. // very old boards won't have a creation activity so no creation date
  155. createdAt: this._now(this.createdAt.board),
  156. labels: [],
  157. customFields: [],
  158. members: [
  159. {
  160. userId: Meteor.userId(),
  161. isAdmin: true,
  162. isActive: true,
  163. isNoComments: false,
  164. isCommentOnly: false,
  165. swimlaneId: false,
  166. },
  167. ],
  168. permission: this.getPermission(trelloBoard.prefs.permissionLevel),
  169. slug: getSlug(trelloBoard.name) || 'board',
  170. stars: 0,
  171. title: Boards.uniqueTitle(trelloBoard.name),
  172. };
  173. // now add other members
  174. if (trelloBoard.memberships) {
  175. trelloBoard.memberships.forEach(trelloMembership => {
  176. const trelloId = trelloMembership.idMember;
  177. // do we have a mapping?
  178. if (this.members[trelloId]) {
  179. const wekanId = this.members[trelloId];
  180. // do we already have it in our list?
  181. const wekanMember = boardToCreate.members.find(
  182. wekanMember => wekanMember.userId === wekanId,
  183. );
  184. if (wekanMember) {
  185. // we're already mapped, but maybe with lower rights
  186. if (!wekanMember.isAdmin) {
  187. wekanMember.isAdmin = this.getAdmin(trelloMembership.memberType);
  188. }
  189. } else {
  190. boardToCreate.members.push({
  191. userId: wekanId,
  192. isAdmin: this.getAdmin(trelloMembership.memberType),
  193. isActive: true,
  194. isNoComments: false,
  195. isCommentOnly: false,
  196. swimlaneId: false,
  197. });
  198. }
  199. }
  200. });
  201. }
  202. if (trelloBoard.labels) {
  203. trelloBoard.labels.forEach(label => {
  204. const labelToCreate = {
  205. _id: Random.id(6),
  206. color: label.color ? label.color : 'black',
  207. name: label.name,
  208. };
  209. // We need to remember them by Trello ID, as this is the only ref we have
  210. // when importing cards.
  211. this.labels[label.id] = labelToCreate._id;
  212. boardToCreate.labels.push(labelToCreate);
  213. });
  214. }
  215. const boardId = Boards.direct.insert(boardToCreate);
  216. Boards.direct.update(boardId, { $set: { modifiedAt: this._now() } });
  217. // log activity
  218. Activities.direct.insert({
  219. activityType: 'importBoard',
  220. boardId,
  221. createdAt: this._now(),
  222. source: {
  223. id: trelloBoard.id,
  224. system: 'Trello',
  225. url: trelloBoard.url,
  226. },
  227. // We attribute the import to current user,
  228. // not the author from the original object.
  229. userId: this._user(),
  230. });
  231. if (trelloBoard.customFields) {
  232. trelloBoard.customFields.forEach(field => {
  233. const fieldToCreate = {
  234. // trelloId: field.id,
  235. name: field.name,
  236. showOnCard: field.display.cardFront,
  237. showLabelOnMiniCard: field.display.cardFront,
  238. automaticallyOnCard: true,
  239. alwaysOnCard: false,
  240. type: field.type,
  241. boardIds: [boardId],
  242. settings: {},
  243. };
  244. if (field.type === 'list') {
  245. fieldToCreate.type = 'dropdown';
  246. fieldToCreate.settings = {
  247. dropdownItems: field.options.map(opt => {
  248. return {
  249. _id: opt.id,
  250. name: opt.value.text,
  251. };
  252. }),
  253. };
  254. }
  255. // We need to remember them by Trello ID, as this is the only ref we have
  256. // when importing cards.
  257. this.customFields[field.id] = CustomFields.direct.insert(fieldToCreate);
  258. });
  259. }
  260. return boardId;
  261. }
  262. /**
  263. * Create the Wekan cards corresponding to the supplied Trello cards,
  264. * as well as all linked data: activities, comments, and attachments
  265. * @param trelloCards
  266. * @param boardId
  267. * @returns {Array}
  268. */
  269. createCards(trelloCards, boardId) {
  270. const result = [];
  271. trelloCards.forEach(card => {
  272. const cardToCreate = {
  273. archived: card.closed,
  274. boardId,
  275. // very old boards won't have a creation activity so no creation date
  276. createdAt: this._now(this.createdAt.cards[card.id]),
  277. dateLastActivity: this._now(),
  278. description: card.desc,
  279. listId: this.lists[card.idList],
  280. swimlaneId: this.swimlane,
  281. sort: card.pos,
  282. title: card.name,
  283. // we attribute the card to its creator if available
  284. userId: this._user(this.createdBy.cards[card.id]),
  285. dueAt: card.due ? this._now(card.due) : null,
  286. };
  287. // add labels
  288. if (card.idLabels) {
  289. cardToCreate.labelIds = card.idLabels.map(trelloId => {
  290. return this.labels[trelloId];
  291. });
  292. }
  293. // add members {
  294. if (card.idMembers) {
  295. const wekanMembers = [];
  296. // we can't just map, as some members may not have been mapped
  297. card.idMembers.forEach(trelloId => {
  298. if (this.members[trelloId]) {
  299. const wekanId = this.members[trelloId];
  300. // we may map multiple Trello members to the same wekan user
  301. // in which case we risk adding the same user multiple times
  302. if (!wekanMembers.find(wId => wId === wekanId)) {
  303. wekanMembers.push(wekanId);
  304. }
  305. }
  306. return true;
  307. });
  308. if (wekanMembers.length > 0) {
  309. cardToCreate.members = wekanMembers;
  310. }
  311. }
  312. // add vote
  313. if (card.idMembersVoted) {
  314. // Trello only know's positive votes
  315. const positiveVotes = [];
  316. card.idMembersVoted.forEach(trelloId => {
  317. if (this.members[trelloId]) {
  318. const wekanId = this.members[trelloId];
  319. // we may map multiple Trello members to the same wekan user
  320. // in which case we risk adding the same user multiple times
  321. if (!positiveVotes.find(wId => wId === wekanId)) {
  322. positiveVotes.push(wekanId);
  323. }
  324. }
  325. return true;
  326. });
  327. if (positiveVotes.length > 0) {
  328. cardToCreate.vote = {
  329. question: cardToCreate.title,
  330. public: true,
  331. positive: positiveVotes,
  332. };
  333. }
  334. }
  335. if (card.customFieldItems) {
  336. cardToCreate.customFields = [];
  337. card.customFieldItems.forEach(item => {
  338. const custom = {
  339. _id: this.customFields[item.idCustomField],
  340. };
  341. if (item.idValue) {
  342. custom.value = item.idValue;
  343. } else if (item.value.hasOwnProperty('checked')) {
  344. custom.value = item.value.checked === 'true';
  345. } else if (item.value.hasOwnProperty('text')) {
  346. custom.value = item.value.text;
  347. } else if (item.value.hasOwnProperty('date')) {
  348. custom.value = item.value.date;
  349. } else if (item.value.hasOwnProperty('number')) {
  350. custom.value = item.value.number;
  351. }
  352. cardToCreate.customFields.push(custom);
  353. });
  354. }
  355. // insert card
  356. const cardId = Cards.direct.insert(cardToCreate);
  357. // keep track of Trello id => Wekan id
  358. this.cards[card.id] = cardId;
  359. // log activity
  360. // Activities.direct.insert({
  361. // activityType: 'importCard',
  362. // boardId,
  363. // cardId,
  364. // createdAt: this._now(),
  365. // listId: cardToCreate.listId,
  366. // source: {
  367. // id: card.id,
  368. // system: 'Trello',
  369. // url: card.url,
  370. // },
  371. // // we attribute the import to current user,
  372. // // not the author of the original card
  373. // userId: this._user(),
  374. // });
  375. // add comments
  376. const comments = this.comments[card.id];
  377. if (comments) {
  378. comments.forEach(comment => {
  379. const commentToCreate = {
  380. boardId,
  381. cardId,
  382. createdAt: this._now(comment.date),
  383. text: comment.data.text,
  384. // we attribute the comment to the original author, default to current user
  385. userId: this._user(comment.idMemberCreator),
  386. };
  387. // dateLastActivity will be set from activity insert, no need to
  388. // update it ourselves
  389. const commentId = CardComments.direct.insert(commentToCreate);
  390. // We need to keep adding comment activities this way with Trello
  391. // because it doesn't provide a comment ID
  392. Activities.direct.insert({
  393. activityType: 'addComment',
  394. boardId: commentToCreate.boardId,
  395. cardId: commentToCreate.cardId,
  396. commentId,
  397. createdAt: this._now(comment.date),
  398. // we attribute the addComment (not the import)
  399. // to the original author - it is needed by some UI elements.
  400. userId: commentToCreate.userId,
  401. });
  402. });
  403. }
  404. const attachments = this.attachments[card.id];
  405. const trelloCoverId = card.idAttachmentCover;
  406. if (attachments && Meteor.isServer) {
  407. attachments.forEach(att => {
  408. const self = this;
  409. const opts = {
  410. type: att.type ? att.type : undefined,
  411. userId: self._user(att.userId),
  412. meta: {
  413. boardId,
  414. cardId,
  415. source: 'import',
  416. },
  417. };
  418. const cb = (error, fileObj) => {
  419. if (error) {
  420. throw error;
  421. }
  422. self.attachmentIds[att._id] = fileObj._id;
  423. if (trelloCoverId === att._id) {
  424. Cards.direct.update(cardId, {
  425. $set: { coverId: fileObj._id },
  426. });
  427. }
  428. };
  429. if (att.url) {
  430. Attachment.load(att.url, opts, cb, true);
  431. } else if (att.file) {
  432. Attachment.write(att.file, opts, cb, true);
  433. }
  434. });
  435. if (links.length) {
  436. let desc = cardToCreate.description.trim();
  437. if (desc) {
  438. desc += '\n\n';
  439. }
  440. desc += `## ${TAPi18n.__('links-heading')}\n`;
  441. links.forEach(link => {
  442. desc += `* ${link}\n`;
  443. });
  444. Cards.direct.update(cardId, {
  445. $set: {
  446. description: desc,
  447. },
  448. });
  449. }
  450. }
  451. result.push(cardId);
  452. });
  453. return result;
  454. }
  455. // Create labels if they do not exist and load this.labels.
  456. createLabels(trelloLabels, board) {
  457. trelloLabels.forEach(label => {
  458. const color = label.color;
  459. const name = label.name;
  460. const existingLabel = board.getLabel(name, color);
  461. if (existingLabel) {
  462. this.labels[label.id] = existingLabel._id;
  463. } else {
  464. const idLabelCreated = board.pushLabel(name, color);
  465. this.labels[label.id] = idLabelCreated;
  466. }
  467. });
  468. }
  469. createLists(trelloLists, boardId) {
  470. trelloLists.forEach(list => {
  471. const listToCreate = {
  472. archived: list.closed,
  473. boardId,
  474. // We are being defensing here by providing a default date (now) if the
  475. // creation date wasn't found on the action log. This happen on old
  476. // Trello boards (eg from 2013) that didn't log the 'createList' action
  477. // we require.
  478. createdAt: this._now(this.createdAt.lists[list.id]),
  479. title: list.name,
  480. sort: list.pos,
  481. };
  482. const listId = Lists.direct.insert(listToCreate);
  483. Lists.direct.update(listId, { $set: { updatedAt: this._now() } });
  484. this.lists[list.id] = listId;
  485. // log activity
  486. // Activities.direct.insert({
  487. // activityType: 'importList',
  488. // boardId,
  489. // createdAt: this._now(),
  490. // listId,
  491. // source: {
  492. // id: list.id,
  493. // system: 'Trello',
  494. // },
  495. // // We attribute the import to current user,
  496. // // not the creator of the original object
  497. // userId: this._user(),
  498. // });
  499. });
  500. }
  501. createSwimlanes(boardId) {
  502. const swimlaneToCreate = {
  503. archived: false,
  504. boardId,
  505. // We are being defensing here by providing a default date (now) if the
  506. // creation date wasn't found on the action log. This happen on old
  507. // Wekan boards (eg from 2013) that didn't log the 'createList' action
  508. // we require.
  509. createdAt: this._now(),
  510. title: 'Default',
  511. sort: 1,
  512. };
  513. const swimlaneId = Swimlanes.direct.insert(swimlaneToCreate);
  514. Swimlanes.direct.update(swimlaneId, { $set: { updatedAt: this._now() } });
  515. this.swimlane = swimlaneId;
  516. }
  517. createChecklists(trelloChecklists) {
  518. trelloChecklists.forEach(checklist => {
  519. if (this.cards[checklist.idCard]) {
  520. // Create the checklist
  521. const checklistToCreate = {
  522. cardId: this.cards[checklist.idCard],
  523. title: checklist.name,
  524. createdAt: this._now(),
  525. sort: checklist.pos,
  526. };
  527. const checklistId = Checklists.direct.insert(checklistToCreate);
  528. // keep track of Trello id => Wekan id
  529. this.checklists[checklist.id] = checklistId;
  530. // Now add the items to the checklistItems
  531. let counter = 0;
  532. checklist.checkItems.forEach(item => {
  533. counter++;
  534. const checklistItemTocreate = {
  535. _id: checklistId + counter,
  536. title: item.name,
  537. checklistId: this.checklists[checklist.id],
  538. cardId: this.cards[checklist.idCard],
  539. sort: item.pos,
  540. isFinished: item.state === 'complete',
  541. };
  542. ChecklistItems.direct.insert(checklistItemTocreate);
  543. });
  544. }
  545. });
  546. }
  547. getAdmin(trelloMemberType) {
  548. return trelloMemberType === 'admin';
  549. }
  550. getColor(trelloColorCode) {
  551. // trello color name => wekan color
  552. const mapColors = {
  553. blue: 'belize',
  554. orange: 'pumpkin',
  555. green: 'nephritis',
  556. red: 'pomegranate',
  557. purple: 'wisteria',
  558. pink: 'moderatepink',
  559. lime: 'limegreen',
  560. sky: 'strongcyan',
  561. grey: 'midnight',
  562. };
  563. const wekanColor = mapColors[trelloColorCode];
  564. return wekanColor || Boards.simpleSchema()._schema.color.allowedValues[0];
  565. }
  566. getPermission(trelloPermissionCode) {
  567. if (trelloPermissionCode === 'public') {
  568. return 'public';
  569. }
  570. // Wekan does NOT have organization level, so we default both 'private' and
  571. // 'org' to private.
  572. return 'private';
  573. }
  574. parseActions(trelloActions) {
  575. trelloActions.forEach(action => {
  576. if (action.type === 'addAttachmentToCard') {
  577. // We have to be cautious, because the attachment could have been removed later.
  578. // In that case Trello still reports its addition, but removes its 'url' field.
  579. // So we test for that
  580. const trelloAttachment = action.data.attachment;
  581. // We need the idMemberCreator
  582. trelloAttachment.idMemberCreator = action.idMemberCreator;
  583. if (trelloAttachment.url) {
  584. // we cannot actually create the Wekan attachment, because we don't yet
  585. // have the cards to attach it to, so we store it in the instance variable.
  586. const trelloCardId = action.data.card.id;
  587. if (!this.attachments[trelloCardId]) {
  588. this.attachments[trelloCardId] = [];
  589. }
  590. this.attachments[trelloCardId].push(trelloAttachment);
  591. }
  592. } else if (action.type === 'commentCard') {
  593. const id = action.data.card.id;
  594. if (this.comments[id]) {
  595. this.comments[id].push(action);
  596. } else {
  597. this.comments[id] = [action];
  598. }
  599. } else if (action.type === 'createBoard') {
  600. this.createdAt.board = action.date;
  601. } else if (action.type === 'createCard') {
  602. const cardId = action.data.card.id;
  603. this.createdAt.cards[cardId] = action.date;
  604. this.createdBy.cards[cardId] = action.idMemberCreator;
  605. } else if (action.type === 'createList') {
  606. const listId = action.data.list.id;
  607. this.createdAt.lists[listId] = action.date;
  608. }
  609. });
  610. }
  611. importActions(actions, boardId) {
  612. actions.forEach(action => {
  613. switch (action.type) {
  614. // Board related actions
  615. // TODO: addBoardMember, removeBoardMember
  616. case 'createBoard': {
  617. Activities.direct.insert({
  618. userId: this._user(action.idMemberCreator),
  619. type: 'board',
  620. activityTypeId: boardId,
  621. activityType: 'createBoard',
  622. boardId,
  623. createdAt: this._now(action.date),
  624. });
  625. break;
  626. }
  627. // List related activities
  628. // TODO: removeList, archivedList
  629. case 'createList': {
  630. Activities.direct.insert({
  631. userId: this._user(action.idMemberCreator),
  632. type: 'list',
  633. activityType: 'createList',
  634. listId: this.lists[action.data.list.id],
  635. boardId,
  636. createdAt: this._now(action.date),
  637. });
  638. break;
  639. }
  640. // Card related activities
  641. // TODO: archivedCard, restoredCard, joinMember, unjoinMember
  642. case 'createCard': {
  643. Activities.direct.insert({
  644. userId: this._user(action.idMemberCreator),
  645. activityType: 'createCard',
  646. listId: this.lists[action.data.list.id],
  647. cardId: this.cards[action.data.card.id],
  648. boardId,
  649. createdAt: this._now(action.date),
  650. });
  651. break;
  652. }
  653. case 'updateCard': {
  654. if (action.data.old.idList) {
  655. Activities.direct.insert({
  656. userId: this._user(action.idMemberCreator),
  657. oldListId: this.lists[action.data.old.idList],
  658. activityType: 'moveCard',
  659. listId: this.lists[action.data.listAfter.id],
  660. cardId: this.cards[action.data.card.id],
  661. boardId,
  662. createdAt: this._now(action.date),
  663. });
  664. }
  665. break;
  666. }
  667. // Comment related activities
  668. // Trello doesn't export the comment id
  669. // Attachment related activities
  670. case 'addAttachmentToCard': {
  671. Activities.direct.insert({
  672. userId: this._user(action.idMemberCreator),
  673. type: 'card',
  674. activityType: 'addAttachment',
  675. attachmentId: this.attachmentIds[action.data.attachment.id],
  676. cardId: this.cards[action.data.card.id],
  677. boardId,
  678. createdAt: this._now(action.date),
  679. });
  680. break;
  681. }
  682. // Checklist related activities
  683. case 'addChecklistToCard': {
  684. Activities.direct.insert({
  685. userId: this._user(action.idMemberCreator),
  686. activityType: 'addChecklist',
  687. cardId: this.cards[action.data.card.id],
  688. checklistId: this.checklists[action.data.checklist.id],
  689. boardId,
  690. createdAt: this._now(action.date),
  691. });
  692. break;
  693. }
  694. }
  695. // Trello doesn't have an add checklist item action
  696. });
  697. }
  698. check(board) {
  699. try {
  700. // check(data, {
  701. // membersMapping: Match.Optional(Object),
  702. // });
  703. this.checkActions(board.actions);
  704. this.checkBoard(board);
  705. this.checkLabels(board.labels);
  706. this.checkLists(board.lists);
  707. this.checkCards(board.cards);
  708. this.checkChecklists(board.checklists);
  709. } catch (e) {
  710. throw new Meteor.Error('error-json-schema');
  711. }
  712. }
  713. create(board, currentBoardId) {
  714. // TODO : Make isSandstorm variable global
  715. const isSandstorm =
  716. Meteor.settings &&
  717. Meteor.settings.public &&
  718. Meteor.settings.public.sandstorm;
  719. if (isSandstorm && currentBoardId) {
  720. const currentBoard = Boards.findOne(currentBoardId);
  721. currentBoard.archive();
  722. }
  723. this.parseActions(board.actions);
  724. const boardId = this.createBoardAndLabels(board);
  725. this.createLists(board.lists, boardId);
  726. this.createSwimlanes(boardId);
  727. this.createCards(board.cards, boardId);
  728. this.createChecklists(board.checklists);
  729. this.importActions(board.actions, boardId);
  730. // XXX add members
  731. return boardId;
  732. }
  733. }