Action button Enable/Disable by Resource roles

Hi,

Is it possible to Enable/Disable the action button of screen on the basis of Resource roles.
For example if system-full-access must have right to Create,Edit or remove access but minimal or report-access users cannot Create,Edit or remove.

Screenshot from 2022-12-09 16-35-52

Hi Adnan,

First of all, the standard CRUD actions are automatically disabled if the current user doesn’t have permission to the corresponding operation with the entity (due to the combination of assigned roles).

But you can also make any action enabled/disabled programmatically. For example:

@Named("departmentsTable.create")
private CreateAction<Department> departmentsTableCreate;

@Autowired
private CurrentAuthentication currentAuthentication;

@Subscribe
public void onBeforeShow(BeforeShowEvent event) {
    departmentsTableCreate.setEnabled(hasRole("hr-manager"));
}

private boolean hasRole(String roleCode) {
    return currentAuthentication.getAuthentication().getAuthorities().stream()
            .anyMatch(grantedAuthority -> roleCode.equals(grantedAuthority.getAuthority()));
}

2 Likes