aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2024-01-16 20:48:48 -0800
committerAnton Tananaev <anton@traccar.org>2024-01-16 20:48:48 -0800
commit79a4cf9355b08e0b306146a94bd65adb5ed963a5 (patch)
tree54c706d22b0f07eea217affa5131891f678a70bb
parent7855762df494ed113210d5d202a13de279b13dcc (diff)
downloadtrackermap-server-79a4cf9355b08e0b306146a94bd65adb5ed963a5.tar.gz
trackermap-server-79a4cf9355b08e0b306146a94bd65adb5ed963a5.tar.bz2
trackermap-server-79a4cf9355b08e0b306146a94bd65adb5ed963a5.zip
Return existing user on second share
-rw-r--r--src/main/java/org/traccar/api/resource/DeviceResource.java28
1 files changed, 17 insertions, 11 deletions
diff --git a/src/main/java/org/traccar/api/resource/DeviceResource.java b/src/main/java/org/traccar/api/resource/DeviceResource.java
index d7c5a5477..00a3fc5b9 100644
--- a/src/main/java/org/traccar/api/resource/DeviceResource.java
+++ b/src/main/java/org/traccar/api/resource/DeviceResource.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2022 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2024 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -214,18 +214,24 @@ public class DeviceResource extends BaseObjectResource<Device> {
new Condition.Equals("id", deviceId),
new Condition.Permission(User.class, user.getId(), Device.class))));
- User share = new User();
- share.setName(device.getName());
- share.setEmail(user.getEmail() + ":" + device.getUniqueId());
- share.setExpirationTime(expiration);
- share.setTemporary(true);
- share.setReadonly(true);
- share.setLimitCommands(!config.getBoolean(Keys.WEB_SHARE_DEVICE_COMMANDS));
- share.setDisableReports(!config.getBoolean(Keys.WEB_SHARE_DEVICE_REPORTS));
+ String shareEmail = user.getEmail() + ":" + device.getUniqueId();
+ User share = storage.getObject(User.class, new Request(
+ new Columns.All(), new Condition.Equals("email", shareEmail)));
- share.setId(storage.addObject(share, new Request(new Columns.Exclude("id"))));
+ if (share == null) {
+ share = new User();
+ share.setName(device.getName());
+ share.setEmail(shareEmail);
+ share.setExpirationTime(expiration);
+ share.setTemporary(true);
+ share.setReadonly(true);
+ share.setLimitCommands(!config.getBoolean(Keys.WEB_SHARE_DEVICE_COMMANDS));
+ share.setDisableReports(!config.getBoolean(Keys.WEB_SHARE_DEVICE_REPORTS));
- storage.addPermission(new Permission(User.class, share.getId(), Device.class, deviceId));
+ share.setId(storage.addObject(share, new Request(new Columns.Exclude("id"))));
+
+ storage.addPermission(new Permission(User.class, share.getId(), Device.class, deviceId));
+ }
return tokenManager.generateToken(share.getId(), expiration);
}