mirror of
https://github.com/dalbodeule/snap-admin.git
synced 2025-12-15 04:41:58 +09:00
@DisableCreate
This commit is contained in:
@@ -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()) {
|
||||
|
||||
Reference in New Issue
Block a user