Pessimistic Locking & Deleting

Hi

We are currently exploring pessimistic locking and it is working great for simultaneous users trying to edit the same entity. However I would have expected the pessimistic lock to also prevent a user from deleting a record if another user is editing it. Is this correct or are we doing something wrong as this is causing access denied errors.

User 1 is in edit mode:

User 2 selects the same record and clicks remove:

User 2 remove is successful despite user 1 being in edit mode:

User 1 tries to save entity and receives access denied:

Thanks
David

Hi David,

Currently, the locking information is only analyzed inside entity editors, not in RemoveActions of browse screens. You may search for com.haulmont.cuba.core.app.LockService usages and see how it works.

If necessary, you can easily modify remove actions in order to check whether the entity instance is locked.

It may be something like this:

@UiController("pesslock_Order.browse")
@UiDescriptor("order-browse.xml")
@LookupComponent("ordersTable")
@LoadDataBeforeShow
public class OrderBrowse extends StandardLookup<Order> {

    @Named("ordersTable.remove")
    private RemoveAction<Order> ordersTableRemove;

    @Inject
    private GroupTable<Order> ordersTable;

    @Inject
    private LockService lockService;
    
    @Inject
    private Notifications notifications;

    @Subscribe("ordersTable.remove")
    public void onOrdersTableRemove(Action.ActionPerformedEvent event) {
        Order order = ordersTable.getSingleSelected();
        LockInfo lockInfo = lockService.getLockInfo(order.getMetaClass().getName(), order.getId().toString());
        if (lockInfo != null) {
            notifications.create(Notifications.NotificationType.WARNING)
                    .withCaption("The order is locked by other user")
                    .show();
        } else {
            ordersTableRemove.execute();
        }
    }
}

That works. Thanks Maxim. :+1: