Deny edit constraints based on attribute value "Status"

I want to deny edit operation based on ‘status’ attribute value. For example if status is ‘Closed’ then no role except admin can change the record.

As suggested by @chizhikov (Deny Editing based on attribute value - #3 от пользователя umeshhodwala - CUBA.Platform), I applied following solution-

import com.haulmont.cuba.core.Persistence
Persistence persistence = AppBeans.get(Persistence.class)

return !({E}, “status”) in (“CLOSE”))

The solution works fine when user tries to change any other attribute for closed record except ‘Status’ itself. If user changes ‘status’ attribute from “CLOSE” to any other, it allows.

Status is Enum with two value - Assigned and Closed

Why this strange behavior. Please advice



Any advise please

Any suggestion please

Hi, Umesh!

I can’t reproduce described behavior - status editing from Close to Assigned is denied in my realization.
Please, check it in this test project: (86.4 KB)

You need to create new user under UserGroup access group and log in with this newly created user to test the constraint.
Please, let me know the results.

Thanks @chizhikov,

The reason of strange behavior was due to Enum definition, I was using Name - CLOSE and Value - Close, When I made both CLOSE, it is working.

I thought about this but because constraint was working with other attribute changing, it should have worked for status field.

Thanks for demo this force me to change Enum and that solved the issue.