$base.filterSecurity()
filterSecurity($base)
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. With filterSecurity, the final result of a script (or an intermediate result) can be explicitly secured so that it only contains objects the user may read.
The check is applied recursively:
null.Because accesses in TL-Script return their results unfiltered, the result of a script is not secured automatically. A script whose result is shown to a user or passed on to another context should therefore wrap its overall result at the outermost level with filterSecurity. This guarantees that the returned result only contains objects that the logged-in user is allowed to see.
Only the final result should be secured, not every intermediate step: if used too early in an evaluation, 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.
| 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 |
Type: Same type as the argument
The given value, containing only the business objects that the logged-in user is allowed to read.
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.
$contract.get(`owner`).filterSecurity()
Output: The owner of the contract if the logged-in user is allowed to read it, otherwise null.
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.