users.js 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537
  1. import { SyncedCron } from 'meteor/percolate:synced-cron';
  2. // Sandstorm context is detected using the METEOR_SETTINGS environment variable
  3. // in the package definition.
  4. const isSandstorm =
  5. Meteor.settings && Meteor.settings.public && Meteor.settings.public.sandstorm;
  6. Users = Meteor.users;
  7. const allowedSortValues = [
  8. '-modifiedAt',
  9. 'modifiedAt',
  10. '-title',
  11. 'title',
  12. '-sort',
  13. 'sort',
  14. ];
  15. const defaultSortBy = allowedSortValues[0];
  16. /**
  17. * A User in wekan
  18. */
  19. Users.attachSchema(
  20. new SimpleSchema({
  21. username: {
  22. /**
  23. * the username of the user
  24. */
  25. type: String,
  26. optional: true,
  27. // eslint-disable-next-line consistent-return
  28. autoValue() {
  29. if (this.isInsert && !this.isSet) {
  30. const name = this.field('profile.fullname');
  31. if (name.isSet) {
  32. return name.value.toLowerCase().replace(/\s/g, '');
  33. }
  34. }
  35. },
  36. },
  37. emails: {
  38. /**
  39. * the list of emails attached to a user
  40. */
  41. type: [Object],
  42. optional: true,
  43. },
  44. 'emails.$.address': {
  45. /**
  46. * The email address
  47. */
  48. type: String,
  49. regEx: SimpleSchema.RegEx.Email,
  50. },
  51. 'emails.$.verified': {
  52. /**
  53. * Has the email been verified
  54. */
  55. type: Boolean,
  56. },
  57. createdAt: {
  58. /**
  59. * creation date of the user
  60. */
  61. type: Date,
  62. // eslint-disable-next-line consistent-return
  63. autoValue() {
  64. if (this.isInsert) {
  65. return new Date();
  66. } else if (this.isUpsert) {
  67. return { $setOnInsert: new Date() };
  68. } else {
  69. this.unset();
  70. }
  71. },
  72. },
  73. modifiedAt: {
  74. type: Date,
  75. denyUpdate: false,
  76. // eslint-disable-next-line consistent-return
  77. autoValue() {
  78. if (this.isInsert || this.isUpsert || this.isUpdate) {
  79. return new Date();
  80. } else {
  81. this.unset();
  82. }
  83. },
  84. },
  85. profile: {
  86. /**
  87. * profile settings
  88. */
  89. type: Object,
  90. optional: true,
  91. // eslint-disable-next-line consistent-return
  92. autoValue() {
  93. if (this.isInsert && !this.isSet) {
  94. return {
  95. boardView: 'board-view-lists',
  96. };
  97. }
  98. },
  99. },
  100. 'profile.avatarUrl': {
  101. /**
  102. * URL of the avatar of the user
  103. */
  104. type: String,
  105. optional: true,
  106. },
  107. 'profile.emailBuffer': {
  108. /**
  109. * list of email buffers of the user
  110. */
  111. type: [String],
  112. optional: true,
  113. },
  114. 'profile.fullname': {
  115. /**
  116. * full name of the user
  117. */
  118. type: String,
  119. optional: true,
  120. },
  121. 'profile.showDesktopDragHandles': {
  122. /**
  123. * does the user want to hide system messages?
  124. */
  125. type: Boolean,
  126. optional: true,
  127. },
  128. 'profile.hiddenSystemMessages': {
  129. /**
  130. * does the user want to hide system messages?
  131. */
  132. type: Boolean,
  133. optional: true,
  134. },
  135. 'profile.hiddenMinicardLabelText': {
  136. /**
  137. * does the user want to hide minicard label texts?
  138. */
  139. type: Boolean,
  140. optional: true,
  141. },
  142. 'profile.initials': {
  143. /**
  144. * initials of the user
  145. */
  146. type: String,
  147. optional: true,
  148. },
  149. 'profile.invitedBoards': {
  150. /**
  151. * board IDs the user has been invited to
  152. */
  153. type: [String],
  154. optional: true,
  155. },
  156. 'profile.language': {
  157. /**
  158. * language of the user
  159. */
  160. type: String,
  161. optional: true,
  162. },
  163. 'profile.notifications': {
  164. /**
  165. * enabled notifications for the user
  166. */
  167. type: [Object],
  168. optional: true,
  169. },
  170. 'profile.notifications.$.activity': {
  171. /**
  172. * The id of the activity this notification references
  173. */
  174. type: String,
  175. },
  176. 'profile.notifications.$.read': {
  177. /**
  178. * the date on which this notification was read
  179. */
  180. type: Date,
  181. optional: true,
  182. },
  183. 'profile.showCardsCountAt': {
  184. /**
  185. * showCardCountAt field of the user
  186. */
  187. type: Number,
  188. optional: true,
  189. },
  190. 'profile.starredBoards': {
  191. /**
  192. * list of starred board IDs
  193. */
  194. type: [String],
  195. optional: true,
  196. },
  197. 'profile.icode': {
  198. /**
  199. * icode
  200. */
  201. type: String,
  202. optional: true,
  203. },
  204. 'profile.boardView': {
  205. /**
  206. * boardView field of the user
  207. */
  208. type: String,
  209. optional: true,
  210. allowedValues: [
  211. 'board-view-lists',
  212. 'board-view-swimlanes',
  213. 'board-view-cal',
  214. ],
  215. },
  216. 'profile.listSortBy': {
  217. /**
  218. * default sort list for user
  219. */
  220. type: String,
  221. optional: true,
  222. defaultValue: defaultSortBy,
  223. allowedValues: allowedSortValues,
  224. },
  225. 'profile.templatesBoardId': {
  226. /**
  227. * Reference to the templates board
  228. */
  229. type: String,
  230. defaultValue: '',
  231. },
  232. 'profile.cardTemplatesSwimlaneId': {
  233. /**
  234. * Reference to the card templates swimlane Id
  235. */
  236. type: String,
  237. defaultValue: '',
  238. },
  239. 'profile.listTemplatesSwimlaneId': {
  240. /**
  241. * Reference to the list templates swimlane Id
  242. */
  243. type: String,
  244. defaultValue: '',
  245. },
  246. 'profile.boardTemplatesSwimlaneId': {
  247. /**
  248. * Reference to the board templates swimlane Id
  249. */
  250. type: String,
  251. defaultValue: '',
  252. },
  253. services: {
  254. /**
  255. * services field of the user
  256. */
  257. type: Object,
  258. optional: true,
  259. blackbox: true,
  260. },
  261. heartbeat: {
  262. /**
  263. * last time the user has been seen
  264. */
  265. type: Date,
  266. optional: true,
  267. },
  268. isAdmin: {
  269. /**
  270. * is the user an admin of the board?
  271. */
  272. type: Boolean,
  273. optional: true,
  274. },
  275. createdThroughApi: {
  276. /**
  277. * was the user created through the API?
  278. */
  279. type: Boolean,
  280. optional: true,
  281. },
  282. loginDisabled: {
  283. /**
  284. * loginDisabled field of the user
  285. */
  286. type: Boolean,
  287. optional: true,
  288. },
  289. authenticationMethod: {
  290. /**
  291. * authentication method of the user
  292. */
  293. type: String,
  294. optional: false,
  295. defaultValue: 'password',
  296. },
  297. }),
  298. );
  299. Users.allow({
  300. update(userId, doc) {
  301. const user = Users.findOne({ _id: userId });
  302. if ((user && user.isAdmin) || (Meteor.user() && Meteor.user().isAdmin))
  303. return true;
  304. if (!user) {
  305. return false;
  306. }
  307. return doc._id === userId;
  308. },
  309. remove(userId, doc) {
  310. const adminsNumber = Users.find({ isAdmin: true }).count();
  311. const { isAdmin } = Users.findOne(
  312. { _id: userId },
  313. { fields: { isAdmin: 1 } },
  314. );
  315. // Prevents remove of the only one administrator
  316. if (adminsNumber === 1 && isAdmin && userId === doc._id) {
  317. return false;
  318. }
  319. // If it's the user or an admin
  320. return userId === doc._id || isAdmin;
  321. },
  322. fetch: [],
  323. });
  324. // Search a user in the complete server database by its name or username. This
  325. // is used for instance to add a new user to a board.
  326. const searchInFields = ['username', 'profile.fullname'];
  327. Users.initEasySearch(searchInFields, {
  328. use: 'mongo-db',
  329. returnFields: [...searchInFields, 'profile.avatarUrl'],
  330. });
  331. if (Meteor.isClient) {
  332. Users.helpers({
  333. isBoardMember() {
  334. const board = Boards.findOne(Session.get('currentBoard'));
  335. return board && board.hasMember(this._id);
  336. },
  337. isNotNoComments() {
  338. const board = Boards.findOne(Session.get('currentBoard'));
  339. return (
  340. board && board.hasMember(this._id) && !board.hasNoComments(this._id)
  341. );
  342. },
  343. isNoComments() {
  344. const board = Boards.findOne(Session.get('currentBoard'));
  345. return board && board.hasNoComments(this._id);
  346. },
  347. isNotCommentOnly() {
  348. const board = Boards.findOne(Session.get('currentBoard'));
  349. return (
  350. board && board.hasMember(this._id) && !board.hasCommentOnly(this._id)
  351. );
  352. },
  353. isCommentOnly() {
  354. const board = Boards.findOne(Session.get('currentBoard'));
  355. return board && board.hasCommentOnly(this._id);
  356. },
  357. isNotWorker() {
  358. const board = Boards.findOne(Session.get('currentBoard'));
  359. return board && board.hasMember(this._id) && !board.hasWorker(this._id);
  360. },
  361. isWorker() {
  362. const board = Boards.findOne(Session.get('currentBoard'));
  363. return board && board.hasWorker(this._id);
  364. },
  365. isBoardAdmin(boardId = Session.get('currentBoard')) {
  366. const board = Boards.findOne(boardId);
  367. return board && board.hasAdmin(this._id);
  368. },
  369. });
  370. }
  371. Users.helpers({
  372. boards() {
  373. return Boards.find(
  374. { 'members.userId': this._id },
  375. { sort: { sort: 1 /* boards default sorting */ } },
  376. );
  377. },
  378. starredBoards() {
  379. const { starredBoards = [] } = this.profile || {};
  380. return Boards.find(
  381. { archived: false, _id: { $in: starredBoards } },
  382. {
  383. sort: { sort: 1 /* boards default sorting */ },
  384. },
  385. );
  386. },
  387. hasStarred(boardId) {
  388. const { starredBoards = [] } = this.profile || {};
  389. return _.contains(starredBoards, boardId);
  390. },
  391. invitedBoards() {
  392. const { invitedBoards = [] } = this.profile || {};
  393. return Boards.find(
  394. { archived: false, _id: { $in: invitedBoards } },
  395. {
  396. sort: { sort: 1 /* boards default sorting */ },
  397. },
  398. );
  399. },
  400. isInvitedTo(boardId) {
  401. const { invitedBoards = [] } = this.profile || {};
  402. return _.contains(invitedBoards, boardId);
  403. },
  404. _getListSortBy() {
  405. const profile = this.profile || {};
  406. const sortBy = profile.listSortBy || defaultSortBy;
  407. const keyPattern = /^(-{0,1})(.*$)/;
  408. const ret = [];
  409. if (keyPattern.exec(sortBy)) {
  410. ret[0] = RegExp.$2;
  411. ret[1] = RegExp.$1 ? -1 : 1;
  412. }
  413. return ret;
  414. },
  415. hasSortBy() {
  416. // if use doesn't have dragHandle, then we can let user to choose sort list by different order
  417. return !this.hasShowDesktopDragHandles();
  418. },
  419. getListSortBy() {
  420. return this._getListSortBy()[0];
  421. },
  422. getListSortTypes() {
  423. return allowedSortValues;
  424. },
  425. getListSortByDirection() {
  426. return this._getListSortBy()[1];
  427. },
  428. hasTag(tag) {
  429. const { tags = [] } = this.profile || {};
  430. return _.contains(tags, tag);
  431. },
  432. hasNotification(activityId) {
  433. const { notifications = [] } = this.profile || {};
  434. return _.contains(notifications, activityId);
  435. },
  436. notifications() {
  437. const { notifications = [] } = this.profile || {};
  438. for (const index in notifications) {
  439. if (!notifications.hasOwnProperty(index)) continue;
  440. const notification = notifications[index];
  441. // this preserves their db sort order for editing
  442. notification.dbIndex = index;
  443. notification.activity = Activities.findOne(notification.activity);
  444. }
  445. // this sorts them newest to oldest to match Trello's behavior
  446. notifications.reverse();
  447. return notifications;
  448. },
  449. hasShowDesktopDragHandles() {
  450. const profile = this.profile || {};
  451. return profile.showDesktopDragHandles || false;
  452. },
  453. hasHiddenSystemMessages() {
  454. const profile = this.profile || {};
  455. return profile.hiddenSystemMessages || false;
  456. },
  457. hasHiddenMinicardLabelText() {
  458. const profile = this.profile || {};
  459. return profile.hiddenMinicardLabelText || false;
  460. },
  461. getEmailBuffer() {
  462. const { emailBuffer = [] } = this.profile || {};
  463. return emailBuffer;
  464. },
  465. getInitials() {
  466. const profile = this.profile || {};
  467. if (profile.initials) return profile.initials;
  468. else if (profile.fullname) {
  469. return profile.fullname
  470. .split(/\s+/)
  471. .reduce((memo, word) => {
  472. return memo + word[0];
  473. }, '')
  474. .toUpperCase();
  475. } else {
  476. return this.username[0].toUpperCase();
  477. }
  478. },
  479. getLimitToShowCardsCount() {
  480. const profile = this.profile || {};
  481. return profile.showCardsCountAt;
  482. },
  483. getName() {
  484. const profile = this.profile || {};
  485. return profile.fullname || this.username;
  486. },
  487. getLanguage() {
  488. const profile = this.profile || {};
  489. return profile.language || 'en';
  490. },
  491. getTemplatesBoardId() {
  492. return (this.profile || {}).templatesBoardId;
  493. },
  494. getTemplatesBoardSlug() {
  495. return (Boards.findOne((this.profile || {}).templatesBoardId) || {}).slug;
  496. },
  497. remove() {
  498. User.remove({ _id: this._id });
  499. },
  500. });
  501. Users.mutations({
  502. toggleBoardStar(boardId) {
  503. const queryKind = this.hasStarred(boardId) ? '$pull' : '$addToSet';
  504. return {
  505. [queryKind]: {
  506. 'profile.starredBoards': boardId,
  507. },
  508. };
  509. },
  510. addInvite(boardId) {
  511. return {
  512. $addToSet: {
  513. 'profile.invitedBoards': boardId,
  514. },
  515. };
  516. },
  517. removeInvite(boardId) {
  518. return {
  519. $pull: {
  520. 'profile.invitedBoards': boardId,
  521. },
  522. };
  523. },
  524. addTag(tag) {
  525. return {
  526. $addToSet: {
  527. 'profile.tags': tag,
  528. },
  529. };
  530. },
  531. removeTag(tag) {
  532. return {
  533. $pull: {
  534. 'profile.tags': tag,
  535. },
  536. };
  537. },
  538. toggleTag(tag) {
  539. if (this.hasTag(tag)) this.removeTag(tag);
  540. else this.addTag(tag);
  541. },
  542. setListSortBy(value) {
  543. return {
  544. $set: {
  545. 'profile.listSortBy': value,
  546. },
  547. };
  548. },
  549. toggleDesktopHandles(value = false) {
  550. return {
  551. $set: {
  552. 'profile.showDesktopDragHandles': !value,
  553. },
  554. };
  555. },
  556. toggleSystem(value = false) {
  557. return {
  558. $set: {
  559. 'profile.hiddenSystemMessages': !value,
  560. },
  561. };
  562. },
  563. toggleLabelText(value = false) {
  564. return {
  565. $set: {
  566. 'profile.hiddenMinicardLabelText': !value,
  567. },
  568. };
  569. },
  570. addNotification(activityId) {
  571. return {
  572. $addToSet: {
  573. 'profile.notifications': { activity: activityId },
  574. },
  575. };
  576. },
  577. removeNotification(activityId) {
  578. return {
  579. $pull: {
  580. 'profile.notifications': { activity: activityId },
  581. },
  582. };
  583. },
  584. addEmailBuffer(text) {
  585. return {
  586. $addToSet: {
  587. 'profile.emailBuffer': text,
  588. },
  589. };
  590. },
  591. clearEmailBuffer() {
  592. return {
  593. $set: {
  594. 'profile.emailBuffer': [],
  595. },
  596. };
  597. },
  598. setAvatarUrl(avatarUrl) {
  599. return { $set: { 'profile.avatarUrl': avatarUrl } };
  600. },
  601. setShowCardsCountAt(limit) {
  602. return { $set: { 'profile.showCardsCountAt': limit } };
  603. },
  604. setBoardView(view) {
  605. return {
  606. $set: {
  607. 'profile.boardView': view,
  608. },
  609. };
  610. },
  611. });
  612. Meteor.methods({
  613. setListSortBy(value) {
  614. check(value, String);
  615. Meteor.user().setListSortBy(value);
  616. },
  617. toggleDesktopDragHandles() {
  618. const user = Meteor.user();
  619. user.toggleDesktopHandles(user.hasShowDesktopDragHandles());
  620. },
  621. toggleSystemMessages() {
  622. const user = Meteor.user();
  623. user.toggleSystem(user.hasHiddenSystemMessages());
  624. },
  625. toggleMinicardLabelText() {
  626. const user = Meteor.user();
  627. user.toggleLabelText(user.hasHiddenMinicardLabelText());
  628. },
  629. changeLimitToShowCardsCount(limit) {
  630. check(limit, Number);
  631. Meteor.user().setShowCardsCountAt(limit);
  632. },
  633. });
  634. if (Meteor.isServer) {
  635. Meteor.methods({
  636. setCreateUser(fullname, username, password, isAdmin, isActive, email) {
  637. if (Meteor.user() && Meteor.user().isAdmin) {
  638. check(fullname, String);
  639. check(username, String);
  640. check(password, String);
  641. check(isAdmin, String);
  642. check(isActive, String);
  643. check(email, String);
  644. const nUsersWithUsername = Users.find({ username }).count();
  645. const nUsersWithEmail = Users.find({ email }).count();
  646. if (nUsersWithUsername > 0) {
  647. throw new Meteor.Error('username-already-taken');
  648. } else if (nUsersWithEmail > 0) {
  649. throw new Meteor.Error('email-already-taken');
  650. } else {
  651. Accounts.createUser({
  652. fullname,
  653. username,
  654. password,
  655. isAdmin,
  656. isActive,
  657. email: email.toLowerCase(),
  658. from: 'admin',
  659. });
  660. }
  661. }
  662. },
  663. setUsername(username, userId) {
  664. if (Meteor.user() && Meteor.user().isAdmin) {
  665. check(username, String);
  666. check(userId, String);
  667. const nUsersWithUsername = Users.find({ username }).count();
  668. if (nUsersWithUsername > 0) {
  669. throw new Meteor.Error('username-already-taken');
  670. } else {
  671. Users.update(userId, { $set: { username } });
  672. }
  673. }
  674. },
  675. setEmail(email, userId) {
  676. if (Meteor.user() && Meteor.user().isAdmin) {
  677. if (Array.isArray(email)) {
  678. email = email.shift();
  679. }
  680. check(email, String);
  681. const existingUser = Users.findOne(
  682. { 'emails.address': email },
  683. { fields: { _id: 1 } },
  684. );
  685. if (existingUser) {
  686. throw new Meteor.Error('email-already-taken');
  687. } else {
  688. Users.update(userId, {
  689. $set: {
  690. emails: [
  691. {
  692. address: email,
  693. verified: false,
  694. },
  695. ],
  696. },
  697. });
  698. }
  699. }
  700. },
  701. setUsernameAndEmail(username, email, userId) {
  702. if (Meteor.user() && Meteor.user().isAdmin) {
  703. check(username, String);
  704. if (Array.isArray(email)) {
  705. email = email.shift();
  706. }
  707. check(email, String);
  708. check(userId, String);
  709. Meteor.call('setUsername', username, userId);
  710. Meteor.call('setEmail', email, userId);
  711. }
  712. },
  713. setPassword(newPassword, userId) {
  714. if (Meteor.user() && Meteor.user().isAdmin) {
  715. check(userId, String);
  716. check(newPassword, String);
  717. if (Meteor.user().isAdmin) {
  718. Accounts.setPassword(userId, newPassword);
  719. }
  720. }
  721. },
  722. // we accept userId, username, email
  723. inviteUserToBoard(username, boardId) {
  724. check(username, String);
  725. check(boardId, String);
  726. const inviter = Meteor.user();
  727. const board = Boards.findOne(boardId);
  728. const allowInvite =
  729. inviter &&
  730. board &&
  731. board.members &&
  732. _.contains(_.pluck(board.members, 'userId'), inviter._id) &&
  733. _.where(board.members, { userId: inviter._id })[0].isActive;
  734. // GitHub issue 2060
  735. //_.where(board.members, { userId: inviter._id })[0].isAdmin;
  736. if (!allowInvite) throw new Meteor.Error('error-board-notAMember');
  737. this.unblock();
  738. const posAt = username.indexOf('@');
  739. let user = null;
  740. if (posAt >= 0) {
  741. user = Users.findOne({ emails: { $elemMatch: { address: username } } });
  742. } else {
  743. user = Users.findOne(username) || Users.findOne({ username });
  744. }
  745. if (user) {
  746. if (user._id === inviter._id)
  747. throw new Meteor.Error('error-user-notAllowSelf');
  748. } else {
  749. if (posAt <= 0) throw new Meteor.Error('error-user-doesNotExist');
  750. if (Settings.findOne({ disableRegistration: true })) {
  751. throw new Meteor.Error('error-user-notCreated');
  752. }
  753. // Set in lowercase email before creating account
  754. const email = username.toLowerCase();
  755. username = email.substring(0, posAt);
  756. const newUserId = Accounts.createUser({ username, email });
  757. if (!newUserId) throw new Meteor.Error('error-user-notCreated');
  758. // assume new user speak same language with inviter
  759. if (inviter.profile && inviter.profile.language) {
  760. Users.update(newUserId, {
  761. $set: {
  762. 'profile.language': inviter.profile.language,
  763. },
  764. });
  765. }
  766. Accounts.sendEnrollmentEmail(newUserId);
  767. user = Users.findOne(newUserId);
  768. }
  769. board.addMember(user._id);
  770. user.addInvite(boardId);
  771. //Check if there is a subtasks board
  772. if (board.subtasksDefaultBoardId) {
  773. const subBoard = Boards.findOne(board.subtasksDefaultBoardId);
  774. //If there is, also add user to that board
  775. if (subBoard) {
  776. subBoard.addMember(user._id);
  777. user.addInvite(subBoard._id);
  778. }
  779. }
  780. try {
  781. const params = {
  782. user: user.username,
  783. inviter: inviter.username,
  784. board: board.title,
  785. url: board.absoluteUrl(),
  786. };
  787. const lang = user.getLanguage();
  788. Email.send({
  789. to: user.emails[0].address.toLowerCase(),
  790. from: Accounts.emailTemplates.from,
  791. subject: TAPi18n.__('email-invite-subject', params, lang),
  792. text: TAPi18n.__('email-invite-text', params, lang),
  793. });
  794. } catch (e) {
  795. throw new Meteor.Error('email-fail', e.message);
  796. }
  797. return { username: user.username, email: user.emails[0].address };
  798. },
  799. });
  800. Accounts.onCreateUser((options, user) => {
  801. const userCount = Users.find().count();
  802. if (userCount === 0) {
  803. user.isAdmin = true;
  804. return user;
  805. }
  806. if (user.services.oidc) {
  807. let email = user.services.oidc.email;
  808. if (Array.isArray(email)) {
  809. email = email.shift();
  810. }
  811. email = email.toLowerCase();
  812. user.username = user.services.oidc.username;
  813. user.emails = [{ address: email, verified: true }];
  814. const initials = user.services.oidc.fullname
  815. .match(/\b[a-zA-Z]/g)
  816. .join('')
  817. .toUpperCase();
  818. user.profile = {
  819. initials,
  820. fullname: user.services.oidc.fullname,
  821. boardView: 'board-view-lists',
  822. };
  823. user.authenticationMethod = 'oauth2';
  824. // see if any existing user has this email address or username, otherwise create new
  825. const existingUser = Meteor.users.findOne({
  826. $or: [{ 'emails.address': email }, { username: user.username }],
  827. });
  828. if (!existingUser) return user;
  829. // copy across new service info
  830. const service = _.keys(user.services)[0];
  831. existingUser.services[service] = user.services[service];
  832. existingUser.emails = user.emails;
  833. existingUser.username = user.username;
  834. existingUser.profile = user.profile;
  835. existingUser.authenticationMethod = user.authenticationMethod;
  836. Meteor.users.remove({ _id: existingUser._id }); // remove existing record
  837. return existingUser;
  838. }
  839. if (options.from === 'admin') {
  840. user.createdThroughApi = true;
  841. return user;
  842. }
  843. const disableRegistration = Settings.findOne().disableRegistration;
  844. // If this is the first Authentication by the ldap and self registration disabled
  845. if (disableRegistration && options && options.ldap) {
  846. user.authenticationMethod = 'ldap';
  847. return user;
  848. }
  849. // If self registration enabled
  850. if (!disableRegistration) {
  851. return user;
  852. }
  853. if (!options || !options.profile) {
  854. throw new Meteor.Error(
  855. 'error-invitation-code-blank',
  856. 'The invitation code is required',
  857. );
  858. }
  859. const invitationCode = InvitationCodes.findOne({
  860. code: options.profile.invitationcode,
  861. email: options.email,
  862. valid: true,
  863. });
  864. if (!invitationCode) {
  865. throw new Meteor.Error(
  866. 'error-invitation-code-not-exist',
  867. // eslint-disable-next-line quotes
  868. "The invitation code doesn't exist",
  869. );
  870. } else {
  871. user.profile = { icode: options.profile.invitationcode };
  872. user.profile.boardView = 'board-view-lists';
  873. // Deletes the invitation code after the user was created successfully.
  874. setTimeout(
  875. Meteor.bindEnvironment(() => {
  876. InvitationCodes.remove({ _id: invitationCode._id });
  877. }),
  878. 200,
  879. );
  880. return user;
  881. }
  882. });
  883. }
  884. const addCronJob = _.debounce(
  885. Meteor.bindEnvironment(function notificationCleanupDebounced() {
  886. // passed in the removeAge has to be a number standing for the number of days after a notification is read before we remove it
  887. const envRemoveAge =
  888. process.env.NOTIFICATION_TRAY_AFTER_READ_DAYS_BEFORE_REMOVE;
  889. // default notifications will be removed 2 days after they are read
  890. const defaultRemoveAge = 2;
  891. const removeAge = parseInt(envRemoveAge, 10) || defaultRemoveAge;
  892. SyncedCron.add({
  893. name: 'notification_cleanup',
  894. schedule: parser => parser.text('every 1 days'),
  895. job: () => {
  896. for (const user of Users.find()) {
  897. if (!user.profile || !user.profile.notifications) continue;
  898. for (const notification of user.profile.notifications) {
  899. if (notification.read) {
  900. const removeDate = new Date(notification.read);
  901. removeDate.setDate(removeDate.getDate() + removeAge);
  902. if (removeDate <= new Date()) {
  903. user.removeNotification(notification.activity);
  904. }
  905. }
  906. }
  907. }
  908. },
  909. });
  910. SyncedCron.start();
  911. }),
  912. 500,
  913. );
  914. if (Meteor.isServer) {
  915. // Let mongoDB ensure username unicity
  916. Meteor.startup(() => {
  917. allowedSortValues.forEach(value => {
  918. Lists._collection._ensureIndex(value);
  919. });
  920. Users._collection._ensureIndex({ modifiedAt: -1 });
  921. Users._collection._ensureIndex(
  922. {
  923. username: 1,
  924. },
  925. { unique: true },
  926. );
  927. Meteor.defer(() => {
  928. addCronJob();
  929. });
  930. });
  931. // OLD WAY THIS CODE DID WORK: When user is last admin of board,
  932. // if admin is removed, board is removed.
  933. // NOW THIS IS COMMENTED OUT, because other board users still need to be able
  934. // to use that board, and not have board deleted.
  935. // Someone can be later changed to be admin of board, by making change to database.
  936. // TODO: Add UI for changing someone as board admin.
  937. //Users.before.remove((userId, doc) => {
  938. // Boards
  939. // .find({members: {$elemMatch: {userId: doc._id, isAdmin: true}}})
  940. // .forEach((board) => {
  941. // // If only one admin for the board
  942. // if (board.members.filter((e) => e.isAdmin).length === 1) {
  943. // Boards.remove(board._id);
  944. // }
  945. // });
  946. //});
  947. // Each board document contains the de-normalized number of users that have
  948. // starred it. If the user star or unstar a board, we need to update this
  949. // counter.
  950. // We need to run this code on the server only, otherwise the incrementation
  951. // will be done twice.
  952. Users.after.update(function(userId, user, fieldNames) {
  953. // The `starredBoards` list is hosted on the `profile` field. If this
  954. // field hasn't been modificated we don't need to run this hook.
  955. if (!_.contains(fieldNames, 'profile')) return;
  956. // To calculate a diff of board starred ids, we get both the previous
  957. // and the newly board ids list
  958. function getStarredBoardsIds(doc) {
  959. return doc.profile && doc.profile.starredBoards;
  960. }
  961. const oldIds = getStarredBoardsIds(this.previous);
  962. const newIds = getStarredBoardsIds(user);
  963. // The _.difference(a, b) method returns the values from a that are not in
  964. // b. We use it to find deleted and newly inserted ids by using it in one
  965. // direction and then in the other.
  966. function incrementBoards(boardsIds, inc) {
  967. boardsIds.forEach(boardId => {
  968. Boards.update(boardId, { $inc: { stars: inc } });
  969. });
  970. }
  971. incrementBoards(_.difference(oldIds, newIds), -1);
  972. incrementBoards(_.difference(newIds, oldIds), +1);
  973. });
  974. const fakeUserId = new Meteor.EnvironmentVariable();
  975. const getUserId = CollectionHooks.getUserId;
  976. CollectionHooks.getUserId = () => {
  977. return fakeUserId.get() || getUserId();
  978. };
  979. if (!isSandstorm) {
  980. Users.after.insert((userId, doc) => {
  981. const fakeUser = {
  982. extendAutoValueContext: {
  983. userId: doc._id,
  984. },
  985. };
  986. fakeUserId.withValue(doc._id, () => {
  987. /*
  988. // Insert the Welcome Board
  989. Boards.insert({
  990. title: TAPi18n.__('welcome-board'),
  991. permission: 'private',
  992. }, fakeUser, (err, boardId) => {
  993. Swimlanes.insert({
  994. title: TAPi18n.__('welcome-swimlane'),
  995. boardId,
  996. sort: 1,
  997. }, fakeUser);
  998. ['welcome-list1', 'welcome-list2'].forEach((title, titleIndex) => {
  999. Lists.insert({title: TAPi18n.__(title), boardId, sort: titleIndex}, fakeUser);
  1000. });
  1001. });
  1002. */
  1003. Boards.insert(
  1004. {
  1005. title: TAPi18n.__('templates'),
  1006. permission: 'private',
  1007. type: 'template-container',
  1008. },
  1009. fakeUser,
  1010. (err, boardId) => {
  1011. // Insert the reference to our templates board
  1012. Users.update(fakeUserId.get(), {
  1013. $set: { 'profile.templatesBoardId': boardId },
  1014. });
  1015. // Insert the card templates swimlane
  1016. Swimlanes.insert(
  1017. {
  1018. title: TAPi18n.__('card-templates-swimlane'),
  1019. boardId,
  1020. sort: 1,
  1021. type: 'template-container',
  1022. },
  1023. fakeUser,
  1024. (err, swimlaneId) => {
  1025. // Insert the reference to out card templates swimlane
  1026. Users.update(fakeUserId.get(), {
  1027. $set: { 'profile.cardTemplatesSwimlaneId': swimlaneId },
  1028. });
  1029. },
  1030. );
  1031. // Insert the list templates swimlane
  1032. Swimlanes.insert(
  1033. {
  1034. title: TAPi18n.__('list-templates-swimlane'),
  1035. boardId,
  1036. sort: 2,
  1037. type: 'template-container',
  1038. },
  1039. fakeUser,
  1040. (err, swimlaneId) => {
  1041. // Insert the reference to out list templates swimlane
  1042. Users.update(fakeUserId.get(), {
  1043. $set: { 'profile.listTemplatesSwimlaneId': swimlaneId },
  1044. });
  1045. },
  1046. );
  1047. // Insert the board templates swimlane
  1048. Swimlanes.insert(
  1049. {
  1050. title: TAPi18n.__('board-templates-swimlane'),
  1051. boardId,
  1052. sort: 3,
  1053. type: 'template-container',
  1054. },
  1055. fakeUser,
  1056. (err, swimlaneId) => {
  1057. // Insert the reference to out board templates swimlane
  1058. Users.update(fakeUserId.get(), {
  1059. $set: { 'profile.boardTemplatesSwimlaneId': swimlaneId },
  1060. });
  1061. },
  1062. );
  1063. },
  1064. );
  1065. });
  1066. });
  1067. }
  1068. Users.after.insert((userId, doc) => {
  1069. if (doc.createdThroughApi) {
  1070. // The admin user should be able to create a user despite disabling registration because
  1071. // it is two different things (registration and creation).
  1072. // So, when a new user is created via the api (only admin user can do that) one must avoid
  1073. // the disableRegistration check.
  1074. // Issue : https://github.com/wekan/wekan/issues/1232
  1075. // PR : https://github.com/wekan/wekan/pull/1251
  1076. Users.update(doc._id, { $set: { createdThroughApi: '' } });
  1077. return;
  1078. }
  1079. //invite user to corresponding boards
  1080. const disableRegistration = Settings.findOne().disableRegistration;
  1081. // If ldap, bypass the inviation code if the self registration isn't allowed.
  1082. // TODO : pay attention if ldap field in the user model change to another content ex : ldap field to connection_type
  1083. if (doc.authenticationMethod !== 'ldap' && disableRegistration) {
  1084. const invitationCode = InvitationCodes.findOne({
  1085. code: doc.profile.icode,
  1086. valid: true,
  1087. });
  1088. if (!invitationCode) {
  1089. throw new Meteor.Error('error-invitation-code-not-exist');
  1090. } else {
  1091. invitationCode.boardsToBeInvited.forEach(boardId => {
  1092. const board = Boards.findOne(boardId);
  1093. board.addMember(doc._id);
  1094. });
  1095. if (!doc.profile) {
  1096. doc.profile = {};
  1097. }
  1098. doc.profile.invitedBoards = invitationCode.boardsToBeInvited;
  1099. Users.update(doc._id, { $set: { profile: doc.profile } });
  1100. InvitationCodes.update(invitationCode._id, { $set: { valid: false } });
  1101. }
  1102. }
  1103. });
  1104. }
  1105. // USERS REST API
  1106. if (Meteor.isServer) {
  1107. // Middleware which checks that API is enabled.
  1108. JsonRoutes.Middleware.use(function(req, res, next) {
  1109. const api = req.url.startsWith('/api');
  1110. if ((api === true && process.env.WITH_API === 'true') || api === false) {
  1111. return next();
  1112. } else {
  1113. res.writeHead(301, { Location: '/' });
  1114. return res.end();
  1115. }
  1116. });
  1117. /**
  1118. * @operation get_current_user
  1119. *
  1120. * @summary returns the current user
  1121. * @return_type Users
  1122. */
  1123. JsonRoutes.add('GET', '/api/user', function(req, res) {
  1124. try {
  1125. Authentication.checkLoggedIn(req.userId);
  1126. const data = Meteor.users.findOne({ _id: req.userId });
  1127. delete data.services;
  1128. JsonRoutes.sendResult(res, {
  1129. code: 200,
  1130. data,
  1131. });
  1132. } catch (error) {
  1133. JsonRoutes.sendResult(res, {
  1134. code: 200,
  1135. data: error,
  1136. });
  1137. }
  1138. });
  1139. /**
  1140. * @operation get_all_users
  1141. *
  1142. * @summary return all the users
  1143. *
  1144. * @description Only the admin user (the first user) can call the REST API.
  1145. * @return_type [{ _id: string,
  1146. * username: string}]
  1147. */
  1148. JsonRoutes.add('GET', '/api/users', function(req, res) {
  1149. try {
  1150. Authentication.checkUserId(req.userId);
  1151. JsonRoutes.sendResult(res, {
  1152. code: 200,
  1153. data: Meteor.users.find({}).map(function(doc) {
  1154. return { _id: doc._id, username: doc.username };
  1155. }),
  1156. });
  1157. } catch (error) {
  1158. JsonRoutes.sendResult(res, {
  1159. code: 200,
  1160. data: error,
  1161. });
  1162. }
  1163. });
  1164. /**
  1165. * @operation get_user
  1166. *
  1167. * @summary get a given user
  1168. *
  1169. * @description Only the admin user (the first user) can call the REST API.
  1170. *
  1171. * @param {string} userId the user ID
  1172. * @return_type Users
  1173. */
  1174. JsonRoutes.add('GET', '/api/users/:userId', function(req, res) {
  1175. try {
  1176. Authentication.checkUserId(req.userId);
  1177. const id = req.params.userId;
  1178. JsonRoutes.sendResult(res, {
  1179. code: 200,
  1180. data: Meteor.users.findOne({ _id: id }),
  1181. });
  1182. } catch (error) {
  1183. JsonRoutes.sendResult(res, {
  1184. code: 200,
  1185. data: error,
  1186. });
  1187. }
  1188. });
  1189. /**
  1190. * @operation edit_user
  1191. *
  1192. * @summary edit a given user
  1193. *
  1194. * @description Only the admin user (the first user) can call the REST API.
  1195. *
  1196. * Possible values for *action*:
  1197. * - `takeOwnership`: The admin takes the ownership of ALL boards of the user (archived and not archived) where the user is admin on.
  1198. * - `disableLogin`: Disable a user (the user is not allowed to login and his login tokens are purged)
  1199. * - `enableLogin`: Enable a user
  1200. *
  1201. * @param {string} userId the user ID
  1202. * @param {string} action the action
  1203. * @return_type {_id: string,
  1204. * title: string}
  1205. */
  1206. JsonRoutes.add('PUT', '/api/users/:userId', function(req, res) {
  1207. try {
  1208. Authentication.checkUserId(req.userId);
  1209. const id = req.params.userId;
  1210. const action = req.body.action;
  1211. let data = Meteor.users.findOne({ _id: id });
  1212. if (data !== undefined) {
  1213. if (action === 'takeOwnership') {
  1214. data = Boards.find(
  1215. {
  1216. 'members.userId': id,
  1217. 'members.isAdmin': true,
  1218. },
  1219. { sort: { sort: 1 /* boards default sorting */ } },
  1220. ).map(function(board) {
  1221. if (board.hasMember(req.userId)) {
  1222. board.removeMember(req.userId);
  1223. }
  1224. board.changeOwnership(id, req.userId);
  1225. return {
  1226. _id: board._id,
  1227. title: board.title,
  1228. };
  1229. });
  1230. } else {
  1231. if (action === 'disableLogin' && id !== req.userId) {
  1232. Users.update(
  1233. { _id: id },
  1234. {
  1235. $set: {
  1236. loginDisabled: true,
  1237. 'services.resume.loginTokens': '',
  1238. },
  1239. },
  1240. );
  1241. } else if (action === 'enableLogin') {
  1242. Users.update({ _id: id }, { $set: { loginDisabled: '' } });
  1243. }
  1244. data = Meteor.users.findOne({ _id: id });
  1245. }
  1246. }
  1247. JsonRoutes.sendResult(res, {
  1248. code: 200,
  1249. data,
  1250. });
  1251. } catch (error) {
  1252. JsonRoutes.sendResult(res, {
  1253. code: 200,
  1254. data: error,
  1255. });
  1256. }
  1257. });
  1258. /**
  1259. * @operation add_board_member
  1260. * @tag Boards
  1261. *
  1262. * @summary Add New Board Member with Role
  1263. *
  1264. * @description Only the admin user (the first user) can call the REST API.
  1265. *
  1266. * **Note**: see [Boards.set_board_member_permission](#set_board_member_permission)
  1267. * to later change the permissions.
  1268. *
  1269. * @param {string} boardId the board ID
  1270. * @param {string} userId the user ID
  1271. * @param {boolean} isAdmin is the user an admin of the board
  1272. * @param {boolean} isNoComments disable comments
  1273. * @param {boolean} isCommentOnly only enable comments
  1274. * @return_type {_id: string,
  1275. * title: string}
  1276. */
  1277. JsonRoutes.add('POST', '/api/boards/:boardId/members/:userId/add', function(
  1278. req,
  1279. res,
  1280. ) {
  1281. try {
  1282. Authentication.checkUserId(req.userId);
  1283. const userId = req.params.userId;
  1284. const boardId = req.params.boardId;
  1285. const action = req.body.action;
  1286. const { isAdmin, isNoComments, isCommentOnly } = req.body;
  1287. let data = Meteor.users.findOne({ _id: userId });
  1288. if (data !== undefined) {
  1289. if (action === 'add') {
  1290. data = Boards.find({
  1291. _id: boardId,
  1292. }).map(function(board) {
  1293. if (!board.hasMember(userId)) {
  1294. board.addMember(userId);
  1295. function isTrue(data) {
  1296. return data.toLowerCase() === 'true';
  1297. }
  1298. board.setMemberPermission(
  1299. userId,
  1300. isTrue(isAdmin),
  1301. isTrue(isNoComments),
  1302. isTrue(isCommentOnly),
  1303. userId,
  1304. );
  1305. }
  1306. return {
  1307. _id: board._id,
  1308. title: board.title,
  1309. };
  1310. });
  1311. }
  1312. }
  1313. JsonRoutes.sendResult(res, {
  1314. code: 200,
  1315. data: query,
  1316. });
  1317. } catch (error) {
  1318. JsonRoutes.sendResult(res, {
  1319. code: 200,
  1320. data: error,
  1321. });
  1322. }
  1323. });
  1324. /**
  1325. * @operation remove_board_member
  1326. * @tag Boards
  1327. *
  1328. * @summary Remove Member from Board
  1329. *
  1330. * @description Only the admin user (the first user) can call the REST API.
  1331. *
  1332. * @param {string} boardId the board ID
  1333. * @param {string} userId the user ID
  1334. * @param {string} action the action (needs to be `remove`)
  1335. * @return_type {_id: string,
  1336. * title: string}
  1337. */
  1338. JsonRoutes.add(
  1339. 'POST',
  1340. '/api/boards/:boardId/members/:userId/remove',
  1341. function(req, res) {
  1342. try {
  1343. Authentication.checkUserId(req.userId);
  1344. const userId = req.params.userId;
  1345. const boardId = req.params.boardId;
  1346. const action = req.body.action;
  1347. let data = Meteor.users.findOne({ _id: userId });
  1348. if (data !== undefined) {
  1349. if (action === 'remove') {
  1350. data = Boards.find({
  1351. _id: boardId,
  1352. }).map(function(board) {
  1353. if (board.hasMember(userId)) {
  1354. board.removeMember(userId);
  1355. }
  1356. return {
  1357. _id: board._id,
  1358. title: board.title,
  1359. };
  1360. });
  1361. }
  1362. }
  1363. JsonRoutes.sendResult(res, {
  1364. code: 200,
  1365. data: query,
  1366. });
  1367. } catch (error) {
  1368. JsonRoutes.sendResult(res, {
  1369. code: 200,
  1370. data: error,
  1371. });
  1372. }
  1373. },
  1374. );
  1375. /**
  1376. * @operation new_user
  1377. *
  1378. * @summary Create a new user
  1379. *
  1380. * @description Only the admin user (the first user) can call the REST API.
  1381. *
  1382. * @param {string} username the new username
  1383. * @param {string} email the email of the new user
  1384. * @param {string} password the password of the new user
  1385. * @return_type {_id: string}
  1386. */
  1387. JsonRoutes.add('POST', '/api/users/', function(req, res) {
  1388. try {
  1389. Authentication.checkUserId(req.userId);
  1390. const id = Accounts.createUser({
  1391. username: req.body.username,
  1392. email: req.body.email,
  1393. password: req.body.password,
  1394. from: 'admin',
  1395. });
  1396. JsonRoutes.sendResult(res, {
  1397. code: 200,
  1398. data: {
  1399. _id: id,
  1400. },
  1401. });
  1402. } catch (error) {
  1403. JsonRoutes.sendResult(res, {
  1404. code: 200,
  1405. data: error,
  1406. });
  1407. }
  1408. });
  1409. /**
  1410. * @operation delete_user
  1411. *
  1412. * @summary Delete a user
  1413. *
  1414. * @description Only the admin user (the first user) can call the REST API.
  1415. *
  1416. * @param {string} userId the ID of the user to delete
  1417. * @return_type {_id: string}
  1418. */
  1419. JsonRoutes.add('DELETE', '/api/users/:userId', function(req, res) {
  1420. try {
  1421. Authentication.checkUserId(req.userId);
  1422. const id = req.params.userId;
  1423. Meteor.users.remove({ _id: id });
  1424. JsonRoutes.sendResult(res, {
  1425. code: 200,
  1426. data: {
  1427. _id: id,
  1428. },
  1429. });
  1430. } catch (error) {
  1431. JsonRoutes.sendResult(res, {
  1432. code: 200,
  1433. data: error,
  1434. });
  1435. }
  1436. });
  1437. }
  1438. export default Users;