Subscription.mjs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import mongoose from '../infrastructure/Mongoose.mjs'
  2. import { TeamInviteSchema } from './TeamInvite.mjs'
  3. import { callbackify } from '@overleaf/promise-utils'
  4. const { Schema } = mongoose
  5. const { ObjectId } = Schema
  6. const PaymentProvider = {
  7. service: {
  8. type: String,
  9. },
  10. subscriptionId: {
  11. type: String,
  12. },
  13. state: {
  14. type: String,
  15. },
  16. pausePeriodStart: {
  17. type: Date,
  18. },
  19. pausePeriodEnd: {
  20. type: Date,
  21. },
  22. trialStartedAt: {
  23. type: Date,
  24. },
  25. trialEndsAt: {
  26. type: Date,
  27. },
  28. }
  29. export const SubscriptionSchema = new Schema(
  30. {
  31. admin_id: {
  32. type: ObjectId,
  33. ref: 'User',
  34. index: { unique: true, dropDups: true },
  35. },
  36. manager_ids: {
  37. type: [ObjectId],
  38. ref: 'User',
  39. required: true,
  40. validate: function (managers) {
  41. // require at least one manager
  42. return !!managers.length
  43. },
  44. },
  45. member_ids: [{ type: ObjectId, ref: 'User' }],
  46. groupPolicy: { type: ObjectId, ref: 'GroupPolicy' },
  47. invited_emails: [String],
  48. teamInvites: [TeamInviteSchema],
  49. recurlySubscription_id: String,
  50. teamName: { type: String },
  51. teamNotice: { type: String },
  52. planCode: { type: String },
  53. groupPlan: { type: Boolean, default: false },
  54. domainCaptureEnabled: { type: Boolean, default: false },
  55. managedUsersEnabled: { type: Boolean, default: false },
  56. membersLimit: { type: Number, default: 0 },
  57. membersLimitNotificationSent: { type: Boolean, default: false },
  58. customAccount: Boolean,
  59. features: {
  60. managedUsers: { type: Boolean, default: true },
  61. groupSSO: { type: Boolean, default: true },
  62. domainCapture: { type: Boolean, default: false },
  63. },
  64. userFeaturesDisabled: Boolean,
  65. addOns: Schema.Types.Mixed,
  66. overleaf: {
  67. id: {
  68. type: Number,
  69. index: {
  70. unique: true,
  71. partialFilterExpression: { 'overleaf.id': { $exists: true } },
  72. },
  73. },
  74. },
  75. recurlyStatus: {
  76. state: {
  77. type: String,
  78. },
  79. trialStartedAt: {
  80. type: Date,
  81. },
  82. trialEndsAt: {
  83. type: Date,
  84. },
  85. },
  86. paymentProvider: PaymentProvider,
  87. previousPaymentProvider: PaymentProvider,
  88. collectionMethod: {
  89. type: String,
  90. enum: ['automatic', 'manual'],
  91. default: 'automatic',
  92. },
  93. v1_id: {
  94. type: Number,
  95. required: false,
  96. min: 1,
  97. },
  98. salesforce_id: {
  99. type: String,
  100. required: false,
  101. validate: {
  102. validator: function (salesforceId) {
  103. return (
  104. salesforceId == null ||
  105. salesforceId === '' ||
  106. salesforceId.match(/^(?:[A-Za-z0-9]{15}|[A-Za-z0-9]{18})$/)
  107. )
  108. },
  109. },
  110. },
  111. ssoConfig: { type: ObjectId, ref: 'SSOConfig' },
  112. sharingPermissions: {
  113. byEmail: {
  114. type: String,
  115. enum: ['anyone_in_x', 'anyone'],
  116. default: 'anyone',
  117. },
  118. byLinkSharing: {
  119. type: String,
  120. enum: ['no_one', 'anyone_in_x', 'anyone'],
  121. default: 'anyone',
  122. },
  123. },
  124. },
  125. { minimize: false }
  126. )
  127. // Subscriptions have no v1 data to fetch
  128. async function fetchV1DataPromise() {
  129. return this
  130. }
  131. SubscriptionSchema.method('fetchV1Data', callbackify(fetchV1DataPromise))
  132. SubscriptionSchema.method('fetchV1DataPromise', fetchV1DataPromise)
  133. export const Subscription = mongoose.model('Subscription', SubscriptionSchema)