فهرست منبع

Merge pull request #2153 from overleaf/spd-subscription-indexes

Make default for Subscription.manager_ids 'required'

GitOrigin-RevId: 18aa899736270bbb7eacbda53824a2ed52ca936f
Simon Detheridge 7 سال پیش
والد
کامیت
696527df8d

+ 1 - 1
services/web/app/src/models/Subscription.js

@@ -23,7 +23,7 @@ const SubscriptionSchema = new Schema({
     ref: 'User',
     ref: 'User',
     index: { unique: true, dropDups: true }
     index: { unique: true, dropDups: true }
   },
   },
-  manager_ids: [{ type: ObjectId, ref: 'User' }],
+  manager_ids: { type: [ObjectId], ref: 'User', required: true },
   member_ids: [{ type: ObjectId, ref: 'User' }],
   member_ids: [{ type: ObjectId, ref: 'User' }],
   invited_emails: [String],
   invited_emails: [String],
   teamInvites: [TeamInviteSchema],
   teamInvites: [TeamInviteSchema],

+ 7 - 2
services/web/test/acceptance/src/FeatureUpdaterTests.js

@@ -94,8 +94,10 @@ describe('FeatureUpdater.refreshFeatures', function() {
 
 
   describe('when the user is in a group subscription', function() {
   describe('when the user is in a group subscription', function() {
     beforeEach(function() {
     beforeEach(function() {
+      const groupAdminId = ObjectId()
       return Subscription.create({
       return Subscription.create({
-        admin_id: ObjectId(),
+        admin_id: groupAdminId,
+        manager_ids: [groupAdminId],
         member_ids: [this.user._id],
         member_ids: [this.user._id],
         groupAccount: true,
         groupAccount: true,
         planCode: 'collaborator',
         planCode: 'collaborator',
@@ -280,6 +282,8 @@ describe('FeatureUpdater.refreshFeatures', function() {
 
 
   describe('when the user has a group and personal subscription', function() {
   describe('when the user has a group and personal subscription', function() {
     beforeEach(function(done) {
     beforeEach(function(done) {
+      const groupAdminId = ObjectId()
+
       Subscription.create(
       Subscription.create(
         {
         {
           admin_id: this.user._id,
           admin_id: this.user._id,
@@ -293,7 +297,8 @@ describe('FeatureUpdater.refreshFeatures', function() {
           }
           }
           return Subscription.create(
           return Subscription.create(
             {
             {
-              admin_id: ObjectId(),
+              admin_id: groupAdminId,
+              manager_ids: [groupAdminId],
               member_ids: [this.user._id],
               member_ids: [this.user._id],
               groupAccount: true,
               groupAccount: true,
               planCode: 'collaborator',
               planCode: 'collaborator',

+ 5 - 2
services/web/test/acceptance/src/helpers/Subscription.js

@@ -11,7 +11,7 @@ class Subscription {
     this.admin_id = options.adminId || ObjectId()
     this.admin_id = options.adminId || ObjectId()
     this.overleaf = options.overleaf || {}
     this.overleaf = options.overleaf || {}
     this.groupPlan = options.groupPlan
     this.groupPlan = options.groupPlan
-    this.manager_ids = []
+    this.manager_ids = options.managerIds || [this.admin_id]
     this.member_ids = options.memberIds || []
     this.member_ids = options.memberIds || []
     this.invited_emails = options.invitedEmails || []
     this.invited_emails = options.invitedEmails || []
     this.teamInvites = options.teamInvites || []
     this.teamInvites = options.teamInvites || []
@@ -28,8 +28,11 @@ class Subscription {
       this,
       this,
       options,
       options,
       (error, subscription) => {
       (error, subscription) => {
+        if (error) {
+          return callback(error)
+        }
         this._id = subscription._id
         this._id = subscription._id
-        callback(error)
+        callback()
       }
       }
     )
     )
   }
   }