make tickets assignable to users

This commit is contained in:
j3d1 2024-01-22 17:21:22 +01:00
parent 4be8109753
commit e605292bf0
11 changed files with 317 additions and 110 deletions

View file

@ -1,6 +1,7 @@
from django.db import models
from django_softdelete.models import SoftDeleteModel
from authentication.models import ExtendedUser
from inventory.models import Event
from django.db.models.signals import post_save, pre_save
from django.dispatch import receiver
@ -32,7 +33,6 @@ class IssueThread(SoftDeleteModel):
id = models.AutoField(primary_key=True)
uuid = models.CharField(max_length=255, unique=True, null=False, blank=False)
name = models.CharField(max_length=255)
assigned_to = models.CharField(max_length=255, null=True)
manually_created = models.BooleanField(default=False)
def short_uuid(self):
@ -51,10 +51,24 @@ class IssueThread(SoftDeleteModel):
return
self.state_changes.create(state=value)
@property
def assigned_to(self):
try:
return self.assignments.order_by('-timestamp').first().assigned_to
except AttributeError:
return None
@assigned_to.setter
def assigned_to(self, value):
if self.assigned_to == value:
return
self.assignments.create(assigned_to=value)
class Meta:
permissions = [
('send_mail', 'Can send mail'),
('add_issuethread_manual', 'Can add issue thread manually'),
('assign_issuethread', 'Can assign issue thread'),
]
@ -70,12 +84,6 @@ def create_issue_thread(sender, instance, created, **kwargs):
if created:
StateChange.objects.create(issue_thread=instance, state='pending_new')
class Meta:
permissions = [
('send_mail', 'Can send mail'),
('add_issuethread_manual', 'Can add issue thread manually'),
]
class Comment(models.Model):
id = models.AutoField(primary_key=True)
@ -89,3 +97,10 @@ class StateChange(models.Model):
issue_thread = models.ForeignKey(IssueThread, on_delete=models.CASCADE, related_name='state_changes')
state = models.CharField(max_length=255, choices=STATE_CHOICES, default='pending_new')
timestamp = models.DateTimeField(auto_now_add=True)
class Assignment(models.Model):
id = models.AutoField(primary_key=True)
issue_thread = models.ForeignKey(IssueThread, on_delete=models.CASCADE, related_name='assignments')
assigned_to = models.ForeignKey(ExtendedUser, on_delete=models.CASCADE, related_name='assigned_tickets')
timestamp = models.DateTimeField(auto_now_add=True)