mirror of
				https://git.jami.net/savoirfairelinux/jami-jams.git
				synced 2025-10-30 07:57:19 +08:00 
			
		
		
		
	jams-server: remove 404 handling when returning lists
We instead return 200 with an empty list Change-Id: I43f10783548ec4581e6fcdddc187adb8247d2b5b
This commit is contained in:
		| @ -19,3 +19,5 @@ derby.log | ||||
| extras | ||||
| jams | ||||
| jams-server/src/main/resources/webapp | ||||
|  | ||||
| package-lock.json | ||||
|  | ||||
| @ -146,3 +146,11 @@ Don't forget to launch jams locally at least once before proceeding. | ||||
| The files in the `filters` folder are prefixed "A", "B", "C" and "D" so that the | ||||
| order of execution of the filters are right (jakarta registers filters in | ||||
| alphabetical order). | ||||
|  | ||||
| ## Notes about jams-server | ||||
| - /api/admin is the route for all admins actions, it gives read and write permissions to all users' data | ||||
| - /api/auth is the route for **authenticated** users, it lets you read all | ||||
| users' data and edit your own profile. This route has nothing to do with authentication | ||||
| - /api/login is the route to authenticate users | ||||
| - /api/install is the routes used to setup jams initially, once the initial setup | ||||
| is done its endpoints tells the client that the server is already installed | ||||
|  | ||||
| @ -1,6 +1,7 @@ | ||||
| #!/usr/bin/env bash | ||||
| #!/usr/bin/env sh | ||||
|  | ||||
| cd jams-react-client | ||||
| npm run format | ||||
| cd .. | ||||
|  | ||||
| google-java-format -i -a **/*.java | ||||
| google-java-format -i -a --skip-reflowing-long-strings --skip-javadoc-formatting **/*.java | ||||
|  | ||||
| @ -69,7 +69,7 @@ install_auth() { | ||||
| install_settings() { | ||||
|     post '/api/install/settings' \ | ||||
|         '{ | ||||
|             "serverDomain":"http://localhost:3000", | ||||
|             "serverDomain":"http://localhost:8080", | ||||
|             "crlLifetime":300000, | ||||
|             "deviceLifetime":31556952000, | ||||
|             "userLifetime":31556952000, | ||||
|  | ||||
| @ -23,7 +23,6 @@ | ||||
|  | ||||
| package net.jami.jams.common.objects.contacts; | ||||
|  | ||||
|  | ||||
| import lombok.EqualsAndHashCode; | ||||
| import lombok.Getter; | ||||
| import lombok.NoArgsConstructor; | ||||
|  | ||||
| @ -22,7 +22,6 @@ | ||||
|  */ | ||||
| package net.jami.jams.common.objects.devices; | ||||
|  | ||||
|  | ||||
| import lombok.AllArgsConstructor; | ||||
| import lombok.Getter; | ||||
| import lombok.NoArgsConstructor; | ||||
|  | ||||
| @ -158,9 +158,6 @@ export default function Groups() { | ||||
|                 auth.authenticated = false; | ||||
|                 history.push("/"); | ||||
|               } | ||||
|               if (error.response.status === 404) { | ||||
|                 group["groupMembersLength"] = 0; | ||||
|               } | ||||
|             }); | ||||
|         }); | ||||
|         setGroups(allGroups); | ||||
|  | ||||
| @ -27,7 +27,6 @@ import static net.jami.jams.server.Server.dataStore; | ||||
| import static net.jami.jams.server.Server.userAuthenticationModule; | ||||
|  | ||||
| import com.google.gson.Gson; | ||||
| import com.google.gson.JsonObject; | ||||
|  | ||||
| import jakarta.servlet.ServletException; | ||||
| import jakarta.servlet.annotation.WebServlet; | ||||
|  | ||||
| @ -31,14 +31,8 @@ public class GroupsServlet extends HttpServlet { | ||||
|     @JsonContent | ||||
|     protected void doGet(HttpServletRequest req, HttpServletResponse resp) | ||||
|             throws ServletException, IOException { | ||||
|  | ||||
|         List<Group> groups = dataStore.getGroupDao().getAll(); | ||||
|  | ||||
|         if (!groups.isEmpty()) { | ||||
|             resp.getOutputStream().write(gson.toJson(groups).getBytes()); | ||||
|             resp.setStatus(200); | ||||
|         } else { | ||||
|             resp.setStatus(404); | ||||
|         } | ||||
|         resp.getOutputStream().write(gson.toJson(groups).getBytes()); | ||||
|         resp.setStatus(200); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -44,23 +44,16 @@ public class UserGroupServlet extends HttpServlet { | ||||
|     @ScopedServletMethod(securityGroups = {AccessLevel.ADMIN}) | ||||
|     @JsonContent | ||||
|     protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { | ||||
|  | ||||
|         String groupId = req.getPathInfo().replace("/", ""); | ||||
|  | ||||
|         List<UserGroupMapping> result = dataStore.getUserGroupMappingsDao().getByGroupId(groupId); | ||||
|  | ||||
|         if (result.isEmpty()) resp.sendError(404, "No users found for this group!"); | ||||
|         else { | ||||
|             resp.getOutputStream().write(gson.toJson(result).getBytes()); | ||||
|             resp.setStatus(200); | ||||
|         } | ||||
|         resp.getOutputStream().write(gson.toJson(result).getBytes()); | ||||
|         resp.setStatus(200); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     @ScopedServletMethod(securityGroups = {AccessLevel.ADMIN}) | ||||
|     @JsonContent | ||||
|     protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { | ||||
|  | ||||
|         String groupId = req.getPathInfo().replace("/", ""); | ||||
|  | ||||
|         JsonObject obj = gson.fromJson(req.getReader(), JsonObject.class); | ||||
| @ -70,7 +63,7 @@ public class UserGroupServlet extends HttpServlet { | ||||
|                 dataStore.getUserGroupMappingsDao().getByGroupIdAndUsername(groupId, username); | ||||
|  | ||||
|         if (existingMapping.isPresent()) { | ||||
|             resp.sendError(409, "The user already part of the group!"); | ||||
|             resp.sendError(HttpServletResponse.SC_CONFLICT, "The user already part of the group!"); | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|  | ||||
| @ -42,15 +42,9 @@ public class UserGroupsServlet extends HttpServlet { | ||||
|     @ScopedServletMethod(securityGroups = {AccessLevel.ADMIN}) | ||||
|     @JsonContent | ||||
|     protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { | ||||
|  | ||||
|         String username = req.getPathInfo().replace("/", ""); | ||||
|  | ||||
|         List<UserGroupMapping> result = dataStore.getUserGroupMappingsDao().getByUsername(username); | ||||
|  | ||||
|         if (result.isEmpty()) resp.sendError(404, "No groups found for this user!"); | ||||
|         else { | ||||
|             resp.getOutputStream().write(gson.toJson(result).getBytes()); | ||||
|             resp.setStatus(200); | ||||
|         } | ||||
|         resp.getOutputStream().write(gson.toJson(result).getBytes()); | ||||
|         resp.setStatus(200); | ||||
|     } | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Léo Banno-Cloutier
					Léo Banno-Cloutier