trelloCreator.js 24 KB

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