mirror of
https://github.com/dalbodeule/snap-admin.git
synced 2025-06-09 05:48:20 +00:00
@DisableCreate
This commit is contained in:
parent
7b2eb02cd4
commit
a05ce27d24
@ -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");
|
||||||
@ -412,6 +418,12 @@ public class DefaultDbAdminController {
|
|||||||
|
|
||||||
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()) {
|
||||||
pkValue = null;
|
pkValue = null;
|
||||||
|
@ -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;
|
||||||
|
@ -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>
|
||||||
|
@ -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>
|
||||||
|
@ -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"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user