From 15cbadb2e319e20bb3e39879c5ef1d1db3e04597 Mon Sep 17 00:00:00 2001 From: Adams Pierre David <57180807+adamspd@users.noreply.github.com> Date: Sat, 10 Feb 2024 01:40:59 +0100 Subject: [PATCH 1/4] Only admin and appt owner can delete it --- appointment/views_admin.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/appointment/views_admin.py b/appointment/views_admin.py index 5fbfac3..21569eb 100644 --- a/appointment/views_admin.py +++ b/appointment/views_admin.py @@ -239,7 +239,7 @@ def fetch_service_list_for_staff(request): # Ensure the staff member is associated with this appointment if not Appointment.objects.filter(id=appointment_id, appointment_request__staff_member=staff_member).exists(): - return json_response(_("You do not have permission to access this appointment."), status_code=403) + return handle_unauthorized_response(request, _("You do not have permission to access this appointment."), response_type='html') else: # Fetch all services for the staff member (create mode) try: @@ -346,7 +346,7 @@ def update_personal_info(request, staff_user_id=None): 'email': user.email, }, user=user) - context = get_generic_context_with_extra(request=request, extra={'form': form}) + context = get_generic_context_with_extra(request=request, extra={'form': form, 'btn_text': _("Update")}) return render(request, 'administration/manage_staff_personal_info.html', context) @@ -386,7 +386,7 @@ def create_new_staff_member(request): return redirect('appointment:add_staff_member_personal_info') form = PersonalInformationForm() - context = get_generic_context_with_extra(request=request, extra={'form': form}) + context = get_generic_context_with_extra(request=request, extra={'form': form, 'btn_text': _("Create")}) return render(request, 'administration/manage_staff_personal_info.html', context=context) @@ -491,6 +491,9 @@ def get_service_list(request, response_type='html'): @require_staff_or_superuser def delete_appointment(request, appointment_id): appointment = get_object_or_404(Appointment, pk=appointment_id) + if not check_extensive_permissions(appointment.get_staff_member().user_id, request.user, appointment): + message = _("You can only delete your own appointments.") + return handle_unauthorized_response(request, message, 'html') appointment.delete() messages.success(request, _("Appointment deleted successfully!")) return redirect('appointment:get_user_appointments') @@ -502,6 +505,9 @@ def delete_appointment_ajax(request): data = json.loads(request.body) appointment_id = data.get("appointment_id") appointment = get_object_or_404(Appointment, pk=appointment_id) + if not check_extensive_permissions(appointment.get_staff_member().user_id, request.user, appointment): + message = _("You can only delete your own appointments.") + return json_response(message, status=403, success=False, error_code=ErrorCode.NOT_AUTHORIZED) appointment.delete() return json_response(_("Appointment deleted successfully.")) From 0062f3937229c9c21b18db0cef30b85a10069bb2 Mon Sep 17 00:00:00 2001 From: Adams Pierre David <57180807+adamspd@users.noreply.github.com> Date: Tue, 13 Feb 2024 01:43:11 +0100 Subject: [PATCH 2/4] Revert json response message --- appointment/views_admin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appointment/views_admin.py b/appointment/views_admin.py index 21569eb..38d9d88 100644 --- a/appointment/views_admin.py +++ b/appointment/views_admin.py @@ -239,7 +239,7 @@ def fetch_service_list_for_staff(request): # Ensure the staff member is associated with this appointment if not Appointment.objects.filter(id=appointment_id, appointment_request__staff_member=staff_member).exists(): - return handle_unauthorized_response(request, _("You do not have permission to access this appointment."), response_type='html') + return json_response(_("You do not have permission to access this appointment."), status_code=403) else: # Fetch all services for the staff member (create mode) try: From a8f8719d7b8b01b0c2872b5a55c95349e7347920 Mon Sep 17 00:00:00 2001 From: Adams Pierre David <57180807+adamspd@users.noreply.github.com> Date: Tue, 13 Feb 2024 01:44:06 +0100 Subject: [PATCH 3/4] Minor fixes --- appointment/static/js/appointments.js | 2 +- .../manage_staff_personal_info.html | 2 +- .../administration/manage_working_hours.html | 8 +- .../appointment/default_thank_you.html | 12 +- .../templates/error_pages/403_forbidden.html | 103 +++++++++--------- .../templates/error_pages/404_not_found.html | 2 +- appointment/utils/json_context.py | 3 +- 7 files changed, 66 insertions(+), 66 deletions(-) diff --git a/appointment/static/js/appointments.js b/appointment/static/js/appointments.js index 4c9dfdc..9e10e93 100644 --- a/appointment/static/js/appointments.js +++ b/appointment/static/js/appointments.js @@ -199,7 +199,7 @@ function getAvailableSlots(selectedDate, staffId = null) { console.log('No staff ID provided, displaying error message.'); const errorMessage = $('
'+ noStaffMemberSelectedTxt + '
'); errorMessageContainer.append(errorMessage); - // Optionally disable the submit button here + // Optionally disable the "submit" button here $('.btn-submit-appointment').attr('disabled', 'disabled'); return; // Exit the function early } diff --git a/appointment/templates/administration/manage_staff_personal_info.html b/appointment/templates/administration/manage_staff_personal_info.html index eddb4f5..b409a97 100644 --- a/appointment/templates/administration/manage_staff_personal_info.html +++ b/appointment/templates/administration/manage_staff_personal_info.html @@ -29,7 +29,7 @@