aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/traccar/api')
-rw-r--r--src/main/java/org/traccar/api/resource/NotificationResource.java12
-rw-r--r--src/main/java/org/traccar/api/resource/PasswordResource.java2
-rw-r--r--src/main/java/org/traccar/api/resource/ReportResource.java4
-rw-r--r--src/main/java/org/traccar/api/security/PermissionsService.java4
4 files changed, 14 insertions, 8 deletions
diff --git a/src/main/java/org/traccar/api/resource/NotificationResource.java b/src/main/java/org/traccar/api/resource/NotificationResource.java
index cf4b66fa1..2fc103e20 100644
--- a/src/main/java/org/traccar/api/resource/NotificationResource.java
+++ b/src/main/java/org/traccar/api/resource/NotificationResource.java
@@ -31,7 +31,9 @@ import org.traccar.api.ExtendedObjectResource;
import org.traccar.model.Event;
import org.traccar.model.Notification;
import org.traccar.model.Typed;
+import org.traccar.model.User;
import org.traccar.notification.MessageException;
+import org.traccar.storage.StorageException;
@Path("notifications")
@Produces(MediaType.APPLICATION_JSON)
@@ -56,10 +58,11 @@ public class NotificationResource extends ExtendedObjectResource<Notification> {
@POST
@Path("test")
- public Response testMessage() throws MessageException, InterruptedException {
+ public Response testMessage() throws MessageException, InterruptedException, StorageException {
+ User user = permissionsService.getUser(getUserId());
for (Typed method : Context.getNotificatorManager().getAllNotificatorTypes()) {
Context.getNotificatorManager()
- .getNotificator(method.getType()).sendSync(getUserId(), new Event("test", 0), null);
+ .getNotificator(method.getType()).sendSync(user, new Event("test", 0), null);
}
return Response.noContent().build();
}
@@ -67,8 +70,9 @@ public class NotificationResource extends ExtendedObjectResource<Notification> {
@POST
@Path("test/{notificator}")
public Response testMessage(@PathParam("notificator") String notificator)
- throws MessageException, InterruptedException {
- Context.getNotificatorManager().getNotificator(notificator).sendSync(getUserId(), new Event("test", 0), null);
+ throws MessageException, InterruptedException, StorageException {
+ User user = permissionsService.getUser(getUserId());
+ Context.getNotificatorManager().getNotificator(notificator).sendSync(user, new Event("test", 0), null);
return Response.noContent().build();
}
diff --git a/src/main/java/org/traccar/api/resource/PasswordResource.java b/src/main/java/org/traccar/api/resource/PasswordResource.java
index 0642ff3cc..ed7131718 100644
--- a/src/main/java/org/traccar/api/resource/PasswordResource.java
+++ b/src/main/java/org/traccar/api/resource/PasswordResource.java
@@ -55,7 +55,7 @@ public class PasswordResource extends BaseResource {
velocityContext.put("token", token);
NotificationMessage fullMessage =
TextTemplateFormatter.formatMessage(velocityContext, "passwordReset", "full");
- Context.getMailManager().sendMessage(userId, fullMessage.getSubject(), fullMessage.getBody());
+ Context.getMailManager().sendMessage(user, fullMessage.getSubject(), fullMessage.getBody());
break;
}
}
diff --git a/src/main/java/org/traccar/api/resource/ReportResource.java b/src/main/java/org/traccar/api/resource/ReportResource.java
index 96b32a4f0..3c1b8f715 100644
--- a/src/main/java/org/traccar/api/resource/ReportResource.java
+++ b/src/main/java/org/traccar/api/resource/ReportResource.java
@@ -43,6 +43,7 @@ import org.traccar.api.BaseResource;
import org.traccar.helper.LogAction;
import org.traccar.model.Event;
import org.traccar.model.Position;
+import org.traccar.model.User;
import org.traccar.model.UserRestrictions;
import org.traccar.reports.EventsReportProvider;
import org.traccar.reports.SummaryReportProvider;
@@ -97,8 +98,9 @@ public class ReportResource extends BaseResource {
attachment.setDataHandler(new DataHandler(new ByteArrayDataSource(
stream.toByteArray(), "application/octet-stream")));
+ User user = permissionsService.getUser(userId);
Context.getMailManager().sendMessage(
- userId, "Report", "The report is in the attachment.", attachment);
+ user, "Report", "The report is in the attachment.", attachment);
} catch (StorageException | IOException | MessagingException e) {
LOGGER.warn("Report failed", e);
}
diff --git a/src/main/java/org/traccar/api/security/PermissionsService.java b/src/main/java/org/traccar/api/security/PermissionsService.java
index 12a2189e9..9ec3b43c1 100644
--- a/src/main/java/org/traccar/api/security/PermissionsService.java
+++ b/src/main/java/org/traccar/api/security/PermissionsService.java
@@ -46,7 +46,7 @@ public class PermissionsService {
this.storage = storage;
}
- private Server getServer() throws StorageException {
+ public Server getServer() throws StorageException {
if (server == null) {
server = storage.getObject(
Server.class, new Request(new Columns.All()));
@@ -54,7 +54,7 @@ public class PermissionsService {
return server;
}
- private User getUser(long userId) throws StorageException {
+ public User getUser(long userId) throws StorageException {
if (user == null) {
user = storage.getObject(
User.class, new Request(new Columns.All(), new Condition.Equals("id", "id", userId)));