how to create generic filter in cuba 6.2 ?

Hi,
I want to create one generic filter that would be applicable to all datasources > How to achieve this?

Could you elaborate? What do you mean by generic filter?

In our application I want to add some condition to all the datasources. for example I have attached employeeId in all the tables, like employeeQualification, employeeExperience etc. I have already set the employeeId in session. When the user logs in to the application and navigates to Experience Browse page, he should be able to see only his experience detail. Now I am doing this by modifying the JPQL query in employeeexperience-brows.xml like select e from test$EmployeeExperience e where e.employee.id = :session$employeeId. We want to add the same condition to every entity associated with Employee. Is this the only way to achieve this or we can write one filter for this and it will be applicable to all tables.

Also we need the hr manager to see every employee’s detail(the condition should not be applied when HR logs in).

How can we achieve this ?

I think you can use security constraints: Constraints - CUBA Platform. Developer’s Manual
In your case, create a constraint for the access group that your users belong to, and add a constraint for the test$EmployeeExperience entity with the following “where clause”:


{E}.employee.id = :session$employeeId

These condition will be added to each JPQL query for the specified entity.

1 Like

Thanks Konstantin. It worked.