Hiding button for particular role

How can I hide one button (not default button) for a particular role. In cuba it can be done.

Thanks

You have to write some code.

The simplest solution is to check if the user has a particular role by looking into the authorities collection of the current authentication object as shown in the example here: Authentication :: Jmix Documentation

A more clean and extendable solution is to define a Specific policy in a resource role and test if the user has the permission to this resource using AccessManager. For example, if you define demo.myButton policy, you can use it as follows:

@Autowired
private Button myButton;
@Autowired
private AccessManager accessManager;

@Subscribe
public void onBeforeShow(BeforeShowEvent event) {
    SpecificOperationAccessContext accessContext =
            new SpecificOperationAccessContext("demo.myButton");
    accessManager.applyRegisteredConstraints(accessContext);
    if (!accessContext.isPermitted()) {
        myButton.setEnabled(false);
    }
}

Thanks @krivopustov, I will try it. I am just migrating this project from cuba.

But I am using such items like hiding button, making textfield/lookup hidden/disabled based on role in more than 200 locations and it will be very cumbersome. :cry:

Secondly, if my roles changed as per customer requirements then i have to code again???

Do we are planning to have specific policies like in cuba (in roles) where it was very easy?
Sometimes I miss Cuba, very much. :anguished:

1 Like

Please express your opinion in this issue:

I have expressed my opinion on issue.

However, for line of work like me whare i am developing app for clients and hosting same app for different clients, this utility is must. Shifting to jmix from cuba is not possible without this utility. It was promised that jmix will be cuba++ but ???.

Without this, I have to recode for any change in access requirement of client. Any addition of role will require re-coding. I can’t use same app for different clients.

I think jmix team should take their user’s opinion in consideration before deciding in dropping any functionality which was available in cuba.

I can’t migrate to jmix without this and cuba will not be actively improved…

I don’t know what to do?? :sob: :sob::sob::sob::sob::sob::sob::sob::sob::sob::sob::sob:

@krivopustov , Is there any possibility that this functionality will be included in jmix?

regards

Hi @umeshhodwala

Added to the roadmap but currently without specific timeframe.