Skip to content

Commit

Permalink
Merge branch 'no-enrollments' of 'https://github.com/evamillan/grimoi…
Browse files Browse the repository at this point in the history
…relab-sortinghat'

Merges #529
Closes #529
Fixes #528
  • Loading branch information
sduenas committed Apr 19, 2021
2 parents c5497a9 + 4f2f4df commit 2f3796b
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 8 deletions.
3 changes: 3 additions & 0 deletions sortinghat/core/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ class IdentityFilterType(graphene.InputObjectType):
two dates, following ISO-8601 format. Examples:\n* `>=2020-10-12T09:35:06.13045+01:00` \
\n * `2020-10-12T00:00:00..2020-11-22T00:00:00`.'
)
is_enrolled = graphene.Boolean(required=False)
last_updated = graphene.String(
required=False,
description='Filter with a comparison operator (>, >=, <, <=) and a date OR with a range operator (..) between\
Expand Down Expand Up @@ -921,6 +922,8 @@ def resolve_individuals(self, info, filters=None,
.filter(start__lte=date2,
end__gte=date1)
.values_list('individual__mk')))
if filters and 'is_enrolled' in filters:
query = query.filter(enrollments__isnull=not filters['is_enrolled'])
if filters and 'last_updated' in filters:
# Accepted date format is ISO 8601, YYYY-MM-DDTHH:MM:SS
try:
Expand Down
40 changes: 40 additions & 0 deletions tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,18 @@
}
}
}"""
SH_INDIVIDUALS_IS_ENROLLED_FILTER = """{
individuals(filters: {isEnrolled: %s}) {
entities {
mk
enrollments {
organization {
name
}
}
}
}
}"""
SH_INDIVIDUALS_LAST_UPDATED_FILTER = """{
individuals(filters: {lastUpdated: "%s"}) {
entities {
Expand Down Expand Up @@ -2359,6 +2371,34 @@ def test_filter_enrollment_date(self):
individuals = executed['data']['individuals']['entities']
self.assertEqual(len(individuals), 0)

def test_filter_is_enrolled(self):
"""Check whether it returns the uuids searched when using isEnrolled filter"""

org = Organization.objects.create(name='Bitergia')
indv1 = Individual.objects.create(mk='17ab00ed3825ec2f50483e33c88df223264182ba')
indv2 = Individual.objects.create(mk='c6d2504fde0e34b78a185c4b709e5442d045451c')
Enrollment.objects.create(individual=indv1, organization=org)

client = graphene.test.Client(schema)

# Test enrolled individual
executed = client.execute(SH_INDIVIDUALS_IS_ENROLLED_FILTER % 'true',
context_value=self.context_value)
individuals = executed['data']['individuals']['entities']
self.assertEqual(len(individuals), 1)
indv = individuals[0]
self.assertEqual(indv['mk'], '17ab00ed3825ec2f50483e33c88df223264182ba')
enrollment = indv['enrollments'][0]
self.assertEqual(enrollment['organization']['name'], 'Bitergia')

# Test not enrolled individual
executed = client.execute(SH_INDIVIDUALS_IS_ENROLLED_FILTER % 'false',
context_value=self.context_value)
individuals = executed['data']['individuals']['entities']
self.assertEqual(len(individuals), 1)
indv = individuals[0]
self.assertEqual(indv['mk'], 'c6d2504fde0e34b78a185c4b709e5442d045451c')

def test_filter_last_updated(self):
"""Check whether it returns the uuids searched when using a date filter"""

Expand Down
4 changes: 4 additions & 0 deletions ui/src/components/Search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ export default {
{
filter: "enrollmentDate",
type: "date"
},
{
filter: "isEnrolled",
type: "boolean"
}
]
},
Expand Down
7 changes: 7 additions & 0 deletions ui/src/views/SearchHelp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,13 @@
</tbody>
</template>
</v-simple-table>

<p class="subtitle-2 mt-8">Filter by enrollment status</p>
<p>
You can search for individuals based on whether they have any
affiliation, using the <code>isEnrolled:true</code> and
<code>isEnrolled:false</code> filters.
</p>
</v-card-text>
</v-card>
</v-main>
Expand Down
12 changes: 6 additions & 6 deletions ui/tests/unit/__snapshots__/mutations.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ exports[`IndividualsTable Mock query for deleteIdentity 1`] = `
filterselector="true"
orderoptions="[object Object],[object Object],[object Object]"
orderselector="true"
validfilters="[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]"
validfilters="[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]"
/>
<v-tooltip-stub
Expand Down Expand Up @@ -452,7 +452,7 @@ exports[`IndividualsTable Mock query for merge 1`] = `
filterselector="true"
orderoptions="[object Object],[object Object],[object Object]"
orderselector="true"
validfilters="[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]"
validfilters="[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]"
/>
<v-tooltip-stub
Expand Down Expand Up @@ -817,7 +817,7 @@ exports[`IndividualsTable Mock query for moveIdentity 1`] = `
filterselector="true"
orderoptions="[object Object],[object Object],[object Object]"
orderselector="true"
validfilters="[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]"
validfilters="[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]"
/>
<v-tooltip-stub
Expand Down Expand Up @@ -1182,7 +1182,7 @@ exports[`IndividualsTable Mock query for unmerge 1`] = `
filterselector="true"
orderoptions="[object Object],[object Object],[object Object]"
orderselector="true"
validfilters="[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]"
validfilters="[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]"
/>
<v-tooltip-stub
Expand Down Expand Up @@ -1547,7 +1547,7 @@ exports[`IndividualsTable Mock query for updateEnrollment 1`] = `
filterselector="true"
orderoptions="[object Object],[object Object],[object Object]"
orderselector="true"
validfilters="[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]"
validfilters="[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]"
/>
<v-tooltip-stub
Expand Down Expand Up @@ -1912,7 +1912,7 @@ exports[`IndividualsTable Mock query for withdraw 1`] = `
filterselector="true"
orderoptions="[object Object],[object Object],[object Object]"
orderselector="true"
validfilters="[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]"
validfilters="[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]"
/>
<v-tooltip-stub
Expand Down
4 changes: 2 additions & 2 deletions ui/tests/unit/__snapshots__/queries.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ exports[`IndividualsTable Mock query for getCountries 1`] = `
filterselector="true"
orderoptions="[object Object],[object Object],[object Object]"
orderselector="true"
validfilters="[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]"
validfilters="[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]"
/>
<v-tooltip-stub
Expand Down Expand Up @@ -461,7 +461,7 @@ exports[`IndividualsTable Mock query for getPaginatedIndividuals 1`] = `
filterselector="true"
orderoptions="[object Object],[object Object],[object Object]"
orderselector="true"
validfilters="[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]"
validfilters="[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]"
/>
<v-tooltip-stub
Expand Down

0 comments on commit 2f3796b

Please sign in to comment.