diff options
Diffstat (limited to 'src/main/java/org/traccar/api/resource')
5 files changed, 36 insertions, 21 deletions
diff --git a/src/main/java/org/traccar/api/resource/CommandResource.java b/src/main/java/org/traccar/api/resource/CommandResource.java index c23d91e77..66ec0f8a3 100644 --- a/src/main/java/org/traccar/api/resource/CommandResource.java +++ b/src/main/java/org/traccar/api/resource/CommandResource.java @@ -23,6 +23,7 @@ import org.traccar.BaseProtocol; import org.traccar.ServerManager; import org.traccar.api.ExtendedObjectResource; import org.traccar.database.CommandsManager; +import org.traccar.helper.LogAction; import org.traccar.helper.model.DeviceUtil; import org.traccar.model.Command; import org.traccar.model.Device; @@ -140,6 +141,8 @@ public class CommandResource extends ExtendedObjectResource<Command> { return Response.accepted(queuedCommand).build(); } } + + LogAction.command(getUserId(), groupId, entity.getDeviceId(), entity.getType()); return Response.ok(entity).build(); } diff --git a/src/main/java/org/traccar/api/resource/DeviceResource.java b/src/main/java/org/traccar/api/resource/DeviceResource.java index 56253152f..971c29c60 100644 --- a/src/main/java/org/traccar/api/resource/DeviceResource.java +++ b/src/main/java/org/traccar/api/resource/DeviceResource.java @@ -137,10 +137,8 @@ public class DeviceResource extends BaseObjectResource<Device> { @Path("{id}/accumulators") @PUT public Response updateAccumulators(DeviceAccumulators entity) throws Exception { - if (permissionsService.notAdmin(getUserId())) { - permissionsService.checkManager(getUserId()); - permissionsService.checkPermission(Device.class, getUserId(), entity.getDeviceId()); - } + permissionsService.checkEdit(getUserId(), Device.class, false); + permissionsService.checkPermission(Device.class, getUserId(), entity.getDeviceId()); Position position = storage.getObject(Position.class, new Request( new Columns.All(), new Condition.LatestPositions(entity.getDeviceId()))); @@ -171,7 +169,7 @@ public class DeviceResource extends BaseObjectResource<Device> { throw new IllegalArgumentException(); } - LogAction.resetDeviceAccumulators(getUserId(), entity.getDeviceId()); + LogAction.resetAccumulators(getUserId(), entity.getDeviceId()); return Response.noContent().build(); } diff --git a/src/main/java/org/traccar/api/resource/NotificationResource.java b/src/main/java/org/traccar/api/resource/NotificationResource.java index 43dc1fa98..a41d00cf3 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 - 2023 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 2024 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. @@ -46,6 +46,8 @@ import java.util.ArrayList; import java.util.Collection; import java.util.LinkedList; import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; @Path("notifications") @Produces(MediaType.APPLICATION_JSON) @@ -80,8 +82,11 @@ public class NotificationResource extends ExtendedObjectResource<Notification> { @GET @Path("notificators") - public Collection<Typed> getNotificators() { - return notificatorManager.getAllNotificatorTypes(); + public Collection<Typed> getNotificators(@QueryParam("announcement") boolean announcement) { + Set<String> announcementsUnsupported = Set.of("command", "web"); + return notificatorManager.getAllNotificatorTypes().stream() + .filter(typed -> !announcement || !announcementsUnsupported.contains(typed.getType())) + .collect(Collectors.toUnmodifiableSet()); } @POST @@ -120,7 +125,9 @@ public class NotificationResource extends ExtendedObjectResource<Notification> { } } for (User user : users) { - notificatorManager.getNotificator(notificator).send(user, message, null, null); + if (!user.getTemporary()) { + notificatorManager.getNotificator(notificator).send(user, message, null, null); + } } return Response.noContent().build(); } diff --git a/src/main/java/org/traccar/api/resource/ReportResource.java b/src/main/java/org/traccar/api/resource/ReportResource.java index 55a96fa90..81f409c0f 100644 --- a/src/main/java/org/traccar/api/resource/ReportResource.java +++ b/src/main/java/org/traccar/api/resource/ReportResource.java @@ -113,7 +113,7 @@ public class ReportResource extends SimpleObjectResource<Report> { @QueryParam("from") Date from, @QueryParam("to") Date to) throws StorageException { permissionsService.checkRestriction(getUserId(), UserRestrictions::getDisableReports); - LogAction.logReport(getUserId(), "combined", from, to, deviceIds, groupIds); + LogAction.report(getUserId(), false, "combined", from, to, deviceIds, groupIds); return combinedReportProvider.getObjects(getUserId(), deviceIds, groupIds, from, to); } @@ -125,7 +125,7 @@ public class ReportResource extends SimpleObjectResource<Report> { @QueryParam("from") Date from, @QueryParam("to") Date to) throws StorageException { permissionsService.checkRestriction(getUserId(), UserRestrictions::getDisableReports); - LogAction.logReport(getUserId(), "route", from, to, deviceIds, groupIds); + LogAction.report(getUserId(), false, "route", from, to, deviceIds, groupIds); return routeReportProvider.getObjects(getUserId(), deviceIds, groupIds, from, to); } @@ -140,7 +140,7 @@ public class ReportResource extends SimpleObjectResource<Report> { @QueryParam("mail") boolean mail) throws StorageException { permissionsService.checkRestriction(getUserId(), UserRestrictions::getDisableReports); return executeReport(getUserId(), mail, stream -> { - LogAction.logReport(getUserId(), "route", from, to, deviceIds, groupIds); + LogAction.report(getUserId(), false, "route", from, to, deviceIds, groupIds); routeReportProvider.getExcel(stream, getUserId(), deviceIds, groupIds, from, to); }); } @@ -166,7 +166,7 @@ public class ReportResource extends SimpleObjectResource<Report> { @QueryParam("from") Date from, @QueryParam("to") Date to) throws StorageException { permissionsService.checkRestriction(getUserId(), UserRestrictions::getDisableReports); - LogAction.logReport(getUserId(), "events", from, to, deviceIds, groupIds); + LogAction.report(getUserId(), false, "events", from, to, deviceIds, groupIds); return eventsReportProvider.getObjects(getUserId(), deviceIds, groupIds, types, from, to); } @@ -182,7 +182,7 @@ public class ReportResource extends SimpleObjectResource<Report> { @QueryParam("mail") boolean mail) throws StorageException { permissionsService.checkRestriction(getUserId(), UserRestrictions::getDisableReports); return executeReport(getUserId(), mail, stream -> { - LogAction.logReport(getUserId(), "events", from, to, deviceIds, groupIds); + LogAction.report(getUserId(), false, "events", from, to, deviceIds, groupIds); eventsReportProvider.getExcel(stream, getUserId(), deviceIds, groupIds, types, from, to); }); } @@ -209,7 +209,7 @@ public class ReportResource extends SimpleObjectResource<Report> { @QueryParam("to") Date to, @QueryParam("daily") boolean daily) throws StorageException { permissionsService.checkRestriction(getUserId(), UserRestrictions::getDisableReports); - LogAction.logReport(getUserId(), "summary", from, to, deviceIds, groupIds); + LogAction.report(getUserId(), false, "summary", from, to, deviceIds, groupIds); return summaryReportProvider.getObjects(getUserId(), deviceIds, groupIds, from, to, daily); } @@ -225,7 +225,7 @@ public class ReportResource extends SimpleObjectResource<Report> { @QueryParam("mail") boolean mail) throws StorageException { permissionsService.checkRestriction(getUserId(), UserRestrictions::getDisableReports); return executeReport(getUserId(), mail, stream -> { - LogAction.logReport(getUserId(), "summary", from, to, deviceIds, groupIds); + LogAction.report(getUserId(), false, "summary", from, to, deviceIds, groupIds); summaryReportProvider.getExcel(stream, getUserId(), deviceIds, groupIds, from, to, daily); }); } @@ -251,7 +251,7 @@ public class ReportResource extends SimpleObjectResource<Report> { @QueryParam("from") Date from, @QueryParam("to") Date to) throws StorageException { permissionsService.checkRestriction(getUserId(), UserRestrictions::getDisableReports); - LogAction.logReport(getUserId(), "trips", from, to, deviceIds, groupIds); + LogAction.report(getUserId(), false, "trips", from, to, deviceIds, groupIds); return tripsReportProvider.getObjects(getUserId(), deviceIds, groupIds, from, to); } @@ -266,7 +266,7 @@ public class ReportResource extends SimpleObjectResource<Report> { @QueryParam("mail") boolean mail) throws StorageException { permissionsService.checkRestriction(getUserId(), UserRestrictions::getDisableReports); return executeReport(getUserId(), mail, stream -> { - LogAction.logReport(getUserId(), "trips", from, to, deviceIds, groupIds); + LogAction.report(getUserId(), false, "trips", from, to, deviceIds, groupIds); tripsReportProvider.getExcel(stream, getUserId(), deviceIds, groupIds, from, to); }); } @@ -291,7 +291,7 @@ public class ReportResource extends SimpleObjectResource<Report> { @QueryParam("from") Date from, @QueryParam("to") Date to) throws StorageException { permissionsService.checkRestriction(getUserId(), UserRestrictions::getDisableReports); - LogAction.logReport(getUserId(), "stops", from, to, deviceIds, groupIds); + LogAction.report(getUserId(), false, "stops", from, to, deviceIds, groupIds); return stopsReportProvider.getObjects(getUserId(), deviceIds, groupIds, from, to); } @@ -306,7 +306,7 @@ public class ReportResource extends SimpleObjectResource<Report> { @QueryParam("mail") boolean mail) throws StorageException { permissionsService.checkRestriction(getUserId(), UserRestrictions::getDisableReports); return executeReport(getUserId(), mail, stream -> { - LogAction.logReport(getUserId(), "stops", from, to, deviceIds, groupIds); + LogAction.report(getUserId(), false, "stops", from, to, deviceIds, groupIds); stopsReportProvider.getExcel(stream, getUserId(), deviceIds, groupIds, from, to); }); } @@ -326,7 +326,7 @@ public class ReportResource extends SimpleObjectResource<Report> { @Path("devices/{type:xlsx|mail}") @GET @Produces(EXCEL) - public Response geDevicesExcel( + public Response getDevicesExcel( @PathParam("type") String type) throws StorageException { permissionsService.checkRestriction(getUserId(), UserRestrictions::getDisableReports); return executeReport(getUserId(), type.equals("mail"), stream -> { diff --git a/src/main/java/org/traccar/api/resource/ServerResource.java b/src/main/java/org/traccar/api/resource/ServerResource.java index 2a72d2773..eb10ac763 100644 --- a/src/main/java/org/traccar/api/resource/ServerResource.java +++ b/src/main/java/org/traccar/api/resource/ServerResource.java @@ -161,4 +161,11 @@ public class ServerResource extends BaseResource { return cacheManager.toString(); } + @Path("reboot") + @POST + public void reboot() throws StorageException { + permissionsService.checkAdmin(getUserId()); + System.exit(130); + } + } |