mirror of
https://github.com/traccar/traccar.git
synced 2026-05-19 06:02:22 -04:00
- Add server-wide "device readonly" flag
- Allow "device readonly" users send commands
This commit is contained in:
@@ -16,6 +16,10 @@
|
||||
<column name="sms" type="BOOLEAN" defaultValueBoolean="false" />
|
||||
</addColumn>
|
||||
|
||||
<addColumn tableName="server">
|
||||
<column name="devicereadonly" type="BOOLEAN" defaultValueBoolean="false" />
|
||||
</addColumn>
|
||||
|
||||
</changeSet>
|
||||
|
||||
</databaseChangeLog>
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
UPDATE server SET
|
||||
registration = :registration,
|
||||
readonly = :readonly,
|
||||
deviceReadonly = :deviceReadonly,
|
||||
map = :map,
|
||||
bingKey = :bingKey,
|
||||
mapUrl = :mapUrl,
|
||||
|
||||
@@ -34,7 +34,6 @@ public class CommandResource extends BaseResource {
|
||||
@POST
|
||||
public Response add(Command entity) {
|
||||
Context.getPermissionsManager().checkReadonly(getUserId());
|
||||
Context.getPermissionsManager().checkDeviceReadonly(getUserId());
|
||||
Context.getPermissionsManager().checkDevice(getUserId(), entity.getDeviceId());
|
||||
Context.getConnectionManager().getActiveDevice(entity.getDeviceId()).sendCommand(entity);
|
||||
return Response.ok(entity).build();
|
||||
|
||||
@@ -223,7 +223,7 @@ public class PermissionsManager {
|
||||
}
|
||||
|
||||
public void checkDeviceReadonly(long userId) throws SecurityException {
|
||||
if (!isAdmin(userId) && isDeviceReadonly(userId)) {
|
||||
if (!isAdmin(userId) && (server.getDeviceReadonly() || isDeviceReadonly(userId))) {
|
||||
throw new SecurityException("Account is device readonly");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,16 @@ public class Server extends Extensible {
|
||||
this.readonly = readonly;
|
||||
}
|
||||
|
||||
private boolean deviceReadonly;
|
||||
|
||||
public boolean getDeviceReadonly() {
|
||||
return deviceReadonly;
|
||||
}
|
||||
|
||||
public void setDeviceReadonly(boolean deviceReadonly) {
|
||||
this.deviceReadonly = deviceReadonly;
|
||||
}
|
||||
|
||||
private String map;
|
||||
|
||||
public String getMap() {
|
||||
|
||||
Reference in New Issue
Block a user