Skip to content

Commit

Permalink
Merge pull request #1406 from the-deep/feature/lead-additional-filters
Browse files Browse the repository at this point in the history
Add Lead's isAssessment & hasAssessment in EntryFilter
  • Loading branch information
AdityaKhatri authored Apr 4, 2024
2 parents 30abb9d + 141515a commit b0f857c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion apps/deep_explore/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def _save_snapshot(
snapshot,
generate_download_file=True,
):
file_content, errors = generate_query_snapshot(gql_query, {'fitler': filters})
file_content, errors = generate_query_snapshot(gql_query, {'filter': filters})
if file_content is None:
logger.error(f'Failed to generate: {errors}', exc_info=True)
return
Expand Down
7 changes: 7 additions & 0 deletions apps/entry/filter_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,8 @@ class EntryGQFilterSet(GrapheneFilterSetMixin, UserResourceGqlFilterSet):
lead_authoring_organization_types = IDListFilter(method='authoring_organization_types_filter')
lead_author_organizations = IDListFilter(field_name='lead__authors')
lead_source_organizations = IDListFilter(field_name='lead__source')
lead_has_assessment = django_filters.BooleanFilter(method='lead_has_assessment_filter', help_text='Lead has assessment.')
lead_is_assessment = django_filters.BooleanFilter(field_name='lead__is_assessment_lead')

search = django_filters.CharFilter(method='search_filter')
created_by = IDListFilter()
Expand Down Expand Up @@ -643,6 +645,11 @@ def lead_group_label_filter(self, queryset, name, value):
return queryset.filter(entrygrouplabel__group__title__icontains=value)
return queryset

def lead_has_assessment_filter(self, qs, _, value):
if value is None:
return qs
return qs.filter(lead__assessmentregistry__isnull=not value)

