Skip to content

Commit

Permalink
Merge branch 'dev' into laupoh-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
laupoh authored Feb 20, 2024
2 parents 48078d0 + 2050e1a commit 3fc9946
Show file tree
Hide file tree
Showing 14 changed files with 365 additions and 380 deletions.
26 changes: 16 additions & 10 deletions app/controllers/SessionController.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,21 +124,27 @@ private CompletionStage<Result> hakaLogin(Http.Request request) {
Reservation externalReservation = getUpcomingExternalReservation(eppn);
boolean isTemporaryVisitor = externalReservation != null;
User user = DB.find(User.class).where().eq("eppn", eppn).findOne();
boolean newUser = user == null;
try {
if (newUser) {
if (user == null) {
user = createNewUser(eppn, request, isTemporaryVisitor);
} else {
updateUser(user, request);
}
} catch (NotFoundException | AddressException e) {
logger.error("Login failed", e);
String headers = request
.headers()
.asMap()
.entrySet()
.stream()
.map(entry -> String.format("%s: %s", entry.getKey(), entry.getValue()))
.collect(Collectors.joining());
logger.error("Received following request headers: {}", headers);
return wrapAsPromise(badRequest(e.getMessage()));
}
user.setLastLogin(new Date());
user.save();
if (newUser) {
associateWithPreEnrolments(user);
}
associateWithPreEnrolments(user);
return handleExternalReservationAndCreateSession(user, externalReservation, request);
}

Expand Down Expand Up @@ -219,7 +225,7 @@ private Reservation getUpcomingExternalReservation(String eppn) {
.gt("endAt", now)
.orderBy("startAt")
.findList();
return reservations.isEmpty() ? null : reservations.get(0);
return reservations.isEmpty() ? null : reservations.getFirst();
}

private CompletionStage<Result> handleExternalReservation(User user, Reservation reservation)
Expand Down Expand Up @@ -375,19 +381,19 @@ private CompletionStage<Result> createSession(User user, boolean isTemporaryVisi
payload.put("id", user.getId().toString());
payload.put("email", user.getEmail());
if (!user.getPermissions().isEmpty()) {
// For now we support just a single permission
payload.put("permissions", user.getPermissions().get(0).getValue());
// For now, we support just a single permission
payload.put("permissions", user.getPermissions().getFirst().getValue());
}
// If (regular) user has just one role, set it as the one used for login
if (user.getRoles().size() == 1 && !isTemporaryVisitor) {
payload.put("role", user.getRoles().get(0).getName());
payload.put("role", user.getRoles().getFirst().getName());
}
List<Role> roles = isTemporaryVisitor
? DB.find(Role.class).where().eq("name", Role.Name.STUDENT.toString()).findList()
: user.getRoles();
if (isTemporaryVisitor) {
payload.put("visitingStudent", "true");
payload.put("role", roles.get(0).getName()); // forced login as student
payload.put("role", roles.getFirst().getName()); // forced login as student
}
ObjectNode result = Json.newObject();
result.put("id", user.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ public CompletionStage<ExamEnrolment> requestEnrolment(User user, Reservation re
Exam document = JsonDeserializer.deserialize(Exam.class, root);
// Set references so that:
// - external ref is the reference we got from outside. Must not be changed.
// - local ref is an UUID X. It is used locally for referencing the exam
// - local ref is a UUID X. It is used locally for referencing the exam
// - content's hash is set to X in order to simplify things with frontend

String externalRef = document.getHash();
Expand Down
2 changes: 2 additions & 0 deletions ui/.prettierrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ trailingComma: 'all'
singleQuote: true
printWidth: 120
tabWidth: 4
plugins:
- 'prettier-plugin-organize-imports'
86 changes: 50 additions & 36 deletions ui/src/app/calendar/calendar.component.html
Original file line number Diff line number Diff line change
@@ -1,54 +1,66 @@
<div id="dashboard">
<div class="col-12 mt-2">
<div class="student-details-title-wrap">
<xm-history-back xmAutoFocus></xm-history-back>
<h1 class="student-exam-details-title">{{ 'i18n_calendar' | translate }}</h1>
<div class="row">
<div class="col-12 mt-2">
<div class="student-details-title-wrap">
<xm-history-back xmAutoFocus></xm-history-back>
<h1 class="student-exam-details-title">{{ 'i18n_calendar' | translate }}</h1>
</div>
</div>
</div>

<!-- Phase 1: Exam Info -->
@if (examInfo && reservationWindowSize) {
<xm-calendar-exam-info
[examInfo]="examInfo"
[reservationWindowSize]="reservationWindowSize"
[collaborative]="isCollaborative"
></xm-calendar-exam-info>
<div class="row mt-3">
<div class="col-12 p-0">
<xm-calendar-exam-info
[examInfo]="examInfo"
[reservationWindowSize]="reservationWindowSize"
[collaborative]="isCollaborative"
></xm-calendar-exam-info>
</div>
</div>
}
<!-- Phase 2: Optional exam section selection (optional) -->
@if (examInfo && hasOptionalSections()) {
<div class="mt-3">
<xm-calendar-optional-sections
[examInfo]="examInfo"
(selected)="onSectionSelection($event)"
></xm-calendar-optional-sections>
<div class="row mt-3">
<div class="col-12 p-0">
<xm-calendar-optional-sections
[examInfo]="examInfo"
(selected)="onSectionSelection($event)"
></xm-calendar-optional-sections>
</div>
</div>
}
<!-- Phase 3: Organisation picker -->
@if (isInteroperable && isExternal) {
<div class="mt-3">
<xm-calendar-organisation-picker
[sequenceNumber]="getSequenceNumber('organization')"
[disabled]="!sectionSelectionOk()"
(selected)="setOrganisation($event)"
(cancelled)="makeInternalReservation()"
></xm-calendar-organisation-picker>
<div class="row mt-3">
<div class="col-12 p-0">
<xm-calendar-organisation-picker
[sequenceNumber]="getSequenceNumber('organization')"
[disabled]="!sectionSelectionOk()"
(selected)="setOrganisation($event)"
(cancelled)="makeInternalReservation()"
></xm-calendar-organisation-picker>
</div>
</div>
}
<!-- Phase 4: Room picker -->
<div class="mt-3">
<xm-calendar-slot-picker
[sequenceNumber]="getSequenceNumber('room')"
[isInteroperable]="isInteroperable"
[isExternal]="isExternal"
[isCollaborative]="isCollaborative"
[organisation]="selectedOrganisation"
[minDate]="minDate"
[maxDate]="maxDate"
[disabled]="!sectionSelectionOk()"
(cancelled)="makeExternalReservation()"
(selected)="createReservation($event)"
>
</xm-calendar-slot-picker>
<div class="row mt-3">
<div class="col-12 p-0">
<xm-calendar-slot-picker
[sequenceNumber]="getSequenceNumber('room')"
[isInteroperable]="isInteroperable"
[isExternal]="isExternal"
[isCollaborative]="isCollaborative"
[organisation]="selectedOrganisation"
[minDate]="minDate"
[maxDate]="maxDate"
[disabled]="!sectionSelectionOk()"
(cancelled)="makeExternalReservation()"
(selected)="createReservation($event)"
>
</xm-calendar-slot-picker>
</div>
</div>

<!-- Reservation confirmation -->
Expand All @@ -58,10 +70,12 @@ <h1 class="student-exam-details-title">{{ 'i18n_calendar' | translate }}</h1>
<div class="row student-enrolment-wrapper details-view" [ngClass]="reservation ? '' : 'notactive'">
<div class="col-md-12">
<div class="row">
<span class="col-md-12 mb-3">
<span class="col-md-6 mb-3">
<h2 class="calendar-phase-title">
{{ getSequenceNumber('confirmation') }}. {{ 'i18n_calendar_phase_3' | translate }}
</h2>
</span>
<span class="col-md-6">
<span class="calendar-phase-icon float-end" [hidden]="!reservation">
<img class="arrow_icon" src="/assets/images/icon-phase.png" alt="" />
</span>
Expand Down
16 changes: 10 additions & 6 deletions ui/src/app/calendar/helpers/exam-info.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ import type { ExamInfo } from '../calendar.service';
template: `
<div class="row student-enrolment-wrapper details-view">
<div class="col-md-12">
<div class="row">
<span class="col-md-12">
<div class="row align-items-center">
<div class="col-md-8">
<h2 class="calendar-phase-title">1. {{ 'i18n_calendar_phase_1' | translate }}</h2>
<span class="calendar-phase-icon float-end">
<img class="arrow_icon" src="/assets/images/icon-phase.png" alt="" />
</span>
</span>
</div>
<div class="col-md-4">
<img
class="calendar-phase-icon float-end arrow_icon"
src="/assets/images/icon-phase.png"
alt=""
/>
</div>
</div>
<div class="row">
<div class="col-md-12">
Expand Down
Loading

0 comments on commit 3fc9946

Please sign in to comment.