Action (standard or custom) disallowed by default for everyone

For example, GroupTable export to excel standard action ExcelAction is allowed for everyone by default.
I need disallow it by default and manage allow permission for every table throu roles.
What I do:

  1. create separate specific permission in web-permissions.xml for every table (screen) I need
  2. set action disabled:
  3. check permission in screen controller:
@Subscribe
public void onBeforeShow(BeforeShowEvent event) {
    if (security.isSpecificPermitted("app.exportExcel.subdivisions")) {
        excelBtn.getAction().setEnabled(true);
    } else {
        // just in case as action disabled by default: <action id="excel" type="excel" enable="false"/>
        excelBtn.getAction().setEnabled(false);
    }
}

Is this is good solution ?

I can rewrite above code as:

excelBtn.getAction().setEnabled(security.isSpecificPermitted("app.exportExcel.subdivisions"));

or inject action:

subdivisionsTableExcel.setEnabled(security.isSpecificPermitted("app.exportExcel.subdivisions"));

But is creation specific permission for action is good solution ? Or better use UI permission (“edit” permission for “excelBtn”) ?

Hi,
I would do this way:

  • add “gui:actions” tag to web-spring.xml if it’s not there yet, see Custom Action Types - CUBA Platform. Developer’s Manual
  • create your own action class, mark it with @ActionType(“excel”)
  • extend it from com.haulmont.cuba.gui.actions.list.ExcelAction class
  • override isPermitted() method and check for specific permission in this method

Your own action class will replace all “excel” action occurences in screen descriptor, including screens inherited from platform and add-ons.

Specific permission is better than UI permission, because it’s better documented, i.e. you can assign meaningful caption to it.