Skip to content

Commit

Permalink
CM-868: added backend adjustments necessary for frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
sniedzielski committed Apr 18, 2024
1 parent 24ab99c commit d0b51bf
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 11 deletions.
8 changes: 4 additions & 4 deletions grievance_social_protection/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
"gql_mutation_delete_categorys_perms": ["123007"],
"tickets_attachments_root_path": None,

"grievance_types": [DEFAULT_STRING],
"grievance_flags": [DEFAULT_STRING],
"grievance_channels": [DEFAULT_STRING],
"grievance_types": [DEFAULT_STRING, 'Category A', 'Category B'],
"grievance_flags": [DEFAULT_STRING, 'Flag A', 'Flag B'],
"grievance_channels": [DEFAULT_STRING, 'Channel A', 'Channel B'],
"default_responses": {DEFAULT_STRING: DEFAULT_STRING},
"grievance_anonymized_fields": {DEFAULT_STRING: []},
# CRON timedelta: {days},{hours}
"resolution_times": DEFAULT_TIME_RESOLUTION,
"default_resolution": {DEFAULT_STRING: DEFAULT_TIME_RESOLUTION},
"default_resolution": {DEFAULT_STRING: DEFAULT_TIME_RESOLUTION, 'Category A': '4,0', 'Category B': '6,12'},

"attending_staff_role_ids": [],
"default_attending_staff_role_ids": {DEFAULT_STRING: [1, 2]},
Expand Down
10 changes: 9 additions & 1 deletion grievance_social_protection/gql_mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class TicketStatusEnum(graphene.Enum):
RESOLVED = Ticket.TicketStatus.RESOLVED
CLOSED = Ticket.TicketStatus.CLOSED

key = graphene.String(required=True)
key = graphene.String(required=False)
title = graphene.String(required=False)
description = graphene.String(required=False)
reporter_type = graphene.String(required=True, max_lenght=255)
Expand All @@ -31,10 +31,14 @@ class TicketStatusEnum(graphene.Enum):
status = graphene.Field(TicketStatusEnum, required=False)
priority = graphene.String(required=False)
due_date = graphene.Date(required=False)
category = graphene.String(required=True)
flags = graphene.String(required=False)
channel = graphene.String(required=False)


class UpdateTicketInputType(CreateTicketInputType):
id = graphene.UUID(required=True)
resolution = graphene.String(required=False)


class CreateTicketMutation(BaseHistoryModelCreateMutationMixin, BaseMutation):
Expand All @@ -57,6 +61,8 @@ def _mutate(cls, user, **data):
service = TicketService(user)
response = service.create(data)
if client_mutation_id:
ticket_id = response['data']['id']
ticket = Ticket.objects.get(id=ticket_id)
TicketMutation.object_mutated(user, client_mutation_id=client_mutation_id, Ticket=ticket)

if not response['success']:
Expand Down Expand Up @@ -87,6 +93,8 @@ def _mutate(cls, user, **data):
service = TicketService(user)
response = service.update(data)
if client_mutation_id:
ticket_id = response['data']['id']
ticket = Ticket.objects.get(id=ticket_id)
TicketMutation.object_mutated(user, client_mutation_id=client_mutation_id, Ticket=ticket)

if not response['success']:
Expand Down
22 changes: 22 additions & 0 deletions grievance_social_protection/gql_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,16 @@ class Meta:
model = Ticket
interfaces = (graphene.relay.Node,)
filter_fields = {
"id": ["exact", "isnull"],
"key": ["exact", "istartswith", "icontains", "iexact"],
"title": ["exact", "istartswith", "icontains", "iexact"],
"description": ["exact", "istartswith", "icontains", "iexact"],
"status": ["exact", "istartswith", "icontains", "iexact"],
"priority": ["exact", "istartswith", "icontains", "iexact"],
"category": ["exact", "istartswith", "icontains", "iexact"],
"flags": ["exact", "istartswith", "icontains", "iexact"],
"channel": ["exact", "istartswith", "icontains", "iexact"],
"resolution": ["exact", "istartswith", "icontains", "iexact"],
'reporter_id': ["exact"],
"due_date": ["exact", "istartswith", "icontains", "iexact"],
"date_of_incident": ["exact", "istartswith", "icontains", "iexact"],
Expand Down Expand Up @@ -88,11 +93,17 @@ class AttendingStaffRoleGQLType(ObjectType):
role_ids = graphene.List(graphene.String)


class ResolutionTimesByCategoryGQLType(ObjectType):
category = graphene.String()
resolution_time = graphene.String()


class GrievanceTypeConfigurationGQLType(ObjectType):
grievance_types = graphene.List(graphene.String)
grievance_flags = graphene.List(graphene.String)
grievance_channels = graphene.List(graphene.String)
grievance_category_staff_roles = graphene.List(AttendingStaffRoleGQLType)
grievance_default_resolutions_by_category = graphene.List(ResolutionTimesByCategoryGQLType)

def resolve_grievance_types(self, info):
return TicketConfig.grievance_types
Expand All @@ -113,3 +124,14 @@ def resolve_grievance_category_staff_roles(self, info):
category_staff_role_list.append(category_staff_role)

return category_staff_role_list

def resolve_grievance_default_resolutions_by_category(self, info):
category_resolution_time_list = []
for category_key, resolution_time in TicketConfig.default_resolution.items():
category_resolution_time = ResolutionTimesByCategoryGQLType(
category=category_key,
resolution_time=resolution_time
)
category_resolution_time_list.append(category_resolution_time)

return category_resolution_time_list
23 changes: 23 additions & 0 deletions grievance_social_protection/migrations/0010_auto_20240417_1050.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.2.19 on 2024-04-17 10:50

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('grievance_social_protection', '0009_comment_historicalcomment_historicalticket_ticket_ticketmutation'),
]

