Skip to content

Commit

Permalink
fix(core): When an item that may be linked to a ticket is deleted, re…
Browse files Browse the repository at this point in the history
…move the ticket link

ref: #15 #248 #336 #376 #381
  • Loading branch information
jon-nfc committed Nov 7, 2024
1 parent 99ed0d1 commit 43962d4
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/config_management/models/groups.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import re

from django.db import models
from django.db.models.signals import post_delete
from django.dispatch import receiver
from django.forms import ValidationError

from rest_framework.reverse import reverse
Expand All @@ -11,6 +13,7 @@
from app.helpers.merge_software import merge_software

from core.mixin.history_save import SaveHistory
from core.signal.ticket_linked_item_delete import TicketLinkedItem, deleted_model

from itam.models.device import Device, DeviceSoftware
from itam.models.software import Software, SoftwareVersion
Expand Down Expand Up @@ -346,6 +349,13 @@ def __str__(self):



@receiver(post_delete, sender=ConfigGroups, dispatch_uid='config_group_delete_signal')
def signal_deleted_model(sender, instance, using, **kwargs):

deleted_model.send(sender='config_group_deleted', item_id=instance.id, item_type = TicketLinkedItem.Modules.CONFIG_GROUP)



class ConfigGroupHosts(GroupsCommonFields, SaveHistory):


Expand Down
12 changes: 12 additions & 0 deletions app/itam/models/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from datetime import timedelta

from django.db import models
from django.db.models.signals import post_delete
from django.dispatch import receiver
from django.forms import ValidationError

from rest_framework import serializers
Expand All @@ -16,6 +18,7 @@

from core.classes.icon import Icon
from core.mixin.history_save import SaveHistory
from core.signal.ticket_linked_item_delete import TicketLinkedItem, deleted_model

from itam.models.device_common import DeviceCommonFields, DeviceCommonFieldsName
from itam.models.device_models import DeviceModel
Expand Down Expand Up @@ -500,6 +503,15 @@ def get_configuration(self):
return config



@receiver(post_delete, sender=Device, dispatch_uid='device_delete_signal')
def signal_deleted_model(sender, instance, using, **kwargs):

deleted_model.send(sender='device_deleted', item_id=instance.id, item_type = TicketLinkedItem.Modules.DEVICE)




class DeviceSoftware(DeviceCommonFields, SaveHistory):
""" A way for the device owner to configure software to install/remove """

Expand Down
11 changes: 11 additions & 0 deletions app/itam/models/operating_system.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from django.db import models
from django.db.models.signals import post_delete
from django.dispatch import receiver

from rest_framework.reverse import reverse

Expand All @@ -7,6 +9,7 @@

from core.mixin.history_save import SaveHistory
from core.models.manufacturer import Manufacturer
from core.signal.ticket_linked_item_delete import TicketLinkedItem, deleted_model



Expand Down Expand Up @@ -163,6 +166,14 @@ def __str__(self):
return self.name



@receiver(post_delete, sender=OperatingSystem, dispatch_uid='operating_system_delete_signal')
def signal_deleted_model(sender, instance, using, **kwargs):

deleted_model.send(sender='operating_system_deleted', item_id=instance.id, item_type = TicketLinkedItem.Modules.OPERATING_SYSTEM)



class OperatingSystemVersion(OperatingSystemCommonFields, SaveHistory):


Expand Down
10 changes: 10 additions & 0 deletions app/itam/models/software.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from django.db import models
from django.db.models.signals import post_delete
from django.dispatch import receiver

from rest_framework.reverse import reverse

Expand All @@ -7,6 +9,7 @@

from core.mixin.history_save import SaveHistory
from core.models.manufacturer import Manufacturer
from core.signal.ticket_linked_item_delete import TicketLinkedItem, deleted_model

from settings.models.app_settings import AppSettings

Expand Down Expand Up @@ -248,6 +251,13 @@ def __str__(self):



@receiver(post_delete, sender=Software, dispatch_uid='software_delete_signal')
def signal_deleted_model(sender, instance, using, **kwargs):

deleted_model.send(sender='software_deleted', item_id=instance.id, item_type = TicketLinkedItem.Modules.SOFTWARE)



class SoftwareVersion(SoftwareCommonFields, SaveHistory):


Expand Down
11 changes: 11 additions & 0 deletions app/itim/models/clusters.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
from django.contrib.auth.models import User
from django.db import models
from django.db.models.signals import post_delete
from django.dispatch import receiver
from django.forms import ValidationError

from rest_framework.reverse import reverse

from access.fields import *
from access.models import Team, TenancyObject

from core.signal.ticket_linked_item_delete import TicketLinkedItem, deleted_model

from itam.models.device import Device


Expand Down Expand Up @@ -329,3 +333,10 @@ def rendered_config(self):
def __str__(self):

return self.name



@receiver(post_delete, sender=Cluster, dispatch_uid='cluster_delete_signal')
def signal_deleted_model(sender, instance, using, **kwargs):

deleted_model.send(sender='cluster_deleted', item_id=instance.id, item_type = TicketLinkedItem.Modules.CLUSTER)
11 changes: 11 additions & 0 deletions app/itim/models/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

from django.contrib.auth.models import User
from django.db import models
from django.db.models.signals import post_delete
from django.dispatch import receiver
from django.forms import ValidationError

from rest_framework.reverse import reverse

from access.fields import *
from access.models import Team, TenancyObject

from core.signal.ticket_linked_item_delete import TicketLinkedItem, deleted_model

from itam.models.device import Device

from itim.models.clusters import Cluster
Expand Down Expand Up @@ -374,3 +378,10 @@ def save(self, force_insert=False, force_update=False, using=None, update_fields
def __str__(self):

return self.name



@receiver(post_delete, sender=Service, dispatch_uid='service_delete_signal')
def signal_deleted_model(sender, instance, using, **kwargs):

deleted_model.send(sender='service_deleted', item_id=instance.id, item_type = TicketLinkedItem.Modules.SERVICE)

0 comments on commit 43962d4

Please sign in to comment.