cards.js 93 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753
  1. import {
  2. ALLOWED_COLORS,
  3. TYPE_CARD,
  4. TYPE_LINKED_BOARD,
  5. TYPE_LINKED_CARD,
  6. } from '../config/const';
  7. Cards = new Mongo.Collection('cards');
  8. // XXX To improve pub/sub performances a card document should include a
  9. // de-normalized number of comments so we don't have to publish the whole list
  10. // of comments just to display the number of them in the board view.
  11. Cards.attachSchema(
  12. new SimpleSchema({
  13. title: {
  14. /**
  15. * the title of the card
  16. */
  17. type: String,
  18. optional: true,
  19. defaultValue: '',
  20. },
  21. archived: {
  22. /**
  23. * is the card archived
  24. */
  25. type: Boolean,
  26. // eslint-disable-next-line consistent-return
  27. autoValue() {
  28. // eslint-disable-line consistent-return
  29. if (this.isInsert && !this.isSet) {
  30. return false;
  31. }
  32. },
  33. },
  34. archivedAt: {
  35. /**
  36. * latest archiving date
  37. */
  38. type: Date,
  39. optional: true,
  40. },
  41. parentId: {
  42. /**
  43. * ID of the parent card
  44. */
  45. type: String,
  46. optional: true,
  47. defaultValue: '',
  48. },
  49. listId: {
  50. /**
  51. * List ID where the card is
  52. */
  53. type: String,
  54. optional: true,
  55. defaultValue: '',
  56. },
  57. swimlaneId: {
  58. /**
  59. * Swimlane ID where the card is
  60. */
  61. type: String,
  62. },
  63. // The system could work without this `boardId` information (we could deduce
  64. // the board identifier from the card), but it would make the system more
  65. // difficult to manage and less efficient.
  66. boardId: {
  67. /**
  68. * Board ID of the card
  69. */
  70. type: String,
  71. optional: true,
  72. defaultValue: '',
  73. },
  74. coverId: {
  75. /**
  76. * Cover ID of the card
  77. */
  78. type: String,
  79. optional: true,
  80. defaultValue: '',
  81. },
  82. color: {
  83. type: String,
  84. optional: true,
  85. allowedValues: ALLOWED_COLORS,
  86. },
  87. createdAt: {
  88. /**
  89. * creation date
  90. */
  91. type: Date,
  92. // eslint-disable-next-line consistent-return
  93. autoValue() {
  94. if (this.isInsert) {
  95. return new Date();
  96. } else if (this.isUpsert) {
  97. return { $setOnInsert: new Date() };
  98. } else {
  99. this.unset();
  100. }
  101. },
  102. },
  103. modifiedAt: {
  104. type: Date,
  105. denyUpdate: false,
  106. // eslint-disable-next-line consistent-return
  107. autoValue() {
  108. if (this.isInsert || this.isUpsert || this.isUpdate) {
  109. return new Date();
  110. } else {
  111. this.unset();
  112. }
  113. },
  114. },
  115. customFields: {
  116. /**
  117. * list of custom fields
  118. */
  119. type: [Object],
  120. optional: true,
  121. defaultValue: [],
  122. },
  123. 'customFields.$': {
  124. type: new SimpleSchema({
  125. _id: {
  126. /**
  127. * the ID of the related custom field
  128. */
  129. type: String,
  130. optional: true,
  131. defaultValue: '',
  132. },
  133. value: {
  134. /**
  135. * value attached to the custom field
  136. */
  137. type: Match.OneOf(String, Number, Boolean, Date, [String]),
  138. optional: true,
  139. defaultValue: '',
  140. },
  141. 'value.$': {
  142. type: String,
  143. optional: true,
  144. },
  145. }),
  146. },
  147. dateLastActivity: {
  148. /**
  149. * Date of last activity
  150. */
  151. type: Date,
  152. autoValue() {
  153. return new Date();
  154. },
  155. },
  156. description: {
  157. /**
  158. * description of the card
  159. */
  160. type: String,
  161. optional: true,
  162. defaultValue: '',
  163. },
  164. requestedBy: {
  165. /**
  166. * who requested the card (ID of the user)
  167. */
  168. type: String,
  169. optional: true,
  170. defaultValue: '',
  171. },
  172. assignedBy: {
  173. /**
  174. * who assigned the card (ID of the user)
  175. */
  176. type: String,
  177. optional: true,
  178. defaultValue: '',
  179. },
  180. labelIds: {
  181. /**
  182. * list of labels ID the card has
  183. */
  184. type: [String],
  185. optional: true,
  186. defaultValue: [],
  187. },
  188. members: {
  189. /**
  190. * list of members (user IDs)
  191. */
  192. type: [String],
  193. optional: true,
  194. defaultValue: [],
  195. },
  196. assignees: {
  197. /**
  198. * who is assignee of the card (user ID),
  199. * maximum one ID of assignee in array.
  200. */
  201. type: [String],
  202. optional: true,
  203. defaultValue: [],
  204. },
  205. receivedAt: {
  206. /**
  207. * Date the card was received
  208. */
  209. type: Date,
  210. optional: true,
  211. },
  212. startAt: {
  213. /**
  214. * Date the card was started to be worked on
  215. */
  216. type: Date,
  217. optional: true,
  218. },
  219. dueAt: {
  220. /**
  221. * Date the card is due
  222. */
  223. type: Date,
  224. optional: true,
  225. },
  226. endAt: {
  227. /**
  228. * Date the card ended
  229. */
  230. type: Date,
  231. optional: true,
  232. },
  233. spentTime: {
  234. /**
  235. * How much time has been spent on this
  236. */
  237. type: Number,
  238. decimal: true,
  239. optional: true,
  240. defaultValue: 0,
  241. },
  242. isOvertime: {
  243. /**
  244. * is the card over time?
  245. */
  246. type: Boolean,
  247. defaultValue: false,
  248. optional: true,
  249. },
  250. // XXX Should probably be called `authorId`. Is it even needed since we have
  251. // the `members` field?
  252. userId: {
  253. /**
  254. * user ID of the author of the card
  255. */
  256. type: String,
  257. // eslint-disable-next-line consistent-return
  258. autoValue() {
  259. // eslint-disable-line consistent-return
  260. if (this.isInsert && !this.isSet) {
  261. return this.userId;
  262. }
  263. },
  264. },
  265. sort: {
  266. /**
  267. * Sort value
  268. */
  269. type: Number,
  270. decimal: true,
  271. defaultValue: 0,
  272. optional: true,
  273. },
  274. subtaskSort: {
  275. /**
  276. * subtask sort value
  277. */
  278. type: Number,
  279. decimal: true,
  280. defaultValue: -1,
  281. optional: true,
  282. },
  283. type: {
  284. /**
  285. * type of the card
  286. */
  287. type: String,
  288. defaultValue: TYPE_CARD,
  289. // allowedValues: [TYPE_CARD, TYPE_LINKED_CARD, TYPE_LINKED_BOARD, TYPE_TEMPLATE_CARD],
  290. },
  291. linkedId: {
  292. /**
  293. * ID of the linked card
  294. */
  295. type: String,
  296. optional: true,
  297. defaultValue: '',
  298. },
  299. vote: {
  300. /**
  301. * vote object, see below
  302. */
  303. type: Object,
  304. optional: true,
  305. },
  306. 'vote.question': {
  307. type: String,
  308. defaultValue: '',
  309. },
  310. 'vote.positive': {
  311. /**
  312. * list of members (user IDs)
  313. */
  314. type: [String],
  315. optional: true,
  316. defaultValue: [],
  317. },
  318. 'vote.negative': {
  319. /**
  320. * list of members (user IDs)
  321. */
  322. type: [String],
  323. optional: true,
  324. defaultValue: [],
  325. },
  326. 'vote.end': {
  327. type: Date,
  328. optional: true,
  329. defaultValue: null,
  330. },
  331. 'vote.public': {
  332. type: Boolean,
  333. defaultValue: false,
  334. },
  335. 'vote.allowNonBoardMembers': {
  336. type: Boolean,
  337. defaultValue: false,
  338. },
  339. poker: {
  340. /**
  341. * poker object, see below
  342. */
  343. type: Object,
  344. optional: true,
  345. },
  346. 'poker.question': {
  347. type: Boolean,
  348. defaultValue: false,
  349. },
  350. 'poker.one': {
  351. /**
  352. * poker card one
  353. */
  354. type: [String],
  355. optional: true,
  356. defaultValue: [],
  357. },
  358. 'poker.two': {
  359. /**
  360. * poker card two
  361. */
  362. type: [String],
  363. optional: true,
  364. defaultValue: [],
  365. },
  366. 'poker.three': {
  367. /**
  368. * poker card three
  369. */
  370. type: [String],
  371. optional: true,
  372. defaultValue: [],
  373. },
  374. 'poker.five': {
  375. /**
  376. * poker card five
  377. */
  378. type: [String],
  379. optional: true,
  380. defaultValue: [],
  381. },
  382. 'poker.eight': {
  383. /**
  384. * poker card eight
  385. */
  386. type: [String],
  387. optional: true,
  388. defaultValue: [],
  389. },
  390. 'poker.thirteen': {
  391. /**
  392. * poker card thirteen
  393. */
  394. type: [String],
  395. optional: true,
  396. defaultValue: [],
  397. },
  398. 'poker.twenty': {
  399. /**
  400. * poker card twenty
  401. */
  402. type: [String],
  403. optional: true,
  404. defaultValue: [],
  405. },
  406. 'poker.forty': {
  407. /**
  408. * poker card forty
  409. */
  410. type: [String],
  411. optional: true,
  412. defaultValue: [],
  413. },
  414. 'poker.oneHundred': {
  415. /**
  416. * poker card oneHundred
  417. */
  418. type: [String],
  419. optional: true,
  420. defaultValue: [],
  421. },
  422. 'poker.unsure': {
  423. /**
  424. * poker card unsure
  425. */
  426. type: [String],
  427. optional: true,
  428. defaultValue: [],
  429. },
  430. 'poker.end': {
  431. type: Date,
  432. optional: true,
  433. defaultValue: null,
  434. },
  435. 'poker.allowNonBoardMembers': {
  436. type: Boolean,
  437. defaultValue: false,
  438. },
  439. 'poker.estimation': {
  440. /**
  441. * poker estimation value
  442. */
  443. type: Number,
  444. optional: true,
  445. },
  446. targetId_gantt: {
  447. /**
  448. * ID of card which is the child link in gantt view
  449. */
  450. type: [String],
  451. optional: true,
  452. defaultValue: [],
  453. },
  454. linkType_gantt: {
  455. /**
  456. * ID of card which is the parent link in gantt view
  457. */
  458. type: [Number],
  459. decimal: false,
  460. optional: true,
  461. defaultValue: [],
  462. },
  463. linkId_gantt: {
  464. /**
  465. * ID of card which is the parent link in gantt view
  466. */
  467. type: [String],
  468. optional: true,
  469. defaultValue: [],
  470. },
  471. cardNumber: {
  472. /**
  473. * A boardwise sequentially increasing number that is assigned
  474. * to every newly created card
  475. */
  476. type: Number,
  477. decimal: true,
  478. optional: true,
  479. defaultValue: 0,
  480. },
  481. }),
  482. );
  483. Cards.allow({
  484. insert(userId, doc) {
  485. return allowIsBoardMember(userId, Boards.findOne(doc.boardId));
  486. },
  487. update(userId, doc, fields) {
  488. // Allow board members or logged in users if only vote get's changed
  489. return (
  490. allowIsBoardMember(userId, Boards.findOne(doc.boardId)) ||
  491. (_.isEqual(fields, ['vote', 'modifiedAt', 'dateLastActivity']) &&
  492. !!userId)
  493. );
  494. },
  495. remove(userId, doc) {
  496. return allowIsBoardMember(userId, Boards.findOne(doc.boardId));
  497. },
  498. fetch: ['boardId'],
  499. });
  500. Cards.helpers({
  501. // Gantt https://github.com/wekan/wekan/issues/2870#issuecomment-857171127
  502. setGanttTargetId(sourceId, targetId, linkType, linkId){
  503. return Cards.update({ _id: sourceId}, {
  504. $push: {
  505. targetId_gantt: targetId,
  506. linkType_gantt : linkType,
  507. linkId_gantt: linkId
  508. }
  509. });
  510. },
  511. removeGanttTargetId(sourceId, targetId, linkType, linkId){
  512. return Cards.update({ _id: sourceId}, {
  513. $pull: {
  514. targetId_gantt: targetId,
  515. linkType_gantt : linkType,
  516. linkId_gantt: linkId
  517. }
  518. });
  519. },
  520. mapCustomFieldsToBoard(boardId) {
  521. // Map custom fields to new board
  522. return this.customFields.map(cf => {
  523. const oldCf = CustomFields.findOne(cf._id);
  524. const newCf = CustomFields.findOne({
  525. boardIds: boardId,
  526. name: oldCf.name,
  527. type: oldCf.type,
  528. });
  529. if (newCf) {
  530. cf._id = newCf._id;
  531. } else if (!_.contains(oldCf.boardIds, boardId)) {
  532. oldCf.addBoard(boardId);
  533. }
  534. return cf;
  535. });
  536. },
  537. copy(boardId, swimlaneId, listId) {
  538. const oldId = this._id;
  539. const oldCard = Cards.findOne(oldId);
  540. // we must only copy the labels and custom fields if the target board
  541. // differs from the source board
  542. if (this.boardId !== boardId) {
  543. const oldBoard = Boards.findOne(this.boardId);
  544. const oldBoardLabels = oldBoard.labels;
  545. // Get old label names
  546. const oldCardLabels = _.pluck(
  547. _.filter(oldBoardLabels, label => {
  548. return _.contains(this.labelIds, label._id);
  549. }),
  550. 'name',
  551. );
  552. const newBoard = Boards.findOne(boardId);
  553. const newBoardLabels = newBoard.labels;
  554. const newCardLabels = _.pluck(
  555. _.filter(newBoardLabels, label => {
  556. return _.contains(oldCardLabels, label.name);
  557. }),
  558. '_id',
  559. );
  560. // now set the new label ids
  561. delete this.labelIds;
  562. this.labelIds = newCardLabels;
  563. this.customFields = this.mapCustomFieldsToBoard(newBoard._id);
  564. }
  565. delete this._id;
  566. this.boardId = boardId;
  567. this.cardNumber = Boards.findOne(boardId).getNextCardNumber();
  568. this.swimlaneId = swimlaneId;
  569. this.listId = listId;
  570. const _id = Cards.insert(this);
  571. // Copy attachments
  572. oldCard.attachments().forEach(att => {
  573. att.cardId = _id;
  574. delete att._id;
  575. return Attachments.insert(att);
  576. });
  577. // copy checklists
  578. Checklists.find({ cardId: oldId }).forEach(ch => {
  579. ch.copy(_id);
  580. });
  581. // copy subtasks
  582. Cards.find({ parentId: oldId }).forEach(subtask => {
  583. subtask.parentId = _id;
  584. subtask._id = null;
  585. Cards.insert(subtask);
  586. });
  587. // copy card comments
  588. CardComments.find({ cardId: oldId }).forEach(cmt => {
  589. cmt.copy(_id);
  590. });
  591. return _id;
  592. },
  593. link(boardId, swimlaneId, listId) {
  594. // TODO is there a better method to create a deepcopy?
  595. linkCard = JSON.parse(JSON.stringify(this));
  596. // TODO is this how it is meant to be?
  597. linkCard.linkedId = linkCard.linkedId || linkCard._id;
  598. linkCard.boardId = boardId;
  599. linkCard.swimlaneId = swimlaneId;
  600. linkCard.listId = listId;
  601. linkCard.type = 'cardType-linkedCard';
  602. delete linkCard._id;
  603. // TODO shall we copy the labels for a linked card?!
  604. delete linkCard.labelIds;
  605. return Cards.insert(linkCard);
  606. },
  607. list() {
  608. return Lists.findOne(this.listId);
  609. },
  610. swimlane() {
  611. return Swimlanes.findOne(this.swimlaneId);
  612. },
  613. board() {
  614. return Boards.findOne(this.boardId);
  615. },
  616. getList() {
  617. const list = this.list();
  618. if (!list) {
  619. return {
  620. _id: this.listId,
  621. title: 'Undefined List',
  622. archived: false,
  623. colorClass: '',
  624. };
  625. }
  626. return list;
  627. },
  628. getSwimlane() {
  629. const swimlane = this.swimlane();
  630. if (!swimlane) {
  631. return {
  632. _id: this.swimlaneId,
  633. title: 'Undefined Swimlane',
  634. archived: false,
  635. colorClass: '',
  636. };
  637. }
  638. return swimlane;
  639. },
  640. getBoard() {
  641. const board = this.board();
  642. if (!board) {
  643. return {
  644. _id: this.boardId,
  645. title: 'Undefined Board',
  646. archived: false,
  647. colorClass: '',
  648. };
  649. }
  650. return board;
  651. },
  652. labels() {
  653. const boardLabels = this.board().labels;
  654. const cardLabels = _.filter(boardLabels, label => {
  655. return _.contains(this.labelIds, label._id);
  656. });
  657. return cardLabels;
  658. },
  659. hasLabel(labelId) {
  660. return _.contains(this.labelIds, labelId);
  661. },
  662. user() {
  663. return Users.findOne(this.userId);
  664. },
  665. isAssigned(memberId) {
  666. return _.contains(this.getMembers(), memberId);
  667. },
  668. isAssignee(assigneeId) {
  669. return _.contains(this.getAssignees(), assigneeId);
  670. },
  671. activities() {
  672. if (this.isLinkedCard()) {
  673. return Activities.find(
  674. { cardId: this.linkedId },
  675. { sort: { createdAt: -1 } },
  676. );
  677. } else if (this.isLinkedBoard()) {
  678. return Activities.find(
  679. { boardId: this.linkedId },
  680. { sort: { createdAt: -1 } },
  681. );
  682. } else {
  683. return Activities.find({ cardId: this._id }, { sort: { createdAt: -1 } });
  684. }
  685. },
  686. comments() {
  687. if (this.isLinkedCard()) {
  688. return CardComments.find(
  689. { cardId: this.linkedId },
  690. { sort: { createdAt: -1 } },
  691. );
  692. } else {
  693. return CardComments.find(
  694. { cardId: this._id },
  695. { sort: { createdAt: -1 } },
  696. );
  697. }
  698. },
  699. attachments() {
  700. if (this.isLinkedCard()) {
  701. return Attachments.find(
  702. { cardId: this.linkedId },
  703. { sort: { uploadedAt: -1 } },
  704. );
  705. } else {
  706. return Attachments.find(
  707. { cardId: this._id },
  708. { sort: { uploadedAt: -1 } },
  709. );
  710. }
  711. },
  712. cover() {
  713. if (!this.coverId) return false;
  714. const cover = Attachments.findOne(this.coverId);
  715. // if we return a cover before it is fully stored, we will get errors when we try to display it
  716. // todo XXX we could return a default "upload pending" image in the meantime?
  717. return cover && cover.url() && cover;
  718. },
  719. checklists() {
  720. if (this.isLinkedCard()) {
  721. return Checklists.find({ cardId: this.linkedId }, { sort: { sort: 1 } });
  722. } else {
  723. return Checklists.find({ cardId: this._id }, { sort: { sort: 1 } });
  724. }
  725. },
  726. checklistItemCount() {
  727. const checklists = this.checklists().fetch();
  728. return checklists
  729. .map(checklist => {
  730. return checklist.itemCount();
  731. })
  732. .reduce((prev, next) => {
  733. return prev + next;
  734. }, 0);
  735. },
  736. checklistFinishedCount() {
  737. const checklists = this.checklists().fetch();
  738. return checklists
  739. .map(checklist => {
  740. return checklist.finishedCount();
  741. })
  742. .reduce((prev, next) => {
  743. return prev + next;
  744. }, 0);
  745. },
  746. checklistFinished() {
  747. return (
  748. this.hasChecklist() &&
  749. this.checklistItemCount() === this.checklistFinishedCount()
  750. );
  751. },
  752. hasChecklist() {
  753. return this.checklistItemCount() !== 0;
  754. },
  755. subtasks() {
  756. return Cards.find(
  757. {
  758. parentId: this._id,
  759. archived: false,
  760. },
  761. {
  762. sort: {
  763. sort: 1,
  764. },
  765. },
  766. );
  767. },
  768. subtasksFinished() {
  769. return Cards.find({
  770. parentId: this._id,
  771. archived: true,
  772. });
  773. },
  774. allSubtasks() {
  775. return Cards.find({
  776. parentId: this._id,
  777. });
  778. },
  779. subtasksCount() {
  780. const subtasks = this.subtasks();
  781. return subtasks.count();
  782. },
  783. subtasksFinishedCount() {
  784. const subtasksArchived = this.subtasksFinished();
  785. return subtasksArchived.count();
  786. },
  787. allSubtasksCount() {
  788. const allSubtasks = this.allSubtasks();
  789. return allSubtasks.count();
  790. },
  791. allowsSubtasks() {
  792. return this.subtasksCount() !== 0;
  793. },
  794. customFieldIndex(customFieldId) {
  795. return _.pluck(this.customFields, '_id').indexOf(customFieldId);
  796. },
  797. // customFields with definitions
  798. customFieldsWD() {
  799. // get all definitions
  800. const definitions = CustomFields.find({
  801. boardIds: { $in: [this.boardId] },
  802. }).fetch();
  803. if (!definitions) {
  804. return {};
  805. }
  806. // match right definition to each field
  807. if (!this.customFields) return [];
  808. const ret = this.customFields.map(customField => {
  809. const definition = definitions.find(definition => {
  810. return definition._id === customField._id;
  811. });
  812. if (!definition) {
  813. return {};
  814. }
  815. //search for "True Value" which is for DropDowns other then the Value (which is the id)
  816. let trueValue = customField.value;
  817. if (
  818. definition.settings.dropdownItems &&
  819. definition.settings.dropdownItems.length > 0
  820. ) {
  821. for (let i = 0; i < definition.settings.dropdownItems.length; i++) {
  822. if (definition.settings.dropdownItems[i]._id === customField.value) {
  823. trueValue = definition.settings.dropdownItems[i].name;
  824. }
  825. }
  826. }
  827. return {
  828. _id: customField._id,
  829. value: customField.value,
  830. trueValue,
  831. definition,
  832. };
  833. });
  834. // at linked cards custom fields definition is not found
  835. ret.sort(
  836. (a, b) =>
  837. a.definition !== undefined &&
  838. b.definition !== undefined &&
  839. a.definition.name !== undefined &&
  840. b.definition.name !== undefined &&
  841. a.definition.name.localeCompare(b.definition.name),
  842. );
  843. return ret;
  844. },
  845. colorClass() {
  846. if (this.color) return this.color;
  847. return '';
  848. },
  849. absoluteUrl() {
  850. const board = this.board();
  851. return FlowRouter.url('card', {
  852. boardId: board._id,
  853. slug: board.slug,
  854. cardId: this._id,
  855. });
  856. },
  857. originRelativeUrl() {
  858. const board = this.board();
  859. return FlowRouter.path('card', {
  860. boardId: board._id,
  861. slug: board.slug,
  862. cardId: this._id,
  863. });
  864. },
  865. canBeRestored() {
  866. const list = Lists.findOne({
  867. _id: this.listId,
  868. });
  869. if (
  870. !list.getWipLimit('soft') &&
  871. list.getWipLimit('enabled') &&
  872. list.getWipLimit('value') === list.cards().count()
  873. ) {
  874. return false;
  875. }
  876. return true;
  877. },
  878. parentCard() {
  879. if (this.parentId === '') {
  880. return null;
  881. }
  882. return Cards.findOne(this.parentId);
  883. },
  884. parentCardName() {
  885. let result = '';
  886. if (this.parentId !== '') {
  887. const card = Cards.findOne(this.parentId);
  888. if (card) {
  889. result = card.title;
  890. }
  891. }
  892. return result;
  893. },
  894. parentListId() {
  895. const result = [];
  896. let crtParentId = this.parentId;
  897. while (crtParentId !== '') {
  898. const crt = Cards.findOne(crtParentId);
  899. if (crt === null || crt === undefined) {
  900. // maybe it has been deleted
  901. break;
  902. }
  903. if (crtParentId in result) {
  904. // circular reference
  905. break;
  906. }
  907. result.unshift(crtParentId);
  908. crtParentId = crt.parentId;
  909. }
  910. return result;
  911. },
  912. parentList() {
  913. const resultId = [];
  914. const result = [];
  915. let crtParentId = this.parentId;
  916. while (crtParentId !== '') {
  917. const crt = Cards.findOne(crtParentId);
  918. if (crt === null || crt === undefined) {
  919. // maybe it has been deleted
  920. break;
  921. }
  922. if (crtParentId in resultId) {
  923. // circular reference
  924. break;
  925. }
  926. resultId.unshift(crtParentId);
  927. result.unshift(crt);
  928. crtParentId = crt.parentId;
  929. }
  930. return result;
  931. },
  932. parentString(sep) {
  933. return this.parentList()
  934. .map(function(elem) {
  935. return elem.title;
  936. })
  937. .join(sep);
  938. },
  939. isTopLevel() {
  940. return this.parentId === '';
  941. },
  942. isLinkedCard() {
  943. return this.type === 'cardType-linkedCard';
  944. },
  945. isLinkedBoard() {
  946. return this.type === 'cardType-linkedBoard';
  947. },
  948. isLinked() {
  949. return this.isLinkedCard() || this.isLinkedBoard();
  950. },
  951. setDescription(description) {
  952. if (this.isLinkedCard()) {
  953. return Cards.update({ _id: this.linkedId }, { $set: { description } });
  954. } else if (this.isLinkedBoard()) {
  955. return Boards.update({ _id: this.linkedId }, { $set: { description } });
  956. } else {
  957. return Cards.update({ _id: this._id }, { $set: { description } });
  958. }
  959. },
  960. getDescription() {
  961. if (this.isLinkedCard()) {
  962. const card = Cards.findOne({ _id: this.linkedId });
  963. if (card && card.description) return card.description;
  964. else return null;
  965. } else if (this.isLinkedBoard()) {
  966. const board = Boards.findOne({ _id: this.linkedId });
  967. if (board && board.description) return board.description;
  968. else return null;
  969. } else if (this.description) {
  970. return this.description;
  971. } else {
  972. return null;
  973. }
  974. },
  975. getMembers() {
  976. if (this.isLinkedCard()) {
  977. const card = Cards.findOne({ _id: this.linkedId });
  978. if (card === undefined) {
  979. return null;
  980. } else {
  981. return card.members;
  982. }
  983. } else if (this.isLinkedBoard()) {
  984. const board = Boards.findOne({ _id: this.linkedId });
  985. if (board === undefined) {
  986. return null;
  987. } else {
  988. return board.activeMembers().map(member => {
  989. return member.userId;
  990. });
  991. }
  992. } else {
  993. return this.members;
  994. }
  995. },
  996. getAssignees() {
  997. if (this.isLinkedCard()) {
  998. const card = Cards.findOne({ _id: this.linkedId });
  999. if (card === undefined) {
  1000. return null;
  1001. } else {
  1002. return card.assignees;
  1003. }
  1004. } else if (this.isLinkedBoard()) {
  1005. const board = Boards.findOne({ _id: this.linkedId });
  1006. if (board === undefined) {
  1007. return null;
  1008. } else {
  1009. return board.activeMembers().map(assignee => {
  1010. return assignee.userId;
  1011. });
  1012. }
  1013. } else {
  1014. return this.assignees;
  1015. }
  1016. },
  1017. assignMember(memberId) {
  1018. if (this.isLinkedCard()) {
  1019. return Cards.update(
  1020. { _id: this.linkedId },
  1021. { $addToSet: { members: memberId } },
  1022. );
  1023. } else if (this.isLinkedBoard()) {
  1024. const board = Boards.findOne({ _id: this.linkedId });
  1025. return board.addMember(memberId);
  1026. } else {
  1027. return Cards.update(
  1028. { _id: this._id },
  1029. { $addToSet: { members: memberId } },
  1030. );
  1031. }
  1032. },
  1033. assignAssignee(assigneeId) {
  1034. if (this.isLinkedCard()) {
  1035. return Cards.update(
  1036. { _id: this.linkedId },
  1037. { $addToSet: { assignees: assigneeId } },
  1038. );
  1039. } else if (this.isLinkedBoard()) {
  1040. const board = Boards.findOne({ _id: this.linkedId });
  1041. return board.addAssignee(assigneeId);
  1042. } else {
  1043. return Cards.update(
  1044. { _id: this._id },
  1045. { $addToSet: { assignees: assigneeId } },
  1046. );
  1047. }
  1048. },
  1049. unassignMember(memberId) {
  1050. if (this.isLinkedCard()) {
  1051. return Cards.update(
  1052. { _id: this.linkedId },
  1053. { $pull: { members: memberId } },
  1054. );
  1055. } else if (this.isLinkedBoard()) {
  1056. const board = Boards.findOne({ _id: this.linkedId });
  1057. return board.removeMember(memberId);
  1058. } else {
  1059. return Cards.update({ _id: this._id }, { $pull: { members: memberId } });
  1060. }
  1061. },
  1062. unassignAssignee(assigneeId) {
  1063. if (this.isLinkedCard()) {
  1064. return Cards.update(
  1065. { _id: this.linkedId },
  1066. { $pull: { assignees: assigneeId } },
  1067. );
  1068. } else if (this.isLinkedBoard()) {
  1069. const board = Boards.findOne({ _id: this.linkedId });
  1070. return board.removeAssignee(assigneeId);
  1071. } else {
  1072. return Cards.update(
  1073. { _id: this._id },
  1074. { $pull: { assignees: assigneeId } },
  1075. );
  1076. }
  1077. },
  1078. toggleMember(memberId) {
  1079. if (this.getMembers() && this.getMembers().indexOf(memberId) > -1) {
  1080. return this.unassignMember(memberId);
  1081. } else {
  1082. return this.assignMember(memberId);
  1083. }
  1084. },
  1085. toggleAssignee(assigneeId) {
  1086. if (this.getAssignees() && this.getAssignees().indexOf(assigneeId) > -1) {
  1087. return this.unassignAssignee(assigneeId);
  1088. } else {
  1089. return this.assignAssignee(assigneeId);
  1090. }
  1091. },
  1092. getReceived() {
  1093. if (this.isLinkedCard()) {
  1094. const card = Cards.findOne({ _id: this.linkedId });
  1095. if (card === undefined) {
  1096. return null;
  1097. } else {
  1098. return card.receivedAt;
  1099. }
  1100. } else {
  1101. return this.receivedAt;
  1102. }
  1103. },
  1104. setReceived(receivedAt) {
  1105. if (this.isLinkedCard()) {
  1106. return Cards.update({ _id: this.linkedId }, { $set: { receivedAt } });
  1107. } else {
  1108. return Cards.update({ _id: this._id }, { $set: { receivedAt } });
  1109. }
  1110. },
  1111. getStart() {
  1112. if (this.isLinkedCard()) {
  1113. const card = Cards.findOne({ _id: this.linkedId });
  1114. if (card === undefined) {
  1115. return null;
  1116. } else {
  1117. return card.startAt;
  1118. }
  1119. } else if (this.isLinkedBoard()) {
  1120. const board = Boards.findOne({ _id: this.linkedId });
  1121. if (board === undefined) {
  1122. return null;
  1123. } else {
  1124. return board.startAt;
  1125. }
  1126. } else {
  1127. return this.startAt;
  1128. }
  1129. },
  1130. setStart(startAt) {
  1131. if (this.isLinkedCard()) {
  1132. return Cards.update({ _id: this.linkedId }, { $set: { startAt } });
  1133. } else if (this.isLinkedBoard()) {
  1134. return Boards.update({ _id: this.linkedId }, { $set: { startAt } });
  1135. } else {
  1136. return Cards.update({ _id: this._id }, { $set: { startAt } });
  1137. }
  1138. },
  1139. getDue() {
  1140. if (this.isLinkedCard()) {
  1141. const card = Cards.findOne({ _id: this.linkedId });
  1142. if (card === undefined) {
  1143. return null;
  1144. } else {
  1145. return card.dueAt;
  1146. }
  1147. } else if (this.isLinkedBoard()) {
  1148. const board = Boards.findOne({ _id: this.linkedId });
  1149. if (board === undefined) {
  1150. return null;
  1151. } else {
  1152. return board.dueAt;
  1153. }
  1154. } else {
  1155. return this.dueAt;
  1156. }
  1157. },
  1158. setDue(dueAt) {
  1159. if (this.isLinkedCard()) {
  1160. return Cards.update({ _id: this.linkedId }, { $set: { dueAt } });
  1161. } else if (this.isLinkedBoard()) {
  1162. return Boards.update({ _id: this.linkedId }, { $set: { dueAt } });
  1163. } else {
  1164. return Cards.update({ _id: this._id }, { $set: { dueAt } });
  1165. }
  1166. },
  1167. getEnd() {
  1168. if (this.isLinkedCard()) {
  1169. const card = Cards.findOne({ _id: this.linkedId });
  1170. if (card === undefined) {
  1171. return null;
  1172. } else {
  1173. return card.endAt;
  1174. }
  1175. } else if (this.isLinkedBoard()) {
  1176. const board = Boards.findOne({ _id: this.linkedId });
  1177. if (board === undefined) {
  1178. return null;
  1179. } else {
  1180. return board.endAt;
  1181. }
  1182. } else {
  1183. return this.endAt;
  1184. }
  1185. },
  1186. setEnd(endAt) {
  1187. if (this.isLinkedCard()) {
  1188. return Cards.update({ _id: this.linkedId }, { $set: { endAt } });
  1189. } else if (this.isLinkedBoard()) {
  1190. return Boards.update({ _id: this.linkedId }, { $set: { endAt } });
  1191. } else {
  1192. return Cards.update({ _id: this._id }, { $set: { endAt } });
  1193. }
  1194. },
  1195. getIsOvertime() {
  1196. if (this.isLinkedCard()) {
  1197. const card = Cards.findOne({ _id: this.linkedId });
  1198. if (card === undefined) {
  1199. return null;
  1200. } else {
  1201. return card.isOvertime;
  1202. }
  1203. } else if (this.isLinkedBoard()) {
  1204. const board = Boards.findOne({ _id: this.linkedId });
  1205. if (board === undefined) {
  1206. return null;
  1207. } else {
  1208. return board.isOvertime;
  1209. }
  1210. } else {
  1211. return this.isOvertime;
  1212. }
  1213. },
  1214. setIsOvertime(isOvertime) {
  1215. if (this.isLinkedCard()) {
  1216. return Cards.update({ _id: this.linkedId }, { $set: { isOvertime } });
  1217. } else if (this.isLinkedBoard()) {
  1218. return Boards.update({ _id: this.linkedId }, { $set: { isOvertime } });
  1219. } else {
  1220. return Cards.update({ _id: this._id }, { $set: { isOvertime } });
  1221. }
  1222. },
  1223. getSpentTime() {
  1224. if (this.isLinkedCard()) {
  1225. const card = Cards.findOne({ _id: this.linkedId });
  1226. if (card === undefined) {
  1227. return null;
  1228. } else {
  1229. return card.spentTime;
  1230. }
  1231. } else if (this.isLinkedBoard()) {
  1232. const board = Boards.findOne({ _id: this.linkedId });
  1233. if (board === undefined) {
  1234. return null;
  1235. } else {
  1236. return board.spentTime;
  1237. }
  1238. } else {
  1239. return this.spentTime;
  1240. }
  1241. },
  1242. setSpentTime(spentTime) {
  1243. if (this.isLinkedCard()) {
  1244. return Cards.update({ _id: this.linkedId }, { $set: { spentTime } });
  1245. } else if (this.isLinkedBoard()) {
  1246. return Boards.update({ _id: this.linkedId }, { $set: { spentTime } });
  1247. } else {
  1248. return Cards.update({ _id: this._id }, { $set: { spentTime } });
  1249. }
  1250. },
  1251. getVoteQuestion() {
  1252. if (this.isLinkedCard()) {
  1253. const card = Cards.findOne({ _id: this.linkedId });
  1254. if (card === undefined) {
  1255. return null;
  1256. } else if (card && card.vote) {
  1257. return card.vote.question;
  1258. } else {
  1259. return null;
  1260. }
  1261. } else if (this.isLinkedBoard()) {
  1262. const board = Boards.findOne({ _id: this.linkedId });
  1263. if (board === undefined) {
  1264. return null;
  1265. } else if (board && board.vote) {
  1266. return board.vote.question;
  1267. } else {
  1268. return null;
  1269. }
  1270. } else if (this.vote) {
  1271. return this.vote.question;
  1272. } else {
  1273. return null;
  1274. }
  1275. },
  1276. getVotePublic() {
  1277. if (this.isLinkedCard()) {
  1278. const card = Cards.findOne({ _id: this.linkedId });
  1279. if (card === undefined) {
  1280. return null;
  1281. } else if (card && card.vote) {
  1282. return card.vote.public;
  1283. } else {
  1284. return null;
  1285. }
  1286. } else if (this.isLinkedBoard()) {
  1287. const board = Boards.findOne({ _id: this.linkedId });
  1288. if (board === undefined) {
  1289. return null;
  1290. } else if (board && board.vote) {
  1291. return board.vote.public;
  1292. } else {
  1293. return null;
  1294. }
  1295. } else if (this.vote) {
  1296. return this.vote.public;
  1297. } else {
  1298. return null;
  1299. }
  1300. },
  1301. getVoteEnd() {
  1302. if (this.isLinkedCard()) {
  1303. const card = Cards.findOne({ _id: this.linkedId });
  1304. if (card === undefined) {
  1305. return null;
  1306. } else if (card && card.vote) {
  1307. return card.vote.end;
  1308. } else {
  1309. return null;
  1310. }
  1311. } else if (this.isLinkedBoard()) {
  1312. const board = Boards.findOne({ _id: this.linkedId });
  1313. if (board === undefined) {
  1314. return null;
  1315. } else if (board && board.vote) {
  1316. return board.vote.end;
  1317. } else {
  1318. return null;
  1319. }
  1320. } else if (this.vote) {
  1321. return this.vote.end;
  1322. } else {
  1323. return null;
  1324. }
  1325. },
  1326. expiredVote() {
  1327. let end = this.getVoteEnd();
  1328. if (end) {
  1329. end = moment(end);
  1330. return end.isBefore(new Date());
  1331. }
  1332. return false;
  1333. },
  1334. voteMemberPositive() {
  1335. if (this.vote && this.vote.positive)
  1336. return Users.find({ _id: { $in: this.vote.positive } });
  1337. return [];
  1338. },
  1339. voteMemberNegative() {
  1340. if (this.vote && this.vote.negative)
  1341. return Users.find({ _id: { $in: this.vote.negative } });
  1342. return [];
  1343. },
  1344. voteState() {
  1345. const userId = Meteor.userId();
  1346. let state;
  1347. if (this.vote) {
  1348. if (this.vote.positive) {
  1349. state = _.contains(this.vote.positive, userId);
  1350. if (state === true) return true;
  1351. }
  1352. if (this.vote.negative) {
  1353. state = _.contains(this.vote.negative, userId);
  1354. if (state === true) return false;
  1355. }
  1356. }
  1357. return null;
  1358. },
  1359. getPokerQuestion() {
  1360. if (this.isLinkedCard()) {
  1361. const card = Cards.findOne({ _id: this.linkedId });
  1362. if (card === undefined) {
  1363. return null;
  1364. } else if (card && card.poker) {
  1365. return card.poker.question;
  1366. } else {
  1367. return null;
  1368. }
  1369. } else if (this.isLinkedBoard()) {
  1370. const board = Boards.findOne({ _id: this.linkedId });
  1371. if (board === undefined) {
  1372. return null;
  1373. } else if (board && board.poker) {
  1374. return board.poker.question;
  1375. } else {
  1376. return null;
  1377. }
  1378. } else if (this.poker) {
  1379. return this.poker.question;
  1380. } else {
  1381. return null;
  1382. }
  1383. },
  1384. getPokerEstimation() {
  1385. if (this.poker) {
  1386. return this.poker.estimation;
  1387. } else {
  1388. return null;
  1389. }
  1390. },
  1391. getPokerEnd() {
  1392. if (this.isLinkedCard()) {
  1393. const card = Cards.findOne({ _id: this.linkedId });
  1394. if (card === undefined) {
  1395. return null;
  1396. } else if (card && card.poker) {
  1397. return card.poker.end;
  1398. } else {
  1399. return null;
  1400. }
  1401. } else if (this.isLinkedBoard()) {
  1402. const board = Boards.findOne({ _id: this.linkedId });
  1403. if (board === undefined) {
  1404. return null;
  1405. } else if (board && board.poker) {
  1406. return board.poker.end;
  1407. } else {
  1408. return null;
  1409. }
  1410. } else if (this.poker) {
  1411. return this.poker.end;
  1412. } else {
  1413. return null;
  1414. }
  1415. },
  1416. expiredPoker() {
  1417. let end = this.getPokerEnd();
  1418. if (end) {
  1419. end = moment(end);
  1420. return end.isBefore(new Date());
  1421. }
  1422. return false;
  1423. },
  1424. pokerMemberOne() {
  1425. if (this.poker && this.poker.one)
  1426. return Users.find({ _id: { $in: this.poker.one } });
  1427. return [];
  1428. },
  1429. pokerMemberTwo() {
  1430. if (this.poker && this.poker.two)
  1431. return Users.find({ _id: { $in: this.poker.two } });
  1432. return [];
  1433. },
  1434. pokerMemberThree() {
  1435. if (this.poker && this.poker.three)
  1436. return Users.find({ _id: { $in: this.poker.three } });
  1437. return [];
  1438. },
  1439. pokerMemberFive() {
  1440. if (this.poker && this.poker.five)
  1441. return Users.find({ _id: { $in: this.poker.five } });
  1442. return [];
  1443. },
  1444. pokerMemberEight() {
  1445. if (this.poker && this.poker.eight)
  1446. return Users.find({ _id: { $in: this.poker.eight } });
  1447. return [];
  1448. },
  1449. pokerMemberThirteen() {
  1450. if (this.poker && this.poker.thirteen)
  1451. return Users.find({ _id: { $in: this.poker.thirteen } });
  1452. return [];
  1453. },
  1454. pokerMemberTwenty() {
  1455. if (this.poker && this.poker.twenty)
  1456. return Users.find({ _id: { $in: this.poker.twenty } });
  1457. return [];
  1458. },
  1459. pokerMemberForty() {
  1460. if (this.poker && this.poker.forty)
  1461. return Users.find({ _id: { $in: this.poker.forty } });
  1462. return [];
  1463. },
  1464. pokerMemberOneHundred() {
  1465. if (this.poker && this.poker.oneHundred)
  1466. return Users.find({ _id: { $in: this.poker.oneHundred } });
  1467. return [];
  1468. },
  1469. pokerMemberUnsure() {
  1470. if (this.poker && this.poker.unsure)
  1471. return Users.find({ _id: { $in: this.poker.unsure } });
  1472. return [];
  1473. },
  1474. pokerState() {
  1475. const userId = Meteor.userId();
  1476. let state;
  1477. if (this.poker) {
  1478. if (this.poker.one) {
  1479. state = _.contains(this.poker.one, userId);
  1480. if (state === true) {
  1481. return 'one';
  1482. }
  1483. }
  1484. if (this.poker.two) {
  1485. state = _.contains(this.poker.two, userId);
  1486. if (state === true) {
  1487. return 'two';
  1488. }
  1489. }
  1490. if (this.poker.three) {
  1491. state = _.contains(this.poker.three, userId);
  1492. if (state === true) {
  1493. return 'three';
  1494. }
  1495. }
  1496. if (this.poker.five) {
  1497. state = _.contains(this.poker.five, userId);
  1498. if (state === true) {
  1499. return 'five';
  1500. }
  1501. }
  1502. if (this.poker.eight) {
  1503. state = _.contains(this.poker.eight, userId);
  1504. if (state === true) {
  1505. return 'eight';
  1506. }
  1507. }
  1508. if (this.poker.thirteen) {
  1509. state = _.contains(this.poker.thirteen, userId);
  1510. if (state === true) {
  1511. return 'thirteen';
  1512. }
  1513. }
  1514. if (this.poker.twenty) {
  1515. state = _.contains(this.poker.twenty, userId);
  1516. if (state === true) {
  1517. return 'twenty';
  1518. }
  1519. }
  1520. if (this.poker.forty) {
  1521. state = _.contains(this.poker.forty, userId);
  1522. if (state === true) {
  1523. return 'forty';
  1524. }
  1525. }
  1526. if (this.poker.oneHundred) {
  1527. state = _.contains(this.poker.oneHundred, userId);
  1528. if (state === true) {
  1529. return 'oneHundred';
  1530. }
  1531. }
  1532. if (this.poker.unsure) {
  1533. state = _.contains(this.poker.unsure, userId);
  1534. if (state === true) {
  1535. return 'unsure';
  1536. }
  1537. }
  1538. }
  1539. return null;
  1540. },
  1541. getId() {
  1542. if (this.isLinked()) {
  1543. return this.linkedId;
  1544. } else {
  1545. return this._id;
  1546. }
  1547. },
  1548. getTitle() {
  1549. if (this.isLinkedCard()) {
  1550. const card = Cards.findOne({ _id: this.linkedId });
  1551. if (card === undefined) {
  1552. return null;
  1553. } else {
  1554. return card.title;
  1555. }
  1556. } else if (this.isLinkedBoard()) {
  1557. const board = Boards.findOne({ _id: this.linkedId });
  1558. if (board === undefined) {
  1559. return null;
  1560. } else {
  1561. return board.title;
  1562. }
  1563. } else if (this.title === undefined) {
  1564. return null;
  1565. } else {
  1566. return this.title;
  1567. }
  1568. },
  1569. getCardNumber() {
  1570. return this.cardNumber;
  1571. },
  1572. getBoardTitle() {
  1573. if (this.isLinkedCard()) {
  1574. const card = Cards.findOne({ _id: this.linkedId });
  1575. if (card === undefined) {
  1576. return null;
  1577. }
  1578. const board = Boards.findOne({ _id: card.boardId });
  1579. if (board === undefined) {
  1580. return null;
  1581. } else {
  1582. return board.title;
  1583. }
  1584. } else if (this.isLinkedBoard()) {
  1585. const board = Boards.findOne({ _id: this.linkedId });
  1586. if (board === undefined) {
  1587. return null;
  1588. } else {
  1589. return board.title;
  1590. }
  1591. } else {
  1592. const board = Boards.findOne({ _id: this.boardId });
  1593. if (board === undefined) {
  1594. return null;
  1595. } else {
  1596. return board.title;
  1597. }
  1598. }
  1599. },
  1600. setTitle(title) {
  1601. if (this.isLinkedCard()) {
  1602. return Cards.update({ _id: this.linkedId }, { $set: { title } });
  1603. } else if (this.isLinkedBoard()) {
  1604. return Boards.update({ _id: this.linkedId }, { $set: { title } });
  1605. } else {
  1606. return Cards.update({ _id: this._id }, { $set: { title } });
  1607. }
  1608. },
  1609. getArchived() {
  1610. if (this.isLinkedCard()) {
  1611. const card = Cards.findOne({ _id: this.linkedId });
  1612. if (card === undefined) {
  1613. return null;
  1614. } else {
  1615. return card.archived;
  1616. }
  1617. } else if (this.isLinkedBoard()) {
  1618. const board = Boards.findOne({ _id: this.linkedId });
  1619. if (board === undefined) {
  1620. return null;
  1621. } else {
  1622. return board.archived;
  1623. }
  1624. } else {
  1625. return this.archived;
  1626. }
  1627. },
  1628. setRequestedBy(requestedBy) {
  1629. if (this.isLinkedCard()) {
  1630. return Cards.update({ _id: this.linkedId }, { $set: { requestedBy } });
  1631. } else {
  1632. return Cards.update({ _id: this._id }, { $set: { requestedBy } });
  1633. }
  1634. },
  1635. getRequestedBy() {
  1636. if (this.isLinkedCard()) {
  1637. const card = Cards.findOne({ _id: this.linkedId });
  1638. if (card === undefined) {
  1639. return null;
  1640. } else {
  1641. return card.requestedBy;
  1642. }
  1643. } else {
  1644. return this.requestedBy;
  1645. }
  1646. },
  1647. setAssignedBy(assignedBy) {
  1648. if (this.isLinkedCard()) {
  1649. return Cards.update({ _id: this.linkedId }, { $set: { assignedBy } });
  1650. } else {
  1651. return Cards.update({ _id: this._id }, { $set: { assignedBy } });
  1652. }
  1653. },
  1654. getAssignedBy() {
  1655. if (this.isLinkedCard()) {
  1656. const card = Cards.findOne({ _id: this.linkedId });
  1657. if (card === undefined) {
  1658. return null;
  1659. } else {
  1660. return card.assignedBy;
  1661. }
  1662. } else {
  1663. return this.assignedBy;
  1664. }
  1665. },
  1666. isTemplateCard() {
  1667. return this.type === 'template-card';
  1668. },
  1669. votePublic() {
  1670. if (this.vote) return this.vote.public;
  1671. return null;
  1672. },
  1673. voteAllowNonBoardMembers() {
  1674. if (this.vote) return this.vote.allowNonBoardMembers;
  1675. return null;
  1676. },
  1677. voteCountNegative() {
  1678. if (this.vote && this.vote.negative) return this.vote.negative.length;
  1679. return null;
  1680. },
  1681. voteCountPositive() {
  1682. if (this.vote && this.vote.positive) return this.vote.positive.length;
  1683. return null;
  1684. },
  1685. voteCount() {
  1686. return this.voteCountPositive() + this.voteCountNegative();
  1687. },
  1688. pokerAllowNonBoardMembers() {
  1689. if (this.poker) return this.poker.allowNonBoardMembers;
  1690. return null;
  1691. },
  1692. pokerCountOne() {
  1693. if (this.poker && this.poker.one) return this.poker.one.length;
  1694. return null;
  1695. },
  1696. pokerCountTwo() {
  1697. if (this.poker && this.poker.two) return this.poker.two.length;
  1698. return null;
  1699. },
  1700. pokerCountThree() {
  1701. if (this.poker && this.poker.three) return this.poker.three.length;
  1702. return null;
  1703. },
  1704. pokerCountFive() {
  1705. if (this.poker && this.poker.five) return this.poker.five.length;
  1706. return null;
  1707. },
  1708. pokerCountEight() {
  1709. if (this.poker && this.poker.eight) return this.poker.eight.length;
  1710. return null;
  1711. },
  1712. pokerCountThirteen() {
  1713. if (this.poker && this.poker.thirteen) return this.poker.thirteen.length;
  1714. return null;
  1715. },
  1716. pokerCountTwenty() {
  1717. if (this.poker && this.poker.twenty) return this.poker.twenty.length;
  1718. return null;
  1719. },
  1720. pokerCountForty() {
  1721. if (this.poker && this.poker.forty) return this.poker.forty.length;
  1722. return null;
  1723. },
  1724. pokerCountOneHundred() {
  1725. if (this.poker && this.poker.oneHundred) return this.poker.oneHundred.length;
  1726. return null;
  1727. },
  1728. pokerCountUnsure() {
  1729. if (this.poker && this.poker.unsure) return this.poker.unsure.length;
  1730. return null;
  1731. },
  1732. pokerCount() {
  1733. return (
  1734. this.pokerCountOne() +
  1735. this.pokerCountTwo() +
  1736. this.pokerCountThree() +
  1737. this.pokerCountFive() +
  1738. this.pokerCountEight() +
  1739. this.pokerCountThirteen() +
  1740. this.pokerCountTwenty() +
  1741. this.pokerCountForty() +
  1742. this.pokerCountOneHundred() +
  1743. this.pokerCountUnsure()
  1744. );
  1745. },
  1746. pokerWinner() {
  1747. const pokerListMaps = [];
  1748. let pokerWinnersListMap = [];
  1749. if (this.expiredPoker()) {
  1750. const one = { count: this.pokerCountOne(), pokerCard: 1 };
  1751. const two = { count: this.pokerCountTwo(), pokerCard: 2 };
  1752. const three = { count: this.pokerCountThree(), pokerCard: 3 };
  1753. const five = { count: this.pokerCountFive(), pokerCard: 5 };
  1754. const eight = { count: this.pokerCountEight(), pokerCard: 8 };
  1755. const thirteen = { count: this.pokerCountThirteen(), pokerCard: 13 };
  1756. const twenty = { count: this.pokerCountTwenty(), pokerCard: 20 };
  1757. const forty = { count: this.pokerCountForty(), pokerCard: 40 };
  1758. const oneHundred = { count: this.pokerCountOneHundred(), pokerCard: 100 };
  1759. const unsure = { count: this.pokerCountUnsure(), pokerCard: 'Unsure' };
  1760. pokerListMaps.push(one);
  1761. pokerListMaps.push(two);
  1762. pokerListMaps.push(three);
  1763. pokerListMaps.push(five);
  1764. pokerListMaps.push(eight);
  1765. pokerListMaps.push(thirteen);
  1766. pokerListMaps.push(twenty);
  1767. pokerListMaps.push(forty);
  1768. pokerListMaps.push(oneHundred);
  1769. pokerListMaps.push(unsure);
  1770. pokerListMaps.sort(function(a, b) {
  1771. return b.count - a.count;
  1772. });
  1773. const max = pokerListMaps[0].count;
  1774. pokerWinnersListMap = pokerListMaps.filter(task => task.count >= max);
  1775. pokerWinnersListMap.sort(function(a, b) {
  1776. return b.pokerCard - a.pokerCard;
  1777. });
  1778. }
  1779. return pokerWinnersListMap[0].pokerCard;
  1780. },
  1781. });
  1782. Cards.mutations({
  1783. applyToChildren(funct) {
  1784. Cards.find({
  1785. parentId: this._id,
  1786. }).forEach(card => {
  1787. funct(card);
  1788. });
  1789. },
  1790. archive() {
  1791. this.applyToChildren(card => {
  1792. return card.archive();
  1793. });
  1794. return {
  1795. $set: {
  1796. archived: true,
  1797. archivedAt: new Date(),
  1798. },
  1799. };
  1800. },
  1801. restore() {
  1802. this.applyToChildren(card => {
  1803. return card.restore();
  1804. });
  1805. return {
  1806. $set: {
  1807. archived: false,
  1808. },
  1809. };
  1810. },
  1811. moveToEndOfList({ listId } = {}) {
  1812. let swimlaneId = this.swimlaneId;
  1813. const boardId = this.boardId;
  1814. let sortIndex = 0;
  1815. // This should never happen, but there was a bug that was fixed in commit
  1816. // ea0239538a68e225c867411a4f3e0d27c158383.
  1817. if (!swimlaneId) {
  1818. const board = Boards.findOne(boardId);
  1819. swimlaneId = board.getDefaultSwimline()._id;
  1820. }
  1821. // Move the minicard to the end of the target list
  1822. let parentElementDom = $(`#swimlane-${this.swimlaneId}`).get(0);
  1823. if (!parentElementDom) parentElementDom = $(':root');
  1824. const lastCardDom = $(parentElementDom)
  1825. .find(`#js-list-${listId} .js-minicard:last`)
  1826. .get(0);
  1827. if (lastCardDom) sortIndex = Utils.calculateIndex(lastCardDom, null).base;
  1828. return this.moveOptionalArgs({
  1829. boardId,
  1830. swimlaneId,
  1831. listId,
  1832. sort: sortIndex,
  1833. });
  1834. },
  1835. moveOptionalArgs({ boardId, swimlaneId, listId, sort } = {}) {
  1836. boardId = boardId || this.boardId;
  1837. swimlaneId = swimlaneId || this.swimlaneId;
  1838. // This should never happen, but there was a bug that was fixed in commit
  1839. // ea0239538a68e225c867411a4f3e0d27c158383.
  1840. if (!swimlaneId) {
  1841. const board = Boards.findOne(boardId);
  1842. swimlaneId = board.getDefaultSwimline()._id;
  1843. }
  1844. listId = listId || this.listId;
  1845. if (sort === undefined || sort === null) sort = this.sort;
  1846. return this.move(boardId, swimlaneId, listId, sort);
  1847. },
  1848. move(boardId, swimlaneId, listId, sort = null) {
  1849. const mutatedFields = {
  1850. boardId,
  1851. swimlaneId,
  1852. listId,
  1853. };
  1854. if (sort !== null) {
  1855. mutatedFields.sort = sort;
  1856. }
  1857. // we must only copy the labels and custom fields if the target board
  1858. // differs from the source board
  1859. if (this.boardId !== boardId) {
  1860. // Get label names
  1861. const oldBoard = Boards.findOne(this.boardId);
  1862. const oldBoardLabels = oldBoard.labels;
  1863. const oldCardLabels = _.pluck(
  1864. _.filter(oldBoardLabels, label => {
  1865. return _.contains(this.labelIds, label._id);
  1866. }),
  1867. 'name',
  1868. );
  1869. const newBoard = Boards.findOne(boardId);
  1870. const newBoardLabels = newBoard.labels;
  1871. const newCardLabelIds = _.pluck(
  1872. _.filter(newBoardLabels, label => {
  1873. return label.name && _.contains(oldCardLabels, label.name);
  1874. }),
  1875. '_id',
  1876. );
  1877. // assign the new card number from the target board
  1878. const newCardNumber = newBoard.getNextCardNumber();
  1879. Object.assign(mutatedFields, {
  1880. labelIds: newCardLabelIds,
  1881. cardNumber: newCardNumber
  1882. });
  1883. mutatedFields.customFields = this.mapCustomFieldsToBoard(newBoard._id);
  1884. }
  1885. Cards.update(this._id, {
  1886. $set: mutatedFields,
  1887. });
  1888. },
  1889. addLabel(labelId) {
  1890. return {
  1891. $addToSet: {
  1892. labelIds: labelId,
  1893. },
  1894. };
  1895. },
  1896. removeLabel(labelId) {
  1897. return {
  1898. $pull: {
  1899. labelIds: labelId,
  1900. },
  1901. };
  1902. },
  1903. toggleLabel(labelId) {
  1904. if (this.labelIds && this.labelIds.indexOf(labelId) > -1) {
  1905. return this.removeLabel(labelId);
  1906. } else {
  1907. return this.addLabel(labelId);
  1908. }
  1909. },
  1910. setColor(newColor) {
  1911. if (newColor === 'white') {
  1912. newColor = null;
  1913. }
  1914. return {
  1915. $set: {
  1916. color: newColor,
  1917. },
  1918. };
  1919. },
  1920. assignMember(memberId) {
  1921. return {
  1922. $addToSet: {
  1923. members: memberId,
  1924. },
  1925. };
  1926. },
  1927. assignAssignee(assigneeId) {
  1928. // If there is not any assignee, allow one assignee, not more.
  1929. /*
  1930. if (this.getAssignees().length === 0) {
  1931. return {
  1932. $addToSet: {
  1933. assignees: assigneeId,
  1934. },
  1935. };
  1936. */
  1937. // Allow more that one assignee:
  1938. // https://github.com/wekan/wekan/issues/3302
  1939. return {
  1940. $addToSet: {
  1941. assignees: assigneeId,
  1942. },
  1943. };
  1944. //} else {
  1945. // return false,
  1946. //}
  1947. },
  1948. unassignMember(memberId) {
  1949. return {
  1950. $pull: {
  1951. members: memberId,
  1952. },
  1953. };
  1954. },
  1955. unassignAssignee(assigneeId) {
  1956. return {
  1957. $pull: {
  1958. assignees: assigneeId,
  1959. },
  1960. };
  1961. },
  1962. toggleMember(memberId) {
  1963. if (this.members && this.members.indexOf(memberId) > -1) {
  1964. return this.unassignMember(memberId);
  1965. } else {
  1966. return this.assignMember(memberId);
  1967. }
  1968. },
  1969. toggleAssignee(assigneeId) {
  1970. if (this.assignees && this.assignees.indexOf(assigneeId) > -1) {
  1971. return this.unassignAssignee(assigneeId);
  1972. } else {
  1973. return this.assignAssignee(assigneeId);
  1974. }
  1975. },
  1976. assignCustomField(customFieldId) {
  1977. return {
  1978. $addToSet: {
  1979. customFields: {
  1980. _id: customFieldId,
  1981. value: null,
  1982. },
  1983. },
  1984. };
  1985. },
  1986. unassignCustomField(customFieldId) {
  1987. return {
  1988. $pull: {
  1989. customFields: {
  1990. _id: customFieldId,
  1991. },
  1992. },
  1993. };
  1994. },
  1995. toggleCustomField(customFieldId) {
  1996. if (this.customFields && this.customFieldIndex(customFieldId) > -1) {
  1997. return this.unassignCustomField(customFieldId);
  1998. } else {
  1999. return this.assignCustomField(customFieldId);
  2000. }
  2001. },
  2002. setCustomField(customFieldId, value) {
  2003. // todo
  2004. const index = this.customFieldIndex(customFieldId);
  2005. if (index > -1) {
  2006. const update = {
  2007. $set: {},
  2008. };
  2009. update.$set[`customFields.${index}.value`] = value;
  2010. return update;
  2011. }
  2012. // TODO
  2013. // Ignatz 18.05.2018: Return null to silence ESLint. No Idea if that is correct
  2014. return null;
  2015. },
  2016. setCover(coverId) {
  2017. return {
  2018. $set: {
  2019. coverId,
  2020. },
  2021. };
  2022. },
  2023. unsetCover() {
  2024. return {
  2025. $unset: {
  2026. coverId: '',
  2027. },
  2028. };
  2029. },
  2030. setReceived(receivedAt) {
  2031. return {
  2032. $set: {
  2033. receivedAt,
  2034. },
  2035. };
  2036. },
  2037. unsetReceived() {
  2038. return {
  2039. $unset: {
  2040. receivedAt: '',
  2041. },
  2042. };
  2043. },
  2044. setStart(startAt) {
  2045. return {
  2046. $set: {
  2047. startAt,
  2048. },
  2049. };
  2050. },
  2051. unsetStart() {
  2052. return {
  2053. $unset: {
  2054. startAt: '',
  2055. },
  2056. };
  2057. },
  2058. setDue(dueAt) {
  2059. return {
  2060. $set: {
  2061. dueAt,
  2062. },
  2063. };
  2064. },
  2065. unsetDue() {
  2066. return {
  2067. $unset: {
  2068. dueAt: '',
  2069. },
  2070. };
  2071. },
  2072. setEnd(endAt) {
  2073. return {
  2074. $set: {
  2075. endAt,
  2076. },
  2077. };
  2078. },
  2079. unsetEnd() {
  2080. return {
  2081. $unset: {
  2082. endAt: '',
  2083. },
  2084. };
  2085. },
  2086. setOvertime(isOvertime) {
  2087. return {
  2088. $set: {
  2089. isOvertime,
  2090. },
  2091. };
  2092. },
  2093. setSpentTime(spentTime) {
  2094. return {
  2095. $set: {
  2096. spentTime,
  2097. },
  2098. };
  2099. },
  2100. unsetSpentTime() {
  2101. return {
  2102. $unset: {
  2103. spentTime: '',
  2104. isOvertime: false,
  2105. },
  2106. };
  2107. },
  2108. setParentId(parentId) {
  2109. return {
  2110. $set: {
  2111. parentId,
  2112. },
  2113. };
  2114. },
  2115. setVoteQuestion(question, publicVote, allowNonBoardMembers) {
  2116. return {
  2117. $set: {
  2118. vote: {
  2119. question,
  2120. public: publicVote,
  2121. allowNonBoardMembers,
  2122. positive: [],
  2123. negative: [],
  2124. },
  2125. },
  2126. };
  2127. },
  2128. unsetVote() {
  2129. return {
  2130. $unset: {
  2131. vote: '',
  2132. },
  2133. };
  2134. },
  2135. setVoteEnd(end) {
  2136. return {
  2137. $set: { 'vote.end': end },
  2138. };
  2139. },
  2140. unsetVoteEnd() {
  2141. return {
  2142. $unset: { 'vote.end': '' },
  2143. };
  2144. },
  2145. setVote(userId, forIt) {
  2146. switch (forIt) {
  2147. case true:
  2148. // vote for it
  2149. return {
  2150. $pull: {
  2151. 'vote.negative': userId,
  2152. },
  2153. $addToSet: {
  2154. 'vote.positive': userId,
  2155. },
  2156. };
  2157. case false:
  2158. // vote against
  2159. return {
  2160. $pull: {
  2161. 'vote.positive': userId,
  2162. },
  2163. $addToSet: {
  2164. 'vote.negative': userId,
  2165. },
  2166. };
  2167. default:
  2168. // Remove votes
  2169. return {
  2170. $pull: {
  2171. 'vote.positive': userId,
  2172. 'vote.negative': userId,
  2173. },
  2174. };
  2175. }
  2176. },
  2177. setPokerQuestion(question, allowNonBoardMembers) {
  2178. return {
  2179. $set: {
  2180. poker: {
  2181. question,
  2182. allowNonBoardMembers,
  2183. one: [],
  2184. two: [],
  2185. three: [],
  2186. five: [],
  2187. eight: [],
  2188. thirteen: [],
  2189. twenty: [],
  2190. forty: [],
  2191. oneHundred: [],
  2192. unsure: [],
  2193. },
  2194. },
  2195. };
  2196. },
  2197. setPokerEstimation(estimation) {
  2198. return {
  2199. $set: { 'poker.estimation': estimation },
  2200. };
  2201. },
  2202. unsetPokerEstimation() {
  2203. return {
  2204. $unset: { 'poker.estimation': '' },
  2205. };
  2206. },
  2207. unsetPoker() {
  2208. return {
  2209. $unset: {
  2210. poker: '',
  2211. },
  2212. };
  2213. },
  2214. setPokerEnd(end) {
  2215. return {
  2216. $set: { 'poker.end': end },
  2217. };
  2218. },
  2219. unsetPokerEnd() {
  2220. return {
  2221. $unset: { 'poker.end': '' },
  2222. };
  2223. },
  2224. setPoker(userId, state) {
  2225. switch (state) {
  2226. case 'one':
  2227. // poker one
  2228. return {
  2229. $pull: {
  2230. 'poker.two': userId,
  2231. 'poker.three': userId,
  2232. 'poker.five': userId,
  2233. 'poker.eight': userId,
  2234. 'poker.thirteen': userId,
  2235. 'poker.twenty': userId,
  2236. 'poker.forty': userId,
  2237. 'poker.oneHundred': userId,
  2238. 'poker.unsure': userId,
  2239. },
  2240. $addToSet: {
  2241. 'poker.one': userId,
  2242. },
  2243. };
  2244. case 'two':
  2245. // poker two
  2246. return {
  2247. $pull: {
  2248. 'poker.one': userId,
  2249. 'poker.three': userId,
  2250. 'poker.five': userId,
  2251. 'poker.eight': userId,
  2252. 'poker.thirteen': userId,
  2253. 'poker.twenty': userId,
  2254. 'poker.forty': userId,
  2255. 'poker.oneHundred': userId,
  2256. 'poker.unsure': userId,
  2257. },
  2258. $addToSet: {
  2259. 'poker.two': userId,
  2260. },
  2261. };
  2262. case 'three':
  2263. // poker three
  2264. return {
  2265. $pull: {
  2266. 'poker.one': userId,
  2267. 'poker.two': userId,
  2268. 'poker.five': userId,
  2269. 'poker.eight': userId,
  2270. 'poker.thirteen': userId,
  2271. 'poker.twenty': userId,
  2272. 'poker.forty': userId,
  2273. 'poker.oneHundred': userId,
  2274. 'poker.unsure': userId,
  2275. },
  2276. $addToSet: {
  2277. 'poker.three': userId,
  2278. },
  2279. };
  2280. case 'five':
  2281. // poker five
  2282. return {
  2283. $pull: {
  2284. 'poker.one': userId,
  2285. 'poker.two': userId,
  2286. 'poker.three': userId,
  2287. 'poker.eight': userId,
  2288. 'poker.thirteen': userId,
  2289. 'poker.twenty': userId,
  2290. 'poker.forty': userId,
  2291. 'poker.oneHundred': userId,
  2292. 'poker.unsure': userId,
  2293. },
  2294. $addToSet: {
  2295. 'poker.five': userId,
  2296. },
  2297. };
  2298. case 'eight':
  2299. // poker eight
  2300. return {
  2301. $pull: {
  2302. 'poker.one': userId,
  2303. 'poker.two': userId,
  2304. 'poker.three': userId,
  2305. 'poker.five': userId,
  2306. 'poker.thirteen': userId,
  2307. 'poker.twenty': userId,
  2308. 'poker.forty': userId,
  2309. 'poker.oneHundred': userId,
  2310. 'poker.unsure': userId,
  2311. },
  2312. $addToSet: {
  2313. 'poker.eight': userId,
  2314. },
  2315. };
  2316. case 'thirteen':
  2317. // poker thirteen
  2318. return {
  2319. $pull: {
  2320. 'poker.one': userId,
  2321. 'poker.two': userId,
  2322. 'poker.three': userId,
  2323. 'poker.five': userId,
  2324. 'poker.eight': userId,
  2325. 'poker.twenty': userId,
  2326. 'poker.forty': userId,
  2327. 'poker.oneHundred': userId,
  2328. 'poker.unsure': userId,
  2329. },
  2330. $addToSet: {
  2331. 'poker.thirteen': userId,
  2332. },
  2333. };
  2334. case 'twenty':
  2335. // poker twenty
  2336. return {
  2337. $pull: {
  2338. 'poker.one': userId,
  2339. 'poker.two': userId,
  2340. 'poker.three': userId,
  2341. 'poker.five': userId,
  2342. 'poker.eight': userId,
  2343. 'poker.thirteen': userId,
  2344. 'poker.forty': userId,
  2345. 'poker.oneHundred': userId,
  2346. 'poker.unsure': userId,
  2347. },
  2348. $addToSet: {
  2349. 'poker.twenty': userId,
  2350. },
  2351. };
  2352. case 'forty':
  2353. // poker forty
  2354. return {
  2355. $pull: {
  2356. 'poker.one': userId,
  2357. 'poker.two': userId,
  2358. 'poker.three': userId,
  2359. 'poker.five': userId,
  2360. 'poker.eight': userId,
  2361. 'poker.thirteen': userId,
  2362. 'poker.twenty': userId,
  2363. 'poker.oneHundred': userId,
  2364. 'poker.unsure': userId,
  2365. },
  2366. $addToSet: {
  2367. 'poker.forty': userId,
  2368. },
  2369. };
  2370. case 'oneHundred':
  2371. // poker one hundred
  2372. return {
  2373. $pull: {
  2374. 'poker.one': userId,
  2375. 'poker.two': userId,
  2376. 'poker.three': userId,
  2377. 'poker.five': userId,
  2378. 'poker.eight': userId,
  2379. 'poker.thirteen': userId,
  2380. 'poker.twenty': userId,
  2381. 'poker.forty': userId,
  2382. 'poker.unsure': userId,
  2383. },
  2384. $addToSet: {
  2385. 'poker.oneHundred': userId,
  2386. },
  2387. };
  2388. case 'unsure':
  2389. // poker unsure
  2390. return {
  2391. $pull: {
  2392. 'poker.one': userId,
  2393. 'poker.two': userId,
  2394. 'poker.three': userId,
  2395. 'poker.five': userId,
  2396. 'poker.eight': userId,
  2397. 'poker.thirteen': userId,
  2398. 'poker.twenty': userId,
  2399. 'poker.forty': userId,
  2400. 'poker.oneHundred': userId,
  2401. },
  2402. $addToSet: {
  2403. 'poker.unsure': userId,
  2404. },
  2405. };
  2406. default:
  2407. // Remove pokers
  2408. return {
  2409. $pull: {
  2410. 'poker.one': userId,
  2411. 'poker.two': userId,
  2412. 'poker.three': userId,
  2413. 'poker.five': userId,
  2414. 'poker.eight': userId,
  2415. 'poker.thirteen': userId,
  2416. 'poker.twenty': userId,
  2417. 'poker.forty': userId,
  2418. 'poker.oneHundred': userId,
  2419. 'poker.unsure': userId,
  2420. },
  2421. };
  2422. }
  2423. },
  2424. replayPoker() {
  2425. return {
  2426. $set: {
  2427. 'poker.one': [],
  2428. 'poker.two': [],
  2429. 'poker.three': [],
  2430. 'poker.five': [],
  2431. 'poker.eight': [],
  2432. 'poker.thirteen': [],
  2433. 'poker.twelve': [],
  2434. 'poker.forty': [],
  2435. 'poker.oneHundred': [],
  2436. 'poker.unsure': [],
  2437. },
  2438. };
  2439. },
  2440. });
  2441. //FUNCTIONS FOR creation of Activities
  2442. function updateActivities(doc, fieldNames, modifier) {
  2443. if (_.contains(fieldNames, 'labelIds') && _.contains(fieldNames, 'boardId')) {
  2444. Activities.find({
  2445. activityType: 'addedLabel',
  2446. cardId: doc._id,
  2447. }).forEach(a => {
  2448. const lidx = doc.labelIds.indexOf(a.labelId);
  2449. if (lidx !== -1 && modifier.$set.labelIds.length > lidx) {
  2450. Activities.update(a._id, {
  2451. $set: {
  2452. labelId: modifier.$set.labelIds[doc.labelIds.indexOf(a.labelId)],
  2453. boardId: modifier.$set.boardId,
  2454. },
  2455. });
  2456. } else {
  2457. Activities.remove(a._id);
  2458. }
  2459. });
  2460. } else if (_.contains(fieldNames, 'boardId')) {
  2461. Activities.remove({
  2462. activityType: 'addedLabel',
  2463. cardId: doc._id,
  2464. });
  2465. }
  2466. }
  2467. function cardMove(
  2468. userId,
  2469. doc,
  2470. fieldNames,
  2471. oldListId,
  2472. oldSwimlaneId,
  2473. oldBoardId,
  2474. ) {
  2475. if (_.contains(fieldNames, 'boardId') && doc.boardId !== oldBoardId) {
  2476. Activities.insert({
  2477. userId,
  2478. activityType: 'moveCardBoard',
  2479. boardName: Boards.findOne(doc.boardId).title,
  2480. boardId: doc.boardId,
  2481. oldBoardId,
  2482. oldBoardName: Boards.findOne(oldBoardId).title,
  2483. cardId: doc._id,
  2484. swimlaneName: Swimlanes.findOne(doc.swimlaneId).title,
  2485. swimlaneId: doc.swimlaneId,
  2486. oldSwimlaneId,
  2487. });
  2488. } else if (
  2489. (_.contains(fieldNames, 'listId') && doc.listId !== oldListId) ||
  2490. (_.contains(fieldNames, 'swimlaneId') && doc.swimlaneId !== oldSwimlaneId)
  2491. ) {
  2492. Activities.insert({
  2493. userId,
  2494. oldListId,
  2495. activityType: 'moveCard',
  2496. listName: Lists.findOne(doc.listId).title,
  2497. listId: doc.listId,
  2498. boardId: doc.boardId,
  2499. cardId: doc._id,
  2500. cardTitle: doc.title,
  2501. swimlaneName: Swimlanes.findOne(doc.swimlaneId).title,
  2502. swimlaneId: doc.swimlaneId,
  2503. oldSwimlaneId,
  2504. });
  2505. }
  2506. }
  2507. function cardState(userId, doc, fieldNames) {
  2508. if (_.contains(fieldNames, 'archived')) {
  2509. if (doc.archived) {
  2510. Activities.insert({
  2511. userId,
  2512. activityType: 'archivedCard',
  2513. listName: Lists.findOne(doc.listId).title,
  2514. boardId: doc.boardId,
  2515. listId: doc.listId,
  2516. cardId: doc._id,
  2517. swimlaneId: doc.swimlaneId,
  2518. });
  2519. } else {
  2520. Activities.insert({
  2521. userId,
  2522. activityType: 'restoredCard',
  2523. boardId: doc.boardId,
  2524. listName: Lists.findOne(doc.listId).title,
  2525. listId: doc.listId,
  2526. cardId: doc._id,
  2527. swimlaneId: doc.swimlaneId,
  2528. });
  2529. }
  2530. }
  2531. }
  2532. function cardMembers(userId, doc, fieldNames, modifier) {
  2533. if (!_.contains(fieldNames, 'members')) return;
  2534. let memberId;
  2535. // Say hello to the new member
  2536. if (modifier.$addToSet && modifier.$addToSet.members) {
  2537. memberId = modifier.$addToSet.members;
  2538. const username = Users.findOne(memberId).username;
  2539. if (!_.contains(doc.members, memberId)) {
  2540. Activities.insert({
  2541. userId,
  2542. username,
  2543. activityType: 'joinMember',
  2544. boardId: doc.boardId,
  2545. cardId: doc._id,
  2546. memberId,
  2547. listId: doc.listId,
  2548. swimlaneId: doc.swimlaneId,
  2549. });
  2550. }
  2551. }
  2552. // Say goodbye to the former member
  2553. if (modifier.$pull && modifier.$pull.members) {
  2554. memberId = modifier.$pull.members;
  2555. const username = Users.findOne(memberId).username;
  2556. // Check that the former member is member of the card
  2557. if (_.contains(doc.members, memberId)) {
  2558. Activities.insert({
  2559. userId,
  2560. username,
  2561. activityType: 'unjoinMember',
  2562. boardId: doc.boardId,
  2563. cardId: doc._id,
  2564. memberId,
  2565. listId: doc.listId,
  2566. swimlaneId: doc.swimlaneId,
  2567. });
  2568. }
  2569. }
  2570. }
  2571. function cardAssignees(userId, doc, fieldNames, modifier) {
  2572. if (!_.contains(fieldNames, 'assignees')) return;
  2573. let assigneeId;
  2574. // Say hello to the new assignee
  2575. if (modifier.$addToSet && modifier.$addToSet.assignees) {
  2576. assigneeId = modifier.$addToSet.assignees;
  2577. const username = Users.findOne(assigneeId).username;
  2578. if (!_.contains(doc.assignees, assigneeId)) {
  2579. Activities.insert({
  2580. userId,
  2581. username,
  2582. activityType: 'joinAssignee',
  2583. boardId: doc.boardId,
  2584. cardId: doc._id,
  2585. assigneeId,
  2586. listId: doc.listId,
  2587. swimlaneId: doc.swimlaneId,
  2588. });
  2589. }
  2590. }
  2591. // Say goodbye to the former assignee
  2592. if (modifier.$pull && modifier.$pull.assignees) {
  2593. assigneeId = modifier.$pull.assignees;
  2594. const username = Users.findOne(assigneeId).username;
  2595. // Check that the former assignee is assignee of the card
  2596. if (_.contains(doc.assignees, assigneeId)) {
  2597. Activities.insert({
  2598. userId,
  2599. username,
  2600. activityType: 'unjoinAssignee',
  2601. boardId: doc.boardId,
  2602. cardId: doc._id,
  2603. assigneeId,
  2604. listId: doc.listId,
  2605. swimlaneId: doc.swimlaneId,
  2606. });
  2607. }
  2608. }
  2609. }
  2610. function cardLabels(userId, doc, fieldNames, modifier) {
  2611. if (!_.contains(fieldNames, 'labelIds')) return;
  2612. let labelId;
  2613. // Say hello to the new label
  2614. if (modifier.$addToSet && modifier.$addToSet.labelIds) {
  2615. labelId = modifier.$addToSet.labelIds;
  2616. if (!_.contains(doc.labelIds, labelId)) {
  2617. const act = {
  2618. userId,
  2619. labelId,
  2620. activityType: 'addedLabel',
  2621. boardId: doc.boardId,
  2622. cardId: doc._id,
  2623. listId: doc.listId,
  2624. swimlaneId: doc.swimlaneId,
  2625. };
  2626. Activities.insert(act);
  2627. }
  2628. }
  2629. // Say goodbye to the label
  2630. if (modifier.$pull && modifier.$pull.labelIds) {
  2631. labelId = modifier.$pull.labelIds;
  2632. // Check that the former member is member of the card
  2633. if (_.contains(doc.labelIds, labelId)) {
  2634. Activities.insert({
  2635. userId,
  2636. labelId,
  2637. activityType: 'removedLabel',
  2638. boardId: doc.boardId,
  2639. cardId: doc._id,
  2640. listId: doc.listId,
  2641. swimlaneId: doc.swimlaneId,
  2642. });
  2643. }
  2644. }
  2645. }
  2646. function cardCustomFields(userId, doc, fieldNames, modifier) {
  2647. if (!_.contains(fieldNames, 'customFields')) return;
  2648. // Say hello to the new customField value
  2649. if (modifier.$set) {
  2650. _.each(modifier.$set, (value, key) => {
  2651. if (key.startsWith('customFields')) {
  2652. const dotNotation = key.split('.');
  2653. // only individual changes are registered
  2654. if (dotNotation.length > 1) {
  2655. const customFieldId = doc.customFields[dotNotation[1]]._id;
  2656. const act = {
  2657. userId,
  2658. customFieldId,
  2659. value,
  2660. activityType: 'setCustomField',
  2661. boardId: doc.boardId,
  2662. cardId: doc._id,
  2663. listId: doc.listId,
  2664. swimlaneId: doc.swimlaneId,
  2665. };
  2666. Activities.insert(act);
  2667. }
  2668. }
  2669. });
  2670. }
  2671. // Say goodbye to the former customField value
  2672. if (modifier.$unset) {
  2673. _.each(modifier.$unset, (value, key) => {
  2674. if (key.startsWith('customFields')) {
  2675. const dotNotation = key.split('.');
  2676. // only individual changes are registered
  2677. if (dotNotation.length > 1) {
  2678. const customFieldId = doc.customFields[dotNotation[1]]._id;
  2679. const act = {
  2680. userId,
  2681. customFieldId,
  2682. activityType: 'unsetCustomField',
  2683. boardId: doc.boardId,
  2684. cardId: doc._id,
  2685. };
  2686. Activities.insert(act);
  2687. }
  2688. }
  2689. });
  2690. }
  2691. }
  2692. function cardCreation(userId, doc) {
  2693. Activities.insert({
  2694. userId,
  2695. activityType: 'createCard',
  2696. boardId: doc.boardId,
  2697. listName: Lists.findOne(doc.listId).title,
  2698. listId: doc.listId,
  2699. cardId: doc._id,
  2700. cardTitle: doc.title,
  2701. swimlaneName: Swimlanes.findOne(doc.swimlaneId).title,
  2702. swimlaneId: doc.swimlaneId,
  2703. });
  2704. }
  2705. function cardRemover(userId, doc) {
  2706. ChecklistItems.remove({
  2707. cardId: doc._id,
  2708. });
  2709. Checklists.remove({
  2710. cardId: doc._id,
  2711. });
  2712. Cards.remove({
  2713. parentId: doc._id,
  2714. });
  2715. CardComments.remove({
  2716. cardId: doc._id,
  2717. });
  2718. Attachments.remove({
  2719. cardId: doc._id,
  2720. });
  2721. }
  2722. const findDueCards = days => {
  2723. const seekDue = ($from, $to, activityType) => {
  2724. Cards.find({
  2725. archived: false,
  2726. dueAt: { $gte: $from, $lt: $to },
  2727. }).forEach(card => {
  2728. const username = Users.findOne(card.userId).username;
  2729. const activity = {
  2730. userId: card.userId,
  2731. username,
  2732. activityType,
  2733. boardId: card.boardId,
  2734. cardId: card._id,
  2735. cardTitle: card.title,
  2736. listId: card.listId,
  2737. timeValue: card.dueAt,
  2738. swimlaneId: card.swimlaneId,
  2739. };
  2740. Activities.insert(activity);
  2741. });
  2742. };
  2743. const now = new Date(),
  2744. aday = 3600 * 24 * 1e3,
  2745. then = day => new Date(now.setHours(0, 0, 0, 0) + day * aday);
  2746. if (!days) return;
  2747. if (!days.map) days = [days];
  2748. days.map(day => {
  2749. let args = [];
  2750. if (day === 0) {
  2751. args = [then(0), then(1), 'duenow'];
  2752. } else if (day > 0) {
  2753. args = [then(1), then(day), 'almostdue'];
  2754. } else {
  2755. args = [then(day), now, 'pastdue'];
  2756. }
  2757. seekDue(...args);
  2758. });
  2759. };
  2760. const addCronJob = _.debounce(
  2761. Meteor.bindEnvironment(function findDueCardsDebounced() {
  2762. const envValue = process.env.NOTIFY_DUE_DAYS_BEFORE_AND_AFTER;
  2763. if (!envValue) {
  2764. return;
  2765. }
  2766. const notifydays = envValue
  2767. .split(',')
  2768. .map(value => {
  2769. const iValue = parseInt(value, 10);
  2770. if (!(iValue > 0 && iValue < 15)) {
  2771. // notifying due is disabled
  2772. return false;
  2773. } else {
  2774. return iValue;
  2775. }
  2776. })
  2777. .filter(Boolean);
  2778. const notifyitvl = process.env.NOTIFY_DUE_AT_HOUR_OF_DAY; //passed in the itvl has to be a number standing for the hour of current time
  2779. const defaultitvl = 8; // default every morning at 8am, if the passed env variable has parsing error use default
  2780. const itvl = parseInt(notifyitvl, 10) || defaultitvl;
  2781. const scheduler = (job => () => {
  2782. const now = new Date();
  2783. const hour = 3600 * 1e3;
  2784. if (now.getHours() === itvl) {
  2785. if (typeof job === 'function') {
  2786. job();
  2787. }
  2788. }
  2789. Meteor.setTimeout(scheduler, hour);
  2790. })(() => {
  2791. findDueCards(notifydays);
  2792. });
  2793. scheduler();
  2794. }),
  2795. 500,
  2796. );
  2797. if (Meteor.isServer) {
  2798. // Cards are often fetched within a board, so we create an index to make these
  2799. // queries more efficient.
  2800. Meteor.startup(() => {
  2801. Cards._collection._ensureIndex({ modifiedAt: -1 });
  2802. Cards._collection._ensureIndex({ boardId: 1, createdAt: -1 });
  2803. // https://github.com/wekan/wekan/issues/1863
  2804. // Swimlane added a new field in the cards collection of mongodb named parentId.
  2805. // When loading a board, mongodb is searching for every cards, the id of the parent (in the swinglanes collection).
  2806. // With a huge database, this result in a very slow app and high CPU on the mongodb side.
  2807. // To correct it, add Index to parentId:
  2808. Cards._collection._ensureIndex({ parentId: 1 });
  2809. // let notifydays = parseInt(process.env.NOTIFY_DUE_DAYS_BEFORE_AND_AFTER) || 2; // default as 2 days b4 and after
  2810. // let notifyitvl = parseInt(process.env.NOTIFY_DUE_AT_HOUR_OF_DAY) || 3600 * 24 * 1e3; // default interval as one day
  2811. // Meteor.call("findDueCards",notifydays,notifyitvl);
  2812. Meteor.defer(() => {
  2813. addCronJob();
  2814. });
  2815. });
  2816. Cards.after.insert((userId, doc) => {
  2817. cardCreation(userId, doc);
  2818. });
  2819. // New activity for card (un)archivage
  2820. Cards.after.update((userId, doc, fieldNames) => {
  2821. cardState(userId, doc, fieldNames);
  2822. });
  2823. //New activity for card moves
  2824. Cards.after.update(function(userId, doc, fieldNames) {
  2825. const oldListId = this.previous.listId;
  2826. const oldSwimlaneId = this.previous.swimlaneId;
  2827. const oldBoardId = this.previous.boardId;
  2828. cardMove(userId, doc, fieldNames, oldListId, oldSwimlaneId, oldBoardId);
  2829. });
  2830. // Add a new activity if we add or remove a member to the card
  2831. Cards.before.update((userId, doc, fieldNames, modifier) => {
  2832. cardMembers(userId, doc, fieldNames, modifier);
  2833. updateActivities(doc, fieldNames, modifier);
  2834. });
  2835. // Add a new activity if we add or remove a assignee to the card
  2836. Cards.before.update((userId, doc, fieldNames, modifier) => {
  2837. cardAssignees(userId, doc, fieldNames, modifier);
  2838. updateActivities(doc, fieldNames, modifier);
  2839. });
  2840. // Add a new activity if we add or remove a label to the card
  2841. Cards.before.update((userId, doc, fieldNames, modifier) => {
  2842. cardLabels(userId, doc, fieldNames, modifier);
  2843. });
  2844. // Add a new activity if we edit a custom field
  2845. Cards.before.update((userId, doc, fieldNames, modifier) => {
  2846. cardCustomFields(userId, doc, fieldNames, modifier);
  2847. });
  2848. // Add a new activity if modify time related field like dueAt startAt etc
  2849. Cards.before.update((userId, doc, fieldNames, modifier) => {
  2850. const dla = 'dateLastActivity';
  2851. const fields = fieldNames.filter(name => name !== dla);
  2852. const timingaction = ['receivedAt', 'dueAt', 'startAt', 'endAt'];
  2853. const action = fields[0];
  2854. if (fields.length > 0 && _.contains(timingaction, action)) {
  2855. // add activities for user change these attributes
  2856. const value = modifier.$set[action];
  2857. const oldvalue = doc[action] || '';
  2858. const activityType = `a-${action}`;
  2859. const card = Cards.findOne(doc._id);
  2860. const list = card.list();
  2861. if (list) {
  2862. // change list modifiedAt, when user modified the key values in
  2863. // timingaction array, if it's endAt, put the modifiedAt of list
  2864. // back to one year ago for sorting purpose
  2865. const modifiedAt = moment()
  2866. .subtract(1, 'year')
  2867. .toISOString();
  2868. const boardId = list.boardId;
  2869. Lists.direct.update(
  2870. {
  2871. _id: list._id,
  2872. },
  2873. {
  2874. $set: {
  2875. modifiedAt,
  2876. boardId,
  2877. },
  2878. },
  2879. );
  2880. }
  2881. const username = Users.findOne(userId).username;
  2882. const activity = {
  2883. userId,
  2884. username,
  2885. activityType,
  2886. boardId: doc.boardId,
  2887. cardId: doc._id,
  2888. cardTitle: doc.title,
  2889. timeKey: action,
  2890. timeValue: value,
  2891. timeOldValue: oldvalue,
  2892. listId: card.listId,
  2893. swimlaneId: card.swimlaneId,
  2894. };
  2895. Activities.insert(activity);
  2896. }
  2897. });
  2898. // Remove all activities associated with a card if we remove the card
  2899. // Remove also card_comments / checklists / attachments
  2900. Cards.before.remove((userId, doc) => {
  2901. cardRemover(userId, doc);
  2902. });
  2903. }
  2904. //SWIMLANES REST API
  2905. if (Meteor.isServer) {
  2906. /**
  2907. * @operation get_swimlane_cards
  2908. * @summary get all cards attached to a swimlane
  2909. *
  2910. * @param {string} boardId the board ID
  2911. * @param {string} swimlaneId the swimlane ID
  2912. * @return_type [{_id: string,
  2913. * title: string,
  2914. * description: string,
  2915. * listId: string}]
  2916. */
  2917. JsonRoutes.add(
  2918. 'GET',
  2919. '/api/boards/:boardId/swimlanes/:swimlaneId/cards',
  2920. function(req, res) {
  2921. const paramBoardId = req.params.boardId;
  2922. const paramSwimlaneId = req.params.swimlaneId;
  2923. Authentication.checkBoardAccess(req.userId, paramBoardId);
  2924. JsonRoutes.sendResult(res, {
  2925. code: 200,
  2926. data: Cards.find({
  2927. boardId: paramBoardId,
  2928. swimlaneId: paramSwimlaneId,
  2929. archived: false,
  2930. }).map(function(doc) {
  2931. return {
  2932. _id: doc._id,
  2933. title: doc.title,
  2934. description: doc.description,
  2935. listId: doc.listId,
  2936. receivedAt: doc.receivedAt,
  2937. startAt: doc.startAt,
  2938. dueAt: doc.dueAt,
  2939. endAt: doc.endAt,
  2940. assignees: doc.assignees,
  2941. };
  2942. }),
  2943. });
  2944. },
  2945. );
  2946. }
  2947. //LISTS REST API
  2948. if (Meteor.isServer) {
  2949. /**
  2950. * @operation get_all_cards
  2951. * @summary Get all Cards attached to a List
  2952. *
  2953. * @param {string} boardId the board ID
  2954. * @param {string} listId the list ID
  2955. * @return_type [{_id: string,
  2956. * title: string,
  2957. * description: string}]
  2958. */
  2959. JsonRoutes.add('GET', '/api/boards/:boardId/lists/:listId/cards', function(
  2960. req,
  2961. res,
  2962. ) {
  2963. const paramBoardId = req.params.boardId;
  2964. const paramListId = req.params.listId;
  2965. Authentication.checkBoardAccess(req.userId, paramBoardId);
  2966. JsonRoutes.sendResult(res, {
  2967. code: 200,
  2968. data: Cards.find({
  2969. boardId: paramBoardId,
  2970. listId: paramListId,
  2971. archived: false,
  2972. }).map(function(doc) {
  2973. return {
  2974. _id: doc._id,
  2975. title: doc.title,
  2976. description: doc.description,
  2977. receivedAt: doc.receivedAt,
  2978. startAt: doc.startAt,
  2979. dueAt: doc.dueAt,
  2980. endAt: doc.endAt,
  2981. assignees: doc.assignees,
  2982. };
  2983. }),
  2984. });
  2985. });
  2986. /**
  2987. * @operation get_card
  2988. * @summary Get a Card
  2989. *
  2990. * @param {string} boardId the board ID
  2991. * @param {string} listId the list ID of the card
  2992. * @param {string} cardId the card ID
  2993. * @return_type Cards
  2994. */
  2995. JsonRoutes.add(
  2996. 'GET',
  2997. '/api/boards/:boardId/lists/:listId/cards/:cardId',
  2998. function(req, res) {
  2999. const paramBoardId = req.params.boardId;
  3000. const paramListId = req.params.listId;
  3001. const paramCardId = req.params.cardId;
  3002. Authentication.checkBoardAccess(req.userId, paramBoardId);
  3003. JsonRoutes.sendResult(res, {
  3004. code: 200,
  3005. data: Cards.findOne({
  3006. _id: paramCardId,
  3007. listId: paramListId,
  3008. boardId: paramBoardId,
  3009. archived: false,
  3010. }),
  3011. });
  3012. },
  3013. );
  3014. /**
  3015. * @operation new_card
  3016. * @summary Create a new Card
  3017. *
  3018. * @param {string} boardId the board ID of the new card
  3019. * @param {string} listId the list ID of the new card
  3020. * @param {string} authorID the user ID of the person owning the card
  3021. * @param {string} parentId the parent ID of the new card
  3022. * @param {string} title the title of the new card
  3023. * @param {string} description the description of the new card
  3024. * @param {string} swimlaneId the swimlane ID of the new card
  3025. * @param {string} [members] the member IDs list of the new card
  3026. * @param {string} [assignees] the array of maximum one ID of assignee of the new card
  3027. * @return_type {_id: string}
  3028. */
  3029. JsonRoutes.add('POST', '/api/boards/:boardId/lists/:listId/cards', function(
  3030. req,
  3031. res,
  3032. ) {
  3033. // Check user is logged in
  3034. Authentication.checkLoggedIn(req.userId);
  3035. const paramBoardId = req.params.boardId;
  3036. // Check user has permission to add card to the board
  3037. const board = Boards.findOne({
  3038. _id: paramBoardId,
  3039. });
  3040. const addPermission = allowIsBoardMemberCommentOnly(req.userId, board);
  3041. Authentication.checkAdminOrCondition(req.userId, addPermission);
  3042. const paramListId = req.params.listId;
  3043. const paramParentId = req.params.parentId;
  3044. const nextCardNumber = board.getNextCardNumber();
  3045. const currentCards = Cards.find(
  3046. {
  3047. listId: paramListId,
  3048. archived: false,
  3049. },
  3050. { sort: ['sort'] },
  3051. );
  3052. const check = Users.findOne({
  3053. _id: req.body.authorId,
  3054. });
  3055. const members = req.body.members;
  3056. const assignees = req.body.assignees;
  3057. if (typeof check !== 'undefined') {
  3058. const id = Cards.direct.insert({
  3059. title: req.body.title,
  3060. boardId: paramBoardId,
  3061. listId: paramListId,
  3062. parentId: paramParentId,
  3063. description: req.body.description,
  3064. userId: req.body.authorId,
  3065. swimlaneId: req.body.swimlaneId,
  3066. sort: currentCards.count(),
  3067. cardNumber: nextCardNumber,
  3068. members,
  3069. assignees,
  3070. });
  3071. JsonRoutes.sendResult(res, {
  3072. code: 200,
  3073. data: {
  3074. _id: id,
  3075. },
  3076. });
  3077. const card = Cards.findOne({
  3078. _id: id,
  3079. });
  3080. cardCreation(req.body.authorId, card);
  3081. } else {
  3082. JsonRoutes.sendResult(res, {
  3083. code: 401,
  3084. });
  3085. }
  3086. });
  3087. /*
  3088. * Note for the JSDoc:
  3089. * 'list' will be interpreted as the path parameter
  3090. * 'listID' will be interpreted as the body parameter
  3091. */
  3092. /**
  3093. * @operation edit_card
  3094. * @summary Edit Fields in a Card
  3095. *
  3096. * @description Edit a card
  3097. *
  3098. * The color has to be chosen between `white`, `green`, `yellow`, `orange`,
  3099. * `red`, `purple`, `blue`, `sky`, `lime`, `pink`, `black`, `silver`,
  3100. * `peachpuff`, `crimson`, `plum`, `darkgreen`, `slateblue`, `magenta`,
  3101. * `gold`, `navy`, `gray`, `saddlebrown`, `paleturquoise`, `mistyrose`,
  3102. * `indigo`:
  3103. *
  3104. * <img src="/card-colors.png" width="40%" alt="Wekan card colors" />
  3105. *
  3106. * Note: setting the color to white has the same effect than removing it.
  3107. *
  3108. * @param {string} boardId the board ID of the card
  3109. * @param {string} list the list ID of the card
  3110. * @param {string} cardId the ID of the card
  3111. * @param {string} [title] the new title of the card
  3112. * @param {string} [sort] the new sort value of the card
  3113. * @param {string} [listId] the new list ID of the card (move operation)
  3114. * @param {string} [description] the new description of the card
  3115. * @param {string} [authorId] change the owner of the card
  3116. * @param {string} [parentId] change the parent of the card
  3117. * @param {string} [labelIds] the new list of label IDs attached to the card
  3118. * @param {string} [swimlaneId] the new swimlane ID of the card
  3119. * @param {string} [members] the new list of member IDs attached to the card
  3120. * @param {string} [assignees] the array of maximum one ID of assignee attached to the card
  3121. * @param {string} [requestedBy] the new requestedBy field of the card
  3122. * @param {string} [assignedBy] the new assignedBy field of the card
  3123. * @param {string} [receivedAt] the new receivedAt field of the card
  3124. * @param {string} [assignBy] the new assignBy field of the card
  3125. * @param {string} [startAt] the new startAt field of the card
  3126. * @param {string} [dueAt] the new dueAt field of the card
  3127. * @param {string} [endAt] the new endAt field of the card
  3128. * @param {string} [spentTime] the new spentTime field of the card
  3129. * @param {boolean} [isOverTime] the new isOverTime field of the card
  3130. * @param {string} [customFields] the new customFields value of the card
  3131. * @param {string} [color] the new color of the card
  3132. * @param {Object} [vote] the vote object
  3133. * @param {string} vote.question the vote question
  3134. * @param {boolean} vote.public show who voted what
  3135. * @param {boolean} vote.allowNonBoardMembers allow all logged in users to vote?
  3136. * @param {Object} [poker] the poker object
  3137. * @param {string} poker.question the vote question
  3138. * @param {boolean} poker.allowNonBoardMembers allow all logged in users to vote?
  3139. * @return_type {_id: string}
  3140. */
  3141. JsonRoutes.add(
  3142. 'PUT',
  3143. '/api/boards/:boardId/lists/:listId/cards/:cardId',
  3144. function(req, res) {
  3145. const paramBoardId = req.params.boardId;
  3146. Authentication.checkBoardAccess(req.userId, paramBoardId);
  3147. const paramCardId = req.params.cardId;
  3148. const paramListId = req.params.listId;
  3149. if (req.body.hasOwnProperty('title')) {
  3150. const newTitle = req.body.title;
  3151. Cards.direct.update(
  3152. {
  3153. _id: paramCardId,
  3154. listId: paramListId,
  3155. boardId: paramBoardId,
  3156. archived: false,
  3157. },
  3158. {
  3159. $set: {
  3160. title: newTitle,
  3161. },
  3162. },
  3163. );
  3164. }
  3165. if (req.body.hasOwnProperty('sort')) {
  3166. const newSort = req.body.sort;
  3167. Cards.direct.update(
  3168. {
  3169. _id: paramCardId,
  3170. listId: paramListId,
  3171. boardId: paramBoardId,
  3172. archived: false,
  3173. },
  3174. {
  3175. $set: {
  3176. sort: newSort,
  3177. },
  3178. },
  3179. );
  3180. }
  3181. if (req.body.hasOwnProperty('parentId')) {
  3182. const newParentId = req.body.parentId;
  3183. Cards.direct.update(
  3184. {
  3185. _id: paramCardId,
  3186. listId: paramListId,
  3187. boardId: paramBoardId,
  3188. archived: false,
  3189. },
  3190. {
  3191. $set: {
  3192. parentId: newParentId,
  3193. },
  3194. },
  3195. );
  3196. }
  3197. if (req.body.hasOwnProperty('description')) {
  3198. const newDescription = req.body.description;
  3199. Cards.direct.update(
  3200. {
  3201. _id: paramCardId,
  3202. listId: paramListId,
  3203. boardId: paramBoardId,
  3204. archived: false,
  3205. },
  3206. {
  3207. $set: {
  3208. description: newDescription,
  3209. },
  3210. },
  3211. );
  3212. }
  3213. if (req.body.hasOwnProperty('color')) {
  3214. const newColor = req.body.color;
  3215. Cards.direct.update(
  3216. {
  3217. _id: paramCardId,
  3218. listId: paramListId,
  3219. boardId: paramBoardId,
  3220. archived: false,
  3221. },
  3222. { $set: { color: newColor } },
  3223. );
  3224. }
  3225. if (req.body.hasOwnProperty('vote')) {
  3226. const newVote = req.body.vote;
  3227. newVote.positive = [];
  3228. newVote.negative = [];
  3229. if (!newVote.hasOwnProperty('public')) newVote.public = false;
  3230. if (!newVote.hasOwnProperty('allowNonBoardMembers'))
  3231. newVote.allowNonBoardMembers = false;
  3232. Cards.direct.update(
  3233. {
  3234. _id: paramCardId,
  3235. listId: paramListId,
  3236. boardId: paramBoardId,
  3237. archived: false,
  3238. },
  3239. { $set: { vote: newVote } },
  3240. );
  3241. }
  3242. if (req.body.hasOwnProperty('poker')) {
  3243. const newPoker = req.body.poker;
  3244. newPoker.one = [];
  3245. newPoker.two = [];
  3246. newPoker.three = [];
  3247. newPoker.five = [];
  3248. newPoker.eight = [];
  3249. newPoker.thirteen = [];
  3250. newPoker.twenty = [];
  3251. newPoker.forty = [];
  3252. newPoker.oneHundred = [];
  3253. newPoker.unsure = [];
  3254. if (!newPoker.hasOwnProperty('allowNonBoardMembers'))
  3255. newPoker.allowNonBoardMembers = false;
  3256. Cards.direct.update(
  3257. {
  3258. _id: paramCardId,
  3259. listId: paramListId,
  3260. boardId: paramBoardId,
  3261. archived: false,
  3262. },
  3263. { $set: { poker: newPoker } },
  3264. );
  3265. }
  3266. if (req.body.hasOwnProperty('labelIds')) {
  3267. let newlabelIds = req.body.labelIds;
  3268. if (_.isString(newlabelIds)) {
  3269. if (newlabelIds === '') {
  3270. newlabelIds = null;
  3271. } else {
  3272. newlabelIds = [newlabelIds];
  3273. }
  3274. }
  3275. Cards.direct.update(
  3276. {
  3277. _id: paramCardId,
  3278. listId: paramListId,
  3279. boardId: paramBoardId,
  3280. archived: false,
  3281. },
  3282. {
  3283. $set: {
  3284. labelIds: newlabelIds,
  3285. },
  3286. },
  3287. );
  3288. }
  3289. if (req.body.hasOwnProperty('requestedBy')) {
  3290. const newrequestedBy = req.body.requestedBy;
  3291. Cards.direct.update(
  3292. {
  3293. _id: paramCardId,
  3294. listId: paramListId,
  3295. boardId: paramBoardId,
  3296. archived: false,
  3297. },
  3298. { $set: { requestedBy: newrequestedBy } },
  3299. );
  3300. }
  3301. if (req.body.hasOwnProperty('assignedBy')) {
  3302. const newassignedBy = req.body.assignedBy;
  3303. Cards.direct.update(
  3304. {
  3305. _id: paramCardId,
  3306. listId: paramListId,
  3307. boardId: paramBoardId,
  3308. archived: false,
  3309. },
  3310. { $set: { assignedBy: newassignedBy } },
  3311. );
  3312. }
  3313. if (req.body.hasOwnProperty('receivedAt')) {
  3314. const newreceivedAt = req.body.receivedAt;
  3315. Cards.direct.update(
  3316. {
  3317. _id: paramCardId,
  3318. listId: paramListId,
  3319. boardId: paramBoardId,
  3320. archived: false,
  3321. },
  3322. { $set: { receivedAt: newreceivedAt } },
  3323. );
  3324. }
  3325. if (req.body.hasOwnProperty('startAt')) {
  3326. const newstartAt = req.body.startAt;
  3327. Cards.direct.update(
  3328. {
  3329. _id: paramCardId,
  3330. listId: paramListId,
  3331. boardId: paramBoardId,
  3332. archived: false,
  3333. },
  3334. { $set: { startAt: newstartAt } },
  3335. );
  3336. }
  3337. if (req.body.hasOwnProperty('dueAt')) {
  3338. const newdueAt = req.body.dueAt;
  3339. Cards.direct.update(
  3340. {
  3341. _id: paramCardId,
  3342. listId: paramListId,
  3343. boardId: paramBoardId,
  3344. archived: false,
  3345. },
  3346. { $set: { dueAt: newdueAt } },
  3347. );
  3348. }
  3349. if (req.body.hasOwnProperty('endAt')) {
  3350. const newendAt = req.body.endAt;
  3351. Cards.direct.update(
  3352. {
  3353. _id: paramCardId,
  3354. listId: paramListId,
  3355. boardId: paramBoardId,
  3356. archived: false,
  3357. },
  3358. { $set: { endAt: newendAt } },
  3359. );
  3360. }
  3361. if (req.body.hasOwnProperty('spentTime')) {
  3362. const newspentTime = req.body.spentTime;
  3363. Cards.direct.update(
  3364. {
  3365. _id: paramCardId,
  3366. listId: paramListId,
  3367. boardId: paramBoardId,
  3368. archived: false,
  3369. },
  3370. { $set: { spentTime: newspentTime } },
  3371. );
  3372. }
  3373. if (req.body.hasOwnProperty('isOverTime')) {
  3374. const newisOverTime = req.body.isOverTime;
  3375. Cards.direct.update(
  3376. {
  3377. _id: paramCardId,
  3378. listId: paramListId,
  3379. boardId: paramBoardId,
  3380. archived: false,
  3381. },
  3382. { $set: { isOverTime: newisOverTime } },
  3383. );
  3384. }
  3385. if (req.body.hasOwnProperty('customFields')) {
  3386. const newcustomFields = req.body.customFields;
  3387. Cards.direct.update(
  3388. {
  3389. _id: paramCardId,
  3390. listId: paramListId,
  3391. boardId: paramBoardId,
  3392. archived: false,
  3393. },
  3394. { $set: { customFields: newcustomFields } },
  3395. );
  3396. }
  3397. if (req.body.hasOwnProperty('members')) {
  3398. let newmembers = req.body.members;
  3399. if (_.isString(newmembers)) {
  3400. if (newmembers === '') {
  3401. newmembers = null;
  3402. } else {
  3403. newmembers = [newmembers];
  3404. }
  3405. }
  3406. Cards.direct.update(
  3407. {
  3408. _id: paramCardId,
  3409. listId: paramListId,
  3410. boardId: paramBoardId,
  3411. archived: false,
  3412. },
  3413. { $set: { members: newmembers } },
  3414. );
  3415. }
  3416. if (req.body.hasOwnProperty('assignees')) {
  3417. let newassignees = req.body.assignees;
  3418. if (_.isString(newassignees)) {
  3419. if (newassignees === '') {
  3420. newassignees = null;
  3421. } else {
  3422. newassignees = [newassignees];
  3423. }
  3424. }
  3425. Cards.direct.update(
  3426. {
  3427. _id: paramCardId,
  3428. listId: paramListId,
  3429. boardId: paramBoardId,
  3430. archived: false,
  3431. },
  3432. { $set: { assignees: newassignees } },
  3433. );
  3434. }
  3435. if (req.body.hasOwnProperty('swimlaneId')) {
  3436. const newParamSwimlaneId = req.body.swimlaneId;
  3437. Cards.direct.update(
  3438. {
  3439. _id: paramCardId,
  3440. listId: paramListId,
  3441. boardId: paramBoardId,
  3442. archived: false,
  3443. },
  3444. { $set: { swimlaneId: newParamSwimlaneId } },
  3445. );
  3446. }
  3447. if (req.body.hasOwnProperty('listId')) {
  3448. const newParamListId = req.body.listId;
  3449. Cards.direct.update(
  3450. {
  3451. _id: paramCardId,
  3452. listId: paramListId,
  3453. boardId: paramBoardId,
  3454. archived: false,
  3455. },
  3456. {
  3457. $set: {
  3458. listId: newParamListId,
  3459. },
  3460. },
  3461. );
  3462. const card = Cards.findOne({
  3463. _id: paramCardId,
  3464. });
  3465. cardMove(
  3466. req.body.authorId,
  3467. card,
  3468. {
  3469. fieldName: 'listId',
  3470. },
  3471. paramListId,
  3472. );
  3473. }
  3474. JsonRoutes.sendResult(res, {
  3475. code: 200,
  3476. data: {
  3477. _id: paramCardId,
  3478. },
  3479. });
  3480. },
  3481. );
  3482. /**
  3483. * @operation delete_card
  3484. * @summary Delete a card from a board
  3485. *
  3486. * @description This operation **deletes** a card, and therefore the card
  3487. * is not put in the recycle bin.
  3488. *
  3489. * @param {string} boardId the board ID of the card
  3490. * @param {string} list the list ID of the card
  3491. * @param {string} cardId the ID of the card
  3492. * @return_type {_id: string}
  3493. */
  3494. JsonRoutes.add(
  3495. 'DELETE',
  3496. '/api/boards/:boardId/lists/:listId/cards/:cardId',
  3497. function(req, res) {
  3498. const paramBoardId = req.params.boardId;
  3499. Authentication.checkBoardAccess(req.userId, paramBoardId);
  3500. const paramListId = req.params.listId;
  3501. const paramCardId = req.params.cardId;
  3502. const card = Cards.findOne({
  3503. _id: paramCardId,
  3504. });
  3505. Cards.direct.remove({
  3506. _id: paramCardId,
  3507. listId: paramListId,
  3508. boardId: paramBoardId,
  3509. });
  3510. cardRemover(req.body.authorId, card);
  3511. JsonRoutes.sendResult(res, {
  3512. code: 200,
  3513. data: {
  3514. _id: paramCardId,
  3515. },
  3516. });
  3517. },
  3518. );
  3519. /**
  3520. * @operation get_cards_by_custom_field
  3521. * @summary Get all Cards that matchs a value of a specific custom field
  3522. *
  3523. * @param {string} boardId the board ID
  3524. * @param {string} customFieldId the list ID
  3525. * @param {string} customFieldValue the value to look for
  3526. * @return_type [{_id: string,
  3527. * title: string,
  3528. * description: string,
  3529. * listId: string,
  3530. * swinlaneId: string}]
  3531. */
  3532. JsonRoutes.add(
  3533. 'GET',
  3534. '/api/boards/:boardId/cardsByCustomField/:customFieldId/:customFieldValue',
  3535. function(req, res) {
  3536. const paramBoardId = req.params.boardId;
  3537. const paramCustomFieldId = req.params.customFieldId;
  3538. const paramCustomFieldValue = req.params.customFieldValue;
  3539. Authentication.checkBoardAccess(req.userId, paramBoardId);
  3540. JsonRoutes.sendResult(res, {
  3541. code: 200,
  3542. data: Cards.find({
  3543. boardId: paramBoardId,
  3544. customFields: {
  3545. $elemMatch: {
  3546. _id: paramCustomFieldId,
  3547. value: paramCustomFieldValue,
  3548. },
  3549. },
  3550. archived: false,
  3551. }).fetch(),
  3552. });
  3553. },
  3554. );
  3555. }
  3556. export default Cards;