diff options
author | Anton Tananaev <anton@traccar.org> | 2022-06-28 08:13:03 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2022-06-28 08:13:03 -0700 |
commit | a487c1efa5dff2a7644ee7f2874967f4bb867b6a (patch) | |
tree | 0d266dd5809dbc5a78d293675005e11b27bf0c2b /src/main | |
parent | ef644e5185b3109b0da30972a0b5c56768c69957 (diff) | |
download | trackermap-server-a487c1efa5dff2a7644ee7f2874967f4bb867b6a.tar.gz trackermap-server-a487c1efa5dff2a7644ee7f2874967f4bb867b6a.tar.bz2 trackermap-server-a487c1efa5dff2a7644ee7f2874967f4bb867b6a.zip |
Fix new device updates
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/org/traccar/api/BaseObjectResource.java | 5 | ||||
-rw-r--r-- | src/main/java/org/traccar/session/ConnectionManager.java | 14 |
2 files changed, 18 insertions, 1 deletions
diff --git a/src/main/java/org/traccar/api/BaseObjectResource.java b/src/main/java/org/traccar/api/BaseObjectResource.java index 489360619..d10843917 100644 --- a/src/main/java/org/traccar/api/BaseObjectResource.java +++ b/src/main/java/org/traccar/api/BaseObjectResource.java @@ -21,6 +21,7 @@ import org.traccar.model.BaseModel; import org.traccar.model.Group; import org.traccar.model.Permission; import org.traccar.model.User; +import org.traccar.session.ConnectionManager; import org.traccar.session.cache.CacheManager; import org.traccar.storage.StorageException; import org.traccar.storage.query.Columns; @@ -41,6 +42,9 @@ public abstract class BaseObjectResource<T extends BaseModel> extends BaseResour @Inject private CacheManager cacheManager; + @Inject + private ConnectionManager connectionManager; + protected final Class<T> baseClass; public BaseObjectResource(Class<T> baseClass) { @@ -68,6 +72,7 @@ public abstract class BaseObjectResource<T extends BaseModel> extends BaseResour LogAction.create(getUserId(), entity); storage.addPermission(new Permission(User.class, getUserId(), baseClass, entity.getId())); cacheManager.invalidatePermission(User.class, getUserId(), baseClass, entity.getId()); + connectionManager.invalidatePermission(User.class, getUserId(), baseClass, entity.getId()); LogAction.link(getUserId(), User.class, getUserId(), baseClass, entity.getId()); return Response.ok(entity).build(); diff --git a/src/main/java/org/traccar/session/ConnectionManager.java b/src/main/java/org/traccar/session/ConnectionManager.java index c2f602c11..27d6184c2 100644 --- a/src/main/java/org/traccar/session/ConnectionManager.java +++ b/src/main/java/org/traccar/session/ConnectionManager.java @@ -364,6 +364,18 @@ public class ConnectionManager implements BroadcastInterface { } } + @Override + public synchronized void invalidatePermission( + Class<? extends BaseModel> clazz1, long id1, + Class<? extends BaseModel> clazz2, long id2) { + if (clazz1.equals(User.class) && clazz2.equals(Device.class)) { + if (listeners.containsKey(id1)) { + userDevices.get(id1).add(id2); + deviceUsers.put(id2, Set.of(id1)); + } + } + } + public interface UpdateListener { void onKeepalive(); void onUpdateDevice(Device device); @@ -379,7 +391,7 @@ public class ConnectionManager implements BroadcastInterface { var devices = storage.getObjects(Device.class, new Request( new Columns.Include("id"), new Condition.Permission(User.class, userId, Device.class))); - userDevices.put(userId, devices.stream().map(BaseModel::getId).collect(Collectors.toUnmodifiableSet())); + userDevices.put(userId, devices.stream().map(BaseModel::getId).collect(Collectors.toSet())); devices.forEach(device -> deviceUsers.computeIfAbsent(device.getId(), id -> new HashSet<>()).add(userId)); } set.add(listener); |