Hi
Is possible we can manage user authorization for specific button action in CUBA? For example, running a calculation through a button action?
1 Like
Hello.
At first, it is possible to manage access rights to specific UI - component.
Required grants may be given to security role. To do this:
- Log in with an Administator account and open āAdministration->Rolesā screen
- Create a new role
- In the role-editor open the āUIā tab
- There you can add required componet to list:
a. choose āScreenā from a dropbox and
b. specify the Component: use āidā of the component (you can find it in the component properties in the Studio) - After that you can specify Permisions: āread-onlyā, āhideā or āeditā
Then just assign the role to your user and the setting will work from a next login.
The second way is to use roleās specific permissions. It is more complicated but considered as more convenient.
- Add a new specific permission to you application. To do this find āpermissions.xmlā - file in you project, and add a new item to it.
<permission-config xmlns="[url=http://schemas.haulmont.com/cuba/permissions.xsd]http://schemas.haulmont.com/cuba/permissions.xsd">[/url];
<specific>
<category id="app">
<permission id="<b>app.DoUserDefinedAction</b>"></permission>
</category>
</specific>
</permission-config>
- Restart your tomcat server
- Now, a new property is available on the āSpecific permissionsā tab of a role-editor (Administration->Roles).
- So, you can check that property for current user in your code, and grant or deny required actions.
Injection of Security-instance is required.
@Inject
private Security security;
.....
public void onTestPermissionClick(Component source) {
if (security.isSpecificPermitted("<b>app.DoUserDefinedAction</b>")){
showNotification("Buttonclick granted", NotificationType.HUMANIZED);
}
else {
showNotification("ButtonClick prohibited", NotificationType.HUMANIZED);
}
}