# Description 1. **Conditional Support for DatabaseController**: - The `DatabaseController` is now annotated with `@Conditional(H2SQLCondition.class)` to ensure it is only available for H2SQL database setups. - This prevents unnecessary exposure of endpoints when the application is configured for H2SQL. 2. **Database Web Template Adjustments**: - The UI elements related to database management are conditionally hidden when the database type is not supported (e.g., `databaseVersion == 'Unknown'`). - Improves user experience by avoiding unsupported operations for non-H2SQL or unknown databases. 3. **Model Attribute Updates**: - Added a check in `DatabaseWebController` to set an informational message (`notSupported`) when the database version is unknown. 4. **H2 Database Compatibility**: - Additional adjustments to ensure the application gracefully handles H2-specific functionality without affecting other database configurations. 5. **Build File Updates**: - Updated the `build.gradle` file to exclude `H2SQLCondition` and related controllers when specific configurations (e.g., security or database type) are disabled. ### Benefits: - Enhances application flexibility by adapting to the configured database type. - Improves user feedback with clear messaging and UI adjustments for unsupported operations. - Prevents accidental exposure of database endpoints in H2SQL setups. ## Checklist - [x] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [x] I have performed a self-review of my own code - [ ] I have attached images of the change if it is UI based - [x] I have commented my code, particularly in hard-to-understand areas - [ ] If my code has heavily changed functionality I have updated relevant docs on [Stirling-PDFs doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) - [x] My changes generate no new warnings - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only)
46 lines
1.7 KiB
Java
46 lines
1.7 KiB
Java
package stirling.software.SPDF.controller.web;
|
|
|
|
import java.util.List;
|
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
import org.springframework.security.core.Authentication;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.ui.Model;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
import stirling.software.SPDF.config.security.database.DatabaseService;
|
|
import stirling.software.SPDF.utils.FileInfo;
|
|
|
|
@Controller
|
|
@Tag(name = "Database Management", description = "Database management and security APIs")
|
|
public class DatabaseWebController {
|
|
|
|
private final DatabaseService databaseService;
|
|
|
|
public DatabaseWebController(DatabaseService databaseService) {
|
|
this.databaseService = databaseService;
|
|
}
|
|
|
|
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
|
@GetMapping("/database")
|
|
public String database(HttpServletRequest request, Model model, Authentication authentication) {
|
|
String error = request.getParameter("error");
|
|
String confirmed = request.getParameter("infoMessage");
|
|
if (error != null) {
|
|
model.addAttribute("error", error);
|
|
} else if (confirmed != null) {
|
|
model.addAttribute("infoMessage", confirmed);
|
|
}
|
|
List<FileInfo> backupList = databaseService.getBackupList();
|
|
model.addAttribute("backupFiles", backupList);
|
|
model.addAttribute("databaseVersion", databaseService.getH2Version());
|
|
if ("Unknown".equalsIgnoreCase(databaseService.getH2Version())) {
|
|
model.addAttribute("infoMessage", "notSupported");
|
|
}
|
|
return "database";
|
|
}
|
|
}
|