diff options
author | Abyss777 <abyss@fox5.ru> | 2017-07-20 08:56:29 +0500 |
---|---|---|
committer | Abyss777 <abyss@fox5.ru> | 2017-07-20 09:52:27 +0500 |
commit | afb9a199f57824ec06c993b6028c35b616f64885 (patch) | |
tree | 1ab2531846dc1ff4c9b5e0d6d71ebcec231aff89 /src/org/traccar/api/resource/GroupResource.java | |
parent | a9478ded48de140d47d17def1ee5329267fe6088 (diff) | |
download | trackermap-server-afb9a199f57824ec06c993b6028c35b616f64885.tar.gz trackermap-server-afb9a199f57824ec06c993b6028c35b616f64885.tar.bz2 trackermap-server-afb9a199f57824ec06c993b6028c35b616f64885.zip |
Combine permission resources and reuse common database functions
Diffstat (limited to 'src/org/traccar/api/resource/GroupResource.java')
-rw-r--r-- | src/org/traccar/api/resource/GroupResource.java | 43 |
1 files changed, 33 insertions, 10 deletions
diff --git a/src/org/traccar/api/resource/GroupResource.java b/src/org/traccar/api/resource/GroupResource.java index ceba69105..97b6d671d 100644 --- a/src/org/traccar/api/resource/GroupResource.java +++ b/src/org/traccar/api/resource/GroupResource.java @@ -32,6 +32,8 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.sql.SQLException; import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.Map; @Path("groups") @Produces(MediaType.APPLICATION_JSON) @@ -61,11 +63,12 @@ public class GroupResource extends BaseResource { public Response add(Group entity) throws SQLException { Context.getPermissionsManager().checkReadonly(getUserId()); Context.getDeviceManager().addGroup(entity); - Context.getDataManager().linkGroup(getUserId(), entity.getId()); + LinkedHashMap<String, Long> link = new LinkedHashMap<>(); + link.put("userId", getUserId()); + link.put("groupId", entity.getId()); + Context.getDataManager().linkObject(link, true); Context.getPermissionsManager().refreshPermissions(); - if (Context.getGeofenceManager() != null) { - Context.getGeofenceManager().refresh(); - } + Context.getPermissionsManager().refreshAllExtendedPermissions(); return Response.ok(entity).build(); } @@ -75,22 +78,42 @@ public class GroupResource extends BaseResource { Context.getPermissionsManager().checkReadonly(getUserId()); Context.getPermissionsManager().checkGroup(getUserId(), entity.getId()); Context.getDeviceManager().updateGroup(entity); - if (Context.getGeofenceManager() != null) { - Context.getGeofenceManager().refresh(); - } + Context.getPermissionsManager().refreshAllExtendedPermissions(); return Response.ok(entity).build(); } - @Path("{id}") + @Path("{id : \\d+}") @DELETE public Response remove(@PathParam("id") long id) throws SQLException { Context.getPermissionsManager().checkReadonly(getUserId()); Context.getPermissionsManager().checkGroup(getUserId(), id); Context.getDeviceManager().removeGroup(id); Context.getPermissionsManager().refreshPermissions(); - if (Context.getGeofenceManager() != null) { - Context.getGeofenceManager().refresh(); + Context.getPermissionsManager().refreshAllExtendedPermissions(); + return Response.noContent().build(); + } + + @Path("/{slave : (geofences|drivers|attributes)}") + @POST + public Response add(Map<String, Long> entity) throws SQLException { + Context.getPermissionsManager().checkReadonly(getUserId()); + for (String key : entity.keySet()) { + Context.getPermissionsManager().checkPermission(key.replace("Id", ""), getUserId(), entity.get(key)); + } + Context.getDataManager().linkObject(entity, true); + Context.getPermissionsManager().refreshPermissions(entity); + return Response.noContent().build(); + } + + @Path("/{slave : (geofences|drivers|attributes)}") + @DELETE + public Response remove(Map<String, Long> entity) throws SQLException { + Context.getPermissionsManager().checkReadonly(getUserId()); + for (String key : entity.keySet()) { + Context.getPermissionsManager().checkPermission(key.replace("Id", ""), getUserId(), entity.get(key)); } + Context.getDataManager().linkObject(entity, false); + Context.getPermissionsManager().refreshPermissions(entity); return Response.noContent().build(); } |