[New] Versions.toJson() require boolean isAdminRequest, triggering what is added to the JSON

This commit is contained in:
Robert von Burg 2023-08-28 15:47:29 +02:00
parent aba85f5d7c
commit d9da84093d
Signed by: eitch
GPG Key ID: 75DB9C85C74331F7
2 changed files with 9 additions and 7 deletions

View File

@ -89,11 +89,11 @@ public class VersionQueryResult {
jsonObject.add(APP_VERSION, this.appVersion.toJson(isAdminRequest));
jsonObject.add(AGENT_VERSION, this.agentVersion.toJson(isAdminRequest));
if (isAdminRequest) {
JsonArray componentVersionsJ = new JsonArray();
this.componentVersions.forEach(c -> componentVersionsJ.add(c.toJson(true)));
jsonObject.add(COMPONENT_VERSIONS, componentVersionsJ);
JsonArray componentVersionsJ = new JsonArray();
this.componentVersions.forEach(c -> componentVersionsJ.add(c.toJson(isAdminRequest)));
jsonObject.add(COMPONENT_VERSIONS, componentVersionsJ);
if (isAdminRequest) {
if (this.errors != null) {
JsonArray errorsJ = new JsonArray();
this.errors.forEach(errorsJ::add);

View File

@ -29,6 +29,7 @@ import jakarta.ws.rs.core.Response;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import li.strolch.agent.api.StrolchAgent;
import li.strolch.agent.api.VersionQueryResult;
import li.strolch.model.StrolchModelConstants;
import li.strolch.privilege.model.Certificate;
import li.strolch.rest.RestfulStrolchComponent;
@ -46,22 +47,23 @@ public class VersionQuery {
Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE);
StrolchAgent agent = RestfulStrolchComponent.getInstance().getAgent();
VersionQueryResult versionQuery = agent.getVersion();
if (cert == null) {
JsonObject jsonObject = new JsonObject();
JsonObject agentVersion = agent.getVersion().getAgentVersion().toJson(false);
JsonObject agentVersion = versionQuery.getAgentVersion().toJson(false);
jsonObject.add(AGENT_VERSION, agentVersion);
if (RestfulStrolchComponent.getInstance().isHideVersionFromUnauthorizedClients()) {
jsonObject.add(APP_VERSION, new JsonObject());
} else {
jsonObject.add(APP_VERSION, agent.getVersion().getAppVersion().toJson(false));
jsonObject.add(APP_VERSION, versionQuery.getAppVersion().toJson(false));
}
return Response.ok(jsonObject.toString(), MediaType.APPLICATION_JSON).build();
}
boolean isStrolchAdmin = cert.hasRole(ROLE_STROLCH_ADMIN);
return Response.ok(agent.getVersion().toJson(isStrolchAdmin).toString(), MediaType.APPLICATION_JSON).build();
return Response.ok(versionQuery.toJson(isStrolchAdmin).toString(), MediaType.APPLICATION_JSON).build();
}
}