Hi Team,
I am very much new to Outsystems. I got one requirement where i need to show or hide the menus based on user roles. Let's say i have Employee list, add employee menu for admin role to display and only employee profile and change pass password for employee role. How can i achieve this.
You can do that by using data action
Check here https://www.outsystems.com/forums/discussion/74003/checking-roles-on-menu-items/
You can follow below steps as well
1) First Create Role
2) Create a Data ation on Menu Block and it will have a Output parameter with boolean data type
4) Drag Drop Check admin role to data action you just created
5) Assign the Output of check admin role to output parameter
6) Inclose the menu item on which you have to check role
and on the visible property set the output of data action
Publish and test
Also check Oml attached
Hope this helps
Thanks
So you should follow this:
1) Create a Client Action that is going to use JavaScript to check the roles. This will work client-side and will avoid unnecessary calls to the server.
Something like this:
And the CheckEmployeeRole JavaScript widget, that uses an API for this purpose:
$parameters.HasRole = $public.Security.checkIfCurrentUserHasRole($roles.Employee);
2) Define the CheckEmployeeRole client action as a Function:
3) Use this function in your Menu, using an If condition:
4) Since this is a Client Side implementation, you should also consider to do Server Side validations because of security. But you will only call server side when necessary.
Don't forget to define the correct roles associated to the each screens:
And use the Check<Role>Role Server Action to check the role of the logged user in your Server Actions:
For instance, use the CheckEmployeeRole validation in your Server Actions that you know they can only be executed by Employees.
Hope that this helps you!
Kind regards,
Rui Barradas
Hello
You can do that by creating a data action on screen or block and then inside the data action flow
Use these actions, this will return you a boolean response, and you can assign it to the output parameter of boolean type , you can use the same variable to show/hide accordingly
You can refer these posts as well
I hope this Helps
Thank You
Hello Santosh,
Hope you're doing well.
Are you working on a Reactive Web Application or Traditional Web Application? Because you should follow different implementations depending on the type of app that you're working with.
I am working on reactive web development.
Hi Santosh,You can implement your redirection logic in the Login screen's Login action(Interface-->Common-->Login-->Login)On this page, you can check the login user role and define the redirection screens according to that.
How about menus. For admin we will have different menu and for manager role we have different menu. How to handle that?
Where ever you want to display the conditional things you will need to check the role and according to that, you will need to put the component under the "if" widget.
Hi Santosh,
You can check the user role on the Login screen and make redirection in the logic screen according to your requirement.
How about menus. For admin we will have different menu and for manager role we have different menu. How to handle that? Do I need to create different menus for all different pages?
This approach leads to several unnecessary server calls. Everytime you render the menu, you call the server to check the roles (using a Data Action), which is not a great approach performance-wise.
As fas as I knw about this, there are lot of post which refer to same solution and the solution was given by Champions and MVP's, I am, I also not aware about it , that we can do that Client Side role check, but I think this is not secure way of doing it.
Thanks for the Information thoug
My answer is given above, which covers both performance and security.
Check it here.
It is correct client side anything is not secure, but Rui also mentioned to do server side validation where needed. Each solution has trade odds, like yours is less performant.
I marked the reply from Rui as solution too.
You can hide or unhide menu items according to the role.
Thank you for all the solution. I guess i got what needs to done and once i will check and mark the ans as solution.