Skip to content

Commit

Permalink
CM-407: add GroupHisotry change log logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan committed Dec 28, 2023
1 parent 1cd7fe8 commit 2313b61
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
23 changes: 23 additions & 0 deletions individual/gql_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
22 changes: 21 additions & 1 deletion individual/schema.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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


Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 2313b61

Please sign in to comment.