🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators canAccess
This page was created by Hans.karlsen on 2017-10-05. Last edited by Wikiadmin on 2026-07-29.

You can use the OCL canAccess operator in MDriven Designer to test whether the current object is allowed to open a specified ViewModel before you create or navigate to that ViewModel.

What canAccess checks

canAccess evaluates the target ViewModel's rooted AccessExpression for the object on the left side of the operator. It returns a Boolean value:

Result Meaning
true The object's values satisfy the target ViewModel's AccessExpression, so the ViewModel can be accessed.
false The object's values do not satisfy the target ViewModel's AccessExpression, so you can prevent the action or report from continuing.

A ViewModel AccessExpression controls whether that ViewModel is shown. An empty AccessExpression defaults to true. ViewModel access evaluation occurs after access-group evaluation; see Documentation:AccessExpression for the AccessExpression behavior and Access control system in MDriven for the wider access-control model.

Syntax

object.canAccess(viewModelName)

object is the current object whose values the rooted AccessExpression will evaluate. viewModelName identifies the ViewModel to test. The expression returns true or false.

Use the ViewModels operator

Use the ViewModels operator to refer to the ViewModel when possible:

self.canAccess(User.ViewModels.UserSettings)

In this example, self is tested against the AccessExpression of the UserSettings ViewModel. Referring to the ViewModel through User.ViewModels.UserSettings lets MDriven Designer notify you if the ViewModel is renamed.

Disable an action before navigation

Use canAccess in an action's enable expression when the action opens a ViewModel whose access depends on its root object.

For example, if an action on a User opens UserSettings:

  1. Select the action in MDriven Designer.
  2. Set the action's enable expression to:
self.canAccess(User.ViewModels.UserSettings)
  1. Configure the action to open the UserSettings ViewModel.

When the UserSettings AccessExpression evaluates to false for that user, the action is disabled. This prevents the user from navigating to a ViewModel that would not be shown. It also prevents creating a report based on a ViewModel and root object that fail the ViewModel's AccessExpression.

Example

Assume that the UserSettings ViewModel has an AccessExpression that allows only users meeting its rule. On a selected user, evaluate:

self.canAccess(User.ViewModels.UserSettings)

If the selected user's values meet the rule, the expression returns true and an action can be enabled. If they do not, it returns false.

Important distinction

canAccess tests the ViewModel's rooted AccessExpression. Use access groups for rules based on global values, such as the logged-in user's roles. Use the ViewModel AccessExpression when access depends on values in the root object. For example, a role-based rule can belong in an access group, while a rule that depends on the selected User belongs in that ViewModel's AccessExpression.

See also