User.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. samlProviderId: { type: String }
  30. }
  31. ],
  32. first_name: { type: String, default: '' },
  33. last_name: { type: String, default: '' },
  34. role: { type: String, default: '' },
  35. institution: { type: String, default: '' },
  36. hashedPassword: String,
  37. isAdmin: { type: Boolean, default: false },
  38. staffAccess: {
  39. publisherMetrics: { type: Boolean, default: false },
  40. publisherManagement: { type: Boolean, default: false },
  41. institutionMetrics: { type: Boolean, default: false },
  42. institutionManagement: { type: Boolean, default: false },
  43. groupMetrics: { type: Boolean, default: false },
  44. groupManagement: { type: Boolean, default: false },
  45. adminMetrics: { type: Boolean, default: false }
  46. },
  47. signUpDate: {
  48. type: Date,
  49. default() {
  50. return new Date()
  51. }
  52. },
  53. lastLoggedIn: { type: Date },
  54. lastLoginIp: { type: String, default: '' },
  55. loginCount: { type: Number, default: 0 },
  56. holdingAccount: { type: Boolean, default: false },
  57. ace: {
  58. mode: { type: String, default: 'none' },
  59. theme: { type: String, default: 'textmate' },
  60. overallTheme: { type: String, default: '' },
  61. fontSize: { type: Number, default: '12' },
  62. autoComplete: { type: Boolean, default: true },
  63. autoPairDelimiters: { type: Boolean, default: true },
  64. spellCheckLanguage: { type: String, default: 'en' },
  65. pdfViewer: { type: String, default: 'pdfjs' },
  66. syntaxValidation: { type: Boolean },
  67. fontFamily: { type: String },
  68. lineHeight: { type: String }
  69. },
  70. features: {
  71. collaborators: {
  72. type: Number,
  73. default: Settings.defaultFeatures.collaborators
  74. },
  75. versioning: { type: Boolean, default: Settings.defaultFeatures.versioning },
  76. dropbox: { type: Boolean, default: Settings.defaultFeatures.dropbox },
  77. github: { type: Boolean, default: Settings.defaultFeatures.github },
  78. gitBridge: { type: Boolean, default: Settings.defaultFeatures.gitBridge },
  79. compileTimeout: {
  80. type: Number,
  81. default: Settings.defaultFeatures.compileTimeout
  82. },
  83. compileGroup: {
  84. type: String,
  85. default: Settings.defaultFeatures.compileGroup
  86. },
  87. templates: { type: Boolean, default: Settings.defaultFeatures.templates },
  88. references: { type: Boolean, default: Settings.defaultFeatures.references },
  89. trackChanges: {
  90. type: Boolean,
  91. default: Settings.defaultFeatures.trackChanges
  92. },
  93. mendeley: { type: Boolean, default: Settings.defaultFeatures.mendeley },
  94. zotero: { type: Boolean, default: Settings.defaultFeatures.zotero },
  95. referencesSearch: {
  96. type: Boolean,
  97. default: Settings.defaultFeatures.referencesSearch
  98. }
  99. },
  100. // when auto-merged from SL and must-reconfirm is set, we may end up using
  101. // `sharelatexHashedPassword` to recover accounts...
  102. sharelatexHashedPassword: String,
  103. must_reconfirm: { type: Boolean, default: false },
  104. referal_id: {
  105. type: String,
  106. default() {
  107. return uuid.v4().split('-')[0]
  108. }
  109. },
  110. refered_users: [{ type: ObjectId, ref: 'User' }],
  111. refered_user_count: { type: Number, default: 0 },
  112. refProviders: {
  113. mendeley: Boolean, // coerce the refProviders values to Booleans
  114. zotero: Boolean
  115. },
  116. betaProgram: { type: Boolean, default: false },
  117. overleaf: {
  118. id: { type: Number },
  119. accessToken: { type: String },
  120. refreshToken: { type: String }
  121. },
  122. awareOfV2: { type: Boolean, default: false },
  123. samlIdentifiers: { type: Array, default: [] },
  124. thirdPartyIdentifiers: { type: Array, default: [] },
  125. migratedAt: { type: Date }
  126. })
  127. const conn = mongoose.createConnection(Settings.mongo.url, {
  128. server: { poolSize: Settings.mongo.poolSize || 10 },
  129. config: { autoIndex: false }
  130. })
  131. const User = conn.model('User', UserSchema)
  132. const model = mongoose.model('User', UserSchema)
  133. exports.User = User
  134. exports.UserSchema = UserSchema