mirror of
https://github.com/dalbodeule/snap-admin.git
synced 2025-08-07 12:41:11 +00:00
DisableExport annotation
This commit is contained in:
33
src/main/java/tech/ailef/dbadmin/external/annotations/DisableExport.java
vendored
Normal file
33
src/main/java/tech/ailef/dbadmin/external/annotations/DisableExport.java
vendored
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Spring Boot Database Admin - An automatically generated CRUD admin UI for Spring Boot apps
|
||||||
|
* Copyright (C) 2023 Ailef (http://ailef.tech)
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
package tech.ailef.dbadmin.external.annotations;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disables delete actions on the Entity class.
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target(ElementType.TYPE)
|
||||||
|
public @interface DisableExport {
|
||||||
|
}
|
@@ -61,6 +61,11 @@ public class DataExportController {
|
|||||||
if (raw == null) raw = false;
|
if (raw == null) raw = false;
|
||||||
|
|
||||||
DbObjectSchema schema = dbAdmin.findSchemaByClassName(className);
|
DbObjectSchema schema = dbAdmin.findSchemaByClassName(className);
|
||||||
|
|
||||||
|
if (!schema.isExportEnabled()) {
|
||||||
|
throw new DbAdminException("Export is not enabled for this table: " + schema.getTableName());
|
||||||
|
}
|
||||||
|
|
||||||
List<String> fieldsToInclude = otherParams.getOrDefault("fields[]", new ArrayList<>());
|
List<String> fieldsToInclude = otherParams.getOrDefault("fields[]", new ArrayList<>());
|
||||||
|
|
||||||
DataExportFormat exportFormat = null;
|
DataExportFormat exportFormat = null;
|
||||||
|
@@ -31,6 +31,7 @@ import jakarta.servlet.http.HttpServletRequest;
|
|||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import tech.ailef.dbadmin.external.DbAdmin;
|
import tech.ailef.dbadmin.external.DbAdmin;
|
||||||
import tech.ailef.dbadmin.external.DbAdminProperties;
|
import tech.ailef.dbadmin.external.DbAdminProperties;
|
||||||
|
import tech.ailef.dbadmin.external.exceptions.DbAdminException;
|
||||||
import tech.ailef.dbadmin.external.exceptions.DbAdminNotFoundException;
|
import tech.ailef.dbadmin.external.exceptions.DbAdminNotFoundException;
|
||||||
import tech.ailef.dbadmin.internal.UserConfiguration;
|
import tech.ailef.dbadmin.internal.UserConfiguration;
|
||||||
|
|
||||||
@@ -50,6 +51,17 @@ public class GlobalController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private DbAdmin dbAdmin;
|
private DbAdmin dbAdmin;
|
||||||
|
|
||||||
|
@ExceptionHandler(DbAdminException.class)
|
||||||
|
public String handleException(Exception e, Model model, HttpServletResponse response) {
|
||||||
|
model.addAttribute("status", "");
|
||||||
|
model.addAttribute("error", "Error");
|
||||||
|
model.addAttribute("message", e.getMessage());
|
||||||
|
model.addAttribute("dbadmin_userConf", userConf);
|
||||||
|
model.addAttribute("dbadmin_baseUrl", getBaseUrl());
|
||||||
|
model.addAttribute("dbadmin_version", dbAdmin.getVersion());
|
||||||
|
return "other/error";
|
||||||
|
}
|
||||||
|
|
||||||
@ExceptionHandler(DbAdminNotFoundException.class)
|
@ExceptionHandler(DbAdminNotFoundException.class)
|
||||||
public String handleNotFound(Exception e, Model model, HttpServletResponse response) {
|
public String handleNotFound(Exception e, Model model, HttpServletResponse response) {
|
||||||
model.addAttribute("status", "404");
|
model.addAttribute("status", "404");
|
||||||
|
@@ -44,6 +44,7 @@ import tech.ailef.dbadmin.external.annotations.ComputedColumn;
|
|||||||
import tech.ailef.dbadmin.external.annotations.DisableCreate;
|
import tech.ailef.dbadmin.external.annotations.DisableCreate;
|
||||||
import tech.ailef.dbadmin.external.annotations.DisableDelete;
|
import tech.ailef.dbadmin.external.annotations.DisableDelete;
|
||||||
import tech.ailef.dbadmin.external.annotations.DisableEdit;
|
import tech.ailef.dbadmin.external.annotations.DisableEdit;
|
||||||
|
import tech.ailef.dbadmin.external.annotations.DisableExport;
|
||||||
import tech.ailef.dbadmin.external.annotations.HiddenColumn;
|
import tech.ailef.dbadmin.external.annotations.HiddenColumn;
|
||||||
import tech.ailef.dbadmin.external.dto.MappingError;
|
import tech.ailef.dbadmin.external.dto.MappingError;
|
||||||
import tech.ailef.dbadmin.external.exceptions.DbAdminException;
|
import tech.ailef.dbadmin.external.exceptions.DbAdminException;
|
||||||
@@ -353,6 +354,10 @@ public class DbObjectSchema {
|
|||||||
return entityClass.getAnnotation(DisableCreate.class) == null;
|
return entityClass.getAnnotation(DisableCreate.class) == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isExportEnabled() {
|
||||||
|
return entityClass.getAnnotation(DisableExport.class) == null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns all the data in this schema, as `DbObject`s
|
* Returns all the data in this schema, as `DbObject`s
|
||||||
* @return
|
* @return
|
||||||
|
@@ -151,7 +151,8 @@
|
|||||||
<span title="Database table name" class="ms-3 label label-primary label-gray font-monospace">
|
<span title="Database table name" class="ms-3 label label-primary label-gray font-monospace">
|
||||||
[[ ${schema.getTableName()} ]]
|
[[ ${schema.getTableName()} ]]
|
||||||
</span>
|
</span>
|
||||||
<button title="Open export data window" type="button" class="btn" data-bs-toggle="modal" data-bs-target="#csvExportModal">
|
<button th:if="${schema.isExportEnabled()}" title="Open export data window" type="button"
|
||||||
|
class="btn" data-bs-toggle="modal" data-bs-target="#csvExportModal">
|
||||||
<i class="bi bi-file-earmark-spreadsheet export-icon" style="font-size: 1.5rem;"></i>
|
<i class="bi bi-file-earmark-spreadsheet export-icon" style="font-size: 1.5rem;"></i>
|
||||||
</button>
|
</button>
|
||||||
</h3>
|
</h3>
|
||||||
|
Reference in New Issue
Block a user