aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/api
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2023-02-20 14:33:36 -0800
committerAnton Tananaev <anton@traccar.org>2023-02-20 14:33:36 -0800
commitcd1d80896b16c84ae0a8a4631a9dba6955e9e344 (patch)
tree8efd18ee259e2b614c9e4450cf9982d6754cdaa6 /src/main/java/org/traccar/api
parent1439422c6f4ce947f6719743b37fa49f251fc97f (diff)
downloadtrackermap-server-cd1d80896b16c84ae0a8a4631a9dba6955e9e344.tar.gz
trackermap-server-cd1d80896b16c84ae0a8a4631a9dba6955e9e344.tar.bz2
trackermap-server-cd1d80896b16c84ae0a8a4631a9dba6955e9e344.zip
Implement command notificator
Diffstat (limited to 'src/main/java/org/traccar/api')
-rw-r--r--src/main/java/org/traccar/api/resource/NotificationResource.java6
-rw-r--r--src/main/java/org/traccar/api/security/PermissionsService.java20
2 files changed, 20 insertions, 6 deletions
diff --git a/src/main/java/org/traccar/api/resource/NotificationResource.java b/src/main/java/org/traccar/api/resource/NotificationResource.java
index d58557601..7005fc083 100644
--- a/src/main/java/org/traccar/api/resource/NotificationResource.java
+++ b/src/main/java/org/traccar/api/resource/NotificationResource.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 - 2022 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2023 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.
@@ -80,7 +80,7 @@ public class NotificationResource extends ExtendedObjectResource<Notification> {
@POST
@Path("test")
- public Response testMessage() throws MessageException, InterruptedException, StorageException {
+ public Response testMessage() throws MessageException, StorageException {
User user = permissionsService.getUser(getUserId());
for (Typed method : notificatorManager.getAllNotificatorTypes()) {
notificatorManager.getNotificator(method.getType()).send(null, user, new Event("test", 0), null);
@@ -91,7 +91,7 @@ public class NotificationResource extends ExtendedObjectResource<Notification> {
@POST
@Path("test/{notificator}")
public Response testMessage(@PathParam("notificator") String notificator)
- throws MessageException, InterruptedException, StorageException {
+ throws MessageException, StorageException {
User user = permissionsService.getUser(getUserId());
notificatorManager.getNotificator(notificator).send(null, user, new Event("test", 0), null);
return Response.noContent().build();
diff --git a/src/main/java/org/traccar/api/security/PermissionsService.java b/src/main/java/org/traccar/api/security/PermissionsService.java
index 4421572d7..18a376601 100644
--- a/src/main/java/org/traccar/api/security/PermissionsService.java
+++ b/src/main/java/org/traccar/api/security/PermissionsService.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2022 Anton Tananaev (anton@traccar.org)
+ * Copyright 2022 - 2023 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.
@@ -23,6 +23,7 @@ import org.traccar.model.Device;
import org.traccar.model.Group;
import org.traccar.model.GroupedModel;
import org.traccar.model.ManagedUser;
+import org.traccar.model.Notification;
import org.traccar.model.ScheduledModel;
import org.traccar.model.Server;
import org.traccar.model.User;
@@ -129,7 +130,7 @@ public class PermissionsService {
GroupedModel before = null;
if (!addition) {
before = storage.getObject(after.getClass(), new Request(
- new Columns.Include("groupId"), new Condition.Equals("id", object.getId())));
+ new Columns.Include("groupId"), new Condition.Equals("id", after.getId())));
}
if (before == null || before.getGroupId() != after.getGroupId()) {
checkPermission(Group.class, userId, after.getGroupId());
@@ -142,13 +143,26 @@ public class PermissionsService {
ScheduledModel before = null;
if (!addition) {
before = storage.getObject(after.getClass(), new Request(
- new Columns.Include("calendarId"), new Condition.Equals("id", object.getId())));
+ new Columns.Include("calendarId"), new Condition.Equals("id", after.getId())));
}
if (before == null || before.getCalendarId() != after.getCalendarId()) {
checkPermission(Calendar.class, userId, after.getCalendarId());
}
}
}
+ if (object instanceof Notification) {
+ Notification after = ((Notification) object);
+ if (after.getCommandId() > 0) {
+ Notification before = null;
+ if (!addition) {
+ before = storage.getObject(after.getClass(), new Request(
+ new Columns.Include("commandId"), new Condition.Equals("id", after.getId())));
+ }
+ if (before == null || before.getCommandId() != after.getCommandId()) {
+ checkPermission(Command.class, userId, after.getCommandId());
+ }
+ }
+ }
}
}