User.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* eslint-disable
  2. max-len,
  3. no-unused-vars,
  4. */
  5. // TODO: This file was created by bulk-decaffeinate.
  6. // Fix any style issues and re-enable lint.
  7. const { Project } = require('./Project')
  8. const Settings = require('settings-sharelatex')
  9. const _ = require('underscore')
  10. const mongoose = require('mongoose')
  11. const uuid = require('uuid')
  12. const { Schema } = mongoose
  13. const { ObjectId } = Schema
  14. // See https://stackoverflow.com/questions/386294/what-is-the-maximum-length-of-a-valid-email-address/574698#574698
  15. const MAX_EMAIL_LENGTH = 254
  16. const UserSchema = new Schema({
  17. email: { type: String, default: '', maxlength: MAX_EMAIL_LENGTH },
  18. emails: [
  19. {
  20. email: { type: String, default: '', maxlength: MAX_EMAIL_LENGTH },
  21. reversedHostname: { type: String, default: '' },
  22. createdAt: {
  23. type: Date,
  24. default() {
  25. return new Date()
  26. }
  27. },
  28. confirmedAt: { type: Date }
  29. }
  30. ],
  31. first_name: { type: String, default: '' },
  32. last_name: { type: String, default: '' },
  33. role: { type: String, default: '' },
  34. institution: { type: String, default: '' },
  35. hashedPassword: String,
  36. isAdmin: { type: Boolean, default: false },
  37. staffAccess: {
  38. publisherMetrics: { type: Boolean, default: false },
  39. publisherManagement: { type: Boolean, default: false },
  40. institutionMetrics: { type: Boolean, default: false },
  41. institutionManagement: { type: Boolean, default: false },
  42. groupMetrics: { type: Boolean, default: false },
  43. groupManagement: { type: Boolean, default: false }
  44. },
  45. signUpDate: {
  46. type: Date,
  47. default() {
  48. return new Date()
  49. }
  50. },
  51. lastLoggedIn: { type: Date },
  52. lastLoginIp: { type: String, default: '' },
  53. loginCount: { type: Number, default: 0 },
  54. holdingAccount: { type: Boolean, default: false },
  55. ace: {
  56. mode: { type: String, default: 'none' },
  57. theme: { type: String, default: 'textmate' },
  58. overallTheme: { type: String, default: '' },
  59. fontSize: { type: Number, default: '12' },
  60. autoComplete: { type: Boolean, default: true },
  61. autoPairDelimiters: { type: Boolean, default: true },
  62. spellCheckLanguage: { type: String, default: 'en' },
  63. pdfViewer: { type: String, default: 'pdfjs' },
  64. syntaxValidation: { type: Boolean },
  65. fontFamily: { type: String },
  66. lineHeight: { type: String }
  67. },
  68. features: {
  69. collaborators: {
  70. type: Number,
  71. default: Settings.defaultFeatures.collaborators
  72. },
  73. versioning: { type: Boolean, default: Settings.defaultFeatures.versioning },
  74. dropbox: { type: Boolean, default: Settings.defaultFeatures.dropbox },
  75. github: { type: Boolean, default: Settings.defaultFeatures.github },
  76. gitBridge: { type: Boolean, default: Settings.defaultFeatures.gitBridge },
  77. compileTimeout: {
  78. type: Number,
  79. default: Settings.defaultFeatures.compileTimeout
  80. },
  81. compileGroup: {
  82. type: String,
  83. default: Settings.defaultFeatures.compileGroup
  84. },
  85. templates: { type: Boolean, default: Settings.defaultFeatures.templates },
  86. references: { type: Boolean, default: Settings.defaultFeatures.references },
  87. trackChanges: {
  88. type: Boolean,
  89. default: Settings.defaultFeatures.trackChanges
  90. },
  91. mendeley: { type: Boolean, default: Settings.defaultFeatures.mendeley },
  92. zotero: { type: Boolean, default: Settings.defaultFeatures.zotero },
  93. referencesSearch: {
  94. type: Boolean,
  95. default: Settings.defaultFeatures.referencesSearch
  96. }
  97. },
  98. // when auto-merged from SL and must-reconfirm is set, we may end up using
  99. // `sharelatexHashedPassword` to recover accounts...
  100. sharelatexHashedPassword: String,
  101. must_reconfirm: { type: Boolean, default: false },
  102. referal_id: {
  103. type: String,
  104. default() {
  105. return uuid.v4().split('-')[0]
  106. }
  107. },
  108. refered_users: [{ type: ObjectId, ref: 'User' }],
  109. refered_user_count: { type: Number, default: 0 },
  110. refProviders: {
  111. mendeley: Boolean, // coerce the refProviders values to Booleans
  112. zotero: Boolean
  113. },
  114. betaProgram: { type: Boolean, default: false },
  115. overleaf: {
  116. id: { type: Number },
  117. accessToken: { type: String },
  118. refreshToken: { type: String }
  119. },
  120. awareOfV2: { type: Boolean, default: false },
  121. thirdPartyIdentifiers: { type: Array, default: [] },
  122. migratedAt: { type: Date }
  123. })
  124. const conn = mongoose.createConnection(Settings.mongo.url, {
  125. server: { poolSize: Settings.mongo.poolSize || 10 },
  126. config: { autoIndex: false }
  127. })
  128. const User = conn.model('User', UserSchema)
  129. const model = mongoose.model('User', UserSchema)
  130. exports.User = User