From 702d68b27d4753cd2042944845b2f4b5369782c7 Mon Sep 17 00:00:00 2001 From: Dennis Oelkers Date: Tue, 8 Nov 2022 12:38:01 +0100 Subject: [PATCH] Improving typing of `PaginatedResponse`. --- .../events/rest/EventDefinitionsResource.java | 2 +- .../rest/EventNotificationsResource.java | 2 +- .../rest/PipelineResource.java | 2 +- .../pipelineprocessor/rest/RuleResource.java | 3 +- .../views/search/rest/DashboardsResource.java | 4 +- .../search/rest/SavedSearchesResource.java | 2 +- .../views/search/rest/ViewsResource.java | 2 +- .../rest/AuthServiceBackendsResource.java | 2 - .../authzroles/AuthzRolesResource.java | 6 +- .../security/rest/EntitySharesResource.java | 2 +- .../rest/models/PaginatedResponse.java | 87 +++++++++++-------- .../rest/resources/system/GrokResource.java | 2 +- .../rest/resources/users/UsersResource.java | 2 +- .../rest/models/PaginatedResponseTest.java | 24 ++--- .../authentication/AuthenticationStore.ts | 8 +- .../EventDefinitionsStore.js | 4 +- .../EventNotificationsStore.ts | 4 +- .../stores/grok-patterns/GrokPatternsStore.ts | 4 +- .../src/stores/pipelines/PipelinesStore.ts | 4 +- .../src/stores/roles/AuthzRolesStore.ts | 6 +- .../src/stores/rules/RulesStore.ts | 4 +- .../src/stores/users/RolesStore.ts | 2 +- .../src/stores/users/UsersStore.ts | 6 +- .../src/views/stores/DashboardsStore.ts | 10 ++- .../src/views/stores/SavedSearchesStore.ts | 10 ++- .../src/views/stores/ViewManagementStore.ts | 2 +- 26 files changed, 117 insertions(+), 89 deletions(-) diff --git a/graylog2-server/src/main/java/org/graylog/events/rest/EventDefinitionsResource.java b/graylog2-server/src/main/java/org/graylog/events/rest/EventDefinitionsResource.java index e186ef81c0792..46d6ad675a9b3 100644 --- a/graylog2-server/src/main/java/org/graylog/events/rest/EventDefinitionsResource.java +++ b/graylog2-server/src/main/java/org/graylog/events/rest/EventDefinitionsResource.java @@ -122,7 +122,7 @@ public PaginatedResponse list(@ApiParam(name = "page") @Quer return isPermitted(RestPermissions.EVENT_DEFINITIONS_READ, event.id()); }, "title", page, perPage); final ImmutableMap context = contextService.contextFor(result.delegate()); - return PaginatedResponse.create("event_definitions", result, query, context); + return PaginatedResponse.create(result, query, context); } @GET diff --git a/graylog2-server/src/main/java/org/graylog/events/rest/EventNotificationsResource.java b/graylog2-server/src/main/java/org/graylog/events/rest/EventNotificationsResource.java index a2fd87a4b0078..a3e04c95a9b5f 100644 --- a/graylog2-server/src/main/java/org/graylog/events/rest/EventNotificationsResource.java +++ b/graylog2-server/src/main/java/org/graylog/events/rest/EventNotificationsResource.java @@ -113,7 +113,7 @@ public PaginatedResponse listNotifications(@ApiParam(name = "pa final PaginatedList result = dbNotificationService.searchPaginated(searchQuery, notification -> { return isPermitted(RestPermissions.EVENT_NOTIFICATIONS_READ, notification.id()); }, "title", page, perPage); - return PaginatedResponse.create("notifications", result, query); + return PaginatedResponse.create(result, query); } @GET diff --git a/graylog2-server/src/main/java/org/graylog/plugins/pipelineprocessor/rest/PipelineResource.java b/graylog2-server/src/main/java/org/graylog/plugins/pipelineprocessor/rest/PipelineResource.java index d98d47e404c39..842d94aba40b5 100644 --- a/graylog2-server/src/main/java/org/graylog/plugins/pipelineprocessor/rest/PipelineResource.java +++ b/graylog2-server/src/main/java/org/graylog/plugins/pipelineprocessor/rest/PipelineResource.java @@ -202,7 +202,7 @@ public PaginatedResponse getPage(@ApiParam(name = "page") @Query .collect(Collectors.toList()); final PaginatedList pipelines = new PaginatedList<>(pipelineList, result.pagination().total(), result.pagination().page(), result.pagination().perPage()); - return PaginatedResponse.create("pipelines", pipelines); + return PaginatedResponse.create(pipelines); } @ApiOperation(value = "Get a processing pipeline", notes = "It can take up to a second until the change is applied") diff --git a/graylog2-server/src/main/java/org/graylog/plugins/pipelineprocessor/rest/RuleResource.java b/graylog2-server/src/main/java/org/graylog/plugins/pipelineprocessor/rest/RuleResource.java index 3bfeba55a2181..ed50e1d9337fe 100644 --- a/graylog2-server/src/main/java/org/graylog/plugins/pipelineprocessor/rest/RuleResource.java +++ b/graylog2-server/src/main/java/org/graylog/plugins/pipelineprocessor/rest/RuleResource.java @@ -213,8 +213,7 @@ public PaginatedResponse getPage(@ApiParam(name = "page") @QueryPara .collect(Collectors.toList()); final PaginatedList rules = new PaginatedList<>(ruleSourceList, result.pagination().total(), result.pagination().page(), result.pagination().perPage()); - return PaginatedResponse.create("rules", rules, - prepareContextForPaginatedResponse(result.delegate())); + return PaginatedResponse.create(rules, prepareContextForPaginatedResponse(result.delegate())); } @VisibleForTesting diff --git a/graylog2-server/src/main/java/org/graylog/plugins/views/search/rest/DashboardsResource.java b/graylog2-server/src/main/java/org/graylog/plugins/views/search/rest/DashboardsResource.java index 3c7cb2d0cc9ed..4672087fc68df 100644 --- a/graylog2-server/src/main/java/org/graylog/plugins/views/search/rest/DashboardsResource.java +++ b/graylog2-server/src/main/java/org/graylog/plugins/views/search/rest/DashboardsResource.java @@ -47,7 +47,7 @@ import static org.graylog2.shared.rest.documentation.generator.Generator.CLOUD_VISIBLE; @RequiresAuthentication -@Api(value = "Dashboards", tags = {CLOUD_VISIBLE}) +@Api(value = "Dashboards", description = "Provide a list of existing dashboards", tags = {CLOUD_VISIBLE}) @Produces(MediaType.APPLICATION_JSON) @Path("/dashboards") public class DashboardsResource extends RestResource { @@ -94,7 +94,7 @@ public PaginatedResponse views(@ApiParam(name = "page") @QueryPa page, perPage); - return PaginatedResponse.create("views", result, query); + return PaginatedResponse.create(result, query); } catch (IllegalArgumentException e) { throw new BadRequestException(e.getMessage(), e); } diff --git a/graylog2-server/src/main/java/org/graylog/plugins/views/search/rest/SavedSearchesResource.java b/graylog2-server/src/main/java/org/graylog/plugins/views/search/rest/SavedSearchesResource.java index 567455e5be5c3..8325fd9693815 100644 --- a/graylog2-server/src/main/java/org/graylog/plugins/views/search/rest/SavedSearchesResource.java +++ b/graylog2-server/src/main/java/org/graylog/plugins/views/search/rest/SavedSearchesResource.java @@ -91,7 +91,7 @@ public PaginatedResponse views(@ApiParam(name = "page") @QueryPa page, perPage); - return PaginatedResponse.create("views", result, query); + return PaginatedResponse.create(result, query); } catch (IllegalArgumentException e) { throw new BadRequestException(e.getMessage(), e); } diff --git a/graylog2-server/src/main/java/org/graylog/plugins/views/search/rest/ViewsResource.java b/graylog2-server/src/main/java/org/graylog/plugins/views/search/rest/ViewsResource.java index 4d4316c5677a8..e4c3b7d13aa33 100644 --- a/graylog2-server/src/main/java/org/graylog/plugins/views/search/rest/ViewsResource.java +++ b/graylog2-server/src/main/java/org/graylog/plugins/views/search/rest/ViewsResource.java @@ -140,7 +140,7 @@ public PaginatedResponse views(@ApiParam(name = "page") @QueryParam("pa page, perPage); - return PaginatedResponse.create("views", result, query); + return PaginatedResponse.create(result, query); } catch (IllegalArgumentException e) { throw new BadRequestException(e.getMessage(), e); } diff --git a/graylog2-server/src/main/java/org/graylog/security/authservice/rest/AuthServiceBackendsResource.java b/graylog2-server/src/main/java/org/graylog/security/authservice/rest/AuthServiceBackendsResource.java index 0266e3a261c9e..eb774bb7f0e9e 100644 --- a/graylog2-server/src/main/java/org/graylog/security/authservice/rest/AuthServiceBackendsResource.java +++ b/graylog2-server/src/main/java/org/graylog/security/authservice/rest/AuthServiceBackendsResource.java @@ -127,7 +127,6 @@ public PaginatedResponse list(@ApiParam(name = "paginatio final PaginatedList list = dbService.findPaginated(paginationParameters, this::checkReadPermission); return PaginatedResponse.create( - "backends", list, Collections.singletonMap("active_backend", activeBackendConfig) ); @@ -201,7 +200,6 @@ public PaginatedResponse getUsers( parseSearchQuery(query), page, perPage, sort, order, activeConfig.id()); return PaginatedResponse.create( - "users", userList, query, Collections.singletonMap("roles", createRoleContext(userList.delegate())) diff --git a/graylog2-server/src/main/java/org/graylog/security/authzroles/AuthzRolesResource.java b/graylog2-server/src/main/java/org/graylog/security/authzroles/AuthzRolesResource.java index 6017ef7f7c733..538db81492119 100644 --- a/graylog2-server/src/main/java/org/graylog/security/authzroles/AuthzRolesResource.java +++ b/graylog2-server/src/main/java/org/graylog/security/authzroles/AuthzRolesResource.java @@ -129,7 +129,7 @@ public PaginatedResponse getList( searchQuery, page, perPage,sort, order); final Map>> userRoleMap = userRoleContext(result); - return PaginatedResponse.create("roles", result, query, ImmutableMap.of("users", userRoleMap)); + return PaginatedResponse.create(result, query, ImmutableMap.of("users", userRoleMap)); } @GET @@ -170,7 +170,7 @@ public PaginatedResponse getUsersForRole( final PaginatedList enrichedResult = new PaginatedList<>(users, result.pagination().total(), result.pagination().page(), result.pagination().perPage()); - return PaginatedResponse.create("users", enrichedResult, query); + return PaginatedResponse.create(enrichedResult, query); } @GET @@ -212,7 +212,7 @@ public PaginatedResponse getListForUser( final PaginatedList result = authzRolesService.findPaginatedByIds( searchQuery, page, perPage,sort, order, user.getRoleIds()); - return PaginatedResponse.create("roles", result, query); + return PaginatedResponse.create(result, query); } @PUT diff --git a/graylog2-server/src/main/java/org/graylog/security/rest/EntitySharesResource.java b/graylog2-server/src/main/java/org/graylog/security/rest/EntitySharesResource.java index 924a106445587..e33b14b54c83c 100644 --- a/graylog2-server/src/main/java/org/graylog/security/rest/EntitySharesResource.java +++ b/graylog2-server/src/main/java/org/graylog/security/rest/EntitySharesResource.java @@ -105,7 +105,7 @@ public PaginatedResponse get(@ApiParam(name = "pagination para final GranteeSharesService.SharesResponse response = granteeSharesService.getPaginatedSharesFor(grnRegistry.ofUser(user), paginationParameters, capabilityFilter, entityTypeFilter); - return PaginatedResponse.create("entities", response.paginatedEntities(), Collections.singletonMap("grantee_capabilities", response.capabilities())); + return PaginatedResponse.create(response.paginatedEntities(), Collections.singletonMap("grantee_capabilities", response.capabilities())); } @POST diff --git a/graylog2-server/src/main/java/org/graylog2/rest/models/PaginatedResponse.java b/graylog2-server/src/main/java/org/graylog2/rest/models/PaginatedResponse.java index 079b984f5d78a..af50daa22d93e 100644 --- a/graylog2-server/src/main/java/org/graylog2/rest/models/PaginatedResponse.java +++ b/graylog2-server/src/main/java/org/graylog2/rest/models/PaginatedResponse.java @@ -17,62 +17,81 @@ package org.graylog2.rest.models; import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonValue; +import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableMap; import org.graylog2.database.PaginatedList; import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.List; import java.util.Map; +import java.util.Optional; @JsonAutoDetect -public class PaginatedResponse { - private final String listKey; - private final PaginatedList paginatedList; - private final String query; - private final Map context; - - private PaginatedResponse(String listKey, PaginatedList paginatedList, @Nullable String query, @Nullable Map context) { - this.listKey = listKey; - this.paginatedList = paginatedList; - this.query = query; - this.context = context; +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@AutoValue +public abstract class PaginatedResponse { + @JsonProperty("entities") + @JsonInclude() + public List entities() { + return new ArrayList<>(paginatedList()); } - @JsonValue - public Map jsonValue() { - final ImmutableMap.Builder builder = ImmutableMap.builder() - .putAll(paginatedList.pagination().asMap()) - .put(listKey, new ArrayList<>(paginatedList)); + @JsonIgnore + public abstract PaginatedList paginatedList(); - if (query != null) { - builder.put("query", query); - } + @JsonProperty("query") + @Nullable + @JsonInclude() + public abstract String query(); - if (paginatedList.grandTotal().isPresent()) { - builder.put("grand_total", paginatedList.grandTotal().get()); - } + @JsonProperty("context") + @Nullable + public abstract Map context(); - if (context != null && !context.isEmpty()) { - builder.put("context", context); - } + @JsonProperty("grand_total") + public Optional grandTotal() { + return paginatedList().grandTotal(); + } + + @JsonProperty("total") + public int total() { + return paginatedList().pagination().total(); + } + + @JsonProperty("count") + public int count() { + return paginatedList().pagination().count(); + } + + @JsonProperty("page") + public int page() { + return paginatedList().pagination().page(); + } - return builder.build(); + @JsonProperty("per_page") + public int perPage() { + return paginatedList().pagination().perPage(); } - public static PaginatedResponse create(String listKey, PaginatedList paginatedList) { - return new PaginatedResponse<>(listKey, paginatedList, null, null); + + public static PaginatedResponse create(PaginatedList paginatedList) { + return create(paginatedList, null, null); } - public static PaginatedResponse create(String listKey, PaginatedList paginatedList, Map context) { - return new PaginatedResponse<>(listKey, paginatedList, null, context); + public static PaginatedResponse create(PaginatedList paginatedList, Map context) { + return create(paginatedList, null, context); } - public static PaginatedResponse create(String listKey, PaginatedList paginatedList, String query) { - return new PaginatedResponse<>(listKey, paginatedList, query, null); + public static PaginatedResponse create(PaginatedList paginatedList, String query) { + return create(paginatedList, query, null); } - public static PaginatedResponse create(String listKey, PaginatedList paginatedList, String query, Map context) { - return new PaginatedResponse<>(listKey, paginatedList, query, context); + public static PaginatedResponse create(PaginatedList paginatedList, String query, Map context) { + return new AutoValue_PaginatedResponse<>(paginatedList, query, context); } } diff --git a/graylog2-server/src/main/java/org/graylog2/rest/resources/system/GrokResource.java b/graylog2-server/src/main/java/org/graylog2/rest/resources/system/GrokResource.java index 39f5c47692c18..c83c79b73d2b7 100644 --- a/graylog2-server/src/main/java/org/graylog2/rest/resources/system/GrokResource.java +++ b/graylog2-server/src/main/java/org/graylog2/rest/resources/system/GrokResource.java @@ -134,7 +134,7 @@ public PaginatedResponse getPage(@ApiParam(name = "page") @QueryPar final PaginatedList result = paginatedGrokPatternService .findPaginated(searchQuery, page, perPage, sort, order); - return PaginatedResponse.create("patterns", result); + return PaginatedResponse.create(result); } @GET diff --git a/graylog2-server/src/main/java/org/graylog2/rest/resources/users/UsersResource.java b/graylog2-server/src/main/java/org/graylog2/rest/resources/users/UsersResource.java index d03cff0b92fd6..6763955ac9e94 100644 --- a/graylog2-server/src/main/java/org/graylog2/rest/resources/users/UsersResource.java +++ b/graylog2-server/src/main/java/org/graylog2/rest/resources/users/UsersResource.java @@ -292,7 +292,7 @@ public PaginatedResponse getPage(@ApiParam(name = "page") @Quer final PaginatedList userOverviewDTOS = new PaginatedList<>(users, result.pagination().total(), result.pagination().page(), result.pagination().perPage()); - return PaginatedResponse.create("users", userOverviewDTOS, query, Collections.singletonMap("admin_user", adminUser)); + return PaginatedResponse.create(userOverviewDTOS, query, Collections.singletonMap("admin_user", adminUser)); } @POST diff --git a/graylog2-server/src/test/java/org/graylog2/rest/models/PaginatedResponseTest.java b/graylog2-server/src/test/java/org/graylog2/rest/models/PaginatedResponseTest.java index efa4d72c9f014..54c5508d3f31d 100644 --- a/graylog2-server/src/test/java/org/graylog2/rest/models/PaginatedResponseTest.java +++ b/graylog2-server/src/test/java/org/graylog2/rest/models/PaginatedResponseTest.java @@ -44,7 +44,7 @@ public void setUp() throws Exception { public void serialize() throws Exception { final ImmutableList values = ImmutableList.of("hello", "world"); final PaginatedList paginatedList = new PaginatedList<>(values, values.size(), 1, 10); - final PaginatedResponse response = PaginatedResponse.create("foo", paginatedList); + final PaginatedResponse response = PaginatedResponse.create(paginatedList); final DocumentContext ctx = JsonPath.parse(objectMapper.writeValueAsString(response)); final JsonPathAssert jsonPathAssert = JsonPathAssert.assertThat(ctx); @@ -53,8 +53,8 @@ public void serialize() throws Exception { jsonPathAssert.jsonPathAsInteger("$.count").isEqualTo(2); jsonPathAssert.jsonPathAsInteger("$.page").isEqualTo(1); jsonPathAssert.jsonPathAsInteger("$.per_page").isEqualTo(10); - jsonPathAssert.jsonPathAsString("$.foo[0]").isEqualTo("hello"); - jsonPathAssert.jsonPathAsString("$.foo[1]").isEqualTo("world"); + jsonPathAssert.jsonPathAsString("$.entities[0]").isEqualTo("hello"); + jsonPathAssert.jsonPathAsString("$.entities[1]").isEqualTo("world"); assertThatThrownBy(() -> jsonPathAssert.jsonPathAsString("$.context")).isInstanceOf(PathNotFoundException.class); } @@ -63,7 +63,7 @@ public void serializeWithContext() throws Exception { final ImmutableList values = ImmutableList.of("hello", "world"); final ImmutableMap context = ImmutableMap.of("context1", "wow"); final PaginatedList paginatedList = new PaginatedList<>(values, values.size(), 1, 10); - final PaginatedResponse response = PaginatedResponse.create("foo", paginatedList, context); + final PaginatedResponse response = PaginatedResponse.create(paginatedList, context); final DocumentContext ctx = JsonPath.parse(objectMapper.writeValueAsString(response)); final JsonPathAssert jsonPathAssert = JsonPathAssert.assertThat(ctx); @@ -72,8 +72,8 @@ public void serializeWithContext() throws Exception { jsonPathAssert.jsonPathAsInteger("$.count").isEqualTo(2); jsonPathAssert.jsonPathAsInteger("$.page").isEqualTo(1); jsonPathAssert.jsonPathAsInteger("$.per_page").isEqualTo(10); - jsonPathAssert.jsonPathAsString("$.foo[0]").isEqualTo("hello"); - jsonPathAssert.jsonPathAsString("$.foo[1]").isEqualTo("world"); + jsonPathAssert.jsonPathAsString("$.entities[0]").isEqualTo("hello"); + jsonPathAssert.jsonPathAsString("$.entities[1]").isEqualTo("world"); jsonPathAssert.jsonPathAsString("$.context.context1").isEqualTo("wow"); } @@ -81,7 +81,7 @@ public void serializeWithContext() throws Exception { public void serializeWithQuery() throws Exception { final ImmutableList values = ImmutableList.of("hello", "world"); final PaginatedList paginatedList = new PaginatedList<>(values, values.size(), 1, 10); - final PaginatedResponse response = PaginatedResponse.create("foo", paginatedList, "query1"); + final PaginatedResponse response = PaginatedResponse.create(paginatedList, "query1"); final DocumentContext ctx = JsonPath.parse(objectMapper.writeValueAsString(response)); final JsonPathAssert jsonPathAssert = JsonPathAssert.assertThat(ctx); @@ -91,8 +91,8 @@ public void serializeWithQuery() throws Exception { jsonPathAssert.jsonPathAsInteger("$.count").isEqualTo(2); jsonPathAssert.jsonPathAsInteger("$.page").isEqualTo(1); jsonPathAssert.jsonPathAsInteger("$.per_page").isEqualTo(10); - jsonPathAssert.jsonPathAsString("$.foo[0]").isEqualTo("hello"); - jsonPathAssert.jsonPathAsString("$.foo[1]").isEqualTo("world"); + jsonPathAssert.jsonPathAsString("$.entities[0]").isEqualTo("hello"); + jsonPathAssert.jsonPathAsString("$.entities[1]").isEqualTo("world"); assertThatThrownBy(() -> jsonPathAssert.jsonPathAsString("$.context")).isInstanceOf(PathNotFoundException.class); } @@ -101,7 +101,7 @@ public void serializeWithQueryAndContext() throws Exception { final ImmutableList values = ImmutableList.of("hello", "world"); final ImmutableMap context = ImmutableMap.of("context1", "wow"); final PaginatedList paginatedList = new PaginatedList<>(values, values.size(), 1, 10); - final PaginatedResponse response = PaginatedResponse.create("foo", paginatedList, "query1", context); + final PaginatedResponse response = PaginatedResponse.create(paginatedList, "query1", context); final DocumentContext ctx = JsonPath.parse(objectMapper.writeValueAsString(response)); final JsonPathAssert jsonPathAssert = JsonPathAssert.assertThat(ctx); @@ -111,8 +111,8 @@ public void serializeWithQueryAndContext() throws Exception { jsonPathAssert.jsonPathAsInteger("$.count").isEqualTo(2); jsonPathAssert.jsonPathAsInteger("$.page").isEqualTo(1); jsonPathAssert.jsonPathAsInteger("$.per_page").isEqualTo(10); - jsonPathAssert.jsonPathAsString("$.foo[0]").isEqualTo("hello"); - jsonPathAssert.jsonPathAsString("$.foo[1]").isEqualTo("world"); + jsonPathAssert.jsonPathAsString("$.entities[0]").isEqualTo("hello"); + jsonPathAssert.jsonPathAsString("$.entities[1]").isEqualTo("world"); jsonPathAssert.jsonPathAsString("$.context.context1").isEqualTo("wow"); } } diff --git a/graylog2-web-interface/src/stores/authentication/AuthenticationStore.ts b/graylog2-web-interface/src/stores/authentication/AuthenticationStore.ts index cde948f44e33b..bed4dd2c8e007 100644 --- a/graylog2-web-interface/src/stores/authentication/AuthenticationStore.ts +++ b/graylog2-web-interface/src/stores/authentication/AuthenticationStore.ts @@ -133,11 +133,11 @@ type PaginatedBackendsResponse = PaginatedResponseType & { context: { active_backend: AuthenticationBackendJSON | null | undefined, }, - backends: Array, + entities: Array, }; type PaginatedUsersResponse = PaginatedResponseType & { - users: Array, + entities: Array, }; export const AuthenticationStore = singletonStore( @@ -234,7 +234,7 @@ export const AuthenticationStore = singletonStore( context: { activeBackend: response.context.active_backend, }, - list: Immutable.List(response.backends.map((backend) => AuthenticationBackend.fromJSON(backend))), + list: Immutable.List(response.entities.map((backend) => AuthenticationBackend.fromJSON(backend))), pagination: { page: response.page, perPage: response.per_page, @@ -254,7 +254,7 @@ export const AuthenticationStore = singletonStore( const promise = fetch('GET', qualifyUrl(url)) .then((response: PaginatedUsersResponse) => ({ - list: Immutable.List(response.users.map((user) => UserOverview.fromJSON(user))), + list: Immutable.List(response.entities.map((user) => UserOverview.fromJSON(user))), pagination: { page: response.page, perPage: response.per_page, diff --git a/graylog2-web-interface/src/stores/event-definitions/EventDefinitionsStore.js b/graylog2-web-interface/src/stores/event-definitions/EventDefinitionsStore.js index c4ab9780f369a..f31c2b1a10cf1 100644 --- a/graylog2-web-interface/src/stores/event-definitions/EventDefinitionsStore.js +++ b/graylog2-web-interface/src/stores/event-definitions/EventDefinitionsStore.js @@ -102,7 +102,7 @@ export const EventDefinitionsStore = singletonStore( const promise = fetch('GET', this.eventDefinitionsUrl({ query: { per_page: 0 } })); promise.then((response) => { - this.all = response.event_definitions; + this.all = response.entities; this.context = response.context; this.propagateChanges(); @@ -122,7 +122,7 @@ export const EventDefinitionsStore = singletonStore( })); promise.then((response) => { - this.eventDefinitions = response.event_definitions; + this.eventDefinitions = response.entities; this.context = response.context; this.query = response.query; diff --git a/graylog2-web-interface/src/stores/event-notifications/EventNotificationsStore.ts b/graylog2-web-interface/src/stores/event-notifications/EventNotificationsStore.ts index 8b71033f6b69f..0e462dde67dc9 100644 --- a/graylog2-web-interface/src/stores/event-notifications/EventNotificationsStore.ts +++ b/graylog2-web-interface/src/stores/event-notifications/EventNotificationsStore.ts @@ -137,7 +137,7 @@ export const EventNotificationsStore = singletonStore( const promise = fetch('GET', this.eventNotificationsUrl({ query: { per_page: 0 } })); promise.then((response) => { - this.all = response.notifications; + this.all = response.entities; this.propagateChanges(); return response; @@ -156,7 +156,7 @@ export const EventNotificationsStore = singletonStore( })); promise.then((response) => { - this.notifications = response.notifications; + this.notifications = response.entities; this.query = response.query; this.pagination = { diff --git a/graylog2-web-interface/src/stores/grok-patterns/GrokPatternsStore.ts b/graylog2-web-interface/src/stores/grok-patterns/GrokPatternsStore.ts index aaf81f0bb8e17..b28cf09a9dd21 100644 --- a/graylog2-web-interface/src/stores/grok-patterns/GrokPatternsStore.ts +++ b/graylog2-web-interface/src/stores/grok-patterns/GrokPatternsStore.ts @@ -35,7 +35,7 @@ type PaginatedResponse = { total: number, page: number, per_page: number, - patterns: Array, + entities: Array, }; type GrokPatternTest = { @@ -89,7 +89,7 @@ export const GrokPatternsStore = singletonStore( }; return { - patterns: response.patterns, + patterns: response.entities, pagination: pagination, }; }) diff --git a/graylog2-web-interface/src/stores/pipelines/PipelinesStore.ts b/graylog2-web-interface/src/stores/pipelines/PipelinesStore.ts index 3466e0250001d..ca77eb32bfeea 100644 --- a/graylog2-web-interface/src/stores/pipelines/PipelinesStore.ts +++ b/graylog2-web-interface/src/stores/pipelines/PipelinesStore.ts @@ -65,7 +65,7 @@ export type StageType = { }; export type PaginatedPipelineResponse = PaginatedListJSON & { - pipelines: Array, + entities: Array, }; export type PaginatedPipelines = PaginatedList; @@ -118,7 +118,7 @@ export const PipelinesStore = singletonStore( const url = PaginationURL(ApiRoutes.PipelinesController.paginatedList().url, page, perPage, query); const promise = fetch('GET', qualifyUrl(url)).then((response: PaginatedPipelineResponse) => ({ - list: Immutable.List(response.pipelines), + list: Immutable.List(response.entities), pagination: { page: response.page, perPage: response.per_page, diff --git a/graylog2-web-interface/src/stores/roles/AuthzRolesStore.ts b/graylog2-web-interface/src/stores/roles/AuthzRolesStore.ts index a8f739ef3aa87..f8755ca3d56a4 100644 --- a/graylog2-web-interface/src/stores/roles/AuthzRolesStore.ts +++ b/graylog2-web-interface/src/stores/roles/AuthzRolesStore.ts @@ -33,7 +33,7 @@ import UserOverview from 'logic/users/UserOverview'; import type { PaginatedListJSON, Pagination } from 'stores/PaginationTypes'; export type PaginatedRolesResponse = PaginatedListJSON & { - roles: Array, + entities: Array, context?: RoleContext, }; @@ -43,7 +43,7 @@ const _responseToPaginatedList = ({ page, per_page, query, - roles = [], + entities: roles = [], context = { users: undefined }, }: PaginatedRolesResponse) => ({ list: Immutable.List(roles.map((r) => Role.fromJSON(r))), @@ -57,7 +57,7 @@ const _responseToPaginatedList = ({ context, }); -const _responseToPaginatedUserList = ({ count, total, page, per_page, query, users }: PaginatedUsersResponse) => ({ +const _responseToPaginatedUserList = ({ count, total, page, per_page, query, entities: users }: PaginatedUsersResponse) => ({ list: Immutable.List(users.map((u) => UserOverview.fromJSON(u))), pagination: { page, diff --git a/graylog2-web-interface/src/stores/rules/RulesStore.ts b/graylog2-web-interface/src/stores/rules/RulesStore.ts index 7e118c83a66cb..32683333f1de3 100644 --- a/graylog2-web-interface/src/stores/rules/RulesStore.ts +++ b/graylog2-web-interface/src/stores/rules/RulesStore.ts @@ -47,7 +47,7 @@ export type RulesContext = { } }; export type PaginatedRulesResponse = PaginatedListJSON & { - rules: Array, + entities: Array, context: RulesContext, }; @@ -155,7 +155,7 @@ export const RulesStore = singletonStore( const url = PaginationURL(ApiRoutes.RulesController.paginatedList().url, page, perPage, query); const promise = fetch('GET', qualifyUrl(url)) .then((response: PaginatedRulesResponse) => ({ - list: response.rules, + list: response.entities, context: response.context, pagination: { count: response.count, diff --git a/graylog2-web-interface/src/stores/users/RolesStore.ts b/graylog2-web-interface/src/stores/users/RolesStore.ts index db0744e61bad6..b880561d8401e 100644 --- a/graylog2-web-interface/src/stores/users/RolesStore.ts +++ b/graylog2-web-interface/src/stores/users/RolesStore.ts @@ -41,7 +41,7 @@ export const RolesStore = singletonStore( loadRoles(): Promise { return fetch('GET', qualifyUrl(ApiRoutes.RolesApiController.listRoles().url)) .then( - (response) => response.roles, + (response) => response.entities, (error) => { if (error.additional.status !== 404) { UserNotification.error(`Loading role list failed with status: ${error}`, diff --git a/graylog2-web-interface/src/stores/users/UsersStore.ts b/graylog2-web-interface/src/stores/users/UsersStore.ts index 5e0d82940f2ed..43283097f3dbd 100644 --- a/graylog2-web-interface/src/stores/users/UsersStore.ts +++ b/graylog2-web-interface/src/stores/users/UsersStore.ts @@ -31,7 +31,7 @@ import User from 'logic/users/User'; import type { PaginatedListJSON, Pagination, PaginatedList } from 'stores/PaginationTypes'; export type PaginatedUsersResponse = PaginatedListJSON & { - users: Array; + entities: Array; context: { admin_user: UserOverviewJSON; }; @@ -203,7 +203,7 @@ export const UsersStore = singletonStore('core.Users', () => Reflux.createStore( loadUsers(query: Query = {}): Promise> { const url = usersUrl({ url: ApiRoutes.UsersApiController.list().url, query }); const promise = fetch('GET', url).then(({ - users, + entities: users, }) => Immutable.List(users.map((user) => UserOverview.fromJSON(user)))); UsersActions.loadUsers.promise(promise); @@ -219,7 +219,7 @@ export const UsersStore = singletonStore('core.Users', () => Reflux.createStore( const promise = fetch('GET', qualifyUrl(url)).then((response: PaginatedUsersResponse) => ({ adminUser: response.context.admin_user ? UserOverview.fromJSON(response.context.admin_user) : undefined, - list: Immutable.List(response.users.map((user) => UserOverview.fromJSON(user))), + list: Immutable.List(response.entities.map((user) => UserOverview.fromJSON(user))), pagination: { page: response.page, perPage: response.per_page, diff --git a/graylog2-web-interface/src/views/stores/DashboardsStore.ts b/graylog2-web-interface/src/views/stores/DashboardsStore.ts index b6390e2b5311b..4a61fb5bed5c6 100644 --- a/graylog2-web-interface/src/views/stores/DashboardsStore.ts +++ b/graylog2-web-interface/src/views/stores/DashboardsStore.ts @@ -21,9 +21,11 @@ import { singletonActions, singletonStore } from 'logic/singleton'; import fetch from 'logic/rest/FetchProvider'; import UserNotification from 'util/UserNotification'; import type { RefluxActions, Store } from 'stores/StoreTypes'; +import type { PaginatedListJSON } from 'stores/PaginationTypes'; import type { PaginatedViews, SortField, SortOrder } from './ViewManagementStore'; +import type { ViewJson } from '../logic/views/View'; import View from '../logic/views/View'; type DashboardsActionsType = RefluxActions<{ @@ -51,6 +53,10 @@ export type DashboardsStoreState = { list: Array | undefined; }; +type PaginatedDashboardsResponse = PaginatedListJSON & { + entities: Array, +}; + const DashboardsStore: Store = singletonStore( 'views.Dashboards', () => Reflux.createStore({ @@ -71,8 +77,8 @@ const DashboardsStore: Store = singletonStore( }, search(query = '', page = 1, perPage = 10, sortBy = 'title', order = 'asc') { const promise = fetch('GET', `${dashboardsUrl}?query=${query}&page=${page}&per_page=${perPage}&sort=${sortBy}&order=${order}`) - .then((response) => { - this.dashboards = response.views.map((item) => View.fromJSON(item)); + .then((response: PaginatedDashboardsResponse) => { + this.dashboards = response.entities.map((item) => View.fromJSON(item)); this.pagination = { total: response.total, diff --git a/graylog2-web-interface/src/views/stores/SavedSearchesStore.ts b/graylog2-web-interface/src/views/stores/SavedSearchesStore.ts index 5bdd66b7a6234..411b66326614a 100644 --- a/graylog2-web-interface/src/views/stores/SavedSearchesStore.ts +++ b/graylog2-web-interface/src/views/stores/SavedSearchesStore.ts @@ -20,6 +20,8 @@ import * as URLUtils from 'util/URLUtils'; import { singletonActions, singletonStore } from 'logic/singleton'; import fetch from 'logic/rest/FetchProvider'; import type { RefluxActions } from 'stores/StoreTypes'; +import type { PaginatedListJSON } from 'stores/PaginationTypes'; +import type View from 'views/logic/views/View'; import type { PaginatedViews, SortField, SortOrder } from './ViewManagementStore'; @@ -27,6 +29,10 @@ export type SavedSearchesActionsType = RefluxActions<{ search: (query?: string, page?: number, perPage?: number, sortBy?: SortField, order?: SortOrder) => Promise, }>; +type PaginatedSavedSearchesResponse = PaginatedListJSON & { + entities: Array, +}; + const SavedSearchesActions: SavedSearchesActionsType = singletonActions( 'views.SavedSearches', () => Reflux.createActions({ @@ -43,8 +49,8 @@ const SavedSearchesStore = singletonStore( search({ query = '', page = 1, perPage = 10, sortBy = 'title', order = 'asc' }): Promise { const promise = fetch('GET', `${savedSearchesUrl}?query=${query}&page=${page}&per_page=${perPage}&sort=${sortBy}&order=${order}`) - .then((response) => ({ - list: response.views, + .then((response: PaginatedSavedSearchesResponse) => ({ + list: response.entities, pagination: { count: response.count, page: response.page, diff --git a/graylog2-web-interface/src/views/stores/ViewManagementStore.ts b/graylog2-web-interface/src/views/stores/ViewManagementStore.ts index 9d2ed540dd709..f010c3d8b48a6 100644 --- a/graylog2-web-interface/src/views/stores/ViewManagementStore.ts +++ b/graylog2-web-interface/src/views/stores/ViewManagementStore.ts @@ -132,7 +132,7 @@ const ViewManagementStore = singletonStore( search(query, page = 1, perPage = 10, sortBy = 'title', order = 'asc') { const promise = fetch('GET', `${viewsUrl}?query=${query}&page=${page}&per_page=${perPage}&sort=${sortBy}&order=${order}`) .then((response) => { - this.views = response.views; + this.views = response.entities; this.pagination = { total: response.total,