operations = [
migrations.AlterField(
model_name='historicalticket',
name='reporter_id',
field=models.CharField(max_length=255),
),
migrations.AlterField(
model_name='ticket',
name='reporter_id',
field=models.CharField(max_length=255),
),
]
43 changes: 43 additions & 0 deletions grievance_social_protection/migrations/0011_auto_20240418_1130.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Generated by Django 3.2.19 on 2024-04-18 11:30

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('grievance_social_protection', '0010_auto_20240417_1050'),
]

operations = [
migrations.AddField(
model_name='historicalticket',
name='category',
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AddField(
model_name='historicalticket',
name='channel',
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AddField(
model_name='historicalticket',
name='flags',
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AddField(
model_name='ticket',
name='category',
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AddField(
model_name='ticket',
name='channel',
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AddField(
model_name='ticket',
name='flags',
field=models.CharField(blank=True, max_length=255, null=True),
),
]
23 changes: 23 additions & 0 deletions grievance_social_protection/migrations/0012_auto_20240418_1137.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.2.19 on 2024-04-18 11:37

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('grievance_social_protection', '0011_auto_20240418_1130'),
]

operations = [
migrations.AddField(
model_name='historicalticket',
name='resolution',
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AddField(
model_name='ticket',
name='resolution',
field=models.CharField(blank=True, max_length=255, null=True),
),
]
7 changes: 6 additions & 1 deletion grievance_social_protection/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class TicketStatus(models.TextChoices):
code = models.CharField(max_length=16, unique=True, blank=True, null=True)

reporter_type = models.ForeignKey(ContentType, on_delete=models.CASCADE, null=False, blank=False)
reporter_id = models.PositiveIntegerField(null=False, blank=False)
reporter_id = models.CharField(max_length=255, null=False, blank=False)
reporter = GenericForeignKey('reporter_type', 'reporter_id')

attending_staff = models.ForeignKey(User, models.DO_NOTHING, blank=True, null=True)
Expand All @@ -41,6 +41,11 @@ class TicketStatus(models.TextChoices):
priority = models.CharField(max_length=20, blank=True, null=True)
due_date = models.DateField(blank=True, null=True)

category = models.CharField(max_length=255, blank=True, null=True)
flags = models.CharField(max_length=255, blank=True, null=True)
channel = models.CharField(max_length=255, blank=True, null=True)
resolution = models.CharField(max_length=255, blank=True, null=True)

def clean(self):
super().clean()
if self.reporter:
Expand Down
5 changes: 2 additions & 3 deletions grievance_social_protection/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ def __init__(self, user, validation_class=TicketValidation):

@register_service_signal('ticket_service.create')
def create(self, obj_data):
self.validation_class.validate_create(self.user, **obj_data)
self._get_content_type(obj_data)
self._generate_code(obj_data)
return super().create(obj_data)
d = super().create(obj_data)
return d

@register_service_signal('ticket_service.update')
def update(self, obj_data):
self.validation_class.validate_update(self.user, **obj_data)
self._get_content_type(obj_data)
return super().update(obj_data)

Expand Down
2 changes: 0 additions & 2 deletions grievance_social_protection/validations.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class TicketValidation(BaseModelValidation):
def validate_create(cls, user, **data):
errors = [
*validate_ticket_unique_code(data),
*validate_reporter(data)
]
if errors:
raise ValidationError(errors)
Expand All @@ -22,7 +21,6 @@ def validate_create(cls, user, **data):
def validate_update(cls, user, **data):
errors = [
*validate_ticket_unique_code(data),
*validate_reporter(data)
]
if errors:
raise ValidationError(errors)
Expand Down

0 comments on commit d0b51bf

Please sign in to comment.