User.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. const Settings = require('@overleaf/settings')
  2. const mongoose = require('../infrastructure/Mongoose')
  3. const TokenGenerator = require('../Features/TokenGenerator/TokenGenerator')
  4. const { Schema } = mongoose
  5. const { ObjectId } = Schema
  6. // See https://stackoverflow.com/questions/386294/what-is-the-maximum-length-of-a-valid-email-address/574698#574698
  7. const MAX_EMAIL_LENGTH = 254
  8. const AuditLogEntrySchema = new Schema({
  9. _id: false,
  10. info: { type: Object },
  11. initiatorId: { type: Schema.Types.ObjectId },
  12. ipAddress: { type: String },
  13. operation: { type: String },
  14. userId: { type: Schema.Types.ObjectId },
  15. timestamp: { type: Date },
  16. })
  17. const UserSchema = new Schema({
  18. email: { type: String, default: '', maxlength: MAX_EMAIL_LENGTH },
  19. emails: [
  20. {
  21. email: { type: String, default: '', maxlength: MAX_EMAIL_LENGTH },
  22. reversedHostname: { type: String, default: '' },
  23. createdAt: {
  24. type: Date,
  25. default() {
  26. return new Date()
  27. },
  28. },
  29. confirmedAt: { type: Date },
  30. samlProviderId: { type: String },
  31. affiliationUnchecked: { type: Boolean },
  32. reconfirmedAt: { type: Date },
  33. },
  34. ],
  35. first_name: { type: String, default: '' },
  36. last_name: { type: String, default: '' },
  37. role: { type: String, default: '' },
  38. institution: { type: String, default: '' },
  39. hashedPassword: String,
  40. isAdmin: { type: Boolean, default: false },
  41. staffAccess: {
  42. publisherMetrics: { type: Boolean, default: false },
  43. publisherManagement: { type: Boolean, default: false },
  44. institutionMetrics: { type: Boolean, default: false },
  45. institutionManagement: { type: Boolean, default: false },
  46. groupMetrics: { type: Boolean, default: false },
  47. groupManagement: { type: Boolean, default: false },
  48. adminMetrics: { type: Boolean, default: false },
  49. },
  50. signUpDate: {
  51. type: Date,
  52. default() {
  53. return new Date()
  54. },
  55. },
  56. lastLoggedIn: { type: Date },
  57. lastLoginIp: { type: String, default: '' },
  58. loginCount: { type: Number, default: 0 },
  59. holdingAccount: { type: Boolean, default: false },
  60. ace: {
  61. mode: { type: String, default: 'none' },
  62. theme: { type: String, default: 'textmate' },
  63. overallTheme: { type: String, default: '' },
  64. fontSize: { type: Number, default: '12' },
  65. autoComplete: { type: Boolean, default: true },
  66. autoPairDelimiters: { type: Boolean, default: true },
  67. spellCheckLanguage: { type: String, default: 'en' },
  68. pdfViewer: { type: String, default: 'pdfjs' },
  69. syntaxValidation: { type: Boolean },
  70. fontFamily: { type: String },
  71. lineHeight: { type: String },
  72. },
  73. features: {
  74. collaborators: {
  75. type: Number,
  76. default: Settings.defaultFeatures.collaborators,
  77. },
  78. versioning: { type: Boolean, default: Settings.defaultFeatures.versioning },
  79. dropbox: { type: Boolean, default: Settings.defaultFeatures.dropbox },
  80. github: { type: Boolean, default: Settings.defaultFeatures.github },
  81. gitBridge: { type: Boolean, default: Settings.defaultFeatures.gitBridge },
  82. compileTimeout: {
  83. type: Number,
  84. default: Settings.defaultFeatures.compileTimeout,
  85. },
  86. compileGroup: {
  87. type: String,
  88. default: Settings.defaultFeatures.compileGroup,
  89. },
  90. templates: { type: Boolean, default: Settings.defaultFeatures.templates },
  91. references: { type: Boolean, default: Settings.defaultFeatures.references },
  92. trackChanges: {
  93. type: Boolean,
  94. default: Settings.defaultFeatures.trackChanges,
  95. },
  96. mendeley: { type: Boolean, default: Settings.defaultFeatures.mendeley },
  97. zotero: { type: Boolean, default: Settings.defaultFeatures.zotero },
  98. referencesSearch: {
  99. type: Boolean,
  100. default: Settings.defaultFeatures.referencesSearch,
  101. },
  102. },
  103. featuresOverrides: [
  104. {
  105. createdAt: {
  106. type: Date,
  107. default() {
  108. return new Date()
  109. },
  110. },
  111. expiresAt: { type: Date },
  112. note: { type: String },
  113. features: {
  114. collaborators: { type: Number },
  115. versioning: { type: Boolean },
  116. dropbox: { type: Boolean },
  117. github: { type: Boolean },
  118. gitBridge: { type: Boolean },
  119. compileTimeout: { type: Number },
  120. compileGroup: { type: String },
  121. templates: { type: Boolean },
  122. trackChanges: { type: Boolean },
  123. mendeley: { type: Boolean },
  124. zotero: { type: Boolean },
  125. referencesSearch: { type: Boolean },
  126. },
  127. },
  128. ],
  129. featuresUpdatedAt: { type: Date },
  130. // when auto-merged from SL and must-reconfirm is set, we may end up using
  131. // `sharelatexHashedPassword` to recover accounts...
  132. sharelatexHashedPassword: String,
  133. must_reconfirm: { type: Boolean, default: false },
  134. referal_id: {
  135. type: String,
  136. default() {
  137. return TokenGenerator.generateReferralId()
  138. },
  139. },
  140. refered_users: [{ type: ObjectId, ref: 'User' }],
  141. refered_user_count: { type: Number, default: 0 },
  142. refProviders: {
  143. // The actual values are managed by third-party-references.
  144. mendeley: Schema.Types.Mixed,
  145. zotero: Schema.Types.Mixed,
  146. },
  147. alphaProgram: { type: Boolean, default: false }, // experimental features
  148. betaProgram: { type: Boolean, default: false },
  149. overleaf: {
  150. id: { type: Number },
  151. accessToken: { type: String },
  152. refreshToken: { type: String },
  153. },
  154. awareOfV2: { type: Boolean, default: false },
  155. samlIdentifiers: { type: Array, default: [] },
  156. thirdPartyIdentifiers: { type: Array, default: [] },
  157. migratedAt: { type: Date },
  158. twoFactorAuthentication: {
  159. createdAt: { type: Date },
  160. enrolledAt: { type: Date },
  161. secret: { type: String },
  162. },
  163. onboardingEmailSentAt: { type: Date },
  164. auditLog: [AuditLogEntrySchema],
  165. splitTests: Schema.Types.Mixed,
  166. })
  167. exports.User = mongoose.model('User', UserSchema)
  168. exports.UserSchema = UserSchema