@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") @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); 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("className", className);
model.addAttribute("schema", schema); model.addAttribute("schema", schema);
model.addAttribute("title", "Entities | " + schema.getJavaClass().getSimpleName() + " | Create"); model.addAttribute("title", "Entities | " + schema.getJavaClass().getSimpleName() + " | Create");
@ -411,6 +417,12 @@ public class DefaultDbAdminController {
boolean create = Boolean.parseBoolean(c); boolean create = Boolean.parseBoolean(c);
DbObjectSchema schema = dbAdmin.findSchemaByClassName(className); 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()); String pkValue = params.get(schema.getPrimaryKey().getName());
if (pkValue == null || pkValue.isBlank()) { if (pkValue == null || pkValue.isBlank()) {

View File

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

View File

@ -50,7 +50,10 @@
</td> </td>
<td class="text-end row-icons"> <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="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> </td>
</tr> </tr>
</table> </table>

View File

@ -62,7 +62,8 @@
</h3> </h3>
<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> th:href="|/${baseUrl}/model/${schema.getClassName()}/create|"><i class="bi bi-plus-square"></i></a>
</h3> </h3>
</div> </div>

View File

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