trelloCreator.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  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,
  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. const boardToCreate = {
  148. archived: trelloBoard.closed,
  149. color: this.getColor(trelloBoard.prefs.background),
  150. // very old boards won't have a creation activity so no creation date
  151. createdAt: this._now(this.createdAt.board),
  152. labels: [],
  153. customFields: [],
  154. members: [
  155. {
  156. userId: Meteor.userId(),
  157. isAdmin: true,
  158. isActive: true,
  159. isNoComments: false,
  160. isCommentOnly: false,
  161. swimlaneId: false,
  162. },
  163. ],
  164. permission: this.getPermission(trelloBoard.prefs.permissionLevel),
  165. slug: getSlug(trelloBoard.name) || 'board',
  166. stars: 0,
  167. title: trelloBoard.name,
  168. };
  169. // now add other members
  170. if (trelloBoard.memberships) {
  171. trelloBoard.memberships.forEach(trelloMembership => {
  172. const trelloId = trelloMembership.idMember;
  173. // do we have a mapping?
  174. if (this.members[trelloId]) {
  175. const wekanId = this.members[trelloId];
  176. // do we already have it in our list?
  177. const wekanMember = boardToCreate.members.find(
  178. wekanMember => wekanMember.userId === wekanId,
  179. );
  180. if (wekanMember) {
  181. // we're already mapped, but maybe with lower rights
  182. if (!wekanMember.isAdmin) {
  183. wekanMember.isAdmin = this.getAdmin(trelloMembership.memberType);
  184. }
  185. } else {
  186. boardToCreate.members.push({
  187. userId: wekanId,
  188. isAdmin: this.getAdmin(trelloMembership.memberType),
  189. isActive: true,
  190. isNoComments: false,
  191. isCommentOnly: false,
  192. swimlaneId: false,
  193. });
  194. }
  195. }
  196. });
  197. }
  198. trelloBoard.labels.forEach(label => {
  199. const labelToCreate = {
  200. _id: Random.id(6),
  201. color: label.color ? label.color : 'black',
  202. name: label.name,
  203. };
  204. // We need to remember them by Trello ID, as this is the only ref we have
  205. // when importing cards.
  206. this.labels[label.id] = labelToCreate._id;
  207. boardToCreate.labels.push(labelToCreate);
  208. });
  209. const boardId = Boards.direct.insert(boardToCreate);
  210. Boards.direct.update(boardId, { $set: { modifiedAt: this._now() } });
  211. // log activity
  212. Activities.direct.insert({
  213. activityType: 'importBoard',
  214. boardId,
  215. createdAt: this._now(),
  216. source: {
  217. id: trelloBoard.id,
  218. system: 'Trello',
  219. url: trelloBoard.url,
  220. },
  221. // We attribute the import to current user,
  222. // not the author from the original object.
  223. userId: this._user(),
  224. });
  225. if (trelloBoard.customFields) {
  226. trelloBoard.customFields.forEach(field => {
  227. const fieldToCreate = {
  228. // trelloId: field.id,
  229. name: field.name,
  230. showOnCard: field.display.cardFront,
  231. showLabelOnMiniCard: field.display.cardFront,
  232. automaticallyOnCard: true,
  233. alwaysOnCard: false,
  234. type: field.type,
  235. boardIds: [boardId],
  236. settings: {},
  237. };
  238. if (field.type === 'list') {
  239. fieldToCreate.type = 'dropdown';
  240. fieldToCreate.settings = {
  241. dropdownItems: field.options.map(opt => {
  242. return {
  243. _id: opt.id,
  244. name: opt.value.text,
  245. };
  246. }),
  247. };
  248. }
  249. // We need to remember them by Trello ID, as this is the only ref we have
  250. // when importing cards.
  251. this.customFields[field.id] = CustomFields.direct.insert(fieldToCreate);
  252. });
  253. }
  254. return boardId;
  255. }
  256. /**
  257. * Create the Wekan cards corresponding to the supplied Trello cards,
  258. * as well as all linked data: activities, comments, and attachments
  259. * @param trelloCards
  260. * @param boardId
  261. * @returns {Array}
  262. */
  263. createCards(trelloCards, boardId) {
  264. const result = [];
  265. trelloCards.forEach(card => {
  266. const cardToCreate = {
  267. archived: card.closed,
  268. boardId,
  269. // very old boards won't have a creation activity so no creation date
  270. createdAt: this._now(this.createdAt.cards[card.id]),
  271. dateLastActivity: this._now(),
  272. description: card.desc,
  273. listId: this.lists[card.idList],
  274. swimlaneId: this.swimlane,
  275. sort: card.pos,
  276. title: card.name,
  277. // we attribute the card to its creator if available
  278. userId: this._user(this.createdBy.cards[card.id]),
  279. dueAt: card.due ? this._now(card.due) : null,
  280. };
  281. // add labels
  282. if (card.idLabels) {
  283. cardToCreate.labelIds = card.idLabels.map(trelloId => {
  284. return this.labels[trelloId];
  285. });
  286. }
  287. // add members {
  288. if (card.idMembers) {
  289. const wekanMembers = [];
  290. // we can't just map, as some members may not have been mapped
  291. card.idMembers.forEach(trelloId => {
  292. if (this.members[trelloId]) {
  293. const wekanId = this.members[trelloId];
  294. // we may map multiple Trello members to the same wekan user
  295. // in which case we risk adding the same user multiple times
  296. if (!wekanMembers.find(wId => wId === wekanId)) {
  297. wekanMembers.push(wekanId);
  298. }
  299. }
  300. return true;
  301. });
  302. if (wekanMembers.length > 0) {
  303. cardToCreate.members = wekanMembers;
  304. }
  305. }
  306. // add vote
  307. if (card.idMembersVoted) {
  308. // Trello only know's positive votes
  309. const positiveVotes = [];
  310. card.idMembersVoted.forEach(trelloId => {
  311. if (this.members[trelloId]) {
  312. const wekanId = this.members[trelloId];
  313. // we may map multiple Trello members to the same wekan user
  314. // in which case we risk adding the same user multiple times
  315. if (!positiveVotes.find(wId => wId === wekanId)) {
  316. positiveVotes.push(wekanId);
  317. }
  318. }
  319. return true;
  320. });
  321. if (positiveVotes.length > 0) {
  322. cardToCreate.vote = {
  323. question: cardToCreate.title,
  324. public: true,
  325. positive: positiveVotes,
  326. };
  327. }
  328. }
  329. if (card.customFieldItems) {
  330. cardToCreate.customFields = [];
  331. card.customFieldItems.forEach(item => {
  332. const custom = {
  333. _id: this.customFields[item.idCustomField],
  334. };
  335. if (item.idValue) {
  336. custom.value = item.idValue;
  337. } else if (item.value.hasOwnProperty('checked')) {
  338. custom.value = item.value.checked === 'true';
  339. } else if (item.value.hasOwnProperty('text')) {
  340. custom.value = item.value.text;
  341. } else if (item.value.hasOwnProperty('date')) {
  342. custom.value = item.value.date;
  343. } else if (item.value.hasOwnProperty('number')) {
  344. custom.value = item.value.number;
  345. }
  346. cardToCreate.customFields.push(custom);
  347. });
  348. }
  349. // insert card
  350. const cardId = Cards.direct.insert(cardToCreate);
  351. // keep track of Trello id => Wekan id
  352. this.cards[card.id] = cardId;
  353. // log activity
  354. // Activities.direct.insert({
  355. // activityType: 'importCard',
  356. // boardId,
  357. // cardId,
  358. // createdAt: this._now(),
  359. // listId: cardToCreate.listId,
  360. // source: {
  361. // id: card.id,
  362. // system: 'Trello',
  363. // url: card.url,
  364. // },
  365. // // we attribute the import to current user,
  366. // // not the author of the original card
  367. // userId: this._user(),
  368. // });
  369. // add comments
  370. const comments = this.comments[card.id];
  371. if (comments) {
  372. comments.forEach(comment => {
  373. const commentToCreate = {
  374. boardId,
  375. cardId,
  376. createdAt: this._now(comment.date),
  377. text: comment.data.text,
  378. // we attribute the comment to the original author, default to current user
  379. userId: this._user(comment.idMemberCreator),
  380. };
  381. // dateLastActivity will be set from activity insert, no need to
  382. // update it ourselves
  383. const commentId = CardComments.direct.insert(commentToCreate);
  384. // We need to keep adding comment activities this way with Trello
  385. // because it doesn't provide a comment ID
  386. Activities.direct.insert({
  387. activityType: 'addComment',
  388. boardId: commentToCreate.boardId,
  389. cardId: commentToCreate.cardId,
  390. commentId,
  391. createdAt: this._now(comment.date),
  392. // we attribute the addComment (not the import)
  393. // to the original author - it is needed by some UI elements.
  394. userId: commentToCreate.userId,
  395. });
  396. });
  397. }
  398. const attachments = this.attachments[card.id];
  399. const trelloCoverId = card.idAttachmentCover;
  400. if (attachments) {
  401. attachments.forEach(att => {
  402. const file = new FS.File();
  403. // Simulating file.attachData on the client generates multiple errors
  404. // - HEAD returns null, which causes exception down the line
  405. // - the template then tries to display the url to the attachment which causes other errors
  406. // so we make it server only, and let UI catch up once it is done, forget about latency comp.
  407. const self = this;
  408. if (Meteor.isServer) {
  409. file.attachData(att.url, function(error) {
  410. file.boardId = boardId;
  411. file.cardId = cardId;
  412. file.userId = self._user(att.idMemberCreator);
  413. // The field source will only be used to prevent adding
  414. // attachments' related activities automatically
  415. file.source = 'import';
  416. if (error) {
  417. throw error;
  418. } else {
  419. const wekanAtt = Attachments.insert(file, () => {
  420. // we do nothing
  421. });
  422. self.attachmentIds[att.id] = wekanAtt._id;
  423. //
  424. if (trelloCoverId === att.id) {
  425. Cards.direct.update(cardId, {
  426. $set: { coverId: wekanAtt._id },
  427. });
  428. }
  429. }
  430. });
  431. }
  432. // todo XXX set cover - if need be
  433. });
  434. }
  435. result.push(cardId);
  436. });
  437. return result;
  438. }
  439. // Create labels if they do not exist and load this.labels.
  440. createLabels(trelloLabels, board) {
  441. trelloLabels.forEach(label => {
  442. const color = label.color;
  443. const name = label.name;
  444. const existingLabel = board.getLabel(name, color);
  445. if (existingLabel) {
  446. this.labels[label.id] = existingLabel._id;
  447. } else {
  448. const idLabelCreated = board.pushLabel(name, color);
  449. this.labels[label.id] = idLabelCreated;
  450. }
  451. });
  452. }
  453. createLists(trelloLists, boardId) {
  454. trelloLists.forEach(list => {
  455. const listToCreate = {
  456. archived: list.closed,
  457. boardId,
  458. // We are being defensing here by providing a default date (now) if the
  459. // creation date wasn't found on the action log. This happen on old
  460. // Trello boards (eg from 2013) that didn't log the 'createList' action
  461. // we require.
  462. createdAt: this._now(this.createdAt.lists[list.id]),
  463. title: list.name,
  464. sort: list.pos,
  465. };
  466. const listId = Lists.direct.insert(listToCreate);
  467. Lists.direct.update(listId, { $set: { updatedAt: this._now() } });
  468. this.lists[list.id] = listId;
  469. // log activity
  470. // Activities.direct.insert({
  471. // activityType: 'importList',
  472. // boardId,
  473. // createdAt: this._now(),
  474. // listId,
  475. // source: {
  476. // id: list.id,
  477. // system: 'Trello',
  478. // },
  479. // // We attribute the import to current user,
  480. // // not the creator of the original object
  481. // userId: this._user(),
  482. // });
  483. });
  484. }
  485. createSwimlanes(boardId) {
  486. const swimlaneToCreate = {
  487. archived: false,
  488. boardId,
  489. // We are being defensing here by providing a default date (now) if the
  490. // creation date wasn't found on the action log. This happen on old
  491. // Wekan boards (eg from 2013) that didn't log the 'createList' action
  492. // we require.
  493. createdAt: this._now(),
  494. title: 'Default',
  495. sort: 1,
  496. };
  497. const swimlaneId = Swimlanes.direct.insert(swimlaneToCreate);
  498. Swimlanes.direct.update(swimlaneId, { $set: { updatedAt: this._now() } });
  499. this.swimlane = swimlaneId;
  500. }
  501. createChecklists(trelloChecklists) {
  502. trelloChecklists.forEach(checklist => {
  503. if (this.cards[checklist.idCard]) {
  504. // Create the checklist
  505. const checklistToCreate = {
  506. cardId: this.cards[checklist.idCard],
  507. title: checklist.name,
  508. createdAt: this._now(),
  509. sort: checklist.pos,
  510. };
  511. const checklistId = Checklists.direct.insert(checklistToCreate);
  512. // keep track of Trello id => Wekan id
  513. this.checklists[checklist.id] = checklistId;
  514. // Now add the items to the checklistItems
  515. let counter = 0;
  516. checklist.checkItems.forEach(item => {
  517. counter++;
  518. const checklistItemTocreate = {
  519. _id: checklistId + counter,
  520. title: item.name,
  521. checklistId: this.checklists[checklist.id],
  522. cardId: this.cards[checklist.idCard],
  523. sort: item.pos,
  524. isFinished: item.state === 'complete',
  525. };
  526. ChecklistItems.direct.insert(checklistItemTocreate);
  527. });
  528. }
  529. });
  530. }
  531. getAdmin(trelloMemberType) {
  532. return trelloMemberType === 'admin';
  533. }
  534. getColor(trelloColorCode) {
  535. // trello color name => wekan color
  536. const mapColors = {
  537. blue: 'belize',
  538. orange: 'pumpkin',
  539. green: 'nephritis',
  540. red: 'pomegranate',
  541. purple: 'wisteria',
  542. pink: 'moderatepink',
  543. lime: 'limegreen',
  544. sky: 'strongcyan',
  545. grey: 'midnight',
  546. };
  547. const wekanColor = mapColors[trelloColorCode];
  548. return wekanColor || Boards.simpleSchema()._schema.color.allowedValues[0];
  549. }
  550. getPermission(trelloPermissionCode) {
  551. if (trelloPermissionCode === 'public') {
  552. return 'public';
  553. }
  554. // Wekan does NOT have organization level, so we default both 'private' and
  555. // 'org' to private.
  556. return 'private';
  557. }
  558. parseActions(trelloActions) {
  559. trelloActions.forEach(action => {
  560. if (action.type === 'addAttachmentToCard') {
  561. // We have to be cautious, because the attachment could have been removed later.
  562. // In that case Trello still reports its addition, but removes its 'url' field.
  563. // So we test for that
  564. const trelloAttachment = action.data.attachment;
  565. // We need the idMemberCreator
  566. trelloAttachment.idMemberCreator = action.idMemberCreator;
  567. if (trelloAttachment.url) {
  568. // we cannot actually create the Wekan attachment, because we don't yet
  569. // have the cards to attach it to, so we store it in the instance variable.
  570. const trelloCardId = action.data.card.id;
  571. if (!this.attachments[trelloCardId]) {
  572. this.attachments[trelloCardId] = [];
  573. }
  574. this.attachments[trelloCardId].push(trelloAttachment);
  575. }
  576. } else if (action.type === 'commentCard') {
  577. const id = action.data.card.id;
  578. if (this.comments[id]) {
  579. this.comments[id].push(action);
  580. } else {
  581. this.comments[id] = [action];
  582. }
  583. } else if (action.type === 'createBoard') {
  584. this.createdAt.board = action.date;
  585. } else if (action.type === 'createCard') {
  586. const cardId = action.data.card.id;
  587. this.createdAt.cards[cardId] = action.date;
  588. this.createdBy.cards[cardId] = action.idMemberCreator;
  589. } else if (action.type === 'createList') {
  590. const listId = action.data.list.id;
  591. this.createdAt.lists[listId] = action.date;
  592. }
  593. });
  594. }
  595. importActions(actions, boardId) {
  596. actions.forEach(action => {
  597. switch (action.type) {
  598. // Board related actions
  599. // TODO: addBoardMember, removeBoardMember
  600. case 'createBoard': {
  601. Activities.direct.insert({
  602. userId: this._user(action.idMemberCreator),
  603. type: 'board',
  604. activityTypeId: boardId,
  605. activityType: 'createBoard',
  606. boardId,
  607. createdAt: this._now(action.date),
  608. });
  609. break;
  610. }
  611. // List related activities
  612. // TODO: removeList, archivedList
  613. case 'createList': {
  614. Activities.direct.insert({
  615. userId: this._user(action.idMemberCreator),
  616. type: 'list',
  617. activityType: 'createList',
  618. listId: this.lists[action.data.list.id],
  619. boardId,
  620. createdAt: this._now(action.date),
  621. });
  622. break;
  623. }
  624. // Card related activities
  625. // TODO: archivedCard, restoredCard, joinMember, unjoinMember
  626. case 'createCard': {
  627. Activities.direct.insert({
  628. userId: this._user(action.idMemberCreator),
  629. activityType: 'createCard',
  630. listId: this.lists[action.data.list.id],
  631. cardId: this.cards[action.data.card.id],
  632. boardId,
  633. createdAt: this._now(action.date),
  634. });
  635. break;
  636. }
  637. case 'updateCard': {
  638. if (action.data.old.idList) {
  639. Activities.direct.insert({
  640. userId: this._user(action.idMemberCreator),
  641. oldListId: this.lists[action.data.old.idList],
  642. activityType: 'moveCard',
  643. listId: this.lists[action.data.listAfter.id],
  644. cardId: this.cards[action.data.card.id],
  645. boardId,
  646. createdAt: this._now(action.date),
  647. });
  648. }
  649. break;
  650. }
  651. // Comment related activities
  652. // Trello doesn't export the comment id
  653. // Attachment related activities
  654. case 'addAttachmentToCard': {
  655. Activities.direct.insert({
  656. userId: this._user(action.idMemberCreator),
  657. type: 'card',
  658. activityType: 'addAttachment',
  659. attachmentId: this.attachmentIds[action.data.attachment.id],
  660. cardId: this.cards[action.data.card.id],
  661. boardId,
  662. createdAt: this._now(action.date),
  663. });
  664. break;
  665. }
  666. // Checklist related activities
  667. case 'addChecklistToCard': {
  668. Activities.direct.insert({
  669. userId: this._user(action.idMemberCreator),
  670. activityType: 'addChecklist',
  671. cardId: this.cards[action.data.card.id],
  672. checklistId: this.checklists[action.data.checklist.id],
  673. boardId,
  674. createdAt: this._now(action.date),
  675. });
  676. break;
  677. }
  678. }
  679. // Trello doesn't have an add checklist item action
  680. });
  681. }
  682. check(board) {
  683. try {
  684. // check(data, {
  685. // membersMapping: Match.Optional(Object),
  686. // });
  687. this.checkActions(board.actions);
  688. this.checkBoard(board);
  689. this.checkLabels(board.labels);
  690. this.checkLists(board.lists);
  691. this.checkCards(board.cards);
  692. this.checkChecklists(board.checklists);
  693. } catch (e) {
  694. throw new Meteor.Error('error-json-schema');
  695. }
  696. }
  697. create(board, currentBoardId) {
  698. // TODO : Make isSandstorm variable global
  699. const isSandstorm =
  700. Meteor.settings &&
  701. Meteor.settings.public &&
  702. Meteor.settings.public.sandstorm;
  703. if (isSandstorm && currentBoardId) {
  704. const currentBoard = Boards.findOne(currentBoardId);
  705. currentBoard.archive();
  706. }
  707. this.parseActions(board.actions);
  708. const boardId = this.createBoardAndLabels(board);
  709. this.createLists(board.lists, boardId);
  710. this.createSwimlanes(boardId);
  711. this.createCards(board.cards, boardId);
  712. this.createChecklists(board.checklists);
  713. this.importActions(board.actions, boardId);
  714. // XXX add members
  715. return boardId;
  716. }
  717. }