Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Enum and check permission in getTopics api #2222

Merged
merged 4 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe("TopicTypeFilter", () => {
});

describe("sets the active Topic type based on a query param", () => {
const producerTopic = "Producer";
const producerTopic = "PRODUCER";
beforeEach(async () => {
const routePath = `/?topicType=${producerTopic}`;

Expand All @@ -86,7 +86,7 @@ describe("TopicTypeFilter", () => {
name: filterLabel,
});

expect(select).toHaveValue("Producer");
expect(select).toHaveValue("PRODUCER");
expect(select).toHaveDisplayValue("Producer");
});
});
Expand Down Expand Up @@ -119,7 +119,7 @@ describe("TopicTypeFilter", () => {

await user.selectOptions(select, option);

expect(select).toHaveValue("Consumer");
expect(select).toHaveValue("CONSUMER");
expect(select).toHaveDisplayValue("Consumer");
});

Expand All @@ -134,10 +134,10 @@ describe("TopicTypeFilter", () => {

await user.selectOptions(select, option);

expect(select).toHaveValue("Consumer");
expect(select).toHaveValue("CONSUMER");

await waitFor(() => {
expect(window.location.search).toEqual(`?topicType=Consumer&page=1`);
expect(window.location.search).toEqual(`?topicType=CONSUMER&page=1`);
});
});
});
Expand Down
4 changes: 2 additions & 2 deletions coral/src/app/features/components/filters/TopicTypeFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import upperFirst from "lodash/upperFirst";
type TopicTypeForFilter = TopicType | "ALL";
const topicTypesForFilter: TopicTypeForFilter[] = [
"ALL",
"Consumer",
"Producer",
"CONSUMER",
"PRODUCER",
];
function TopicTypeFilter() {
const { topicType, setFilterValue } = useFiltersContext();
Expand Down
4 changes: 2 additions & 2 deletions coral/src/app/features/topics/browse/BrowseTopics.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ describe("BrowseTopics.tsx", () => {
await userEvent.selectOptions(select, option);

expect(select).toHaveDisplayValue("Consumer");
expect(select).toHaveValue("Consumer");
expect(select).toHaveValue("CONSUMER");
});

it("fetches new data when user selects 'Consumer Topics'", async () => {
Expand All @@ -451,7 +451,7 @@ describe("BrowseTopics.tsx", () => {

expect(mockGetTopics).toHaveBeenNthCalledWith(2, {
...defaultApiParams,
topicType: "Consumer",
topicType: "CONSUMER",
});
});
});
Expand Down
4 changes: 3 additions & 1 deletion coral/src/domain/topic/topic-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ type NoContent = {
status: boolean;
};

type TopicType = "Consumer" | "Producer";
type TopicType = NonNullable<
KlawApiRequestQueryParameters<"getTopics">["topicType"]
>;

type GetTopicsQueryParameter = KlawApiRequestQueryParameters<"getTopics"> & {
topicType?: TopicType;
Expand Down
2 changes: 1 addition & 1 deletion coral/types/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3272,7 +3272,7 @@ export type operations = {
currentPage?: string;
topicnamesearch?: string;
teamId?: number;
topicType?: string;
topicType?: "PRODUCER" | "CONSUMER";
};
};
responses: {
Expand Down
15 changes: 9 additions & 6 deletions core/src/main/java/io/aiven/klaw/controller/TopicController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import io.aiven.klaw.error.KlawNotAuthorizedException;
import io.aiven.klaw.model.ApiResponse;
import io.aiven.klaw.model.TopicInfo;
import io.aiven.klaw.model.enums.AclPatternType;
import io.aiven.klaw.model.enums.Order;
import io.aiven.klaw.model.enums.RequestOperationType;
import io.aiven.klaw.model.enums.RequestStatus;
import io.aiven.klaw.model.enums.*;
import io.aiven.klaw.model.requests.TopicClaimRequestModel;
import io.aiven.klaw.model.requests.TopicCreateRequestModel;
import io.aiven.klaw.model.requests.TopicDeleteRequestModel;
Expand Down Expand Up @@ -233,11 +230,17 @@ public ResponseEntity<List<List<TopicInfo>>> getTopics(
@RequestParam(value = "currentPage", defaultValue = "") String currentPage,
@RequestParam(value = "topicnamesearch", required = false) String topicNameSearch,
@RequestParam(value = "teamId", required = false) Integer teamId,
@RequestParam(value = "topicType", required = false) String topicType) {
@RequestParam(value = "topicType", required = false) AclType topicType)
throws KlawNotAuthorizedException {

return new ResponseEntity<>(
topicControllerService.getTopics(
envId, pageNo, currentPage, topicNameSearch, teamId, topicType),
envId,
pageNo,
currentPage,
topicNameSearch,
teamId,
topicType != null ? topicType.value : null),
HttpStatus.OK);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1080,9 +1080,11 @@ public List<List<TopicInfo>> getTopics(
String currentPage,
String topicNameSearch,
Integer teamId,
String topicType) {
String topicType)
throws KlawNotAuthorizedException {
log.debug("getTopics {}", topicNameSearch);
String userName = getUserName();
checkIsAuthorized(PermissionType.VIEW_TOPICS);
List<TopicInfo> topicListUpdated =
getTopicsPaginated(
env,
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/resources/static/js/browseTopics.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,11 @@ app.controller("browseTopicsCtrl", function($scope, $http, $location, $window) {
}
else if (sParameterName[0] === "producer")
{
topicType = 'Producer';
topicType = 'PRODUCER';
}
else if (sParameterName[0] === "consumer")
{
topicType = 'Consumer';
topicType = 'CONSUMER';
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ public void getTopics() throws Exception {
.param("pageNo", "1")
.param("topicnamesearch", "testtopic")
.param("teamId", "1001")
.param("topicType", "")
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ public void getTopicDetailsPerEnv() {

@Test
@Order(35)
public void getTopics() {
public void getTopics() throws KlawNotAuthorizedException {
String envSel = "1", pageNo = "1", topicNameSearch = "top";

stubUserInfo();
Expand All @@ -930,7 +930,7 @@ public void getTopics() {

@Test
@Order(36)
public void getTopicsWithProducerFilterAndEnvNoResults() {
public void getTopicsWithProducerFilterAndEnvNoResults() throws KlawNotAuthorizedException {
String envSel = "2", pageNo = "1", topicNameSearch = "top";

stubUserInfo();
Expand Down Expand Up @@ -960,7 +960,7 @@ public void getTopicsWithProducerFilterAndEnvNoResults() {

@Test
@Order(37)
public void getTopicsWithPatternFilter() {
public void getTopicsWithPatternFilter() throws KlawNotAuthorizedException {
String envSel = "1", pageNo = "1", topicNameSearch = "toppic";

stubUserInfo();
Expand Down Expand Up @@ -996,7 +996,7 @@ public void getTopicsWithPatternFilter() {
// topicSearch does not exist in topic names
@Test
@Order(38)
public void getTopicsSearchFailureNotExistingSearch() {
public void getTopicsSearchFailureNotExistingSearch() throws KlawNotAuthorizedException {
String envSel = "1", pageNo = "1", topicNameSearch = "demo";
stubUserInfo();
when(manageDatabase.getTeamsAndAllowedEnvs(anyInt(), anyInt()))
Expand Down Expand Up @@ -1577,7 +1577,7 @@ public void getTopicEventsForCustomOffsetFailureForZeroOffsets() throws KlawExce

@Test
@Order(59)
public void getTopicsWithProducerFilterAndEnv() {
public void getTopicsWithProducerFilterAndEnv() throws KlawNotAuthorizedException {
String envSel = "1", pageNo = "1";

stubUserInfo();
Expand Down Expand Up @@ -1607,7 +1607,7 @@ public void getTopicsWithProducerFilterAndEnv() {

@Test
@Order(60)
public void getTopicsWithConsumerFilterNoResults() {
public void getTopicsWithConsumerFilterNoResults() throws KlawNotAuthorizedException {
String envSel = "1", pageNo = "1", topicNameSearch = "top";

stubUserInfo();
Expand Down Expand Up @@ -1637,7 +1637,7 @@ public void getTopicsWithConsumerFilterNoResults() {

@Test
@Order(61)
public void getTopicsWithPatternFilterOneResult() {
public void getTopicsWithPatternFilterOneResult() throws KlawNotAuthorizedException {
String envSel = "1", pageNo = "1", topicNameSearch = "2";

stubUserInfo();
Expand Down
3 changes: 2 additions & 1 deletion openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2822,7 +2822,8 @@
"in" : "query",
"required" : false,
"schema" : {
"type" : "string"
"type" : "string",
"enum" : [ "PRODUCER", "CONSUMER" ]
}
} ],
"responses" : {
Expand Down