mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-29 20:03:43 -05:00
Merge pull request #6254 from overleaf/jel-saml-entitlement
[web] Always update entitlement in v1 after SAML callback GitOrigin-RevId: 2569d6d8e6142786ad2875c62c9cd4568837654a
This commit is contained in:
parent
bbc5e2d34c
commit
1122a83b60
2 changed files with 30 additions and 21 deletions
|
@ -339,12 +339,6 @@ async function updateEntitlement(
|
||||||
}
|
}
|
||||||
// update v2 user
|
// update v2 user
|
||||||
await User.updateOne(query, update).exec()
|
await User.updateOne(query, update).exec()
|
||||||
// update v1 affiliations record
|
|
||||||
if (hasEntitlement) {
|
|
||||||
await InstitutionsAPI.promises.addEntitlement(userId, institutionEmail)
|
|
||||||
} else {
|
|
||||||
await InstitutionsAPI.promises.removeEntitlement(userId, institutionEmail)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function entitlementAttributeMatches(entitlementAttribute, entitlementMatcher) {
|
function entitlementAttributeMatches(entitlementAttribute, entitlementMatcher) {
|
||||||
|
|
|
@ -91,7 +91,8 @@ class MockV1Api extends AbstractMockApi {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
addAffiliation(userId, email) {
|
addAffiliation(userId, email, entitlement) {
|
||||||
|
let newAffiliation = true
|
||||||
const institution = {}
|
const institution = {}
|
||||||
if (!email) return
|
if (!email) return
|
||||||
if (!this.affiliations[userId]) this.affiliations[userId] = []
|
if (!this.affiliations[userId]) this.affiliations[userId] = []
|
||||||
|
@ -101,8 +102,9 @@ class MockV1Api extends AbstractMockApi {
|
||||||
return affiliationData.email === email
|
return affiliationData.email === email
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
return
|
newAffiliation = false
|
||||||
|
|
||||||
|
if (newAffiliation) {
|
||||||
const domain = email.split('@').pop()
|
const domain = email.split('@').pop()
|
||||||
|
|
||||||
if (this.blocklistedDomains.indexOf(domain.replace('.com', '')) !== -1) {
|
if (this.blocklistedDomains.indexOf(domain.replace('.com', '')) !== -1) {
|
||||||
|
@ -124,6 +126,15 @@ class MockV1Api extends AbstractMockApi {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (entitlement !== undefined) {
|
||||||
|
this.affiliations[userId].forEach(affiliation => {
|
||||||
|
if (affiliation.email === email) {
|
||||||
|
affiliation.cached_entitlement = entitlement
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
setDocExported(token, info) {
|
setDocExported(token, info) {
|
||||||
this.doc_exported[token] = info
|
this.doc_exported[token] = info
|
||||||
}
|
}
|
||||||
|
@ -231,7 +242,11 @@ class MockV1Api extends AbstractMockApi {
|
||||||
})
|
})
|
||||||
|
|
||||||
this.app.post('/api/v2/users/:userId/affiliations', (req, res) => {
|
this.app.post('/api/v2/users/:userId/affiliations', (req, res) => {
|
||||||
this.addAffiliation(req.params.userId, req.body.email)
|
this.addAffiliation(
|
||||||
|
req.params.userId,
|
||||||
|
req.body.email,
|
||||||
|
req.body.entitlement
|
||||||
|
)
|
||||||
res.sendStatus(201)
|
res.sendStatus(201)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue