mirror of
https://github.com/overleaf/overleaf.git
synced 2025-01-27 06:53:55 +00:00
refactor SAMLController to use async throughout
GitOrigin-RevId: dafd76042f460cd34596c8c9023e2378145105e8
This commit is contained in:
parent
558854f51b
commit
88683e9fec
4 changed files with 8 additions and 30 deletions
|
@ -105,15 +105,6 @@ class SAMLSessionDataMissing extends BackwardCompatibleError {
|
|||
}
|
||||
}
|
||||
|
||||
class SAMLUserNotFoundError extends BackwardCompatibleError {
|
||||
constructor(arg) {
|
||||
super(arg)
|
||||
if (!this.message) {
|
||||
this.message = 'user not found for SAML provider and external id'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ThirdPartyIdentityExistsError extends BackwardCompatibleError {
|
||||
constructor(arg) {
|
||||
super(arg)
|
||||
|
@ -201,7 +192,6 @@ module.exports = {
|
|||
NotInV2Error,
|
||||
SAMLIdentityExistsError,
|
||||
SAMLSessionDataMissing,
|
||||
SAMLUserNotFoundError,
|
||||
SLInV2Error,
|
||||
ThirdPartyIdentityExistsError,
|
||||
ThirdPartyUserNotFoundError,
|
||||
|
|
|
@ -65,16 +65,6 @@ async function _addIdentifier(
|
|||
}
|
||||
}
|
||||
|
||||
function _getUserQuery(providerId, externalUserId) {
|
||||
externalUserId = externalUserId.toString()
|
||||
providerId = providerId.toString()
|
||||
const query = {
|
||||
'samlIdentifiers.externalUserId': externalUserId,
|
||||
'samlIdentifiers.providerId': providerId
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
async function _addInstitutionEmail(userId, email, providerId) {
|
||||
const user = await UserGetter.promises.getUser(userId)
|
||||
const query = {
|
||||
|
@ -134,18 +124,16 @@ function _sendUnlinkedEmail(primaryEmail, providerName) {
|
|||
}
|
||||
|
||||
async function getUser(providerId, externalUserId) {
|
||||
if (providerId == null || externalUserId == null) {
|
||||
if (!providerId || !externalUserId) {
|
||||
throw new Error(
|
||||
`invalid arguments: providerId: ${providerId}, externalUserId: ${externalUserId}`
|
||||
)
|
||||
}
|
||||
providerId = providerId.toString()
|
||||
externalUserId = externalUserId.toString()
|
||||
const query = _getUserQuery(providerId, externalUserId)
|
||||
let user = await User.findOne(query).exec()
|
||||
if (!user) {
|
||||
throw new Errors.SAMLUserNotFoundError()
|
||||
}
|
||||
const user = await User.findOne({
|
||||
'samlIdentifiers.externalUserId': externalUserId.toString(),
|
||||
'samlIdentifiers.providerId': providerId.toString()
|
||||
}).exec()
|
||||
|
||||
return user
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ const { promisify } = require('util')
|
|||
const pLimit = require('p-limit')
|
||||
|
||||
module.exports = {
|
||||
promisify,
|
||||
promisifyAll,
|
||||
promisifyMultiResult,
|
||||
callbackifyMultiResult,
|
||||
|
|
|
@ -9,8 +9,7 @@ describe('SAMLIdentityManager', function() {
|
|||
this.Errors = {
|
||||
EmailExistsError: sinon.stub(),
|
||||
NotFoundError: sinon.stub(),
|
||||
SAMLIdentityExistsError: sinon.stub(),
|
||||
SAMLUserNotFoundError: sinon.stub()
|
||||
SAMLIdentityExistsError: sinon.stub()
|
||||
}
|
||||
this.user = {
|
||||
_id: 'user-id-1',
|
||||
|
|
Loading…
Reference in a new issue