From cb18a30aca45a1ce4f0807edeccc39ed29423bbe Mon Sep 17 00:00:00 2001 From: Horilla Date: Mon, 29 Jan 2024 11:48:04 +0530 Subject: [PATCH] [UPDT] OFFBOARDING: Restriction to update the form if its on the requested state --- offboarding/forms.py | 20 +++++++++++++++++-- .../resignation/request_cards.html | 14 +++++++++---- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/offboarding/forms.py b/offboarding/forms.py index a129eb48f..3501f004c 100644 --- a/offboarding/forms.py +++ b/offboarding/forms.py @@ -8,6 +8,7 @@ import contextlib from typing import Any from django import forms from django.template.loader import render_to_string +from django.contrib import messages from base.forms import ModelForm from base import thread_local_middleware from employee.forms import MultipleFileField @@ -263,13 +264,28 @@ class ResignationLetterForm(ModelForm): "is_active", ] self.instance.employee_id = request.user.employee_get + exclude = list(set(exclude)) for field in exclude: del self.fields[field] def save(self, commit: bool = ...) -> Any: - instance = super().save(commit) request = getattr(thread_local_middleware._thread_locals, "request", None) - if request and not request.user.has_perm("offboarding.add_offboardingemployee"): + instance = self.instance + if ( + not request.user.has_perm("offboarding.add_offboardingemployee") + and instance.status == "requested" + ) or request.user.has_perm("add_offboardingemployee"): + instance = super().save(commit) + else: + messages.info( + request, "You cannot edit a request that has been rejected/approved" + ) + + if ( + instance.status == "requested" + and request + and not request.user.has_perm("offboarding.add_offboardingemployee") + ): with contextlib.suppress(Exception): notify.send( request.user.employee_get, diff --git a/offboarding/templates/offboarding/resignation/request_cards.html b/offboarding/templates/offboarding/resignation/request_cards.html index 0e2b22125..14e67b1c1 100644 --- a/offboarding/templates/offboarding/resignation/request_cards.html +++ b/offboarding/templates/offboarding/resignation/request_cards.html @@ -28,23 +28,29 @@
{{ record.status|capfirst }}
- {% if perms.offboarding.change_resignationletter %}
+ {% if perms.offboarding.change_resignationletter %} + aria-label="mail open outline"> + + {% endif %} + + {% if perms.offboarding.delete_resignationletter %} + class="text-danger md hydrated" name="trash-outline" role="img" aria-label="trash outline"> + + {% endif %} +
- {% endif %}