User.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903
  1. const request = require('./request')
  2. const settings = require('@overleaf/settings')
  3. const { db, ObjectId } = require('../../../../app/src/infrastructure/mongodb')
  4. const UserModel = require('../../../../app/src/models/User').User
  5. const UserUpdater = require('../../../../app/src/Features/User/UserUpdater')
  6. const AuthenticationManager = require('../../../../app/src/Features/Authentication/AuthenticationManager')
  7. const { promisify } = require('util')
  8. const fs = require('fs')
  9. const Path = require('path')
  10. let count = settings.test.counterInit
  11. class User {
  12. constructor(options) {
  13. if (options == null) {
  14. options = {}
  15. }
  16. this.emails = [
  17. {
  18. email: options.email || `acceptance-test-${count}@example.com`,
  19. createdAt: new Date(),
  20. },
  21. ]
  22. this.email = this.emails[0].email
  23. this.password = `a-terrible-secret-${count}`
  24. count++
  25. this.jar = request.jar()
  26. this.request = request.defaults({
  27. jar: this.jar,
  28. })
  29. }
  30. setExtraAttributes(user) {
  31. if ((user != null ? user._id : undefined) == null) {
  32. throw new Error('User does not exist')
  33. }
  34. this.id = user._id.toString()
  35. this._id = user._id.toString()
  36. this.first_name = user.first_name
  37. this.referal_id = user.referal_id
  38. }
  39. get(callback) {
  40. db.users.findOne({ _id: ObjectId(this._id) }, callback)
  41. }
  42. getAuditLog(callback) {
  43. this.get((error, user) => {
  44. if (error) return callback(error)
  45. if (!user) return callback(new Error('User not found'))
  46. db.userAuditLogEntries
  47. .find({ userId: ObjectId(this._id) })
  48. .toArray((error, auditLog) => {
  49. if (error) return callback(error)
  50. callback(null, auditLog || [])
  51. })
  52. })
  53. }
  54. getAuditLogWithoutNoise(callback) {
  55. this.getAuditLog((error, auditLog) => {
  56. if (error) return callback(error)
  57. callback(
  58. null,
  59. auditLog.filter(entry => {
  60. return entry.operation !== 'login'
  61. })
  62. )
  63. })
  64. }
  65. mongoUpdate(updateOp, callback) {
  66. db.users.updateOne({ _id: ObjectId(this._id) }, updateOp, callback)
  67. }
  68. register(callback) {
  69. this.registerWithQuery('', callback)
  70. }
  71. registerWithQuery(query, callback) {
  72. if (this._id != null) {
  73. return callback(new Error('User already registered'))
  74. }
  75. this.getCsrfToken(error => {
  76. if (error != null) {
  77. return callback(error)
  78. }
  79. this.request.post(
  80. {
  81. url: `/register${query}`,
  82. json: { email: this.email, password: this.password },
  83. },
  84. (error, response, body) => {
  85. if (error != null) {
  86. return callback(error)
  87. }
  88. db.users.findOne({ email: this.email }, (error, user) => {
  89. if (error != null) {
  90. return callback(error)
  91. }
  92. this.setExtraAttributes(user)
  93. callback(null, user)
  94. })
  95. }
  96. )
  97. })
  98. }
  99. login(callback) {
  100. this.loginWith(this.email, callback)
  101. }
  102. loginWith(email, callback) {
  103. this.ensureUserExists(error => {
  104. if (error != null) {
  105. return callback(error)
  106. }
  107. this.loginWithEmailPassword(email, this.password, callback)
  108. })
  109. }
  110. loginNoUpdate(callback) {
  111. this.loginWithEmailPassword(this.email, this.password, callback)
  112. }
  113. loginWithEmailPassword(email, password, callback) {
  114. this.getCsrfToken(error => {
  115. if (error != null) {
  116. return callback(error)
  117. }
  118. this.request.post(
  119. {
  120. url: settings.enableLegacyLogin ? '/login/legacy' : '/login',
  121. json: {
  122. email,
  123. password,
  124. 'g-recaptcha-response': 'valid',
  125. },
  126. },
  127. (error, response, body) => {
  128. if (error != null) {
  129. return callback(error)
  130. }
  131. // get new csrf token, then return result of login
  132. this.getCsrfToken(err => {
  133. if (err) {
  134. return callback(err)
  135. }
  136. callback(null, response, body)
  137. })
  138. }
  139. )
  140. })
  141. }
  142. ensureUserExists(callback) {
  143. const filter = { email: this.email }
  144. const options = { upsert: true, new: true, setDefaultsOnInsert: true }
  145. AuthenticationManager.hashPassword(
  146. this.password,
  147. (error, hashedPassword) => {
  148. if (error != null) {
  149. return callback(error)
  150. }
  151. UserModel.findOneAndUpdate(
  152. filter,
  153. { $set: { hashedPassword, emails: this.emails } },
  154. options,
  155. (error, user) => {
  156. if (error != null) {
  157. return callback(error)
  158. }
  159. this.setExtraAttributes(user)
  160. callback(null, this.password)
  161. }
  162. )
  163. }
  164. )
  165. }
  166. setFeatures(features, callback) {
  167. const update = {}
  168. for (const key in features) {
  169. const value = features[key]
  170. update[`features.${key}`] = value
  171. }
  172. UserModel.updateOne({ _id: this.id }, update, callback)
  173. }
  174. setFeaturesOverride(featuresOverride, callback) {
  175. const update = { $push: { featuresOverrides: featuresOverride } }
  176. UserModel.updateOne({ _id: this.id }, update, callback)
  177. }
  178. setOverleafId(overleafId, callback) {
  179. UserModel.updateOne(
  180. { _id: this.id },
  181. { 'overleaf.id': overleafId },
  182. callback
  183. )
  184. }
  185. logout(callback) {
  186. this.getCsrfToken(error => {
  187. if (error != null) {
  188. return callback(error)
  189. }
  190. this.request.post(
  191. {
  192. url: '/logout',
  193. json: {
  194. email: this.email,
  195. password: this.password,
  196. },
  197. },
  198. (error, response, body) => {
  199. if (error != null) {
  200. return callback(error)
  201. }
  202. db.users.findOne({ email: this.email }, (error, user) => {
  203. if (error != null) {
  204. return callback(error)
  205. }
  206. if (user == null) {
  207. return callback()
  208. }
  209. this.id = user._id.toString()
  210. this._id = user._id.toString()
  211. callback()
  212. })
  213. }
  214. )
  215. })
  216. }
  217. addEmail(email, callback) {
  218. this.emails.push({ email, createdAt: new Date() })
  219. UserUpdater.addEmailAddress(
  220. this.id,
  221. email,
  222. {},
  223. { initiatorId: this._id, ipAddress: '127:0:0:0' },
  224. callback
  225. )
  226. }
  227. confirmEmail(email, callback) {
  228. for (let idx = 0; idx < this.emails.length; idx++) {
  229. const emailData = this.emails[idx]
  230. if (emailData.email === email) {
  231. this.emails[idx].confirmedAt = new Date()
  232. }
  233. }
  234. UserUpdater.confirmEmail(this.id, email, callback)
  235. }
  236. ensureAdmin(callback) {
  237. this.mongoUpdate({ $set: { isAdmin: true } }, callback)
  238. }
  239. ensureStaffAccess(flag, callback) {
  240. const update = { $set: {} }
  241. update.$set[`staffAccess.${flag}`] = true
  242. this.mongoUpdate(update, callback)
  243. }
  244. upgradeFeatures(callback) {
  245. const features = {
  246. collaborators: -1, // Infinite
  247. versioning: true,
  248. dropbox: true,
  249. compileTimeout: 60,
  250. compileGroup: 'priority',
  251. templates: true,
  252. references: true,
  253. trackChanges: true,
  254. trackChangesVisible: true,
  255. }
  256. this.mongoUpdate({ $set: { features } }, callback)
  257. }
  258. downgradeFeatures(callback) {
  259. const features = {
  260. collaborators: 1,
  261. versioning: false,
  262. dropbox: false,
  263. compileTimeout: 60,
  264. compileGroup: 'standard',
  265. templates: false,
  266. references: false,
  267. trackChanges: false,
  268. trackChangesVisible: false,
  269. }
  270. this.mongoUpdate({ $set: { features } }, callback)
  271. }
  272. defaultFeatures(callback) {
  273. const features = settings.defaultFeatures
  274. this.mongoUpdate({ $set: { features } }, callback)
  275. }
  276. getFeatures(callback) {
  277. db.users.findOne(
  278. { _id: ObjectId(this.id) },
  279. { projection: { features: 1 } },
  280. (error, user) => callback(error, user && user.features)
  281. )
  282. }
  283. fullDeleteUser(email, callback) {
  284. db.users.findOne({ email }, (error, user) => {
  285. if (error != null) {
  286. return callback(error)
  287. }
  288. if (user == null) {
  289. return callback()
  290. }
  291. const userId = user._id
  292. db.projects.deleteMany({ owner_ref: ObjectId(userId) }, err => {
  293. if (err != null) {
  294. callback(err)
  295. }
  296. db.users.deleteOne({ _id: ObjectId(userId) }, callback)
  297. })
  298. })
  299. }
  300. deleteUser(callback) {
  301. this.getCsrfToken(error => {
  302. if (error) {
  303. return callback(error)
  304. }
  305. this.request.post(
  306. {
  307. url: '/user/delete',
  308. json: { password: this.password },
  309. },
  310. (err, res) => {
  311. if (err) {
  312. return callback(err)
  313. }
  314. if (res.statusCode < 200 || res.statusCode >= 300) {
  315. return callback(
  316. new Error('Error received from API: ' + res.statusCode)
  317. )
  318. }
  319. callback()
  320. }
  321. )
  322. })
  323. }
  324. getProject(projectId, callback) {
  325. db.projects.findOne({ _id: ObjectId(projectId.toString()) }, callback)
  326. }
  327. saveProject(project, callback) {
  328. db.projects.updateOne({ _id: project._id }, { $set: project }, callback)
  329. }
  330. createProject(name, options, callback) {
  331. if (typeof options === 'function') {
  332. callback = options
  333. options = {}
  334. }
  335. this.request.post(
  336. {
  337. url: '/project/new',
  338. json: Object.assign({ projectName: name }, options),
  339. },
  340. (error, response, body) => {
  341. if (error != null) {
  342. return callback(error)
  343. }
  344. if ((body != null ? body.project_id : undefined) == null) {
  345. error = new Error(
  346. JSON.stringify([
  347. 'SOMETHING WENT WRONG CREATING PROJECT',
  348. name,
  349. options,
  350. response.statusCode,
  351. response.headers.location,
  352. body,
  353. ])
  354. )
  355. callback(error)
  356. } else {
  357. callback(null, body.project_id)
  358. }
  359. }
  360. )
  361. }
  362. deleteProject(projectId, callback) {
  363. this.request.delete(
  364. {
  365. url: `/project/${projectId}`,
  366. },
  367. (error, response, body) => {
  368. if (error != null) {
  369. return callback(error)
  370. }
  371. callback(null)
  372. }
  373. )
  374. }
  375. undeleteProject(projectId, callback) {
  376. this.request.post(
  377. {
  378. url: `/admin/project/${projectId}/undelete`,
  379. },
  380. (error, response) => {
  381. if (error) {
  382. return callback(error)
  383. }
  384. if (response.statusCode !== 204) {
  385. return callback(
  386. new Error(
  387. `Non-success response when undeleting project: ${response.statusCode}`
  388. )
  389. )
  390. }
  391. callback(null)
  392. }
  393. )
  394. }
  395. deleteProjects(callback) {
  396. db.projects.deleteMany({ owner_ref: ObjectId(this.id) }, callback)
  397. }
  398. openProject(projectId, callback) {
  399. this.request.get(
  400. {
  401. url: `/project/${projectId}`,
  402. },
  403. (error, response, body) => {
  404. if (error != null) {
  405. return callback(error)
  406. }
  407. if (response.statusCode !== 200) {
  408. const err = new Error(
  409. `Non-success response when opening project: ${response.statusCode}`
  410. )
  411. return callback(err)
  412. }
  413. callback(null)
  414. }
  415. )
  416. }
  417. createDocInProject(projectId, parentFolderId, name, callback) {
  418. this.getCsrfToken(error => {
  419. if (error != null) {
  420. return callback(error)
  421. }
  422. this.request.post(
  423. {
  424. url: `/project/${projectId}/doc`,
  425. json: {
  426. name,
  427. parentFolderId,
  428. },
  429. },
  430. (error, response, body) => {
  431. if (error != null) {
  432. return callback(error)
  433. }
  434. callback(null, body._id)
  435. }
  436. )
  437. })
  438. }
  439. uploadFileInProject(projectId, folderId, file, name, contentType, callback) {
  440. const imageFile = fs.createReadStream(
  441. Path.resolve(Path.join(__dirname, '..', '..', 'files', file))
  442. )
  443. this.request.post(
  444. {
  445. uri: `project/${projectId}/upload`,
  446. qs: {
  447. folder_id: String(folderId),
  448. },
  449. formData: {
  450. qqfile: {
  451. value: imageFile,
  452. options: {
  453. filename: name,
  454. contentType,
  455. },
  456. },
  457. },
  458. },
  459. (error, res, body) => {
  460. if (error) {
  461. return callback(error)
  462. }
  463. if (res.statusCode < 200 || res.statusCode >= 300) {
  464. return callback(new Error(`failed to upload file ${res.statusCode}`))
  465. }
  466. callback(null, JSON.parse(body).entity_id)
  467. }
  468. )
  469. }
  470. uploadExampleFileInProject(projectId, folderId, name, callback) {
  471. this.uploadFileInProject(
  472. projectId,
  473. folderId,
  474. '1pixel.png',
  475. name,
  476. 'image/png',
  477. callback
  478. )
  479. }
  480. moveItemInProject(projectId, type, itemId, folderId, callback) {
  481. this.request.post(
  482. {
  483. uri: `project/${projectId}/${type}/${itemId}/move`,
  484. json: {
  485. folder_id: folderId,
  486. },
  487. },
  488. (error, res) => {
  489. if (error) {
  490. return callback(error)
  491. }
  492. if (res.statusCode < 200 || res.statusCode >= 300) {
  493. return callback(new Error(`failed to move ${type} ${res.statusCode}`))
  494. }
  495. callback()
  496. }
  497. )
  498. }
  499. renameItemInProject(projectId, type, itemId, name, callback) {
  500. this.request.post(
  501. {
  502. uri: `project/${projectId}/${type}/${itemId}/rename`,
  503. json: {
  504. name,
  505. },
  506. },
  507. (error, res) => {
  508. if (error) {
  509. return callback(error)
  510. }
  511. if (res.statusCode < 200 || res.statusCode >= 300) {
  512. return callback(
  513. new Error(`failed to rename ${type} ${res.statusCode}`)
  514. )
  515. }
  516. callback()
  517. }
  518. )
  519. }
  520. deleteItemInProject(projectId, type, itemId, callback) {
  521. this.request.delete(
  522. `project/${projectId}/${type}/${itemId}`,
  523. (error, res) => {
  524. if (error) {
  525. return callback(error)
  526. }
  527. if (res.statusCode < 200 || res.statusCode >= 300) {
  528. return callback(
  529. new Error(`failed to delete ${type} ${res.statusCode}`)
  530. )
  531. }
  532. callback()
  533. }
  534. )
  535. }
  536. joinProject(projectId, callback) {
  537. this.request.post(
  538. {
  539. url: `/project/${projectId}/join`,
  540. qs: { user_id: this._id },
  541. auth: {
  542. user: settings.apis.web.user,
  543. pass: settings.apis.web.pass,
  544. sendImmediately: true,
  545. },
  546. json: true,
  547. jar: false,
  548. },
  549. (error, res, body) => {
  550. if (error) {
  551. return callback(error)
  552. }
  553. if (res.statusCode < 200 || res.statusCode >= 300) {
  554. return callback(
  555. new Error(`failed to join project ${projectId} ${res.statusCode}`)
  556. )
  557. }
  558. callback(null, body)
  559. }
  560. )
  561. }
  562. addUserToProject(projectId, user, privileges, callback) {
  563. let updateOp
  564. if (privileges === 'readAndWrite') {
  565. updateOp = { $addToSet: { collaberator_refs: user._id } }
  566. } else if (privileges === 'readOnly') {
  567. updateOp = { $addToSet: { readOnly_refs: user._id } }
  568. }
  569. db.projects.updateOne({ _id: ObjectId(projectId) }, updateOp, callback)
  570. }
  571. makePublic(projectId, level, callback) {
  572. this.request.post(
  573. {
  574. url: `/project/${projectId}/settings/admin`,
  575. json: {
  576. publicAccessLevel: level,
  577. },
  578. },
  579. (error, response, body) => {
  580. if (error != null) {
  581. return callback(error)
  582. }
  583. callback(null)
  584. }
  585. )
  586. }
  587. makePrivate(projectId, callback) {
  588. this.request.post(
  589. {
  590. url: `/project/${projectId}/settings/admin`,
  591. json: {
  592. publicAccessLevel: 'private',
  593. },
  594. },
  595. (error, response, body) => {
  596. if (error != null) {
  597. return callback(error)
  598. }
  599. callback(null)
  600. }
  601. )
  602. }
  603. makeTokenBased(projectId, callback) {
  604. this.request.post(
  605. {
  606. url: `/project/${projectId}/settings/admin`,
  607. json: {
  608. publicAccessLevel: 'tokenBased',
  609. },
  610. },
  611. (error, response, body) => {
  612. if (error != null) {
  613. return callback(error)
  614. }
  615. callback(null)
  616. }
  617. )
  618. }
  619. getCsrfToken(callback) {
  620. this.request.get(
  621. {
  622. url: '/dev/csrf',
  623. },
  624. (err, response, body) => {
  625. if (err != null) {
  626. return callback(err)
  627. }
  628. this.csrfToken = body
  629. this.request = this.request.defaults({
  630. headers: {
  631. 'x-csrf-token': this.csrfToken,
  632. },
  633. })
  634. callback()
  635. }
  636. )
  637. }
  638. changePassword(newPassword, callback) {
  639. this.getCsrfToken(error => {
  640. if (error != null) {
  641. return callback(error)
  642. }
  643. this.request.post(
  644. {
  645. url: '/user/password/update',
  646. json: {
  647. currentPassword: this.password,
  648. newPassword1: newPassword,
  649. newPassword2: newPassword,
  650. },
  651. },
  652. err => {
  653. if (err) {
  654. return callback(err)
  655. }
  656. this.password = newPassword
  657. callback()
  658. }
  659. )
  660. })
  661. }
  662. reconfirmAccountRequest(userEmail, callback) {
  663. this.getCsrfToken(error => {
  664. if (error != null) {
  665. return callback(error)
  666. }
  667. this.request.post(
  668. {
  669. url: '/user/reconfirm',
  670. json: {
  671. email: userEmail,
  672. },
  673. },
  674. (error, response, body) => {
  675. callback(error, response)
  676. }
  677. )
  678. })
  679. }
  680. getUserSettingsPage(callback) {
  681. this.getCsrfToken(error => {
  682. if (error != null) {
  683. return callback(error)
  684. }
  685. this.request.get(
  686. {
  687. url: '/user/settings',
  688. },
  689. (error, response, body) => {
  690. if (error != null) {
  691. return callback(error)
  692. }
  693. callback(null, response.statusCode)
  694. }
  695. )
  696. })
  697. }
  698. updateSettings(newSettings, callback) {
  699. this.getCsrfToken(error => {
  700. if (error != null) {
  701. return callback(error)
  702. }
  703. this.request.post(
  704. {
  705. url: '/user/settings',
  706. json: newSettings,
  707. },
  708. callback
  709. )
  710. })
  711. }
  712. getProjectListPage(callback) {
  713. this.getCsrfToken(error => {
  714. if (error != null) {
  715. return callback(error)
  716. }
  717. this.request.get(
  718. {
  719. url: '/project',
  720. },
  721. (error, response, body) => {
  722. if (error != null) {
  723. return callback(error)
  724. }
  725. callback(null, response.statusCode)
  726. }
  727. )
  728. })
  729. }
  730. isLoggedIn(callback) {
  731. this.request.get('/user/personal_info', (error, response, body) => {
  732. if (error != null) {
  733. return callback(error)
  734. }
  735. if (response.statusCode === 200) {
  736. callback(null, true)
  737. } else if (response.statusCode === 302) {
  738. callback(null, false)
  739. } else {
  740. callback(
  741. new Error(
  742. `unexpected status code from /user/personal_info: ${response.statusCode}`
  743. )
  744. )
  745. }
  746. })
  747. }
  748. transferProjectOwnership(projectId, userId, callback) {
  749. this.getCsrfToken(err => {
  750. if (err != null) {
  751. return callback(err)
  752. }
  753. this.request.post(
  754. {
  755. url: `/project/${projectId.toString()}/transfer-ownership`,
  756. json: {
  757. user_id: userId.toString(),
  758. },
  759. },
  760. (err, response) => {
  761. if (err != null) {
  762. return callback(err)
  763. }
  764. if (response.statusCode !== 204) {
  765. return callback(
  766. new Error(`Unexpected status code: ${response.statusCode}`)
  767. )
  768. }
  769. callback()
  770. }
  771. )
  772. })
  773. }
  774. setV1Id(v1Id, callback) {
  775. UserModel.updateOne(
  776. {
  777. _id: this._id,
  778. },
  779. {
  780. overleaf: {
  781. id: v1Id,
  782. },
  783. },
  784. callback
  785. )
  786. }
  787. setCollaboratorInfo(projectId, userId, info, callback) {
  788. this.getCsrfToken(err => {
  789. if (err != null) {
  790. return callback(err)
  791. }
  792. this.request.put(
  793. {
  794. url: `/project/${projectId.toString()}/users/${userId.toString()}`,
  795. json: info,
  796. },
  797. (err, response) => {
  798. if (err != null) {
  799. return callback(err)
  800. }
  801. if (response.statusCode !== 204) {
  802. return callback(
  803. new Error(`Unexpected status code: ${response.statusCode}`)
  804. )
  805. }
  806. callback()
  807. }
  808. )
  809. })
  810. }
  811. }
  812. User.promises = class extends User {
  813. doRequest(method, params) {
  814. return new Promise((resolve, reject) => {
  815. this.request[method.toLowerCase()](params, (err, response, body) => {
  816. if (err) {
  817. reject(err)
  818. } else {
  819. resolve({ response, body })
  820. }
  821. })
  822. })
  823. }
  824. }
  825. // promisify User class methods - works for methods with 0-1 output parameters,
  826. // otherwise we will need to implement the method manually instead
  827. const nonPromiseMethods = ['constructor', 'setExtraAttributes']
  828. Object.getOwnPropertyNames(User.prototype).forEach(methodName => {
  829. const method = User.prototype[methodName]
  830. if (typeof method === 'function' && !nonPromiseMethods.includes(methodName)) {
  831. User.promises.prototype[methodName] = promisify(method)
  832. }
  833. })
  834. module.exports = User