From 62dc0d1da6aa5274629ea1a1874b7c1393f01bc6 Mon Sep 17 00:00:00 2001 From: Jan Date: Fri, 29 Dec 2023 12:56:11 +0100 Subject: [PATCH] CM-407: add GroupHisotry change log logic (#35) Co-authored-by: Jan --- individual/gql_queries.py | 23 +++++++++++++++++++++++ individual/schema.py | 22 +++++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/individual/gql_queries.py b/individual/gql_queries.py index ea5d50e..28937fc 100644 --- a/individual/gql_queries.py +++ b/individual/gql_queries.py @@ -87,6 +87,29 @@ class Meta: connection_class = ExtendedConnection +class GroupHistoryGQLType(DjangoObjectType): + uuid = graphene.String(source='uuid') + head = graphene.Field(IndividualGQLType) + + def resolve_head(self, info): + return Individual.objects.filter( + groupindividual__group__id=self.id, + groupindividual__role=GroupIndividual.Role.HEAD + ).first() + + class Meta: + model = Group.history.model + interfaces = (graphene.relay.Node,) + filter_fields = { + "id": ["exact"], + "date_created": ["exact", "lt", "lte", "gt", "gte"], + "date_updated": ["exact", "lt", "lte", "gt", "gte"], + "is_deleted": ["exact"], + "version": ["exact"], + } + connection_class = ExtendedConnection + + class GroupIndividualGQLType(DjangoObjectType): uuid = graphene.String(source='uuid') diff --git a/individual/schema.py b/individual/schema.py index f76961f..6e5654a 100644 --- a/individual/schema.py +++ b/individual/schema.py @@ -1,5 +1,6 @@ import graphene import graphene_django_optimizer as gql_optimizer +from graphene_django.filter import DjangoFilterConnectionField import pandas as pd from django.contrib.auth.models import AnonymousUser from django.db.models import Q @@ -14,7 +15,7 @@ UpdateGroupIndividualMutation, DeleteGroupIndividualMutation, \ CreateGroupIndividualsMutation from individual.gql_queries import IndividualGQLType, IndividualDataSourceGQLType, GroupGQLType, GroupIndividualGQLType, \ - IndividualDataSourceUploadGQLType + IndividualDataSourceUploadGQLType, GroupHistoryGQLType from individual.models import Individual, IndividualDataSource, Group, GroupIndividual, IndividualDataSourceUpload @@ -82,6 +83,13 @@ class Query(ExportableQueryMixin, graphene.ObjectType): customFilters=graphene.List(of_type=graphene.String) ) + group_history = OrderedDjangoFilterConnectionField( + GroupHistoryGQLType, + orderBy=graphene.List(of_type=graphene.String), + applyDefaultValidityFilter=graphene.Boolean(), + client_mutation_id=graphene.String() + ) + group_individual = OrderedDjangoFilterConnectionField( GroupIndividualGQLType, orderBy=graphene.List(of_type=graphene.String), @@ -171,6 +179,18 @@ def resolve_group(self, info, **kwargs): ) return gql_optimizer.query(query, info) + def resolve_group_history(self, info, **kwargs): + filters = append_validity_filter(**kwargs) + + client_mutation_id = kwargs.get("client_mutation_id") + if client_mutation_id: + filters.append(Q(mutations__mutation__client_mutation_id=client_mutation_id)) + + Query._check_permissions(info.context.user, + IndividualConfig.gql_group_search_perms) + query = Group.history.filter(*filters) + return gql_optimizer.query(query, info) + def resolve_group_individual(self, info, **kwargs): Query._check_permissions( info.context.user,