Skip to content

Commit

Permalink
CSCEXAM-1333 Fix handling of query params / reservation removal
Browse files Browse the repository at this point in the history
  • Loading branch information
lupari committed Jun 4, 2024
1 parent ddaf21c commit c17a9d9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
9 changes: 3 additions & 6 deletions app/controllers/ReservationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import models.base.GeneratedIdentityModel;
import org.joda.time.DateTime;
import org.joda.time.format.ISODateTimeFormat;
import play.data.DynamicForm;
import play.libs.Json;
import play.mvc.Http;
import play.mvc.Result;
Expand Down Expand Up @@ -140,28 +141,24 @@ public Result getTeachers(Optional<String> filter) {

@Restrict({ @Group("ADMIN") })
public CompletionStage<Result> removeReservation(long id, Http.Request request) throws NotFoundException {
var msg = request.body().asJson().get("msg").asText("");
var enrolment = DB.find(ExamEnrolment.class).where().eq("reservation.id", id).findOne();

if (enrolment == null) {
throw new NotFoundException(String.format("No reservation with id %d for current user.", id));
}

var participation = DB.find(ExamParticipation.class).where().eq("exam", enrolment.getExam()).findOne();

if (participation != null) {
return wrapAsPromise(
forbidden(String.format("i18n_unable_to_remove_reservation (id=%d).", participation.getId()))
);
}

var reservation = enrolment.getReservation();
DynamicForm df = formFactory.form().bindFromRequest(request);
String msg = df.get("msg");
// Let's not send emails about historical reservations
if (reservation.getEndAt().isAfter(DateTime.now())) {
var student = enrolment.getUser();
emailComposer.composeReservationCancellationNotification(student, reservation, msg, false, enrolment);
}

if (reservation.getExternalReservation() != null) {
return externalReservationHandler.removeReservation(reservation, enrolment.getUser(), msg);
} else {
Expand Down
3 changes: 2 additions & 1 deletion ui/src/app/reservation/reservation-details.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { Component, Input, OnChanges } from '@angular/core';
import { RouterLink } from '@angular/router';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { ToastrService } from 'ngx-toastr';
import { noop } from 'rxjs';
import { ExamEnrolment } from 'src/app/enrolment/enrolment.model';
import { ApplyDstPipe } from 'src/app/shared/date/apply-dst.pipe';
import { CourseCodeComponent } from 'src/app/shared/miscellaneous/course-code.component';
Expand Down Expand Up @@ -85,7 +86,7 @@ export class ReservationDetailsComponent implements OnChanges {
this.fixedReservations.splice(this.fixedReservations.indexOf(reservation), 1);
this.toast.info(this.translate.instant('i18n_reservation_removed'));
})
.catch((err) => this.toast.error(err));
.catch(noop);
}

permitRetrial(enrolment: ExamEnrolment) {
Expand Down

0 comments on commit c17a9d9

Please sign in to comment.