def authoring_organization_types_filter(self, qs, name, value):
if value:
qs = qs.annotate(
Expand Down
14 changes: 14 additions & 0 deletions apps/entry/tests/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from entry.factories import EntryFactory, EntryAttributeFactory
from analysis_framework.factories import AnalysisFrameworkFactory, WidgetFactory
from organization.factories import OrganizationFactory, OrganizationTypeFactory
from assessment_registry.factories import AssessmentRegistryFactory
from quality_assurance.factories import EntryReviewCommentFactory

from lead.tests.test_schemas import TestLeadQuerySchema
Expand Down Expand Up @@ -248,6 +249,8 @@ def test_entry_query_filter(self):
$leadPublishedOn: Date
$leadPublishedOnGte: Date
$leadPublishedOnLte: Date
$leadHasAssessment: Boolean
$leadIsAssessment: Boolean
$leads: [ID!]
$leadStatuses: [LeadStatusEnum!]
$leadTitle: String
Expand Down Expand Up @@ -282,6 +285,8 @@ def test_entry_query_filter(self):
leadPublishedOn: $leadPublishedOn
leadPublishedOnGte: $leadPublishedOnGte
leadPublishedOnLte: $leadPublishedOnLte
leadHasAssessment: $leadHasAssessment
leadIsAssessment: $leadIsAssessment
leads: $leads
leadStatuses: $leadStatuses
leadTitle: $leadTitle
Expand Down Expand Up @@ -319,6 +324,7 @@ def test_entry_query_filter(self):
assignee=[member1],
priority=Lead.Priority.HIGH,
status=Lead.Status.IN_PROGRESS,
is_assessment_lead=True,
)
lead2 = LeadFactory.create(
project=project,
Expand All @@ -327,6 +333,7 @@ def test_entry_query_filter(self):
assignee=[member2],
authors=[org2, org3],
priority=Lead.Priority.HIGH,
is_assessment_lead=True,
)
lead3 = LeadFactory.create(
project=project,
Expand Down Expand Up @@ -361,6 +368,9 @@ def test_entry_query_filter(self):
entry4_1 = EntryFactory.create(
project=project, analysis_framework=af, lead=lead4, entry_type=Entry.TagType.EXCERPT, controlled=False)

# For assessment filters
AssessmentRegistryFactory.create(project=project, lead=lead1)

# create entry review comment for entry
EntryReviewCommentFactory(entry=entry1_1, created_by=user, comment_type=EntryReviewComment.CommentType.COMMENT)
EntryReviewCommentFactory(entry=entry2_1, created_by=member1, comment_type=EntryReviewComment.CommentType.CONTROL)
Expand Down Expand Up @@ -408,6 +418,10 @@ def test_entry_query_filter(self):
{'leadStatuses': [self.genum(Lead.Status.IN_PROGRESS), self.genum(Lead.Status.TAGGED)]},
[entry1_1, entry2_1, entry3_1, entry4_1]
),
({'leadIsAssessment': True}, [entry1_1, entry2_1]),
({'leadIsAssessment': False}, [entry3_1, entry4_1]),
({'leadHasAssessment': True}, [entry1_1]),
({'leadHasAssessment': False}, [entry2_1, entry3_1, entry4_1]),
({'hasComment': True}, [entry1_1, entry3_1]),
({'hasComment': False}, [entry2_1, entry4_1]),
({'isVerified': True}, [entry1_1, entry2_1]),
Expand Down
8 changes: 6 additions & 2 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ type AnalysisPillarType {
analyzedEntriesCount: Int!
statements: [AnalyticalStatementType!]
discardedEntries(tags: [DiscardedEntryTagTypeEnum!], page: Int = 1, ordering: String, pageSize: Int): AnalysisPillarDiscardedEntryListType
entries(id: ID, excerpt: String, controlled: Boolean, createdAt: DateTime, createdAtGte: DateTime, createdAtLte: DateTime, modifiedAt: DateTime, modifiedAtGte: DateTime, modifiedAtLte: DateTime, createdBy: [ID!], modifiedBy: [ID!], leads: [ID!], leadCreatedBy: [ID!], leadPublishedOn: Date, leadPublishedOnGte: Date, leadPublishedOnLte: Date, leadTitle: String, leadAssignees: [ID!], leadStatuses: [LeadStatusEnum!], leadPriorities: [LeadPriorityEnum!], leadConfidentialities: [LeadConfidentialityEnum!], leadAuthoringOrganizationTypes: [ID!], leadAuthorOrganizations: [ID!], leadSourceOrganizations: [ID!], search: String, entryTypes: [EntryTagTypeEnum!], projectEntryLabels: [ID!], entriesId: [ID!], geoCustomShape: String, leadGroupLabel: String, filterableData: [EntryFilterDataInputType!], hasComment: Boolean, isVerified: Boolean, discarded: Boolean, excludeEntries: [ID!], page: Int = 1, ordering: String, pageSize: Int): AnalysisPillarEntryListType
entries(id: ID, excerpt: String, controlled: Boolean, createdAt: DateTime, createdAtGte: DateTime, createdAtLte: DateTime, modifiedAt: DateTime, modifiedAtGte: DateTime, modifiedAtLte: DateTime, createdBy: [ID!], modifiedBy: [ID!], leads: [ID!], leadCreatedBy: [ID!], leadPublishedOn: Date, leadPublishedOnGte: Date, leadPublishedOnLte: Date, leadTitle: String, leadAssignees: [ID!], leadStatuses: [LeadStatusEnum!], leadPriorities: [LeadPriorityEnum!], leadConfidentialities: [LeadConfidentialityEnum!], leadAuthoringOrganizationTypes: [ID!], leadAuthorOrganizations: [ID!], leadSourceOrganizations: [ID!], leadHasAssessment: Boolean, leadIsAssessment: Boolean, search: String, entryTypes: [EntryTagTypeEnum!], projectEntryLabels: [ID!], entriesId: [ID!], geoCustomShape: String, leadGroupLabel: String, filterableData: [EntryFilterDataInputType!], hasComment: Boolean, isVerified: Boolean, discarded: Boolean, excludeEntries: [ID!], page: Int = 1, ordering: String, pageSize: Int): AnalysisPillarEntryListType
}

