diff --git a/grievance_social_protection/apps.py b/grievance_social_protection/apps.py index e478650..7a3c301 100644 --- a/grievance_social_protection/apps.py +++ b/grievance_social_protection/apps.py @@ -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]}, diff --git a/grievance_social_protection/gql_mutations.py b/grievance_social_protection/gql_mutations.py index f8ff1d4..c76607b 100644 --- a/grievance_social_protection/gql_mutations.py +++ b/grievance_social_protection/gql_mutations.py @@ -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) @@ -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): @@ -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']: @@ -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']: diff --git a/grievance_social_protection/gql_queries.py b/grievance_social_protection/gql_queries.py index be371ed..e1e82fb 100644 --- a/grievance_social_protection/gql_queries.py +++ b/grievance_social_protection/gql_queries.py @@ -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"], @@ -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 @@ -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 diff --git a/grievance_social_protection/migrations/0010_auto_20240417_1050.py b/grievance_social_protection/migrations/0010_auto_20240417_1050.py new file mode 100644 index 0000000..f5f6172 --- /dev/null +++ b/grievance_social_protection/migrations/0010_auto_20240417_1050.py @@ -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), + ), + ] diff --git a/grievance_social_protection/migrations/0011_auto_20240418_1130.py b/grievance_social_protection/migrations/0011_auto_20240418_1130.py new file mode 100644 index 0000000..d8b37d4 --- /dev/null +++ b/grievance_social_protection/migrations/0011_auto_20240418_1130.py @@ -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), + ), + ] diff --git a/grievance_social_protection/migrations/0012_auto_20240418_1137.py b/grievance_social_protection/migrations/0012_auto_20240418_1137.py new file mode 100644 index 0000000..f83c49a --- /dev/null +++ b/grievance_social_protection/migrations/0012_auto_20240418_1137.py @@ -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), + ), + ] diff --git a/grievance_social_protection/models.py b/grievance_social_protection/models.py index a9534f2..a555f56 100644 --- a/grievance_social_protection/models.py +++ b/grievance_social_protection/models.py @@ -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) @@ -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: diff --git a/grievance_social_protection/services.py b/grievance_social_protection/services.py index bcaca3f..e1cbb67 100644 --- a/grievance_social_protection/services.py +++ b/grievance_social_protection/services.py @@ -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) diff --git a/grievance_social_protection/validations.py b/grievance_social_protection/validations.py index 7bce9bc..84ba6ec 100644 --- a/grievance_social_protection/validations.py +++ b/grievance_social_protection/validations.py @@ -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) @@ -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)