969
Views
8
Comments
Solved
How to check role
Question

Hi,

Using OS11 and the new oustsystems UI framework.

I've made a simple app where on the home page I want to hide some icons depending on the role of the user.

I have the roles created and on the Visible property wanted to add the condition for true or false whether user has role or not but no CheckRole function is available.

I've looked at some posts regarding the issue but I must be missing something.

Where can I find the CheckRole functions?


Thank you!

Rank: #751
Solution

Hi Carlos,

If your are building Mobile or reactive web app, you can check role in offline, using Javascript as below

$parameters.IsManager = $public.Security.checkIfCurrentUserHasRole($roles.ProductManager);

It will check Product Manager Role

CheckRoleOffline.oml

Hi Carlos,

You can click in the visible property, drill down to the roles and expand the role you want, selecting the CheckRole that you need, just like the example:


Hope this can help.


Best regards,

Ricardo

Rank: #394

Hello Carlos,

The answer of Ricardo works for Web Traditional Applications (since the functions are server sided), however, if you're trying for React or Mobile apps I would recommend to check this topic or the documentation.

Cheers!

Rank: #351

Carlos Colaço wrote:

Hi,

Using OS11 and the new oustsystems UI framework.

I've made a simple app where on the home page I want to hide some icons depending on the role of the user.

I have the roles created and on the Visible property wanted to add the condition for true or false whether user has role or not but no CheckRole function is available.

I've looked at some posts regarding the issue but I must be missing something.

Where can I find the CheckRole functions?


Thank you!

Hi Carlos,

If you are working in mobile applications or im reactive web applications, then checkrole only works in server actions.



Rank: #751
Solution

Hi Carlos,

If your are building Mobile or reactive web app, you can check role in offline, using Javascript as below

$parameters.IsManager = $public.Security.checkIfCurrentUserHasRole($roles.ProductManager);

It will check Product Manager Role

CheckRoleOffline.oml

mvp_badge
MVP
Rank: #2

Note that with the browser tools, Reactive web apps can be easily tampered with, so never hide a button and expect it to stay hidden, for example. As for roles, a user could easily tamper with the Security object to get access if that's the only protection you have.

So in general, though you could use JavaScript to check whether someone has a role, do not rely on this to enable access to sensitive information! Instead, use it for displaying only, and always check the roles server-side when accessing and storing information.

Rank: #7401

Hi,


Thanks for the help Pratham and Kilian.


I've used the JavaScript to hide the buttons I wanted by checking if user has the role for it and on the screen itself I only allow the roles intended to navigate there.