Filter objects for readability
Syntax
$base.filterSecurity()
filterSecurity($base)
Description
Applies the read permissions of the logged-in user to a value and removes all business objects that the user is not allowed to see.
When accessing model elements, referenced objects are returned unfiltered in TL-Script – consistent with the user interface, which always shows a referenced object by its label and only secures the navigation into the object. Only access to the attributes of an object is denied if the user must not read the object. An intermediate result of an evaluation may therefore contain objects that the user must not read. With filterSecurity, such a value can be explicitly secured so that it only contains objects the user may read.
The check is applied recursively:
- A single business object that the user must not read becomes
null. - From a collection, the elements that must not be read are removed; the kind of collection (list or set) is preserved.
- Values that are not business objects (e.g. numbers or strings) remain unchanged.
Usage
The overall result of a script does not have to be secured: it is filtered automatically when the application executes the script, unless security was explicitly switched off for that script. A trailing filterSecurity at the end of a script is therefore redundant.
The function is needed to secure a value within an evaluation – e.g. a partial result that the script itself renders or passes on to another context. It should not be applied to every intermediate step: if used too early, subsequent steps may lose objects that are needed for the computation (e.g. for a filter), even though the final result itself would be readable.
Parameters
| Name | Type | Type Description | Mandatory | Default |
|---|---|---|---|---|
| base | Any value | The value to secure: a business object, a collection of business objects or a primitive value. | yes |
Return value
Type: Same type as the argument
The given value, containing only the business objects that the logged-in user is allowed to read.
Examples
Example 1
all(`myModule:Contract`).map(c -> $c.get(`owner`)).filterSecurity()
Output: The owners of all contracts, restricted to the persons that the logged-in user is allowed to read.
Example 2
$contract.get(`owner`).filterSecurity()
Output: The owner of the contract if the logged-in user is allowed to read it, otherwise null.
Example 3
all(`myModule:Contract`).filter(c -> $c.get(`owner`) != null).filterSecurity()
Output: All contracts that have an owner set – the filter evaluates the (unfiltered) owner, and the trailing filterSecurity then restricts the result to the contracts that the logged-in user is allowed to see.