Skip to content

Commit 013c1fb

Browse files
committed
Only admin and appt owner can delete it
1 parent 4542505 commit 013c1fb

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

appointment/views_admin.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def fetch_service_list_for_staff(request):
239239
# Ensure the staff member is associated with this appointment
240240
if not Appointment.objects.filter(id=appointment_id,
241241
appointment_request__staff_member=staff_member).exists():
242-
return json_response(_("You do not have permission to access this appointment."), status_code=403)
242+
return handle_unauthorized_response(request, _("You do not have permission to access this appointment."), response_type='html')
243243
else:
244244
# Fetch all services for the staff member (create mode)
245245
try:
@@ -346,7 +346,7 @@ def update_personal_info(request, staff_user_id=None):
346346
'email': user.email,
347347
}, user=user)
348348

349-
context = get_generic_context_with_extra(request=request, extra={'form': form})
349+
context = get_generic_context_with_extra(request=request, extra={'form': form, 'btn_text': _("Update")})
350350
return render(request, 'administration/manage_staff_personal_info.html', context)
351351

352352

@@ -386,7 +386,7 @@ def create_new_staff_member(request):
386386
return redirect('appointment:add_staff_member_personal_info')
387387

388388
form = PersonalInformationForm()
389-
context = get_generic_context_with_extra(request=request, extra={'form': form})
389+
context = get_generic_context_with_extra(request=request, extra={'form': form, 'btn_text': _("Create")})
390390
return render(request, 'administration/manage_staff_personal_info.html', context=context)
391391

392392

@@ -491,6 +491,9 @@ def get_service_list(request, response_type='html'):
491491
@require_staff_or_superuser
492492
def delete_appointment(request, appointment_id):
493493
appointment = get_object_or_404(Appointment, pk=appointment_id)
494+
if not check_extensive_permissions(appointment.get_staff_member().user_id, request.user, appointment):
495+
message = _("You can only delete your own appointments.")
496+
return handle_unauthorized_response(request, message, 'html')
494497
appointment.delete()
495498
messages.success(request, _("Appointment deleted successfully!"))
496499
return redirect('appointment:get_user_appointments')
@@ -502,6 +505,9 @@ def delete_appointment_ajax(request):
502505
data = json.loads(request.body)
503506
appointment_id = data.get("appointment_id")
504507
appointment = get_object_or_404(Appointment, pk=appointment_id)
508+
if not check_extensive_permissions(appointment.get_staff_member().user_id, request.user, appointment):
509+
message = _("You can only delete your own appointments.")
510+
return json_response(message, status=403, success=False, error_code=ErrorCode.NOT_AUTHORIZED)
505511
appointment.delete()
506512
return json_response(_("Appointment deleted successfully."))
507513

0 commit comments

Comments
 (0)