[FIX] HELPDESK: Fixed edit ticket after deadline for users with permission and moved clean from models to form (#949)
This commit is contained in:
@@ -21,10 +21,12 @@ class YourForm(forms.Form):
|
||||
pass
|
||||
"""
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Any
|
||||
|
||||
from django import forms
|
||||
from django.template.loader import render_to_string
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from base.forms import ModelForm
|
||||
from base.methods import filtersubordinatesemployeemodel, is_reportingmanager
|
||||
@@ -154,6 +156,30 @@ class TicketForm(ModelForm):
|
||||
self.fields["tags"].choices = list(self.fields["tags"].choices)
|
||||
self.fields["tags"].choices.append(("create_new_tag", "Create new tag"))
|
||||
|
||||
def clean(self, *args, **kwargs):
|
||||
cleaned_data = super().clean(*args, **kwargs)
|
||||
deadline = cleaned_data.get("deadline")
|
||||
today = datetime.today().date()
|
||||
request = getattr(horilla_middlewares._thread_locals, "request", None)
|
||||
user = getattr(request, "user", None)
|
||||
|
||||
if deadline and deadline < today:
|
||||
if self.instance and self.instance.pk:
|
||||
if not (
|
||||
user.has_perm("helpdesk.change_ticket")
|
||||
or user.has_perm(
|
||||
"helpdesk.add_ticket"
|
||||
or self.instance.employee_id == user.employee_get
|
||||
)
|
||||
):
|
||||
raise forms.ValidationError(
|
||||
_("Deadline should be greater than today")
|
||||
)
|
||||
else:
|
||||
raise forms.ValidationError(_("Deadline should be greater than today"))
|
||||
|
||||
return cleaned_data
|
||||
|
||||
|
||||
class TicketTagForm(ModelForm):
|
||||
class Meta:
|
||||
|
||||
@@ -130,13 +130,6 @@ class Ticket(HorillaModel):
|
||||
verbose_name = _("Ticket")
|
||||
verbose_name_plural = _("Tickets")
|
||||
|
||||
def clean(self, *args, **kwargs):
|
||||
super().clean(*args, **kwargs)
|
||||
deadline = self.deadline
|
||||
today = datetime.today().date()
|
||||
if deadline < today:
|
||||
raise ValidationError(_("Deadline should be greater than today"))
|
||||
|
||||
def get_raised_on(self):
|
||||
obj_id = self.raised_on
|
||||
if self.assigning_type == "department":
|
||||
|
||||
Reference in New Issue
Block a user