[Developer] #424 load permission rule columns dynamically

This commit is contained in:
devmrko
2026-06-23 14:34:19 +09:00
parent ae3dd6667e
commit e5ba9aedd7
3 changed files with 54 additions and 7 deletions

View File

@@ -12,6 +12,7 @@ import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
@Controller
@@ -28,6 +29,34 @@ public class PermissionController {
this.protectedObjectService = protectedObjectService;
}
@GetMapping("/permissions/object-columns")
@ResponseBody
public List<String> objectColumns(@RequestParam String objectRef) {
if (objectRef == null || objectRef.isBlank()) {
return List.of();
}
if (objectRef.startsWith("protected:")) {
long objectId;
try {
objectId = Long.parseLong(objectRef.substring("protected:".length()));
} catch (NumberFormatException exception) {
return List.of();
}
return protectedObjectService.findColumns(objectId).stream()
.map(column -> column.columnName())
.toList();
}
if (objectRef.startsWith("db:")) {
String value = objectRef.substring("db:".length());
int dot = value.indexOf('.');
if (dot < 1 || dot == value.length() - 1) {
return List.of();
}
return protectedObjectService.findDatabaseColumns(value.substring(0, dot), value.substring(dot + 1));
}
return List.of();
}
@GetMapping("/permissions")
public String permissions(Model model) {
var objects = protectedObjectService.findEnabled();