forked from traccar/traccar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Return existing user on second share
- Loading branch information
Showing
1 changed file
with
17 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2015 - 2022 Anton Tananaev ([email protected]) | ||
* Copyright 2015 - 2024 Anton Tananaev ([email protected]) | ||
* | ||
* 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 String shareDevice( | |
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); | ||
} | ||
|