Skip to content

Commit

Permalink
#139: support user fields TimeZone and Locale
Browse files Browse the repository at this point in the history
  • Loading branch information
JoernBerkefeld committed Mar 22, 2023
1 parent 2b17aea commit 315b553
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 7 deletions.
18 changes: 17 additions & 1 deletion lib/metadataTypes/Role.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const TYPE = require('../../types/mcdev.d');
const MetadataType = require('./MetadataType');
const Util = require('../util/util');
const File = require('../util/file');
const cache = require('../util/cache');

/**
* ImportFile MetadataType
Expand Down Expand Up @@ -62,7 +63,9 @@ class Role extends MetadataType {
const parsed = this.parseResponseBody(results);
if (!retrieveDir) {
// retrieve "Marketing Cloud%" roles not returned by SOAP API
const { roles } = await this.client.rest.get('/platform/v1/setup/quickflow/data');
const { roles, languages, timeZones } = await this.client.rest.get(
'/platform/v1/setup/quickflow/data'
);
// this endpoint does not provide keys
const roleNameKeyMap = {
'Marketing Cloud Administrator': 'SYS_DEF_IMHADMIN',
Expand All @@ -84,6 +87,19 @@ class Role extends MetadataType {
};
}
}
// convert languages to object
const languagesObj = {};
for (const language of languages) {
languagesObj[language.Key] = language;
}
// convert timeZones to object
const timeZonesObj = {};
for (const timeZone of timeZones) {
timeZonesObj[timeZone.id] = timeZone;
}
// cache languages and timeZones to share it with other type-classes
cache.setMetadata('_language', languagesObj);
cache.setMetadata('_timezone', timeZonesObj);
}
if (retrieveDir) {
const savedMetadata = await super.saveResults(parsed, retrieveDir, null);
Expand Down
38 changes: 38 additions & 0 deletions lib/metadataTypes/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,27 @@ class User extends MetadataType {
metadata.c__AssociatedBusinessUnits = [...new Set(metadata.c__AssociatedBusinessUnits)];
}

// Timezone
if (metadata.c__TimeZoneName) {
// find the ID of the timezone
metadata.TimeZone = { Name: metadata.c__TimeZoneName };
metadata.TimeZone.ID = cache.searchForField(
'_timezone',
metadata.c__TimeZoneName,
'description',
'id'
);
delete metadata.c__TimeZoneName;
}

// Locale
if (metadata.c__LocaleCode) {
// confirm it's a valid locale
cache.getByKey('_language', metadata.c__LocaleCode);
metadata.Locale = { LocaleCode: metadata.c__LocaleCode };
delete metadata.c__LocaleCode;
}

// convert SSO / Federation Token into API compliant format
if (metadata.SsoIdentity || metadata.SsoIdentities) {
const ssoIdentity = {};
Expand Down Expand Up @@ -1056,6 +1077,23 @@ class User extends MetadataType {
metadata.c__RoleNamesGlobal = roles;
delete metadata.Roles;

// Timezone
if (metadata.TimeZone?.ID) {
metadata.c__TimeZoneName = cache.searchForField(
'_timezone',
metadata.TimeZone.ID,
'id',
'description'
);
delete metadata.TimeZone;
}

// Locale
if (metadata.Locale?.LocaleCode) {
metadata.c__LocaleCode = metadata.Locale.LocaleCode;
delete metadata.Locale;
}

return metadata;
}
}
Expand Down
46 changes: 40 additions & 6 deletions lib/metadataTypes/definitions/User.definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ module.exports = {
ID: { isCreateable: false, isUpdateable: false, retrieving: false, template: false },
IsAPIUser: { isCreateable: true, isUpdateable: true, retrieving: true, template: true },
IsLocked: { isCreateable: null, isUpdateable: null, retrieving: true, template: true },
LanguageLocale: {
// not supported by API
'LanguageLocale.LocaleCode': {
// seems to always return en-US
isCreateable: false,
isUpdateable: false,
retrieving: false,
Expand All @@ -95,8 +95,19 @@ module.exports = {
retrieving: true,
template: false,
},
Locale: {
// not supported by API
'Locale.LocaleCode': {
isCreateable: true,
isUpdateable: true,
retrieving: true,
template: true,
},
'Locale.ObjectID': {
isCreateable: false,
isUpdateable: false,
retrieving: false,
template: false,
},
'Locale.PartnerKey': {
isCreateable: false,
isUpdateable: false,
retrieving: false,
Expand Down Expand Up @@ -163,8 +174,25 @@ module.exports = {
retrieving: false,
template: false,
},
TimeZone: {
// not supported by API
'TimeZone.ID': {
isCreateable: true,
isUpdateable: true,
retrieving: true,
template: false,
},
'TimeZone.Name': {
isCreateable: true,
isUpdateable: true,
retrieving: true,
template: true,
},
'TimeZone.ObjectID': {
isCreateable: false,
isUpdateable: false,
retrieving: false,
template: false,
},
'TimeZone.PartnerKey': {
isCreateable: false,
isUpdateable: false,
retrieving: false,
Expand Down Expand Up @@ -266,5 +294,11 @@ module.exports = {
c__RoleNamesGlobal: {
skipValidation: true,
},
c__LocaleCode: {
skipValidation: true,
},
c__TimeZoneName: {
skipValidation: true,
},
},
};

0 comments on commit 315b553

Please sign in to comment.