@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");
@ -412,6 +418,12 @@ public class DefaultDbAdminController {
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()) {
pkValue = null;

View File

@ -27,9 +27,16 @@ a {
.disable {
pointer-events: none;
}
input.disable {
background: #EDECEF;
}
a.disable .bi {
color: #9298A0 !important;
}
.btn-secondary.disable {
background-color: #A8ADB3;
border: 1px solid #A8ADB3;

View File

@ -50,7 +50,10 @@
</td>
<td class="text-end row-icons">
<a title="List all" th:href="|/${baseUrl}/model/${schema.getClassName()}|"><i class="bi bi-list"></i></i></a>
<a title="Create new" th:href="|/${baseUrl}/model/${schema.getClassName()}/create|"><i class="bi bi-plus-square"></i></a>
<a th:title="|${!schema.isCreateEnabled() ? 'CREATE disabled for this type' : 'Create new item'}|"
th:class="|${!schema.isCreateEnabled() ? 'disable' : ''}|"
th:href="|/${baseUrl}/model/${schema.getClassName()}/create|"><i class="bi bi-plus-square"></i>
</a>
</td>
</tr>
</table>

View File

@ -62,7 +62,8 @@
</h3>
<h3>
<a title="Create new item"
<a th:title="|${!schema.isCreateEnabled() ? 'CREATE disabled for this type' : 'Create new item'}|"
th:class="|${!schema.isCreateEnabled() ? 'disable' : ''}|"
th:href="|/${baseUrl}/model/${schema.getClassName()}/create|"><i class="bi bi-plus-square"></i></a>
</h3>
</div>

View File

@ -39,8 +39,9 @@
[[ ${schema.getTableName()} ]]
</span>
</h3>
<h3><a title="Create new item"
th:href="|/${baseUrl}/model/${schema.getClassName()}/create|"><i class="bi bi-plus-square"></i></a></h3>
<h3><a th:title="|${!schema.isCreateEnabled() ? 'CREATE disabled for this type' : 'Create new item'}|"
th:href="|/${baseUrl}/model/${schema.getClassName()}/create|"
th:class="|${!schema.isCreateEnabled() ? 'disable' : ''}|"><i class="bi bi-plus-square"></i></a></h3>
</div>
<div class="mb-4 operations-badges">
<span class="align-middle noselect badge"