feat: export details secure access

pull/8040/head
Gauthier LO 2024-12-20 17:15:29 +01:00
parent b8124a880f
commit 08528696c7
1 changed files with 18 additions and 3 deletions

View File

@ -11,7 +11,6 @@ import freemarker.template.TemplateException;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.dto.message.TemplateMessageDTO;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.common.system.query.QueryGenerator;
@ -626,11 +625,27 @@ public class InvoiceController {
@RequestParam("type") String type
) throws IOException, UserException {
log.info("Request for downloading invoice detail by client and period : \nclient : {} \nshops : {}\nstart date : {}\nend date : {}\ntype : {}", clientId, shopIds, startDate, endDate, type);
List<FactureDetail> invoiceDetails = shippingInvoiceService.getInvoiceDetailByShopsAndPeriod(shopIds, startDate, endDate, type);
boolean isEmployee = securityService.checkIsEmployee();
Client client = clientService.getById(clientId);
Client currentClient;
if(client == null) {
log.error("Client {} not found", clientId);
return new byte[0];
}
if (!isEmployee) {
currentClient = clientService.getCurrentClient();
if (currentClient == null) {
log.error("Client is not registered as a user : {}", clientId);
return new byte[0];
}
if(!clientId.equals(currentClient.getId())) {
log.error("Client {} is not authorized to download invoice detail for client {}", currentClient.getInternalCode(), client.getInternalCode());
return new byte[0];
}
}
List<FactureDetail> invoiceDetails = shippingInvoiceService.getInvoiceDetailByShopsAndPeriod(shopIds, startDate, endDate, type);
String period = startDate + "-" + endDate;
return shippingInvoiceService.exportToExcel(invoiceDetails, Collections.emptyList(), Collections.emptyList(), period, client.getInvoiceEntity(), client.getInternalCode());
}
@GetMapping(value = "/downloadInvoiceInventory")
public byte[] downloadInvoiceInventory(@RequestParam("invoiceCode") String invoiceCode, @RequestParam("internalCode") String internalCode, @RequestParam("invoiceEntity") String invoiceEntity) throws IOException {