From d378cba24b22f2fef7ca3e38ce3854243d7e327a Mon Sep 17 00:00:00 2001 From: Dale Hille Date: Thu, 11 Jun 2020 09:29:26 -0400 Subject: [PATCH] Fix: add getOrg to local and passport.local (#404) * add getOrg to local and passport.local The ClusterSubscription client calls subscriptionsByTag which calls getOrg. Currently only the default auth model has getOrg implemented so this would cause local and passport.local users of ClusterSubscription to get errors * ClusterSubscription clients won't have models.User entries --- app/apollo/models/user.local.schema.js | 8 ++++++++ app/apollo/models/user.passport.local.schema.js | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/app/apollo/models/user.local.schema.js b/app/apollo/models/user.local.schema.js index c04d7e4e6..475d866a0 100644 --- a/app/apollo/models/user.local.schema.js +++ b/app/apollo/models/user.local.schema.js @@ -282,6 +282,14 @@ UserLocalSchema.statics.isAuthorized = async function(me, orgId, action, type, a return false; }; +UserLocalSchema.statics.getOrg = async function(models, me) { + let org; + if (AUTH_MODEL === AUTH_MODELS.LOCAL) { + org = await models.Organization.findOne({ orgKeys: me.orgKey }).lean(); + } + return org; +}; + UserLocalSchema.statics.getOrgs = async function(context) { const results = []; const { models, me } = context; diff --git a/app/apollo/models/user.passport.local.schema.js b/app/apollo/models/user.passport.local.schema.js index d5ce3fc79..172006078 100644 --- a/app/apollo/models/user.passport.local.schema.js +++ b/app/apollo/models/user.passport.local.schema.js @@ -281,6 +281,14 @@ UserPassportLocalSchema.statics.isAuthorized = async function(me, orgId, action, return false; }; +UserPassportLocalSchema.statics.getOrg = async function(models, me) { + let org; + if (AUTH_MODEL === AUTH_MODELS.PASSPORT_LOCAL) { + org = await models.Organization.findOne({ orgKeys: me.orgKey }).lean(); + } + return org; +}; + UserPassportLocalSchema.statics.getOrgs = async function(context) { const results = []; const { models, me } = context;