Skip to content

Commit

Permalink
Merge pull request #381 from nofusscomputing/376-test-slash-commands
Browse files Browse the repository at this point in the history
  • Loading branch information
jon-nfc authored Nov 5, 2024
2 parents eeffe2b + 5d88d84 commit b376a60
Show file tree
Hide file tree
Showing 11 changed files with 2,037 additions and 3 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
5 changes: 2 additions & 3 deletions app/core/lib/slash_commands/related_ticket.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import re



class CommandRelatedTicket:
# This summary is used for the user documentation
"""Add to the current ticket a relationship to another ticket. Supports all ticket
Expand Down Expand Up @@ -41,14 +42,12 @@ def command_related_ticket(self, match) -> str:
None: On successfully processing the command
"""

a = 'a'

command = match.group('command')
ticket_id:int = str(match.group('ticket'))

if ticket_id is not None:

from core.serializers.ticket_related import RelatedTicketModelSerializer
from core.serializers.ticket_related import RelatedTickets, RelatedTicketModelSerializer

if command == 'relate':

Expand Down
Empty file added app/core/signal/__init__.py
Empty file.
22 changes: 22 additions & 0 deletions app/core/signal/ticket_linked_item_delete.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

from django import dispatch
from django.dispatch import receiver

from core.models.ticket.ticket_linked_items import TicketLinkedItem

deleted_model = dispatch.Signal()


@receiver(deleted_model)
def signal_deleted_model(sender, item_id, item_type, **kwargs):
"""Clean up model TicketLinkedItems
a model was deleted, remove its link to any tickets it had.
"""

items = TicketLinkedItem.objects.filter(
item_type = item_type,
item = item_id
)

items.delete()
Loading

0 comments on commit b376a60

Please sign in to comment.