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

Make default for Subscription.manager_ids 'required'

GitOrigin-RevId: 18aa899736270bbb7eacbda53824a2ed52ca936f
This commit is contained in:
Simon Detheridge 2019-09-18 11:01:32 +01:00 committed by sharelatex
parent deaf76be39
commit 696527df8d
3 changed files with 13 additions and 5 deletions

View file

@ -23,7 +23,7 @@ const SubscriptionSchema = new Schema({
ref: 'User',
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' }],
invited_emails: [String],
teamInvites: [TeamInviteSchema],

View file

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

View file

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