trelloCreator.js 25 KB

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