Not able to remove user admin of tenant

I have a Company class extended from Tenant class

As we know company class has user admin filed. This user field is crucial for our company class thanks to make use of it in our business logic. We aren’t able to load data associated with that user in company class when that user admin was deleted. That is why, we need to prevent deletion of that user.


As well as, we can’t combine @OnDeleteInverse(DeletePolicy.DENY) which is used to fix our problem unfortunately. Because Tenant class is not accessable to edit.

In short, User Admin should not be removed who was associated with tenant

How can we fix it?

1 Like

Hi,
You can write an EntityChangedEvent listener for that entity:
https://doc.cuba-platform.com/manual-7.2/entityChangedEvent.html

Listen for REMOVED event type, before-commit phase.
Check conditions in the listener, and if the entity removal should be denied - throw an exception.

1 Like