|
|
@@ -81,6 +81,42 @@ async function addEmailAddress(userId, newEmail, affiliationOptions, auditLog) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+async function clearSAMLData(userId, auditLog, sendEmail) {
|
|
|
+ const user = await UserGetter.promises.getUser(userId, {
|
|
|
+ email: 1,
|
|
|
+ emails: 1,
|
|
|
+ })
|
|
|
+
|
|
|
+ await UserAuditLogHandler.promises.addEntry(
|
|
|
+ userId,
|
|
|
+ 'clear-institution-sso-data',
|
|
|
+ auditLog.initiatorId,
|
|
|
+ auditLog.ipAddress,
|
|
|
+ {}
|
|
|
+ )
|
|
|
+
|
|
|
+ const update = {
|
|
|
+ $unset: {
|
|
|
+ samlIdentifiers: 1,
|
|
|
+ 'emails.$[].samlProviderId': 1,
|
|
|
+ },
|
|
|
+ }
|
|
|
+ await UserUpdater.promises.updateUser(userId, update)
|
|
|
+
|
|
|
+ for (const emailData of user.emails) {
|
|
|
+ await InstitutionsAPIPromises.removeEntitlement(userId, emailData.email)
|
|
|
+ }
|
|
|
+
|
|
|
+ await FeaturesUpdater.promises.refreshFeatures(
|
|
|
+ userId,
|
|
|
+ 'clear-institution-sso-data'
|
|
|
+ )
|
|
|
+
|
|
|
+ if (sendEmail) {
|
|
|
+ await EmailHandler.promises.sendEmail('SAMLDataCleared', { to: user.email })
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
async function setDefaultEmailAddress(
|
|
|
userId,
|
|
|
email,
|
|
|
@@ -313,6 +349,8 @@ const UserUpdater = {
|
|
|
})
|
|
|
},
|
|
|
|
|
|
+ clearSAMLData: callbackify(clearSAMLData),
|
|
|
+
|
|
|
// set the default email address by setting the `email` attribute. The email
|
|
|
// must be one of the user's multiple emails (`emails` attribute)
|
|
|
setDefaultEmailAddress: callbackify(setDefaultEmailAddress),
|