Denying of DropDown values in Access Roles

Hi,
As we set the constraint values as {E}.country=‘Tanzania’ for the user, here the data related to Tanzania is show to the user but coming to the dropdown, it is showing all the country instead of showing Tanzania. can you solve this issue.

Thankyou

attachment 1

attachment 2

Hi,

This can be achieved using specific permissions.

  1. Create the specific permissions in web-permissions.xml, for example:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<permission-config xmlns="http://schemas.haulmont.com/cuba/permissions.xsd">
    <specific>
        <category id="Country.Lookup">
            <permission id="Country.Lookup.USA"/>
            <permission id="Country.Lookup.CANADA"/>
            <permission id="Country.Lookup.FRANCE"/>
        </category>
    </specific>
</permission-config>
  1. Create Roles and set allow or deny for these permissions on the Specific tab of the role editor.

  2. Assign these roles to users.

  3. Implement the logic on your screen controller to check current user’s permissions and populate the optionsList for the dropdown only with permitted values, for example:

public class OrderEdit extends AbstractEditor<Order> {

    @Inject
    private Security security;

    @Named("fieldGroup.country")
    private LookupField countryField;

    @Override
    public void init(Map<String, Object> params) {
        List<Country> countries = new ArrayList<>();
        for (Country country : Country.values()) {
            if (security.isSpecificPermitted("Country.Lookup." + country.name())) {
                countries.add(country);
            }
        }
        countryField.setOptionsList(countries);
    }
}

I’ve attached a small sample project illustrating this approach.

demo.zip (96.2K)

Here we are using Enums to display country. Country is coming from EnumCountry class, so can you help me to achieve this for enum class instead of Lookupfield.

Thanks!!

Country in the demo project attached is also Enum.

Hi

I am able to deny the enum values of country in editor screen,but i want to deny the enum values of country in browser screen without using access groups.Please can you provide the code.

Regards,
Akhil

You can use the same logic as for edit screen. For example, you can refresh the datasource using the custom query parameter.

        <groupDatasource id="ordersDs"
                         class="com.company.demo.entity.Order"
                         view="_local">
            <query>
                <![CDATA[select e from demo$Order e where e.country in :custom$countries]]>
            </query>
        </groupDatasource>

    @Override
    public void init(Map<String, Object> params) {
        List<Country> countries = new ArrayList<>();
        for (Country country : Country.values()) {
            if (security.isSpecificPermitted("Country.Lookup." + country.name())) {
                countries.add(country);
            }
        }
        ordersDs.refresh(ParamsMap.of("countries", countries));
    }