Skip to content

Commit

Permalink
Add the permission check and also use an enum to get the topics with …
Browse files Browse the repository at this point in the history
…producers or consumer acls you have setup.

Signed-off-by: Aindriu Lavelle <[email protected]>
  • Loading branch information
aindriu-aiven committed Jan 19, 2024
1 parent 14b0a04 commit c9cc883
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
14 changes: 8 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,16 @@ 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,10 @@ 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
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

0 comments on commit c9cc883

Please sign in to comment.