@DisableCreate

This commit is contained in:
Francesco
2023-10-06 14:52:29 +02:00
parent 7b2eb02cd4
commit a05ce27d24
5 changed files with 29 additions and 5 deletions

View File

@@ -264,9 +264,15 @@ public class DefaultDbAdminController {
@GetMapping("/model/{className}/create")
public String create(Model model, @PathVariable String className) {
public String create(Model model, @PathVariable String className, RedirectAttributes attr) {
DbObjectSchema schema = dbAdmin.findSchemaByClassName(className);
if (!schema.isCreateEnabled()) {
attr.addFlashAttribute("errorTitle", "Unauthorized");
attr.addFlashAttribute("error", "CREATE operations have been disabled on this type (" + schema.getJavaClass().getSimpleName() + ").");
return "redirect:/" + properties.getBaseUrl() + "/model/" + className;
}
model.addAttribute("className", className);
model.addAttribute("schema", schema);
model.addAttribute("title", "Entities | " + schema.getJavaClass().getSimpleName() + " | Create");
@@ -411,6 +417,12 @@ public class DefaultDbAdminController {
boolean create = Boolean.parseBoolean(c);
DbObjectSchema schema = dbAdmin.findSchemaByClassName(className);
if (!schema.isCreateEnabled() && create) {
attr.addFlashAttribute("errorTitle", "Unauthorized");
attr.addFlashAttribute("error", "CREATE operations have been disabled on this type (" + schema.getJavaClass().getSimpleName() + ").");
return "redirect:/" + properties.getBaseUrl() + "/model/" + className;
}
String pkValue = params.get(schema.getPrimaryKey().getName());
if (pkValue == null || pkValue.isBlank()) {