private void isUserOrAdmin( HttpServerRequest request, UserInfos user, final Handler<Boolean> handler) { final String userId = request.params().get("userId"); if (user.getUserId().equals(userId)) { handler.handle(true); return; } final UserInfos.Function adminLocal = getFunction(user, handler); if (adminLocal == null) return; String query = "MATCH (s:Structure)<-[:DEPENDS]-(:ProfileGroup)<-[:IN]-(u:User {id : {userId}}) " + "WHERE s.id IN {structures} " + "RETURN count(*) > 0 as exists "; JsonObject params = new JsonObject() .putArray("structures", new JsonArray(adminLocal.getScope().toArray())) .putString("userId", userId); Neo4j.getInstance() .execute( query, params, new Handler<Message<JsonObject>>() { @Override public void handle(Message<JsonObject> message) { JsonArray res = message.body().getArray("result"); handler.handle( "ok".equals(message.body().getString("status")) && res != null && res.size() == 1 && res.<JsonObject>get(0).getBoolean("exists", false)); } }); }
private UserInfos.Function getFunction(UserInfos user, Handler<Boolean> handler) { Map<String, UserInfos.Function> functions = user.getFunctions(); if (functions == null || functions.isEmpty()) { handler.handle(false); return null; } if (functions.containsKey(DefaultFunctions.SUPER_ADMIN)) { handler.handle(true); return null; } UserInfos.Function adminLocal = functions.get(DefaultFunctions.ADMIN_LOCAL); if (adminLocal == null || adminLocal.getScope() == null) { handler.handle(false); return null; } return adminLocal; }
private void isAdmin(HttpServerRequest request, UserInfos user, Handler<Boolean> handler) { UserInfos.Function adminLocal = getFunction(user, handler); if (adminLocal == null) return; String structureId = request.params().get("structureId"); handler.handle(adminLocal.getScope().contains(structureId)); }