input AnalysisPillarUpdateInputType {
Expand Down Expand Up @@ -3168,6 +3168,8 @@ input EntriesFilterDataInputType {
leadAuthoringOrganizationTypes: [ID!]
leadAuthorOrganizations: [ID!]
leadSourceOrganizations: [ID!]
leadHasAssessment: Boolean
leadIsAssessment: Boolean
search: String
entryTypes: [EntryTagTypeEnum!]
projectEntryLabels: [ID!]
Expand Down Expand Up @@ -3207,6 +3209,8 @@ type EntriesFilterDataType {
leadPublishedOnGte: Date
leadPublishedOnLte: Date
leadTitle: String
leadHasAssessment: Boolean
leadIsAssessment: Boolean
search: String
geoCustomShape: String
leadGroupLabel: String
Expand Down Expand Up @@ -4516,7 +4520,7 @@ type ProjectDetailType {
export(id: ID!): UserExportType
exports(type: [ExportDataTypeEnum!], format: [ExportFormatEnum!], status: [ExportStatusEnum!], search: String, exportedAt: DateTime, exportedAtGte: DateTime, exportedAtLte: DateTime, page: Int = 1, ordering: String, pageSize: Int): UserExportListType
entry(id: ID!): EntryType
entries(id: ID, excerpt: String, controlled: Boolean, createdAt: DateTime, createdAtGte: DateTime, createdAtLte: DateTime, modifiedAt: DateTime, modifiedAtGte: DateTime, modifiedAtLte: DateTime, createdBy: [ID!], modifiedBy: [ID!], leads: [ID!], leadCreatedBy: [ID!], leadPublishedOn: Date, leadPublishedOnGte: Date, leadPublishedOnLte: Date, leadTitle: String, leadAssignees: [ID!], leadStatuses: [LeadStatusEnum!], leadPriorities: [LeadPriorityEnum!], leadConfidentialities: [LeadConfidentialityEnum!], leadAuthoringOrganizationTypes: [ID!], leadAuthorOrganizations: [ID!], leadSourceOrganizations: [ID!], search: String, entryTypes: [EntryTagTypeEnum!], projectEntryLabels: [ID!], entriesId: [ID!], geoCustomShape: String, leadGroupLabel: String, filterableData: [EntryFilterDataInputType!], hasComment: Boolean, isVerified: Boolean, page: Int = 1, ordering: String, pageSize: Int): EntryListType
entries(id: ID, excerpt: String, controlled: Boolean, createdAt: DateTime, createdAtGte: DateTime, createdAtLte: DateTime, modifiedAt: DateTime, modifiedAtGte: DateTime, modifiedAtLte: DateTime, createdBy: [ID!], modifiedBy: [ID!], leads: [ID!], leadCreatedBy: [ID!], leadPublishedOn: Date, leadPublishedOnGte: Date, leadPublishedOnLte: Date, leadTitle: String, leadAssignees: [ID!], leadStatuses: [LeadStatusEnum!], leadPriorities: [LeadPriorityEnum!], leadConfidentialities: [LeadConfidentialityEnum!], leadAuthoringOrganizationTypes: [ID!], leadAuthorOrganizations: [ID!], leadSourceOrganizations: [ID!], leadHasAssessment: Boolean, leadIsAssessment: Boolean, search: String, entryTypes: [EntryTagTypeEnum!], projectEntryLabels: [ID!], entriesId: [ID!], geoCustomShape: String, leadGroupLabel: String, filterableData: [EntryFilterDataInputType!], hasComment: Boolean, isVerified: Boolean, page: Int = 1, ordering: String, pageSize: Int): EntryListType
lead(id: ID!): LeadDetailType
leads(text: String, url: String, createdAt: DateTime, createdAtGte: DateTime, createdAtLte: DateTime, modifiedAt: DateTime, modifiedAtGte: DateTime, modifiedAtLte: DateTime, createdBy: [ID!], modifiedBy: [ID!], ids: [ID!], excludeProvidedLeadsId: Boolean, sourceTypes: [LeadSourceTypeEnum!], priorities: [LeadPriorityEnum!], confidentiality: LeadConfidentialityEnum, statuses: [LeadStatusEnum!], extractionStatus: LeadExtractionStatusEnum, assignees: [ID!], authoringOrganizationTypes: [ID!], authorOrganizations: [ID!], sourceOrganizations: [ID!], hasEntries: Boolean, hasAssessment: Boolean, isAssessment: Boolean, entriesFilterData: EntriesFilterDataInputType, search: String, publishedOn: Date, publishedOnGte: Date, publishedOnLte: Date, emmEntities: String, emmKeywords: String, emmRiskFactors: String, hasDuplicates: Boolean, duplicatesOf: ID, ordering: [LeadOrderingEnum!], page: Int = 1, pageSize: Int): LeadListType
leadGroup(id: ID!): LeadGroupType
Expand Down

0 comments on commit b0f857c

Please sign in to comment.