Websocket doesn't push an update when device becomes unavailable through permissions

keith siilats6 years ago

This is a tricky one

  1. I have two groups "available" and "rented"
  2. I switch through api a device from groupid=1 to groupid=2
  3. My user only has access to group=1, group=2 devices are not available to the user.

The problem is that Websocket will not push a positionupdate if I change from group=1 to group=2 (thinking that since i dont see the device no need to update). Also doesn't push update when I change group back thinking again I don't have access to the device. I fake a positionupdate when I change the group via API to push the websocket update to everyone.

Any idea how to fix this? I didnt find anything obvious.

keith siilats6 years ago

Looks like refreshDeviceAndGroupPermissions should trigger a websocket update

keith siilats6 years ago

I made it in BaseObjectResource update for now, I can send a pull request if you like it

//send for users that have new permission
        if (entity instanceof Device) {
            Device d = (Device)entity;
            Position p=Context.getIdentityManager().getLastPosition(d.getId());
            Context.getConnectionManager().updateDevice((Device)entity);
            if (p!=null)
                Context.getConnectionManager().updatePosition(p);
            Context.getConnectionManager().updateDevice(
                    p.getDeviceId(), Device.STATUS_ONLINE, new Date());
        }