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 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
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
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!
Carlos Colaço wrote:
If you are working in mobile applications or im reactive web applications, then checkrole only works in server actions.
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.
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.
Can you please share you JavaScript?
Shailendra Phadke wrote:
Hi Shailendra!
This is what I have:
Link with If condiftion (If has role then Show)
I check if user has role when he enters the app
So, I check if user has the role Gestor with the js
$parameters.IsGestor = $public.Security.checkIfCurrentUserHasRole($roles.Gestor);
and assign the result to a client variable (true or false).