Nested entity datasource ignores constraints

Hi

I am facing the following problem.

I have two entities - DataArea and Company. DataArea may have multiple companies, so DataArea has a composition field named companies, and Company entity has association field named dataArea. Both entities has disabled boolean fields

Also, I created a view for DataArea with fields from DataArea and Company entities.
I have a constraint defined to filter out disabled entities for the user which is not the member of Administrators group.


{E}.disabled IS NULL OR {E}.disabled = FALSE OR EXISTS(SELECT ur FROM sec$UserRole ur WHERE ur.user.id = :session$userId AND ur.role.name = 'Administrators')

I use dataAreasDs and nested companiesDs datasources to feed two lookupFields on the main window. And it does not filter the nested entity by the constraint. If I open another browse screen it works fine, constraint is applied. Just does not work for that nested datasource.

I can define the same restrictions on the view level as well, but will mean that I have two places where I need to define them.

Is this as designed behaviour or it should not be that way?

Thanks

Hi Darius,

Nested collections can be filtered if you specify Check in database and in memory in the Check Type field and provide a Groovy script for the constraint as explained in the docs: https://doc.cuba-platform.com/manual-6.5/constraints.html.

1 Like

Hi Konstantin,

Thanks. It looks like I need to learn another language :slight_smile: To help me started, would you do me a favour and provide the equivalent in Groovy script for the script I posted in my question?


{E}.disabled IS NULL OR {E}.disabled = FALSE OR EXISTS(SELECT ur FROM sec$UserRole ur WHERE ur.user.id = :session$userId AND ur.role.name = 'Administrators')

Thanks for your help and whole team for the Cuba platform. :slight_smile:

Actually, I was able to compile the script and it is working :):


{E}.disabled == null || (!{E}.disabled) || com.haulmont.cuba.core.global.AppBeans.get(com.haulmont.cuba.core.global.UserSessionSource.class).getUserSession().getRoles().contains("Administrators")
With the help of one of your answers to the post on this forum - [url=https://www.cuba-platform.com/discuss/t/access-group-implement-and-setup_1]https://www.cuba-platform.com/discuss/t/access-group-implement-and-setup_1[/url]

Thanks again