Skip to content

Commit 39be5ae

Browse files
Poleg KashtiPoleg Kashti
authored andcommitted
2 parents 185744b + 273e64c commit 39be5ae

File tree

10 files changed

+63
-44
lines changed

10 files changed

+63
-44
lines changed

.github/workflows/e2e-run.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ jobs:
103103
run: |
104104
mkdir -p ./e2e-tests/target/selenoid-results/video
105105
mkdir -p ./e2e-tests/target/selenoid-results/logs
106-
docker-compose -f ./e2e-tests/selenoid/selenoid-ci.yaml up -d
107-
docker-compose -f ./documentation/compose/e2e-tests.yaml up -d
106+
docker compose -f ./e2e-tests/selenoid/selenoid-ci.yaml up -d
107+
docker compose -f ./documentation/compose/e2e-tests.yaml up -d
108108
109109
- name: Dump Docker logs on failure
110110
if: failure()

api/src/main/java/io/kafbat/ui/controller/AccessController.java

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,33 +45,34 @@ public Mono<ResponseEntity<AuthenticationInfoDTO>> getUserAuthInfo(ServerWebExch
4545
.map(SecurityContext::getAuthentication)
4646
.map(Principal::getName);
4747

48+
var builder = AuthenticationInfoDTO.builder()
49+
.rbacEnabled(accessControlService.isRbacEnabled());
50+
4851
return userName
4952
.zipWith(permissions)
50-
.map(data -> {
51-
var dto = new AuthenticationInfoDTO(accessControlService.isRbacEnabled());
52-
dto.setUserInfo(new UserInfoDTO(data.getT1(), data.getT2()));
53-
return dto;
54-
})
55-
.switchIfEmpty(Mono.just(new AuthenticationInfoDTO(accessControlService.isRbacEnabled())))
53+
.map(data -> (AuthenticationInfoDTO) builder
54+
.userInfo(new UserInfoDTO(data.getT1(), data.getT2()))
55+
.build()
56+
)
57+
.switchIfEmpty(Mono.just(builder.build()))
5658
.map(ResponseEntity::ok);
5759
}
5860

5961
private List<UserPermissionDTO> mapPermissions(List<Permission> permissions, List<String> clusters) {
6062
return permissions
6163
.stream()
62-
.map(permission -> {
63-
UserPermissionDTO dto = new UserPermissionDTO();
64-
dto.setClusters(clusters);
65-
dto.setResource(ResourceTypeDTO.fromValue(permission.getResource().toString().toUpperCase()));
66-
dto.setValue(permission.getValue());
67-
dto.setActions(permission.getParsedActions()
68-
.stream()
69-
.map(p -> p.name().toUpperCase())
70-
.map(this::mapAction)
71-
.filter(Objects::nonNull)
72-
.toList());
73-
return dto;
74-
})
64+
.map(permission -> (UserPermissionDTO) UserPermissionDTO.builder()
65+
.clusters(clusters)
66+
.resource(ResourceTypeDTO.fromValue(permission.getResource().toString().toUpperCase()))
67+
.value(permission.getValue())
68+
.actions(permission.getParsedActions()
69+
.stream()
70+
.map(p -> p.name().toUpperCase())
71+
.map(this::mapAction)
72+
.filter(Objects::nonNull)
73+
.toList())
74+
.build()
75+
)
7576
.toList();
7677
}
7778

api/src/main/java/io/kafbat/ui/controller/KsqlController.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public Mono<ResponseEntity<KsqlCommandV2ResponseDTO>> executeKsql(String cluster
5353
}
5454

