checkAccess
[ Function ]
public static checkAccess(
control: TcHmi.Controls.System.baseTcHmiControl,
requestedAccessright: string
): boolean | null;
Checks an access right of a control. All controls provide the operate and observe rights. Controls can define additional rights names and respond accordingly. Rights are always assigned to groups.
If a right is not explicitly defined on a control itself, its parent control is checked. Therefore, a check is only possible after attaching.
Possible situations:
- In Engineering within Visual Studio a right is always granted.
- If a server does not have a password query, a right is always granted.
- If a control is not attached, no decision is possible.
- If a group of the current user permits the right, the right is granted.
- If no group of the current user permits the right and one group denies the right, the right is denied.
- If no group of the current user permits or denies the right, the parent control is checked.
- If no parent control has explicitly set this right, the standard right applies (operate and observe have "permit" as default).
- Other borderline cases are explained under: Configuring control access
Parameter
Name | Type | Description |
---|---|---|
control | Control to be checked | |
requestedAccessright | Name of the access right to be checked |
Return value
Type | Description |
---|---|
true: The control currently has this right. false: The control does not currently have this right. null: The access right cannot currently be decided. See above. |
Available from 1.8 |
Sample - JavaScript
A right is to be checked in a separate event handler. This must be added in Description.json, otherwise the right cannot be configured in Visual Studio.
var myDiv = $('<div>Hello World!</div>');
myDiv.on('click', function(evt) {
if(TcHmi.Access.checkAccess(myControl, 'doFancyStuff') !== true){
return; // current user has no right to do this
}
// fancy stuff
});
myControl.getElement().append(myDiv);