Skip to content

Commit

Permalink
Merge pull request #135 from openimis/release/24.10
Browse files Browse the repository at this point in the history
MERGING release/24.10 into develop
  • Loading branch information
delcroip authored Nov 1, 2024
2 parents cae6df4 + af4b8f7 commit 62c3ecc
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 11 deletions.
12 changes: 6 additions & 6 deletions individual/gql_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ class GroupGQLType(DjangoObjectType):

def resolve_head(self, info):
return Individual.objects.filter(
groupindividual__group__id=self.id,
groupindividual__role=GroupIndividual.Role.HEAD,
groupindividual__is_deleted=False,
groupindividuals__group__id=self.id,
groupindividuals__role=GroupIndividual.Role.HEAD,
groupindividuals__is_deleted=False,
).first()

class Meta:
Expand Down Expand Up @@ -156,9 +156,9 @@ class GroupHistoryGQLType(DjangoObjectType):

def resolve_head(self, info):
return Individual.objects.filter(
groupindividual__group__id=self.id,
groupindividual__role=GroupIndividual.Role.HEAD,
groupindividual__is_deleted=False,
groupindividuals__group__id=self.id,
groupindividuals__role=GroupIndividual.Role.HEAD,
groupindividuals__is_deleted=False,
).first()

def resolve_user_updated(self, info):
Expand Down
8 changes: 4 additions & 4 deletions individual/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Query(ExportableQueryMixin, graphene.ObjectType):
module_name = "individual"
object_type = "Individual"
object_type_group = "Group"
related_field_individual = "groupindividual__individual"
related_field_individual = "groupindividuals__individual"

individual = OrderedDjangoFilterConnectionField(
IndividualGQLType,
Expand Down Expand Up @@ -167,7 +167,7 @@ def resolve_individual(self, info, **kwargs):

group_id = kwargs.get("groupId")
if group_id:
filters.append(Q(groupindividual__group__id=group_id))
filters.append(Q(groupindividuals__group__id=group_id))

benefit_plan_to_enroll = kwargs.get("benefitPlanToEnroll")
if benefit_plan_to_enroll:
Expand Down Expand Up @@ -302,11 +302,11 @@ def resolve_group(self, info, **kwargs):

first_name = kwargs.get("first_name", None)
if first_name:
filters.append(Q(groupindividual__individual__first_name__icontains=first_name))
filters.append(Q(groupindividuals__individual__first_name__icontains=first_name))

last_name = kwargs.get("last_name", None)
if last_name:
filters.append(Q(groupindividual__individual__last_name__icontains=last_name))
filters.append(Q(groupindividuals__individual__last_name__icontains=last_name))

benefit_plan_to_enroll = kwargs.get("benefitPlanToEnroll")
if benefit_plan_to_enroll:
Expand Down
2 changes: 1 addition & 1 deletion individual/signals/on_validation_import_valid_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def _create_or_update_groups_using_group_code(self):

if group:
assigned_individual_ids = list(Individual.objects.filter(
groupindividual__group=group, is_deleted=False
groupindividuals__group=group, is_deleted=False
).values_list('id', flat=True))
assigned_individual_ids_str = [str(uuid) for uuid in assigned_individual_ids]
updated_ids = list(set(ids_str + assigned_individual_ids_str))
Expand Down
46 changes: 46 additions & 0 deletions individual/tests/graphql_query_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ def test_group_query_general_permission(self):
id
uuid
code
head {{
id
firstName
lastName
}}
}}
}}
}}
Expand Down Expand Up @@ -387,6 +392,47 @@ def test_individual_query_row_security(self):
self.assertTrue(str(self.individual_no_loc_group_a.uuid) in individual_uuids)


def test_individual_query_with_group(self):
date_created = str(self.individual_a.date_created).replace(' ', 'T')
query_str = f'''query {{
individual(dateCreated_Gte: "{date_created}", groupId: "{self.group_a.id}") {{
totalCount
pageInfo {{
hasNextPage
hasPreviousPage
startCursor
endCursor
}}
edges {{
node {{
id
uuid
firstName
lastName
dob
}}
}}
}}
}}'''

response = self.query(
query_str,
headers={"HTTP_AUTHORIZATION": f"Bearer {self.admin_token}"}
)
self.assertResponseNoErrors(response)

content = json.loads(response.content)
individual_data = content['data']['individual']

individual_uuids = list(
e['node']['uuid'] for e in individual_data['edges']
)
self.assertTrue(str(self.individual_a.uuid) in individual_uuids)
self.assertTrue(str(self.individual_no_loc_group_a.uuid) in individual_uuids)
self.assertFalse(str(self.individual_b.uuid) in individual_uuids)
self.assertFalse(str(self.individual_a_no_group.uuid) in individual_uuids)


def test_individual_history_query_row_security(self):
def send_individual_history_query(individual_uuid, as_user_token):
query_str = f'''query {{
Expand Down

0 comments on commit 62c3ecc

Please sign in to comment.