/workspace
The Workspace API module exports the getKeyMethod() which returns a method from the keyMethods{} object.
- layer
- locale
- locales
- roles
The workspace typedef object has templates, locale, locales, dbs, and roles properties. The workspace will be cached in the process by the workspace/cache module.
Requires
- module:/workspace/cache
- module:/workspace/getLocale
- module:/workspace/getLayer
- module:/workspace/getTemplate
- module:/utils/roles
Methods
(async, inner) cacheTemplates(params)
Gets and caches a complete workspace with all locales, layers, and templates pre-loaded.
The workspaceCache method will be forced to clear the cached workspace and load the workspace again which may have changed. This is required for testing purposes. If templates should be loaded in order to extract roles it may be beneficial to use already cached templates.
The method will iterate over the workspace.locales to cache any templates defined in the locales object.
The method will iterate over each layer defined in every locale to cache any templates associated with the layer objects.
Finally each template defined in the workspace.templates will be cached.
Name | Type | Description |
---|---|---|
params | user | Configuration parameter for workspace caching. |
Name | Type | Attributes | Description |
---|---|---|---|
params.user | Object | <optional> | User context for permission checking when loading locales and layers. |
params.force | Boolean | <optional> | Whether the cached workspace should be cleared. |
(async, inner) getKeyMethod(req, res)
The cached workspace requested from the workspaceCache() will be assigned to the workspace variable declared in the module scope.
The method checks whether the req.params.key matches a keyMethods property and returns the matching method.
Name | Type | Description |
---|---|---|
req.params | Object | HTTP request params. |
params.key | string | Workspace API method requested. |
(async, inner) getNestedLocales(req, res) → {res}
The getNestedLocales is returned if the locales method is called with a locale property.
The locale will be requested from the getLocale module. An array of nested locales defined in the locales property of the locale is checked for user access.
Nested locales accessible to the user are returned. The key for a nested locale is an array left to right. For [UK,London]
the London locale will be nested in the UK locale. The name for a nested locale will be concatenated like so UK/London
.
Name | Type | Attributes | Description |
---|---|---|---|
req.params | Object | HTTP request params. | |
params.locale | string | Request nested locales for the locale. | |
params.user | Object | <optional> | User requesting the locales. |
The HTTP response with either an error.message or JSON array of locales in workspace.
- Type:
- res
(async, inner) layer(req, res) → {res}
The method requests a JSON layer from the getLayer module.
The layer is checked for user role access and will return an error if access is denied.
All role information is removed from the layer before being returned to the client.
Name | Type | Attributes | Description |
---|---|---|---|
req.params | Object | HTTP request params. | |
params.locale | string | <optional> | Locale key. |
params.layer | string | Layer key. | |
params.user | Object | <optional> | User requesting the layer. |
The HTTP response with either an error.message or the JSON layer.
- Type:
- res
(async, inner) locale(req, res) → {res}
The method requests a JSON locale from the getLocale module.
All locale layers are requested from the getLayer module with params.layers
flag.
The locale.layers{} object is reduced to an array of layer keys without the params.layers
flag.
Name | Type | Attributes | Description |
---|---|---|---|
req.params | Object | HTTP request params. | |
params.locale | string | <optional> | Locale key. |
params.layers | boolean | <optional> | Whether layer objects should be returned with the locale. |
params.user | Object | <optional> | User requesting the locale. |
The HTTP response with either an error.message or the JSON locale.
- Type:
- res
(async, inner) locales(req, res) → {res}
The locales method returns an array of fully resolved locale objects from the workspace.
Each locale is retrieved via the getLocale method, which merges templates and applies proper role-based access control. Any locales that return errors (e.g., due to access restrictions) are filtered out of the response.
The nestedLocales method will be returned if a locale property is provided in the request params.
Name | Type | Attributes | Description |
---|---|---|---|
req.params | Object | HTTP request params. | |
params.locale | string | <optional> | Request nested locales for the locale. |
params.user | Object | <optional> | User requesting the locales. |
The HTTP response with a JSON array of accessible locale objects.
- Type:
- res
(inner) processTestResults(testConfig) → {Object}
Processes the test configuration and returns formatted results.
Name | Type | Description |
---|---|---|
testConfig | Object | The test configuration object. |
Formatted test results object.
- Type:
- Object
(inner) removeRoles(obj) → {object}
Recursively removes all 'roles' objects from the provided object [locale, layer]. This function is designed to sanitize locale configuration objects before sending to the client, ensuring that role-based permissions data is not exposed.
Name | Type | Description |
---|---|---|
obj | object | A locale or layer JSON object. |
- Type:
- object
(async, inner) roles(req, res) → {Array|Object}
The roles method returns an array of roles returned from the roles utility.
This method is only available to users with admin credentials.
The cacheTemplates method will called to read any template from it's src and cache the template. This is required to extract any roles from the workspace which may be defined in a template only.
The workspace.roles{} object will be returned with the detail=true
url parameter.
A hierarchical tree structure can be requested with the tree=true
url parameter.
Name | Type | Attributes | Description | ||||||
---|---|---|---|---|---|---|---|---|---|
req.params | Object | HTTP request parameter. | |||||||
params.user | Object | User requesting the roles. Properties
| |||||||
params.tree | boolean | <optional> | Whether the roles should be returned as a hierarchical tree structure. |
Returns either an array of roles as strings, detailed roles object, or hierarchical roles tree.
- Type:
- Array |
Object
(inner) templateUse(obj, test)
Iterates through all nested object properties. Test properties found in the test.properties Set. Removes template keys from test.unused_templates Set. Add template keys to test.used_templates Array.
Name | Type | Description |
---|---|---|
obj | Object | The object to test. |
test | Object | The test config object. |
Name | Type | Description |
---|---|---|
test.properties | Set | Set of properties to test ['template', 'templates', 'query'] |
test.workspace_templates | Set | Set of templates _type=workspace templates. |
test.unused_templates | Set | Set of templates not (yet) used. |
test.overwritten_templates | Set | Set of _type=workspace templates which have been overwritten. |
test.used_templates | Array | Array of template keys for each usage. |
(inner) test(req, res)
The workspace/test method which is only available to user with admin credentials requests all locales in workspace.
The cached workspace will be flushed for the test method.
Requesting all locales should add any additional templates to the workspace.
The test method will iterate over all workspace.templates and get from the getTemplate method to check whether any errors are logged on a template in regards to its src parameter.
A flat array of template.err will be returned from the workspace/test method.
Name | Type | Attributes | Description |
---|---|---|---|
req.params | Object | HTTP request parameter. | |
params.detail | Boolean | <optional> | Flag to return the cached workspace. |
params.force | boolean | <optional> | Whether to force refresh the workspace cache. |
params.user | Object | The user requesting the test method. | |
user.admin | Boolean | The user is required to have admin privileges. |
(inner) testWorkspaceLocales(testConfig)
Tests all locales in the workspace for errors and analyzes template usage.
Name | Type | Description |
---|---|---|
testConfig | Object | The test configuration object. |