mirror of
https://github.com/dalbodeule/snap-admin.git
synced 2025-06-08 21:38:21 +00:00
@DisableCreate
This commit is contained in:
parent
7b2eb02cd4
commit
a05ce27d24
@ -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()) {
|
||||
|
@ -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;
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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"
|
||||
|
Loading…
x
Reference in New Issue
Block a user