You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

This server-side class allows to get information about the current user and his prerequisites, for example, assigned roles and preferences.

getContext()


This method allows to get user information given the context (whether this is the system user or an employee having additional attributes against regular users).


Return:

Type

Description

SimpleRecord objectThis method returns an object containing user information.

Example:

getContext
const record = new SimpleUser();
let user = record.getContext(); //user or employee attributes
ss.info(record.hasRole('admin')); //true | false
ss.info("Does this user have the security admin role? " + record.hasRole('security_admin')); // true | false
ss.info("Is the navigator menu pinned for this user? " + record.getPreference('menu.pin')); // -1 / 0 / 1
record.setPreference('New user preference', 'Menu pinning'); 
ss.info("Real preference value: " + record.getPreference('menu.pin')); // Menu pinning
ss.info("Non-existing preference value: " + record.getPreference('Non-existing preference value')); //null
ss.info(user.username);  //admin

getID()


This method gets the current user' ID.


Return:

TypeDescription
StringCurrent user ID.
getID
const record = new SimpleUser();
ss.info(record.getID());

getPreference(preferenceName)


This method allows to get a value of the specified User Preference for the current user.

Parameter(s):

NameTypeMandatoryDefault Value
preferenceNameStringYN

Return:

TypeDescription
StringThis method returns the specified preference value for the current user. If the specified preference does not exist, it returns 'null'.
getPreference
const record = new SimpleUser();
ss.info("Is the navigator menu pinned for this user? " + record.getPreference('menu.pin')); // -1 / 0 / 1

hasRole(role)


This method allows to find out whether the current user is granted with a specified role or not.

Parameter(s):

NameTypeMandatoryDefault Value
roleStringYN

Return:

TypeDescription
BooleanThis method approves or disproves an assumption whether a specified user is granted with a specified role.
hasRole
const record = new SimpleUser();
ss.info("Does this user have the security admin role? " + record.hasRole('security_admin')); // true | false

setPreference(preferenceName, value)


This method allow to set a value for an existing or newly created preference for the current user.

Parameter(s):

NameTypeMandatoryDefault Value
preferenceNameStringYN
valueStringYN

Return:

TypeDescription
VoidThis method does not return a value.
setPreference
const record = new SimpleUser();
record.setPreference('menu.pin', '1');
ss.info(record.getPreference('menu.pin')); // 1

  • No labels