/workspace/composeObj
- Source
Requires
- module:/utils/merge
- module:/workspace/authorization
- module:/workspace/cache
- module:/workspace/getTemplate
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.
| Name | Type | Attributes | Description |
|---|---|---|---|
key | string | ||
val | Object | ||
obj | Object | ||
user | User | <optional> | The requesting user from request params. |
templateScope | array |
- Source
- 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.
| Name | Type | Attributes | Description |
|---|---|---|---|
obj | Object | ||
user | User | <optional> | The requesting user from request params. |
| Name | Type | Attributes | Description |
|---|---|---|---|
obj.template | string | <optional> | Key of template for the object. |
obj.templates | array | <optional> | An array of template keys to be merged into the object. |
user.roles | array.<string> | | <optional> | An array of user roles. Admin endpoints set the roles property to true to bypass role checks. |
- Source
(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.
| Name | Type | Description |
|---|---|---|
template | Object |
- Source
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.
| Name | Type | Attributes | Description |
|---|---|---|---|
obj | Object | ||
template | Object | The template maybe an object with a src property or a string. | |
user | User | <optional> | The requesting user from request params. |
templateScope | array | <optional> | The templateScope is an array that represents nested template roles/scope. |
- Source
Returns the merged obj.
- Type:
- Promise.<Object>
(async, inner) parseKey(key, obj, useropt, templateScope) → {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.
| Name | Type | Attributes | Description |
|---|---|---|---|
key | string | ||
obj | Object | ||
user | User | <optional> | The requesting user from request params. |
templateScope | array |
- Source
Returns an Error if the roles check for the obj fails.
- Type:
- Promise.<(Error|undefined)>
(inner) parseTemplates(obj, useropt, templateScope)
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.
| Name | Type | Attributes | Description |
|---|---|---|---|
obj | Object | ||
user | User | <optional> | The requesting user from request params. |
templateScope | array |
- Source
(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.
| Name | Type | Attributes | Description |
|---|---|---|---|
key | string | ||
val | Object | ||
obj | Object | ||
user | User | <optional> | The requesting user from request params. |
templateScope | array |
- Source
Returns true if the key is 'template' and the val has a key property.
- Type:
- boolean
(async, inner) rolesTemplates(key, val, obj, useropt, templateScope) → {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. Access to the obj will be denied if none of the accessRoles are included in the user.roles array.
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.
| Name | Type | Attributes | Description |
|---|---|---|---|
key | string | ||
val | Object | ||
obj | Object | ||
user | User | <optional> | The requesting user from request params. |
templateScope | array |
| Name | Type | Attributes | Description |
|---|---|---|---|
user.roles | array | | <optional> | An array of user roles. |
- Source
- 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.
| Name | Type | Attributes | Description |
|---|---|---|---|
key | string | ||
val | Object | ||
obj | Object | ||
user | User | <optional> | The requesting user from request params. |
templateScope | array |
- Source
Returns true if the key is 'templates' and the val is an array.
- Type:
- Promise.<boolean>