Skip to content

Commit

Permalink
feat(core): Ability to assign categories to ticket comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jon-nfc committed Sep 13, 2024
1 parent 11948c9 commit 56b7157
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 19 deletions.
16 changes: 16 additions & 0 deletions app/core/forms/ticket_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,34 @@ def __init__(self, request, *args, **kwargs):

self.fields['comment_type'].initial = self.Meta.model.CommentType.TASK

self.fields['category'].queryset = self.fields['category'].queryset.filter(
task = True
)

elif self._comment_type == 'comment':

self.fields['comment_type'].initial = self.Meta.model.CommentType.COMMENT

self.fields['category'].queryset = self.fields['category'].queryset.filter(
comment = True
)

elif self._comment_type == 'solution':

self.fields['comment_type'].initial = self.Meta.model.CommentType.SOLUTION

self.fields['category'].queryset = self.fields['category'].queryset.filter(
solution = True
)

elif self._comment_type == 'notification':

self.fields['comment_type'].initial = self.Meta.model.CommentType.NOTIFICATION

self.fields['category'].queryset = self.fields['category'].queryset.filter(
notification = True
)


allowed_fields = self.fields_allowed

Expand Down
2 changes: 2 additions & 0 deletions app/core/forms/validate_ticket_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class TicketCommentValidation(
'external_system',
'comment_type',
'body',
'category',
'created',
'modified',
'private',
Expand All @@ -74,6 +75,7 @@ class TicketCommentValidation(
]

triage_fields: list = [
'category',
'body',
'private',
'duration',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 5.0.8 on 2024-09-13 03:43
# Generated by Django 5.0.8 on 2024-09-13 03:59

import access.fields
import access.models
Expand Down Expand Up @@ -108,10 +108,10 @@ class Migration(migrations.Migration):
('created', access.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False)),
('modified', access.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False)),
('name', models.CharField(help_text='Category Name', max_length=50, verbose_name='Name')),
('comment', models.BooleanField(default=True, help_text='Use category for standard comment', verbose_name='Change Comment')),
('notification', models.BooleanField(default=True, help_text='Use category for notification comment', verbose_name='Incident Comment')),
('solution', models.BooleanField(default=True, help_text='Use category for solution comment', verbose_name='Problem Comment')),
('task', models.BooleanField(default=True, help_text='Use category for task comment', verbose_name='Project Comment')),
('comment', models.BooleanField(default=True, help_text='Use category for standard comment', verbose_name='Comment')),
('notification', models.BooleanField(default=True, help_text='Use category for notification comment', verbose_name='Notification Comment')),
('solution', models.BooleanField(default=True, help_text='Use category for solution comment', verbose_name='Solution Comment')),
('task', models.BooleanField(default=True, help_text='Use category for task comment', verbose_name='Task Comment')),
('organization', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='access.organization', validators=[access.models.TenancyObject.validatate_organization_exists])),
('parent', models.ForeignKey(blank=True, help_text='The Parent Category', null=True, on_delete=django.db.models.deletion.SET_NULL, to='core.ticketcommentcategory', verbose_name='Parent Category')),
('runbook', models.ForeignKey(blank=True, help_text='The runbook for this category', null=True, on_delete=django.db.models.deletion.SET_NULL, to='assistance.knowledgebase', verbose_name='Runbook')),
Expand Down Expand Up @@ -150,9 +150,10 @@ class Migration(migrations.Migration):
('parent', models.ForeignKey(blank=True, default=None, help_text='Parent ID for creating discussion threads', null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='core.ticketcomment', verbose_name='Parent Comment')),
('responsible_team', models.ForeignKey(blank=True, default=None, help_text='Team whom is responsible for the completion of comment', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='comment_responsible_team', to='access.team', verbose_name='Responsible Team')),
('responsible_user', models.ForeignKey(blank=True, default=None, help_text='User whom is responsible for the completion of comment', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='comment_responsible_user', to=settings.AUTH_USER_MODEL, verbose_name='Responsible User')),
('template', models.ForeignKey(blank=True, default=None, help_text='Comment Template to use', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='comment_template', to='core.ticketcomment', verbose_name='Template')),
('template', models.ForeignKey(blank=True, default=None, help_text='Comment Template to use', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='comment_template', to='core.ticketcomment', verbose_name='Template')),
('ticket', models.ForeignKey(blank=True, default=None, help_text='Ticket this comment belongs to', null=True, on_delete=django.db.models.deletion.CASCADE, to='core.ticket', validators=[core.models.ticket.ticket_comment.TicketComment.validation_ticket_id], verbose_name='Ticket')),
('user', models.ForeignKey(blank=True, help_text='Who made the comment', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='comment_user', to=settings.AUTH_USER_MODEL, verbose_name='User')),
('category', models.ForeignKey(blank=True, default=None, help_text='Category of the comment', null=True, on_delete=django.db.models.deletion.SET_NULL, to='core.ticketcommentcategory', verbose_name='Category')),
],
options={
'verbose_name': 'Comment',
Expand Down
20 changes: 11 additions & 9 deletions app/core/models/ticket/ticket_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from access.models import TenancyObject, Team

from .ticket import Ticket
from .ticket_comment_category import TicketCommentCategory



Expand Down Expand Up @@ -186,22 +187,23 @@ def validation_ticket_id(field):
verbose_name = 'Duration',
)


# category = models.CharField(
# blank = False,
# help_text = "Category of the Ticket",
# max_length = 50,
# unique = True,
# verbose_name = 'Category',
# )
category = models.ForeignKey(
TicketCommentCategory,
blank= True,
default = None,
help_text = 'Category of the comment',
null = True,
on_delete = models.SET_NULL,
verbose_name = 'Category',
)

template = models.ForeignKey(
'self',
blank= True,
default = None,
help_text = 'Comment Template to use',
null = True,
on_delete = models.DO_NOTHING,
on_delete = models.SET_NULL,
related_name = 'comment_template',
verbose_name = 'Template',
)
Expand Down
8 changes: 4 additions & 4 deletions app/core/models/ticket/ticket_comment_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,31 +70,31 @@ class Meta:
default = True,
help_text = 'Use category for standard comment',
null = False,
verbose_name = 'Change Comment',
verbose_name = 'Comment',
)

notification = models.BooleanField(
blank = False,
default = True,
help_text = 'Use category for notification comment',
null = False,
verbose_name = 'Incident Comment',
verbose_name = 'Notification Comment',
)

solution = models.BooleanField(
blank = False,
default = True,
help_text = 'Use category for solution comment',
null = False,
verbose_name = 'Problem Comment',
verbose_name = 'Solution Comment',
)

task = models.BooleanField(
blank = False,
default = True,
help_text = 'Use category for task comment',
null = False,
verbose_name = 'Project Comment',
verbose_name = 'Task Comment',
)


Expand Down

0 comments on commit 56b7157

Please sign in to comment.