Changeset a64c772 for backend/src


Ignore:
Timestamp:
05/25/26 13:43:53 (4 months ago)
Author:
MBK <marija.karapandzova@…>
Branches:
master
Children:
f18b11b
Parents:
84249b1
Message:

Fix doctor authorization and prevent canceling other doctors appointments and restrict them from billing access

File:
1 edited

Legend:

Unmodified
Added
Removed
  • backend/src/main/java/medora/controller/AppointmentController.java

    r84249b1 ra64c772  
    243243            }
    244244
    245             // Verify appointment exists and check permissions for patients
     245            // Verify appointment exists and check permissions
    246246            Appointment appointment = appointmentService.getAppointmentById(appointmentId)
    247247                    .orElseThrow(() -> new RuntimeException("Appointment not found"));
     
    251251                Long appointmentPatientId = appointment.getPatient() != null ? appointment.getPatient().getPatientId() : null;
    252252                if (patientIdFromToken == null || !patientIdFromToken.equals(appointmentPatientId)) {
     253                    return ResponseEntity.status(HttpStatus.FORBIDDEN)
     254                            .body(Map.of("error", "You can only cancel your own appointments"));
     255                }
     256            } else if (role.equals("DOCTOR")) {
     257                Long doctorIdFromToken = securityUtil.getDoctorIdFromRequest(httpRequest);
     258                Long appointmentDoctorId = appointment.getDoctor() != null ? appointment.getDoctor().getDoctorId() : null;
     259                if (doctorIdFromToken == null || !doctorIdFromToken.equals(appointmentDoctorId)) {
    253260                    return ResponseEntity.status(HttpStatus.FORBIDDEN)
    254261                            .body(Map.of("error", "You can only cancel your own appointments"));
Note: See TracChangeset for help on using the changeset viewer.