Skip to content

Commit

Permalink
check reservationId
Browse files Browse the repository at this point in the history
  • Loading branch information
syjer committed Dec 13, 2023
1 parent d5eb3fd commit e10b4d0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/main/java/alfio/controller/api/admin/EventApiController.java
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ public String confirmPayment(@PathVariable("eventName") String eventName,
@PathVariable("reservationId") String reservationId,
@RequestBody TransactionMetadataModification transactionMetadataModification,
Principal principal) {
accessService.checkEventAndReservationOwnership(principal, eventName, Set.of(reservationId));
var event = loadEvent(eventName, principal);
ticketReservationManager.confirmOfflinePayment(event, reservationId, transactionMetadataModification, principal.getName());
ticketReservationManager.findById(reservationId)
Expand All @@ -642,6 +643,7 @@ public String deletePendingPayment(@PathVariable("eventName") String eventName,
@RequestParam(required = false, value = "credit", defaultValue = "false") Boolean creditReservation,
@RequestParam(required = false, value = "notify", defaultValue = "true") Boolean notify,
Principal principal) {
accessService.checkEventAndReservationOwnership(principal, eventName, Set.of(reservationId));
ticketReservationManager.deleteOfflinePayment(loadEvent(eventName, principal), reservationId, false, Boolean.TRUE.equals(creditReservation), notify, principal.getName());
return OK;
}
Expand All @@ -650,14 +652,21 @@ public String deletePendingPayment(@PathVariable("eventName") String eventName,
public List<Triple<Boolean, String, String>> bulkConfirmation(@PathVariable("eventName") String eventName,
Principal principal,
@RequestBody UploadBase64FileModification file) throws IOException, CsvException {

try(InputStreamReader isr = new InputStreamReader(file.getInputStream(), UTF_8); CSVReader reader = new CSVReader(isr)) {
var all = reader.readAll();
var reservationIds = all.stream()
.map(line -> {
Validate.isTrue(line.length >= 2);
return line[0];
})
.collect(Collectors.toSet());
accessService.checkEventAndReservationOwnership(principal, eventName, reservationIds);

Event event = loadEvent(eventName, principal);
return reader.readAll().stream()
return all.stream()
.map(line -> {
String reservationID = null;
try {
Validate.isTrue(line.length >= 2);
reservationID = line[0];
ticketReservationManager.validateAndConfirmOfflinePayment(reservationID, event, new BigDecimal(line[1]), principal.getName());
return Triple.of(Boolean.TRUE, reservationID, "");
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/alfio/manager/AccessService.java
Original file line number Diff line number Diff line change
Expand Up @@ -463,4 +463,12 @@ public void checkCategoryOwnershipAndTicket(Principal principal, String eventNam
throw new AccessDeniedException();
}
}

public void checkEventAndReservationOwnership(Principal principal, String eventName, Set<String> reservationIds) {
var eventAndOrgId = checkEventOwnership(principal, eventName);
if (reservationIds.size() != reservationRepository.countReservationsWithEventId(reservationIds, eventAndOrgId.getId())) {
log.warn("Some reservation ids {} are not in the event {}", reservationIds, eventName);
throw new AccessDeniedException();
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -298,4 +298,7 @@ default Integer countTicketsInReservationForCategories(String reservationId, Col
@Query("update tickets_reservation set vat_status = :vatStatus where id = :reservationId")
int updateVatStatus(@Bind("reservationId") String reservationId,
@Bind("vatStatus") PriceContainer.VatStatus vatStatus);

@Query("select count(id) from tickets_reservation where id in (:ids) and event_id_fk = :eventId")
int countReservationsWithEventId(@Bind("ids") Set<String> reservationIds, @Bind("eventId") int eventId);
}

0 comments on commit e10b4d0

Please sign in to comment.