DisableExport annotation

This commit is contained in:
Francesco
2023-10-17 09:38:55 +02:00
parent 98fb1a67d4
commit 4fb1782888
5 changed files with 57 additions and 1 deletions

View 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 {
}

View File

@@ -61,6 +61,11 @@ public class DataExportController {
if (raw == null) raw = false;
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<>());
DataExportFormat exportFormat = null;

View File

@@ -31,6 +31,7 @@ import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import tech.ailef.dbadmin.external.DbAdmin;
import tech.ailef.dbadmin.external.DbAdminProperties;
import tech.ailef.dbadmin.external.exceptions.DbAdminException;
import tech.ailef.dbadmin.external.exceptions.DbAdminNotFoundException;
import tech.ailef.dbadmin.internal.UserConfiguration;
@@ -50,6 +51,17 @@ public class GlobalController {
@Autowired
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)
public String handleNotFound(Exception e, Model model, HttpServletResponse response) {
model.addAttribute("status", "404");

View File

@@ -44,6 +44,7 @@ import tech.ailef.dbadmin.external.annotations.ComputedColumn;
import tech.ailef.dbadmin.external.annotations.DisableCreate;
import tech.ailef.dbadmin.external.annotations.DisableDelete;
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.dto.MappingError;
import tech.ailef.dbadmin.external.exceptions.DbAdminException;
@@ -353,6 +354,10 @@ public class DbObjectSchema {
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
* @return

View File

@@ -151,7 +151,8 @@
<span title="Database table name" class="ms-3 label label-primary label-gray font-monospace">
[[ ${schema.getTableName()} ]]
</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>
</button>
</h3>