aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/api/SimpleObjectResource.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-02-21 17:33:58 -0800
committerAnton Tananaev <anton@traccar.org>2022-04-05 15:48:51 -0700
commit9ec2d09ad8a757d58f70812b9cf5e835321382e6 (patch)
tree3632335375c62d7e30d32c49b9d952af3eb0b748 /src/main/java/org/traccar/api/SimpleObjectResource.java
parent307c4dd690c5826e076657fa83f2ddd41cec1126 (diff)
downloadtrackermap-server-9ec2d09ad8a757d58f70812b9cf5e835321382e6.tar.gz
trackermap-server-9ec2d09ad8a757d58f70812b9cf5e835321382e6.tar.bz2
trackermap-server-9ec2d09ad8a757d58f70812b9cf5e835321382e6.zip
Migrate permissions to storage
Diffstat (limited to 'src/main/java/org/traccar/api/SimpleObjectResource.java')
-rw-r--r--src/main/java/org/traccar/api/SimpleObjectResource.java30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/main/java/org/traccar/api/SimpleObjectResource.java b/src/main/java/org/traccar/api/SimpleObjectResource.java
index a7fcae0e7..b55bf91e3 100644
--- a/src/main/java/org/traccar/api/SimpleObjectResource.java
+++ b/src/main/java/org/traccar/api/SimpleObjectResource.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2017 - 2022 Anton Tananaev (anton@traccar.org)
* Copyright 2017 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,15 +16,17 @@
*/
package org.traccar.api;
-import java.sql.SQLException;
-import java.util.Collection;
+import org.traccar.model.BaseModel;
+import org.traccar.model.User;
+import org.traccar.storage.StorageException;
+import org.traccar.storage.query.Columns;
+import org.traccar.storage.query.Condition;
+import org.traccar.storage.query.Request;
import javax.ws.rs.GET;
import javax.ws.rs.QueryParam;
-
-import org.traccar.Context;
-import org.traccar.database.BaseObjectManager;
-import org.traccar.model.BaseModel;
+import java.util.Collection;
+import java.util.LinkedList;
public class SimpleObjectResource<T extends BaseModel> extends BaseObjectResource<T> {
@@ -34,10 +36,18 @@ public class SimpleObjectResource<T extends BaseModel> extends BaseObjectResourc
@GET
public Collection<T> get(
- @QueryParam("all") boolean all, @QueryParam("userId") long userId) throws SQLException {
+ @QueryParam("all") boolean all, @QueryParam("userId") long userId) throws StorageException {
+
+ var conditions = new LinkedList<Condition>();
+
+ if (all) {
+ permissionsService.checkAdmin(getUserId());
+ } else {
+ permissionsService.checkUser(getUserId(), userId);
+ conditions.add(new Condition.Permission(User.class, userId, baseClass));
+ }
- BaseObjectManager<T> manager = Context.getManager(getBaseClass());
- return manager.getItems(getSimpleManagerItems(manager, all, userId));
+ return storage.getObjects(baseClass, new Request(new Columns.All(), Condition.merge(conditions)));
}
}