Skip to content

Commit

Permalink
BE: RBAC: Wizard: Fix enums mapping (#278)
Browse files Browse the repository at this point in the history
Co-authored-by: iliax <[email protected]>
  • Loading branch information
iliax and iliax authored May 26, 2024
1 parent a774ab9 commit 22a5053
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import io.kafbat.ui.api.ApplicationConfigApi;
import io.kafbat.ui.config.ClustersProperties;
import io.kafbat.ui.model.ActionDTO;
import io.kafbat.ui.model.ApplicationConfigDTO;
import io.kafbat.ui.model.ApplicationConfigPropertiesDTO;
import io.kafbat.ui.model.ApplicationConfigValidationDTO;
Expand All @@ -18,6 +19,7 @@
import io.kafbat.ui.util.ApplicationRestarter;
import io.kafbat.ui.util.DynamicConfigOperations;
import java.util.Map;
import java.util.Optional;
import javax.annotation.Nullable;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -46,6 +48,12 @@ interface PropertiesMapper {
DynamicConfigOperations.PropertiesStructure fromDto(ApplicationConfigPropertiesDTO dto);

ApplicationConfigPropertiesDTO toDto(DynamicConfigOperations.PropertiesStructure propertiesStructure);

default ActionDTO stringToActionDto(String str) {
return Optional.ofNullable(str)
.map(s -> Enum.valueOf(ActionDTO.class, s.toUpperCase()))
.orElseThrow();
}
}

private final DynamicConfigOperations dynamicConfigOperations;
Expand Down Expand Up @@ -75,7 +83,7 @@ public Mono<ResponseEntity<ApplicationConfigDTO>> getCurrentConfig(ServerWebExch
@Override
public Mono<ResponseEntity<Void>> restartWithConfig(Mono<RestartRequestDTO> restartRequestDto,
ServerWebExchange exchange) {
var context = AccessContext.builder()
var context = AccessContext.builder()
.applicationConfigActions(EDIT)
.operationName("restartWithConfig")
.build();
Expand Down
3 changes: 2 additions & 1 deletion api/src/main/java/io/kafbat/ui/model/rbac/Permission.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.apache.commons.collections.CollectionUtils.isNotEmpty;

import com.google.common.base.Preconditions;
import io.kafbat.ui.model.ActionDTO;
import io.kafbat.ui.model.rbac.permission.PermissibleAction;
import java.util.List;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -50,7 +51,7 @@ public void transform() {
if (value != null) {
this.compiledValuePattern = Pattern.compile(value);
}
if (actions.stream().anyMatch("ALL"::equalsIgnoreCase)) {
if (actions.stream().anyMatch(ActionDTO.ALL.name()::equalsIgnoreCase)) {
this.parsedActions = resource.allActions();
} else {
this.parsedActions = resource.parseActionsWithDependantsUnnest(actions);
Expand Down
1 change: 1 addition & 0 deletions contract/src/main/resources/swagger/kafbat-ui-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3821,6 +3821,7 @@ components:
Action:
type: string
enum:
- ALL
- VIEW
- EDIT
- CREATE
Expand Down

0 comments on commit 22a5053

Please sign in to comment.