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