From 68af658ea2ff9593e5be7a2b2cfcb75c744fd749 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Tue, 25 Jul 2017 10:53:08 +0500 Subject: Move users management to separate manager --- src/org/traccar/api/resource/SessionResource.java | 2 +- src/org/traccar/api/resource/UserResource.java | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) (limited to 'src/org/traccar/api') diff --git a/src/org/traccar/api/resource/SessionResource.java b/src/org/traccar/api/resource/SessionResource.java index acdbb7c87..fa2a14c6f 100644 --- a/src/org/traccar/api/resource/SessionResource.java +++ b/src/org/traccar/api/resource/SessionResource.java @@ -80,7 +80,7 @@ public class SessionResource extends BaseResource { request.getSession().setAttribute(USER_ID_KEY, userId); } } else if (token != null) { - User user = Context.getPermissionsManager().getUserByToken(token); + User user = Context.getUsersManager().getUserByToken(token); if (user != null) { userId = user.getId(); request.getSession().setAttribute(USER_ID_KEY, userId); diff --git a/src/org/traccar/api/resource/UserResource.java b/src/org/traccar/api/resource/UserResource.java index 98395e3cc..d3d82f99d 100644 --- a/src/org/traccar/api/resource/UserResource.java +++ b/src/org/traccar/api/resource/UserResource.java @@ -17,6 +17,7 @@ package org.traccar.api.resource; import org.traccar.Context; import org.traccar.api.BaseResource; +import org.traccar.database.UsersManager; import org.traccar.model.ManagedUser; import org.traccar.model.User; @@ -35,6 +36,7 @@ import javax.ws.rs.core.Response; import java.sql.SQLException; import java.util.Collection; import java.util.Date; +import java.util.Set; @Path("users") @Produces(MediaType.APPLICATION_JSON) @@ -43,17 +45,21 @@ public class UserResource extends BaseResource { @GET public Collection get(@QueryParam("userId") long userId) throws SQLException { + UsersManager usersManager = Context.getUsersManager(); + Set result = null; if (Context.getPermissionsManager().isAdmin(getUserId())) { if (userId != 0) { - return Context.getPermissionsManager().getUsers(userId); + result = usersManager.getManagedItems(userId); } else { - return Context.getPermissionsManager().getAllUsers(); + result = usersManager.getAllItems(); } } else if (Context.getPermissionsManager().isManager(getUserId())) { - return Context.getPermissionsManager().getManagedUsers(getUserId()); + result = usersManager.getManagedItems(getUserId()); + result.add(getUserId()); } else { throw new SecurityException("Admin or manager access required"); } + return usersManager.getItems(User.class, result); } @PermitAll @@ -73,11 +79,11 @@ public class UserResource extends BaseResource { } } } - Context.getPermissionsManager().addUser(entity); + Context.getUsersManager().addItem(entity); if (Context.getPermissionsManager().isManager(getUserId())) { Context.getDataManager().linkObject(User.class, getUserId(), ManagedUser.class, entity.getId(), true); } - Context.getPermissionsManager().refreshUserPermissions(); + Context.getUsersManager().refreshUserItems(); if (Context.getNotificationManager() != null) { Context.getNotificationManager().refresh(); } @@ -91,7 +97,7 @@ public class UserResource extends BaseResource { User before = Context.getPermissionsManager().getUser(entity.getId()); Context.getPermissionsManager().checkUser(getUserId(), entity.getId()); Context.getPermissionsManager().checkUserUpdate(getUserId(), before, entity); - Context.getPermissionsManager().updateUser(entity); + Context.getUsersManager().updateItem(entity); if (Context.getNotificationManager() != null) { Context.getNotificationManager().refresh(); } @@ -103,7 +109,7 @@ public class UserResource extends BaseResource { public Response remove(@PathParam("id") long id) throws SQLException { Context.getPermissionsManager().checkReadonly(getUserId()); Context.getPermissionsManager().checkUser(getUserId(), id); - Context.getPermissionsManager().removeUser(id); + Context.getUsersManager().removeItem(id); if (Context.getGeofenceManager() != null) { Context.getGeofenceManager().refreshUserItems(); } -- cgit v1.2.3