aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/database
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2017-12-28 16:51:41 +1300
committerGitHub <noreply@github.com>2017-12-28 16:51:41 +1300
commit6e0be9857bc26c59936d4446ef15488bd90f5150 (patch)
treecec25dcca31ba5c88db721c750f88a0ddb541f8e /src/org/traccar/database
parentf128ed17780ad56dfd889d617f518cc0310a96a7 (diff)
parent71ef701357da0b4b5c8214418b6b149e87c16ac2 (diff)
downloadtrackermap-server-6e0be9857bc26c59936d4446ef15488bd90f5150.tar.gz
trackermap-server-6e0be9857bc26c59936d4446ef15488bd90f5150.tar.bz2
trackermap-server-6e0be9857bc26c59936d4446ef15488bd90f5150.zip
Merge pull request #3700 from Abyss777/disable_device2
Implement device disable (simple)
Diffstat (limited to 'src/org/traccar/database')
-rw-r--r--src/org/traccar/database/DeviceManager.java26
-rw-r--r--src/org/traccar/database/PermissionsManager.java23
2 files changed, 43 insertions, 6 deletions
diff --git a/src/org/traccar/database/DeviceManager.java b/src/org/traccar/database/DeviceManager.java
index 1031c5da9..cb410b7c0 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 = 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));
}
diff --git a/src/org/traccar/database/PermissionsManager.java b/src/org/traccar/database/PermissionsManager.java
index 0e9097d25..60bda99ce 100644
--- a/src/org/traccar/database/PermissionsManager.java
+++ b/src/org/traccar/database/PermissionsManager.java
@@ -74,13 +74,28 @@ public class PermissionsManager {
return devicePermissions.get(userId);
}
- public Set<Long> getDeviceUsers(long deviceId) {
+ private Set<Long> getAllDeviceUsers(long deviceId) {
if (!deviceUsers.containsKey(deviceId)) {
deviceUsers.put(deviceId, new HashSet<Long>());
}
return deviceUsers.get(deviceId);
}
+ public Set<Long> getDeviceUsers(long deviceId) {
+ Device device = Context.getIdentityManager().getById(deviceId);
+ if (device != null && !device.getDisabled()) {
+ return getAllDeviceUsers(deviceId);
+ } else {
+ Set<Long> result = new HashSet<>();
+ for (long userId : getAllDeviceUsers(deviceId)) {
+ if (getUserAdmin(userId)) {
+ result.add(userId);
+ }
+ }
+ return result;
+ }
+ }
+
public Set<Long> getGroupDevices(long groupId) {
if (!groupDevices.containsKey(groupId)) {
groupDevices.put(groupId, new HashSet<Long>());
@@ -133,7 +148,7 @@ public class PermissionsManager {
deviceUsers.clear();
for (Map.Entry<Long, Set<Long>> entry : devicePermissions.entrySet()) {
for (long deviceId : entry.getValue()) {
- getDeviceUsers(deviceId).add(entry.getKey());
+ getAllDeviceUsers(deviceId).add(entry.getKey());
}
}
}
@@ -179,9 +194,9 @@ public class PermissionsManager {
if (deviceLimit != -1) {
int deviceCount = 0;
if (getUserManager(userId)) {
- deviceCount = Context.getDeviceManager().getManagedItems(userId).size();
+ deviceCount = Context.getDeviceManager().getAllManagedItems(userId).size();
} else {
- deviceCount = Context.getDeviceManager().getUserItems(userId).size();
+ deviceCount = Context.getDeviceManager().getAllUserItems(userId).size();
}
if (deviceCount >= deviceLimit) {
throw new SecurityException("User device limit reached");