Skip to content

BE: RBAC: Wizard: Fix enums mapping #278

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

Merged
merged 6 commits into from
May 26, 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 @@ -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
Loading