From 1ed6886245859754efac76ba8cc412d3ec61523b Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 29 May 2024 17:35:48 -0700 Subject: Allow regular users edit accumulators --- src/main/java/org/traccar/api/resource/DeviceResource.java | 8 +++----- src/main/java/org/traccar/helper/LogAction.java | 8 ++++---- 2 files changed, 7 insertions(+), 9 deletions(-) (limited to 'src/main/java/org/traccar') 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 { @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 { 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/helper/LogAction.java b/src/main/java/org/traccar/helper/LogAction.java index efb02b340..adbe33916 100644 --- a/src/main/java/org/traccar/helper/LogAction.java +++ b/src/main/java/org/traccar/helper/LogAction.java @@ -43,13 +43,13 @@ public final class LogAction { private static final String ACTION_LOGIN = "login"; private static final String ACTION_LOGOUT = "logout"; - private static final String ACTION_DEVICE_ACCUMULATORS = "resetDeviceAccumulators"; + private static final String ACTION_ACCUMULATORS = "accumulators"; private static final String PATTERN_OBJECT = "user: %d, action: %s, object: %s, id: %d"; private static final String PATTERN_LINK = "user: %d, action: %s, owner: %s, id: %d, property: %s, id: %d"; private static final String PATTERN_LOGIN = "user: %d, action: %s, from: %s"; private static final String PATTERN_LOGIN_FAILED = "login failed from: %s"; - private static final String PATTERN_DEVICE_ACCUMULATORS = "user: %d, action: %s, deviceId: %d"; + private static final String PATTERN_ACCUMULATORS = "user: %d, action: %s, deviceId: %d"; private static final String PATTERN_REPORT = "user: %d, %s: %s, from: %s, to: %s, devices: %s, groups: %s"; public static void create(long userId, BaseModel object) { @@ -87,9 +87,9 @@ public final class LogAction { LOGGER.info(String.format(PATTERN_LOGIN_FAILED, remoteAddress)); } - public static void resetDeviceAccumulators(long userId, long deviceId) { + public static void resetAccumulators(long userId, long deviceId) { LOGGER.info(String.format( - PATTERN_DEVICE_ACCUMULATORS, userId, ACTION_DEVICE_ACCUMULATORS, deviceId)); + PATTERN_ACCUMULATORS, userId, ACTION_ACCUMULATORS, deviceId)); } private static void logObjectAction(String action, long userId, Class clazz, long objectId) { -- cgit v1.2.3