diff options
author | Abyss777 <abyss@fox5.ru> | 2017-12-27 16:38:13 +0500 |
---|---|---|
committer | Abyss777 <abyss@fox5.ru> | 2017-12-27 16:38:13 +0500 |
commit | d489eac12119ed62f899569db121364b20b1c9dc (patch) | |
tree | aac938b2511bb9d45a7048236b93c6d740c457be /src/org/traccar/database/DeviceManager.java | |
parent | f128ed17780ad56dfd889d617f518cc0310a96a7 (diff) | |
download | trackermap-server-d489eac12119ed62f899569db121364b20b1c9dc.tar.gz trackermap-server-d489eac12119ed62f899569db121364b20b1c9dc.tar.bz2 trackermap-server-d489eac12119ed62f899569db121364b20b1c9dc.zip |
Implement device disable
Diffstat (limited to 'src/org/traccar/database/DeviceManager.java')
-rw-r--r-- | src/org/traccar/database/DeviceManager.java | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/org/traccar/database/DeviceManager.java b/src/org/traccar/database/DeviceManager.java index 1031c5da9..85ee11c40 100644 --- a/src/org/traccar/database/DeviceManager.java +++ b/src/org/traccar/database/DeviceManager.java @@ -104,15 +104,35 @@ public class DeviceManager extends BaseObjectManager<Device> implements Identity return getItems(getAllItems()); } + public Set<Long> getAllUserItems(long userId) { + return Context.getPermissionsManager().getDevicePermissions(userId); + } + @Override public Set<Long> getUserItems(long userId) { if (Context.getPermissionsManager() != null) { - return Context.getPermissionsManager().getDevicePermissions(userId); + Set<Long> result = new HashSet<>(); + for (long deviceId : Context.getPermissionsManager().getDevicePermissions(userId)) { + Device device = Context.getIdentityManager().getById(deviceId); + if (device != null && !device.getDisabled()) { + result.add(deviceId); + } + } + return result; } else { return new HashSet<>(); } } + public Set<Long> getAllManagedItems(long userId) { + Set<Long> result = new HashSet<>(); + result.addAll(getAllUserItems(userId)); + for (long managedUserId : Context.getUsersManager().getUserItems(userId)) { + result.addAll(getAllUserItems(managedUserId)); + } + return result; + } + @Override public Set<Long> getManagedItems(long userId) { Set<Long> result = new HashSet<>(); @@ -160,6 +180,7 @@ public class DeviceManager extends BaseObjectManager<Device> implements Identity cachedDevice.setCategory(device.getCategory()); cachedDevice.setContact(device.getContact()); cachedDevice.setModel(device.getModel()); + cachedDevice.setDisabled(device.getDisabled()); cachedDevice.setAttributes(device.getAttributes()); if (!device.getUniqueId().equals(cachedDevice.getUniqueId())) { devicesByUniqueId.remove(cachedDevice.getUniqueId()); @@ -246,7 +267,8 @@ public class DeviceManager extends BaseObjectManager<Device> implements Identity List<Position> result = new LinkedList<>(); if (Context.getPermissionsManager() != null) { - for (long deviceId : getUserItems(userId)) { + for (long deviceId : Context.getPermissionsManager().getUserAdmin(userId) + ? getAllUserItems(userId) : getUserItems(userId)) { if (positions.containsKey(deviceId)) { result.add(positions.get(deviceId)); } |