Fix for Feature #64

This commit is contained in:
Jan 2025-12-08 11:11:35 +01:00
parent c3db9ee2a6
commit b1a392b5e0
2 changed files with 6 additions and 1 deletions

View file

@ -26,7 +26,7 @@ export const useActiveUserStore = defineStore('activeUser', {
allowReporting(state) { allowReporting(state) {
if (state.user === null) if (state.user === null)
return false; return false;
return state.user.groups?.includes("super") || state.user.groups?.includes("freight") || state.user.groups?.includes("packaging") || state.user.groups?.includes("material") || state.user.groups?.includes("basic") || state.user.groups?.includes("calculation"); return state.user.groups?.includes("super") || state.user.groups?.includes("basic") || state.user.groups?.includes("calculation");
}, },
isSuper(state) { isSuper(state) {
if (state.user === null) if (state.user === null)

View file

@ -8,6 +8,7 @@ import org.springframework.core.io.InputStreamResource;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
@ -34,6 +35,7 @@ public class ReportingController {
* @param reportingService Service used for generating reports. * @param reportingService Service used for generating reports.
* @param excelReportingService Service used for generating Excel files for reports. * @param excelReportingService Service used for generating Excel files for reports.
*/ */
public ReportingController(ReportingService reportingService, ExcelReportingService excelReportingService) { public ReportingController(ReportingService reportingService, ExcelReportingService excelReportingService) {
this.reportingService = reportingService; this.reportingService = reportingService;
this.excelReportingService = excelReportingService; this.excelReportingService = excelReportingService;
@ -46,6 +48,7 @@ public class ReportingController {
* @return A list of suppliers grouped by categories. * @return A list of suppliers grouped by categories.
*/ */
@GetMapping({"/search", "/search/"}) @GetMapping({"/search", "/search/"})
@PreAuthorize("hasAnyRole('SUPER', 'CALCULATION', 'BASIC')")
public ResponseEntity<List<List<NodeDTO>>> findSupplierForReporting(@RequestParam(value = "material") Integer materialId) { public ResponseEntity<List<List<NodeDTO>>> findSupplierForReporting(@RequestParam(value = "material") Integer materialId) {
return ResponseEntity.ok(reportingService.findSupplierForReporting(materialId)); return ResponseEntity.ok(reportingService.findSupplierForReporting(materialId));
} }
@ -58,6 +61,7 @@ public class ReportingController {
* @return The generated report details. * @return The generated report details.
*/ */
@GetMapping({"/view", "/view/"}) @GetMapping({"/view", "/view/"})
@PreAuthorize("hasAnyRole('SUPER', 'CALCULATION', 'BASIC')")
public ResponseEntity<List<ReportDTO>> getReport(@RequestParam(value = "material") Integer materialId, @RequestParam(value = "sources", required = false) List<Integer> nodeIds, @RequestParam(value = "userSources", required = false) List<Integer> userNodeIds) { public ResponseEntity<List<ReportDTO>> getReport(@RequestParam(value = "material") Integer materialId, @RequestParam(value = "sources", required = false) List<Integer> nodeIds, @RequestParam(value = "userSources", required = false) List<Integer> userNodeIds) {
return ResponseEntity.ok(reportingService.getReport(materialId, nodeIds, userNodeIds)); return ResponseEntity.ok(reportingService.getReport(materialId, nodeIds, userNodeIds));
} }
@ -70,6 +74,7 @@ public class ReportingController {
* @return The Excel file as an attachment in the response. * @return The Excel file as an attachment in the response.
*/ */
@GetMapping({"/download", "/download/"}) @GetMapping({"/download", "/download/"})
@PreAuthorize("hasAnyRole('SUPER', 'CALCULATION', 'BASIC')")
public ResponseEntity<InputStreamResource> downloadReport(@RequestParam(value = "material") Integer materialId, @RequestParam(value = "sources", required = false) List<Integer> nodeIds, @RequestParam(value = "userSources", required = false) List<Integer> userNodeIds) { public ResponseEntity<InputStreamResource> downloadReport(@RequestParam(value = "material") Integer materialId, @RequestParam(value = "sources", required = false) List<Integer> nodeIds, @RequestParam(value = "userSources", required = false) List<Integer> userNodeIds) {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();