Syntax

$object.canRead()

canRead($object)

Description

Checks whether the currently logged-in user is allowed to read the given object and returns a boolean.

In contrast to the implicit security enforcement when accessing attributes (which returns the empty value for a non-readable object), this function never fails and never filters. It lets a script branch explicitly on missing rights – for example to implement an alternative control flow for objects that must not be shown.

The check is evaluated for the currently logged-in user and follows the same rules as the implicit permission enforcement: deny-by-default, role inheritance along the security hierarchy, and full access for administrators or executions in a system context.

Parameters

NameTypeType DescriptionMandatoryDefault
objectBusiness objectThe object whose read access is checked.yes

Return value

Type: Boolean

true if the current user may read the object, false otherwise (in particular for null).

Examples

Example 1

all(`my.module:Contract`).filter(c -> $c.canRead())

Output: All contracts that the logged-in user is allowed to read.

Example 2

if($contract.canRead(), $contract.get(`my.module:Contract#name`), "(not visible)")

Output: The contract name if it is readable, otherwise a placeholder – without provoking a permission error.