From b6866cceed1449c0e9d4bfd0084669babf346046 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Berkefeld?= Date: Thu, 16 Feb 2023 16:04:25 +0100 Subject: [PATCH] #139: support setting SSO flag and FederationID on create/update --- lib/metadataTypes/AccountUser.js | 34 +++++++++++++++++++ .../definitions/AccountUser.definition.js | 23 +++++++++++-- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/lib/metadataTypes/AccountUser.js b/lib/metadataTypes/AccountUser.js index 1ffa36e9a..7e2a3020d 100644 --- a/lib/metadataTypes/AccountUser.js +++ b/lib/metadataTypes/AccountUser.js @@ -77,6 +77,40 @@ class AccountUser extends MetadataType { metadata.Client = { ID: this.buObject.mid, }; + + if (metadata.SsoIdentity || metadata.SsoIdentities) { + const ssoIdentity = {}; + if (metadata.SsoIdentity) { + // assume metadata.SsoIdentity is an object + ssoIdentity.IsActive = metadata.SsoIdentity.IsActive; + ssoIdentity.FederatedId = metadata.SsoIdentity.FederatedId; + delete metadata.SsoIdentity; + } else if (Array.isArray(metadata.SsoIdentities)) { + // be nice and allow SsoIdentities as an alternative if its an array of objects + ssoIdentity.IsActive = metadata.SsoIdentities[0].IsActive; + ssoIdentity.FederatedId = metadata.SsoIdentities[0].FederatedId; + } else if ( + Array.isArray(metadata.SsoIdentities?.SsoIdentity) && + metadata.SsoIdentities?.SsoIdentity.length + ) { + // API-compliant format already provided; just use it + ssoIdentity.IsActive = metadata.SsoIdentities.SsoIdentity[0]?.IsActive; + ssoIdentity.FederatedId = metadata.SsoIdentities.SsoIdentity[0]?.FederatedId; + } else { + throw new TypeError( + 'SsoIdentity should be an object with IsActive and FederatedId properties.' + ); + } + // if SsoIdentity is set, assume this was on purpose and bring it + metadata.SsoIdentities = { + SsoIdentity: [ + { + IsActive: ssoIdentity.IsActive, + FederatedId: ssoIdentity.FederatedId, + }, + ], + }; + } return metadata; } /** diff --git a/lib/metadataTypes/definitions/AccountUser.definition.js b/lib/metadataTypes/definitions/AccountUser.definition.js index ab06bf93a..41122281f 100644 --- a/lib/metadataTypes/definitions/AccountUser.definition.js +++ b/lib/metadataTypes/definitions/AccountUser.definition.js @@ -137,9 +137,26 @@ module.exports = { skipValidation: false, }, SsoIdentities: { - // not supported by API - isCreateable: false, - isUpdateable: false, + isCreateable: true, + isUpdateable: true, + retrieving: false, // retrieve not supported by API + template: false, + }, + 'SsoIdentities[]': { + isCreateable: true, + isUpdateable: true, + retrieving: false, + template: false, + }, + 'SsoIdentities[].IsActive': { + isCreateable: true, + isUpdateable: true, + retrieving: false, + template: false, + }, + 'SsoIdentities[].FederatedID': { + isCreateable: true, + isUpdateable: true, retrieving: false, template: false, },