/workspace/composeObj

Requires

Methods

(async, inner) arrayProperty(key, val, obj, useropt, templateScope) → {Promise.<boolean>}

The arrayProperty method processes array properties of an object. It iterates over each item in the array and checks the roles for each item. If the roles check fails, the item is removed from the array.

Parameters:
NameTypeAttributesDescription
keystring
valObject
objObject
userUser<optional>

The requesting user from request params.

templateScopearray
Returns:
Type: 
Promise.<boolean>

(async, inner) composeObj(obj, useropt)

The composeObj method is the main entry point for composing an object with templates and roles. It will recursively traverse the provided object and its nested objects to identify and process template definitions.

Parameters:
NameTypeAttributesDescription
objObject
userUser<optional>

The requesting user from request params.

Properties
NameTypeAttributesDescription
obj.templatestring<optional>

Key of template for the object.

obj.templatesarray<optional>

An array of template keys to be merged into the object.

user.rolesarray.<string> | boolean<optional>

An array of user roles. Admin endpoints set the roles property to true to bypass role checks.

(inner) filterTemplateProperties(template) → {Object}

The filterTemplateProperties method will first remove any properties defined in the template.exclude_props array from the template object.

If the template.include_props array is defined, only the properties defined in the include_props array will be retained in the template object.

Parameters:
NameTypeDescription
templateObject
Returns:

The template object with filtered properties.

Type: 
Object

(async, inner) mergeTemplateIntoObj(obj, template, useropt, templateScopeopt) → {Promise.<Object>}

The mergeTemplateIntoObj method merges a template into an object. It first retrieves the template using the getTemplate method, then filters the template properties using the filterTemplateProperties method.

Parameters:
NameTypeAttributesDescription
objObject
templateObject

The template maybe an object with a src property or a string.

userUser<optional>

The requesting user from request params.

templateScopearray<optional>

The templateScope is an array that represents nested template roles/scope.

Returns:

Returns the merged obj.

Type: 
Promise.<Object>

(async, inner) parseKey(key, obj, useropt, templateScope, rootopt) → {Promise.<(Error|undefined)>}

The parseKey method processes a single key of an object parsed by the parseTemplates method.

The key value is checked against the queryTemplate, templatesArray, rolesTemplates, and arrayProperty methods in order. The first method to process the key value will short circuit the remaining checks. A key value which is not processed by any of these methods will be traversed recursively by the parseTemplates method.

Parameters:
NameTypeAttributesDescription
keystring
objObject
userUser<optional>

The requesting user from request params.

templateScopearray
rootboolean<optional>

Whether the obj is the root object of the composeObj method.

Returns:

Returns an Error if the roles check for the obj fails.

Type: 
Promise.<(Error|undefined)>

(inner) parseTemplates(obj, useropt, templateScope, rootopt)

The parseTemplates method will recursively traverse the provided object and its nested objects to identify and process template definitions.

If a template object is found, it will be added to the workspace.templates object for later use. The template property will be removed from the object after processing.

If an array of templates is found, each template will be merged into the object in the order they are defined in the array.

Parameters:
NameTypeAttributesDescription
objObject
userUser<optional>

The requesting user from request params.

templateScopearray
rootboolean<optional>

Whether the obj is the root object of the composeObj method.

(inner) queryTemplate(key, val, obj, useropt, templateScope) → {boolean}

The queryTemplate method checks if the key is 'template' and the val is a string or an object with a key property. If so, it will add the template to the workspace.templates object and remove the template property from the obj.

A prototype template into which the object will merged will only be processed if the template is defined in a layer or locale object. A prototype template will not be processed if it is nested in a template.

Access to an object is denied if the user does not have access to a prototype template. This would cause an object to fail if attempting to merge the object into the prototype template. Merging will not be attempted if the template with an access role is defined in a templates array.

Parameters:
NameTypeAttributesDescription
keystring
valObject
objObject
userUser<optional>

The requesting user from request params.

templateScopearray
Returns:

Returns true if the key is 'template' and the val has a key property.

Type: 
boolean

(async, inner) rolesTemplates(key, val, obj, useropt, templateScope, rootopt) → {Promise.<boolean>}

The rolesTemplates method processes the 'roles' property of an object. It iterates over each role and merges the corresponding template into the object if the role value is true or an object.

The role as defined by the key in the roles object will be added to the accessRoles array. This applies to true/null role values as well as object role values which merge role specific properties into the obj.

The root obj of the composeObj method (eg. a layer or locale) is gated by every accessRole. Access to the root obj will be denied if none of the accessRoles are included in the user.roles array. This matches the legacy roles check which gated a layer or locale by every role key.

A nested obj is only gated by the gateRoles defined with a true/null value. Object role values merge role specific properties into a nested obj which remains visible to a user without the role. This allows for a role specific property (eg. skipEntry) to be merged into an infoj entry for some users without hiding the entry from other users.

The user.roles gate does not apply to a user with an authorization_provider property. Scope access for such a user is decided by the provider in the authorizeScope method.

Parameters:
NameTypeAttributesDescription
keystring
valObject
objObject
userUser<optional>

The requesting user from request params.

templateScopearray
rootboolean<optional>

Whether the obj is the root object of the composeObj method.

Properties
NameTypeAttributesDescription
user.rolesarray | boolean<optional>

An array of user roles.

Returns:
Type: 
Promise.<boolean>

(async, inner) templatesArray(key, val, obj, useropt, templateScope) → {Promise.<boolean>}

The method checks if the key is 'templates' and the val is an array. If so, it will merge each template in the array into the object and remove the templates property from the obj.

Parameters:
NameTypeAttributesDescription
keystring
valObject
objObject
userUser<optional>

The requesting user from request params.

templateScopearray
Returns:

Returns true if the key is 'templates' and the val is an array.

Type: 
Promise.<boolean>