diff options
author | Anton Tananaev <anton@traccar.org> | 2022-06-07 06:48:53 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2022-06-07 06:48:53 -0700 |
commit | 8eecfdcf5c59f92158a6c339d1622e0e9d67968c (patch) | |
tree | f0bd5c9d391549ab7b98f87a86938a1341802a23 /src/main/java/org/traccar/api | |
parent | 669bdccecff50eaca46c815598df092ad0fe143d (diff) | |
download | trackermap-server-8eecfdcf5c59f92158a6c339d1622e0e9d67968c.tar.gz trackermap-server-8eecfdcf5c59f92158a6c339d1622e0e9d67968c.tar.bz2 trackermap-server-8eecfdcf5c59f92158a6c339d1622e0e9d67968c.zip |
Pass user to notificators
Diffstat (limited to 'src/main/java/org/traccar/api')
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))); |