5555
@Override
56+
@SuppressWarnings("unchecked")
5657
public Mono<ResponseEntity<Flux<KsqlResponseDTO>>> openKsqlResponsePipe(String clusterName,
5758
String pipeId,
5859
ServerWebExchange exchange) {

api/src/main/java/io/kafbat/ui/controller/TopicsController.java

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package io.kafbat.ui.controller;
22

3+
import static io.kafbat.ui.model.rbac.permission.TopicAction.ANALYSIS_RUN;
4+
import static io.kafbat.ui.model.rbac.permission.TopicAction.ANALYSIS_VIEW;
35
import static io.kafbat.ui.model.rbac.permission.TopicAction.CREATE;
46
import static io.kafbat.ui.model.rbac.permission.TopicAction.DELETE;
57
import static io.kafbat.ui.model.rbac.permission.TopicAction.EDIT;
6-
import static io.kafbat.ui.model.rbac.permission.TopicAction.MESSAGES_READ;
78
import static io.kafbat.ui.model.rbac.permission.TopicAction.VIEW;
89
import static java.util.stream.Collectors.toList;
910

@@ -272,7 +273,7 @@ public Mono<ResponseEntity<Void>> analyzeTopic(String clusterName, String topicN
272273

273274
var context = AccessContext.builder()
274275
.cluster(clusterName)
275-
.topicActions(topicName, MESSAGES_READ)
276+
.topicActions(topicName, ANALYSIS_RUN)
276277
.operationName("analyzeTopic")
277278
.build();
278279

@@ -288,7 +289,7 @@ public Mono<ResponseEntity<Void>> cancelTopicAnalysis(String clusterName, String
288289
ServerWebExchange exchange) {
289290
var context = AccessContext.builder()
290291
.cluster(clusterName)
291-
.topicActions(topicName, MESSAGES_READ)
292+
.topicActions(topicName, ANALYSIS_RUN)
292293
.operationName("cancelTopicAnalysis")
293294
.build();
294295

@@ -306,7 +307,7 @@ public Mono<ResponseEntity<TopicAnalysisDTO>> getTopicAnalysis(String clusterNam
306307

307308
var context = AccessContext.builder()
308309
.cluster(clusterName)
309-
.topicActions(topicName, MESSAGES_READ)
310+
.topicActions(topicName, ANALYSIS_VIEW)
310311
.operationName("getTopicAnalysis")
311312
.build();
312313

@@ -350,18 +351,12 @@ private Comparator<InternalTopic> getComparatorForTopic(
350351
if (orderBy == null) {
351352
return defaultComparator;
352353
}
353-
switch (orderBy) {
354-
case TOTAL_PARTITIONS:
355-
return Comparator.comparing(InternalTopic::getPartitionCount);
356-
case OUT_OF_SYNC_REPLICAS:
357-
return Comparator.comparing(t -> t.getReplicas() - t.getInSyncReplicas());
358-
case REPLICATION_FACTOR:
359-
return Comparator.comparing(InternalTopic::getReplicationFactor);
360-
case SIZE:
361-
return Comparator.comparing(InternalTopic::getSegmentSize);
362-
case NAME:
363-
default:
364-
return defaultComparator;
365-
}
354+
return switch (orderBy) {
355+
case TOTAL_PARTITIONS -> Comparator.comparing(InternalTopic::getPartitionCount);
356+
case OUT_OF_SYNC_REPLICAS -> Comparator.comparing(t -> t.getReplicas() - t.getInSyncReplicas());
357+
case REPLICATION_FACTOR -> Comparator.comparing(InternalTopic::getReplicationFactor);
358+
case SIZE -> Comparator.comparing(InternalTopic::getSegmentSize);
359+
default -> defaultComparator;
360+
};
366361
}
367362
}

api/src/main/java/io/kafbat/ui/model/rbac/permission/TopicAction.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public enum TopicAction implements PermissibleAction {
1313
MESSAGES_READ(VIEW),
1414
MESSAGES_PRODUCE(VIEW),
1515
MESSAGES_DELETE(VIEW, EDIT),
16+
ANALYSIS_VIEW(VIEW),
17+
ANALYSIS_RUN(VIEW, ANALYSIS_VIEW),
1618

1719
;
1820

api/src/test/java/io/kafbat/ui/emitter/MessageFiltersTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ void testBase64DecodingWorks() {
199199
}
200200

201201
private TopicMessageDTO msg() {
202-
return new TopicMessageDTO(1, -1L, OffsetDateTime.now());
202+
return TopicMessageDTO.builder()
203+
.partition(1)
204+
.offset(-1L)
205+
.timestamp(OffsetDateTime.now())
206+
.build();
203207
}
204208
}

contract/pom.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@
4646
<artifactId>javax.annotation-api</artifactId>
4747
<version>1.3.2</version>
4848
</dependency>
49+
<dependency>
50+
<groupId>org.projectlombok</groupId>
51+
<artifactId>lombok</artifactId>
52+
<version>${org.projectlombok.version}</version>
53+
</dependency>
4954
</dependencies>
5055

5156
<build>
@@ -100,6 +105,12 @@
100105
<useTags>true</useTags>
101106
<useSpringBoot3>true</useSpringBoot3>
102107
<dateLibrary>java8</dateLibrary>
108+
<generatedConstructorWithRequiredArgs>false</generatedConstructorWithRequiredArgs>
109+
<additionalModelTypeAnnotations>
110+
@lombok.experimental.SuperBuilder
111+
@lombok.NoArgsConstructor
112+
@lombok.AllArgsConstructor
113+
</additionalModelTypeAnnotations>
103114
</configOptions>
104115
</configuration>
105116
</execution>

frontend/src/components/Topics/Topic/Statistics/Metrics.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const Metrics: React.FC = () => {
6060
buttonSize="M"
6161
permission={{
6262
resource: ResourceType.TOPIC,
63-
action: Action.MESSAGES_READ,
63+
action: Action.ANALYSIS_RUN,
6464
value: params.topicName,
6565
}}
6666
>
@@ -110,7 +110,7 @@ const Metrics: React.FC = () => {
110110
buttonSize="S"
111111
permission={{
112112
resource: ResourceType.TOPIC,
113-
action: Action.MESSAGES_READ,
113+
action: Action.ANALYSIS_RUN,
114114
value: params.topicName,
115115
}}
116116
>

frontend/src/components/Topics/Topic/Statistics/Statistics.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const Statistics: React.FC = () => {
3131
buttonSize="M"
3232
permission={{
3333
resource: ResourceType.TOPIC,
34-
action: Action.MESSAGES_READ,
34+
action: Action.ANALYSIS_RUN,
3535
value: params.topicName,
3636
}}
3737
>

frontend/src/components/Topics/Topic/Topic.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,17 @@ const Topic: React.FC = () => {
194194
>
195195
Settings
196196
</NavLink>
197-
<NavLink
197+
<ActionNavLink
198198
to={clusterTopicStatisticsRelativePath}
199199
className={({ isActive }) => (isActive ? 'is-active' : '')}
200+
permission={{
201+
resource: ResourceType.TOPIC,
202+
action: Action.ANALYSIS_VIEW,
203+
value: topicName,
204+
}}
200205
>
201206
Statistics
202-
</NavLink>
207+
</ActionNavLink>
203208
</Navbar>
204209
<Suspense fallback={<PageLoader />}>
205210
<Routes>

0 commit comments

Comments
 (0)