Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug/1510 fix retrieving users and roles together failing due to missing timezones #1634

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions @types/lib/metadataTypes/Role.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion @types/lib/metadataTypes/Role.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 47 additions & 35 deletions lib/metadataTypes/Role.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,41 +73,6 @@ class Role extends MetadataType {
const results = await this.client.soap.retrieve('Role', fields, requestParams);

const parsed = this.parseResponseBody(results);
if (!retrieveDir) {
// retrieve "Marketing Cloud%" roles not returned by SOAP API
const { roles, 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',
'Marketing Cloud Channel Manager': 'SYS_DEF_CHANNELMANAGER',
'Marketing Cloud Content Editor/Publisher': 'SYS_DEF_CONTENTEDIT',
'Marketing Cloud Security Administrator': 'SYS_DEF_SECURITYADMIN',
'Marketing Cloud Viewer': 'SYS_DEF_VIEWER',
};
for (const role of roles) {
if (roleNameKeyMap[role.roleName]) {
parsed[roleNameKeyMap[role.roleName]] = {
CustomerKey: roleNameKeyMap[role.roleName],
Name: role.roleName,
ObjectID: role.roleID,
Desscription: role.description,
CreatedDate: '2012-02-21T02:09:19.983',
IsSystemDefined: true,
c__notAssignable: true,
};
}
}
// the languages object is incomplete. the actual list is much longer --> ignoring it here
// convert timeZones to object
const timeZonesObj = {};
for (const timeZone of timeZones) {
timeZonesObj[timeZone.id] = timeZone;
}
// cache timeZones to share it with other type-classes
cache.setMetadata('_timezone', timeZonesObj);
}
if (retrieveDir) {
const savedMetadata = await super.saveResults(parsed, retrieveDir, null);
Util.logger.info(
Expand All @@ -117,9 +82,56 @@ class Role extends MetadataType {

await this.runDocumentOnRetrieve(key, savedMetadata);
}

await this.cacheDefaultRolesAndTimezones(parsed);

return { metadata: parsed, type: this.definition.type };
}

/**
* adds default roles to the list of retrieved roles for proper caching (but not storing)
* also caches available timezones for retrieve-user
*
* @param {MetadataTypeMap} parsed list or previously retrieved items as reference
*/
static async cacheDefaultRolesAndTimezones(parsed) {
// retrieve "Marketing Cloud%" roles not returned by SOAP API for cache (required by retrieve-user)
// also cache available timezones for retrieve-user
Util.logger.info(Util.getGrayMsg(' - Caching default roles and timezones'));
const { roles, 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',
'Marketing Cloud Channel Manager': 'SYS_DEF_CHANNELMANAGER',
'Marketing Cloud Content Editor/Publisher': 'SYS_DEF_CONTENTEDIT',
'Marketing Cloud Security Administrator': 'SYS_DEF_SECURITYADMIN',
'Marketing Cloud Viewer': 'SYS_DEF_VIEWER',
};
for (const role of roles) {
if (roleNameKeyMap[role.roleName]) {
parsed[roleNameKeyMap[role.roleName]] = {
CustomerKey: roleNameKeyMap[role.roleName],
Name: role.roleName,
ObjectID: role.roleID,
Desscription: role.description,
CreatedDate: '2012-02-21T02:09:19.983',
IsSystemDefined: true,
c__notAssignable: true,
};
}
}
// the languages object is incomplete. the actual list is much longer --> ignoring it here
// convert timeZones to object
const timeZonesObj = {};
for (const timeZone of timeZones) {
timeZonesObj[timeZone.id] = timeZone;
}
// cache timeZones to share it with other type-classes
cache.setMetadata('_timezone', timeZonesObj);
}

/**
* Gets executed before deploying metadata
*
Expand Down
Loading