aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/api/resource/PermissionsResource.java
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2017-07-22 11:16:14 +0500
committerAbyss777 <abyss@fox5.ru>2017-07-22 11:16:14 +0500
commit4cb47c38af63696470acdc91d7b7d01512f6b2e7 (patch)
treea07ae10919ff97d8c5b91bd381508675d8fb8d6b /src/org/traccar/api/resource/PermissionsResource.java
parent69c46399ee0f6b3dd2b0589cb412e9e17f040369 (diff)
downloadtrackermap-server-4cb47c38af63696470acdc91d7b7d01512f6b2e7.tar.gz
trackermap-server-4cb47c38af63696470acdc91d7b7d01512f6b2e7.tar.bz2
trackermap-server-4cb47c38af63696470acdc91d7b7d01512f6b2e7.zip
- Add Permission helper Class
- Reorganize permission check and link - Optimize calendar retrieving
Diffstat (limited to 'src/org/traccar/api/resource/PermissionsResource.java')
-rw-r--r--src/org/traccar/api/resource/PermissionsResource.java29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/org/traccar/api/resource/PermissionsResource.java b/src/org/traccar/api/resource/PermissionsResource.java
index 515efbe41..88fd9d092 100644
--- a/src/org/traccar/api/resource/PermissionsResource.java
+++ b/src/org/traccar/api/resource/PermissionsResource.java
@@ -29,16 +29,38 @@ import javax.ws.rs.core.Response;
import org.traccar.Context;
import org.traccar.api.BaseResource;
+import org.traccar.model.Device;
+import org.traccar.model.Permission;
+import org.traccar.model.User;
@Path("permissions")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class PermissionsResource extends BaseResource {
+ private void checkPermission(Permission permission, boolean link) {
+ if (!link && permission.getOwnerClass().equals(User.class)
+ && permission.getPropertyClass().equals(Device.class)) {
+ if (getUserId() != permission.getOwnerId()) {
+ Context.getPermissionsManager().checkUser(getUserId(), permission.getOwnerId());
+ } else {
+ Context.getPermissionsManager().checkAdmin(getUserId());
+ }
+ } else {
+ Context.getPermissionsManager().checkPermission(
+ permission.getOwnerClass(), getUserId(), permission.getOwnerId());
+ }
+ Context.getPermissionsManager().checkPermission(
+ permission.getPropertyClass(), getUserId(), permission.getPropertyId());
+ }
+
@POST
public Response add(LinkedHashMap<String, Long> entity) throws SQLException, ClassNotFoundException {
Context.getPermissionsManager().checkReadonly(getUserId());
- checkAndLinkPermission(entity, true);
+ Permission permission = new Permission(entity);
+ checkPermission(permission, true);
+ Context.getDataManager().linkObject(permission.getOwnerClass(), permission.getOwnerId(),
+ permission.getPropertyClass(), permission.getPropertyId(), true);
Context.getPermissionsManager().refreshPermissions(entity);
return Response.noContent().build();
}
@@ -46,7 +68,10 @@ public class PermissionsResource extends BaseResource {
@DELETE
public Response remove(LinkedHashMap<String, Long> entity) throws SQLException, ClassNotFoundException {
Context.getPermissionsManager().checkReadonly(getUserId());
- checkAndLinkPermission(entity, false);
+ Permission permission = new Permission(entity);
+ checkPermission(permission, false);
+ Context.getDataManager().linkObject(permission.getOwnerClass(), permission.getOwnerId(),
+ permission.getPropertyClass(), permission.getPropertyId(), false);
Context.getPermissionsManager().refreshPermissions(entity);
return Response.noContent().build();
}