diff --git a/individual/gql_queries.py b/individual/gql_queries.py index 02dc730..7476c64 100644 --- a/individual/gql_queries.py +++ b/individual/gql_queries.py @@ -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: @@ -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): diff --git a/individual/schema.py b/individual/schema.py index 93c4d00..4442c20 100644 --- a/individual/schema.py +++ b/individual/schema.py @@ -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, @@ -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: @@ -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: diff --git a/individual/signals/on_validation_import_valid_items.py b/individual/signals/on_validation_import_valid_items.py index cca3d3c..486c740 100644 --- a/individual/signals/on_validation_import_valid_items.py +++ b/individual/signals/on_validation_import_valid_items.py @@ -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)) diff --git a/individual/tests/graphql_query_test.py b/individual/tests/graphql_query_test.py index 8207928..cd2a95e 100644 --- a/individual/tests/graphql_query_test.py +++ b/individual/tests/graphql_query_test.py @@ -59,6 +59,11 @@ def test_group_query_general_permission(self): id uuid code + head {{ + id + firstName + lastName + }} }} }} }} @@ -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 {{