Beispiel #1
0
class Query:
    analysis = DjangoObjectField(AnalysisType)
    analyses = DjangoPaginatedListObjectField(
        AnalysisListType,
        pagination=PageGraphqlPagination(
            page_size_query_param='pageSize'
        )
    )

    # Pillar
    analysis_pillar = DjangoObjectField(AnalysisPillarDetailType)
    analysis_pillars = DjangoPaginatedListObjectField(
        AnalysisPillarListType,
        pagination=PageGraphqlPagination(
            page_size_query_param='pageSize'
        )
    )

    @staticmethod
    def resolve_analyses(root, info, **kwargs) -> QuerySet:
        return get_analysis_qs(info)

    @staticmethod
    def resolve_analysis_pillars(root, info, **kwargs) -> QuerySet:
        return get_analysis_pillar_qs(info)
Beispiel #2
0
class UnifiedConnectorQueryType(graphene.ObjectType):
    unified_connector = DjangoObjectField(UnifiedConnectorType)
    unified_connectors = DjangoPaginatedListObjectField(
        UnifiedConnectorListType,
        pagination=NoOrderingPageGraphqlPagination(
            page_size_query_param='pageSize', ))
    connector_source = DjangoObjectField(ConnectorSourceType)
    connector_sources = DjangoPaginatedListObjectField(
        ConnectorSourceListType,
        pagination=NoOrderingPageGraphqlPagination(
            page_size_query_param='pageSize', ))
    connector_source_lead = DjangoObjectField(ConnectorSourceLeadType)
    connector_source_leads = DjangoPaginatedListObjectField(
        ConnectorSourceLeadListType,
        pagination=NoOrderingPageGraphqlPagination(
            page_size_query_param='pageSize', ))

    @staticmethod
    def resolve_unified_connectors(root, info, **kwargs) -> QuerySet:
        return get_unified_connector_qs(info)

    @staticmethod
    def resolve_connector_sources(root, info, **kwargs) -> QuerySet:
        return get_connector_source_qs(info)

    @staticmethod
    def resolve_connector_source_leads(root, info, **kwargs) -> QuerySet:
        return get_connector_source_lead_qs(info)
Beispiel #3
0
class Query:
    lead = DjangoObjectField(LeadDetailType)
    leads = DjangoPaginatedListObjectField(
        LeadListType,
        pagination=NoOrderingPageGraphqlPagination(
            page_size_query_param='pageSize', ))
    lead_group = DjangoObjectField(LeadGroupType)
    lead_groups = DjangoPaginatedListObjectField(
        LeadGroupListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'))
    emm_entities = DjangoPaginatedListObjectField(
        EmmEntityListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'))
    lead_emm_triggers = DjangoPaginatedListObjectField(
        LeadEmmTriggerListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'))
    # TODO: Add Pagination
    emm_keywords = graphene.List(graphene.NonNull(EmmKeyWordType))
    emm_risk_factors = graphene.List(graphene.NonNull(EmmKeyRiskFactorType))

    @staticmethod
    def resolve_leads(root, info, **kwargs) -> QuerySet:
        return get_lead_qs(info)

    @staticmethod
    def resolve_lead_groups(root, info, **kwargs) -> QuerySet:
        return get_lead_group_qs(info)

    @staticmethod
    def resolve_emm_entities(root, info, **kwargs) -> QuerySet:
        return get_emm_entities_qs(info)

    @staticmethod
    def resolve_lead_emm_triggers(root, info, **kwargs) -> QuerySet:
        return get_lead_emm_entities_qs(info)

    @staticmethod
    def resolve_emm_keywords(root, info, **kwargs):
        return LeadEMMTrigger.objects.filter(
            lead__project=info.context.active_project).values(
                'emm_keyword').annotate(
                    total_count=models.Sum('count'),
                    key=models.F('emm_keyword'),
                    label=models.F('emm_keyword')).order_by('emm_keyword')

    @staticmethod
    def resolve_emm_risk_factors(root, info, **kwargs):
        return LeadEMMTrigger.objects.filter(
            ~models.Q(emm_risk_factor=''),
            ~models.Q(emm_risk_factor=None),
            lead__project=info.context.active_project,
        ).values('emm_risk_factor').annotate(
            total_count=models.Sum('count'),
            key=models.F('emm_risk_factor'),
            label=models.F('emm_risk_factor'),
        ).order_by('emm_risk_factor')
Beispiel #4
0
class Query:
    project = DjangoObjectField(ProjectDetailType)
    projects = DjangoPaginatedListObjectField(
        ProjectListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'))
    recent_projects = graphene.List(graphene.NonNull(ProjectDetailType))
    project_explore_stats = graphene.Field(ProjectExploreStatType)

    # only the region for which project are public
    projects_by_region = DjangoPaginatedListObjectField(
        ProjectByRegionListType)

    # PUBLIC NODES
    public_projects = DjangoPaginatedListObjectField(
        PublicProjectListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'))
    public_projects_by_region = DjangoPaginatedListObjectField(
        PublicProjectByRegionListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'))

    # NOTE: This is a custom feature, see https://github.com/the-deep/graphene-django-extras
    # see: https://github.com/eamigo86/graphene-django-extras/compare/graphene-v2...the-deep:graphene-v2

    @staticmethod
    def resolve_projects(root, info, **kwargs) -> QuerySet:
        return Project.get_for_gq(info.context.user).distinct()

    @staticmethod
    def resolve_recent_projects(root, info, **kwargs) -> QuerySet:
        # only the recent project of the user member of
        queryset = Project.get_for_gq(info.context.user, only_member=True)
        return Project.get_recent_active_projects(info.context.user, queryset)

    @staticmethod
    def resolve_projects_by_region(root, info, **kwargs):
        return Region.objects\
            .filter(centroid__isnull=False)\
            .order_by('centroid')

    @staticmethod
    def resolve_project_explore_stats(root, info, **kwargs):
        return info.context.dl.project.resolve_explore_stats()

    # PUBLIC RESOLVERS
    @staticmethod
    def resolve_public_projects(root, info, **kwargs) -> QuerySet:
        return PublicProjectListType.queryset()

    @staticmethod
    def resolve_public_projects_by_region(*args, **kwargs):
        return Query.resolve_projects_by_region(*args, **kwargs)
Beispiel #5
0
class AnalysisPillarDetailType(AnalysisPillarType):
    class Meta:
        model = AnalysisPillar
        skip_registry = True
        only_fields = (
            'id',
            'title', 'main_statement', 'information_gap', 'assignee',
            'filters',
        )

    entries = DjangoPaginatedListObjectField(
        AnalysisPillarEntryListType,
        pagination=PageGraphqlPagination(
            page_size_query_param='pageSize'
        )
    )

    @staticmethod
    def resolve_entries(root, info, **kwargs):
        # filtering out the entries whose lead published_on date is less than analysis end_date
        queryset = get_entry_qs(info).filter(
            project=root.analysis.project_id,
            lead__published_on__lte=root.analysis.end_date
        )
        discarded_entries_qs = DiscardedEntry.objects.filter(analysis_pillar=root).values('entry')
        if kwargs.get('discarded'):  # NOTE: From AnalysisPillarEntryGQFilterSet.discarded
            return queryset.filter(id__in=discarded_entries_qs)
        return queryset.exclude(id__in=discarded_entries_qs)
Beispiel #6
0
class Query:
    analysis_framework = DjangoObjectField(AnalysisFrameworkDetailType)
    analysis_frameworks = DjangoPaginatedListObjectField(
        AnalysisFrameworkListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'))
    public_analysis_frameworks = DjangoPaginatedListObjectField(
        PublicAnalysisFrameworkListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'))

    @staticmethod
    def resolve_analysis_frameworks(root, info, **kwargs) -> QuerySet:
        return AnalysisFramework.get_for_gq(info.context.user).distinct()

    @staticmethod
    def resolve_public_analysis_frameworks(root, info, **kwargs) -> QuerySet:
        return AnalysisFramework.objects.filter(is_private=False).distinct()
Beispiel #7
0
class Query:
    entry = DjangoObjectField(EntryType)
    entries = DjangoPaginatedListObjectField(
        EntryListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'))

    @staticmethod
    def resolve_entries(root, info, **kwargs) -> QuerySet:
        return get_entry_qs(info)
Beispiel #8
0
class Query:
    region = DjangoObjectField(RegionDetailType)
    regions = DjangoPaginatedListObjectField(
        RegionListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'))

    @staticmethod
    def resolve_regions(root, info, **kwargs):
        return get_users_region_qs(info)
Beispiel #9
0
class Query:
    organization = DjangoObjectField(OrganizationType)
    organizations = DjangoPaginatedListObjectField(
        OrganizationListType,
        pagination=NoOrderingPageGraphqlPagination(
            page_size_query_param='pageSize'))
    public_organizations = DjangoPaginatedListObjectField(
        PublicOrganizationListObjectType,
        pagination=NoOrderingPageGraphqlPagination(
            page_size_query_param='pageSize'))
    organization_type = DjangoObjectField(OrganizationTypeType)
    organization_types = DjangoPaginatedListObjectField(
        OrganizationTypeListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'))

    def resolve_organizations(root, info, **kwargs):
        # Filterout merged organizations
        return Organization.objects.filter(parent__isnull=True).all()
Beispiel #10
0
class Query:
    export = DjangoObjectField(UserExportType)
    exports = DjangoPaginatedListObjectField(
        UserExportListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'))

    @staticmethod
    def resolve_exports(root, info, **kwargs) -> QuerySet:
        return get_export_qs(info).filter(is_preview=False)
Beispiel #11
0
class ProjectScopeQuery:
    geo_areas = DjangoPaginatedListObjectField(
        ProjectGeoAreaListType,
        pagination=NoOrderingPageGraphqlPagination(
            page_size_query_param='pageSize'))

    @staticmethod
    def resolve_geo_areas(queryset, info, **kwargs):
        return get_geo_area_queryset_for_project_geo_area_type(
            queryset=GeoArea.get_for_project(info.context.active_project))
Beispiel #12
0
class Query:
    review_comment = DjangoObjectField(EntryReviewCommentDetailType)
    review_comments = DjangoPaginatedListObjectField(
        EntryReviewCommentListType,
        pagination=NoOrderingPageGraphqlPagination(
            page_size_query_param='pageSize'))

    @staticmethod
    def resolve_review_comments(root, info, **kwargs):
        return get_entry_comment_qs(info)
Beispiel #13
0
class Query:
    me = graphene.Field(UserMeType)
    user = DjangoObjectField(UserType)
    users = DjangoPaginatedListObjectField(
        UserListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'))

    @staticmethod
    def resolve_me(root, info, **kwargs) -> Union[User, None]:
        if info.context.user.is_authenticated:
            return info.context.user
        return None
Beispiel #14
0
class Query:
    assessment = DjangoObjectField(AssessmentType)
    assessments = DjangoPaginatedListObjectField(
        AssessmentListType,
        pagination=PageGraphqlPagination(
            page_size_query_param='pageSize'
        )
    )

    @staticmethod
    def resolve_assessments(root, info, **kwargs) -> QuerySet:
        return get_assessment_qs(info)
Beispiel #15
0
class ProjectDetailType(
        # -- Start --Project scopped entities
        LeadQuery,
        EntryQuery,
        ExportQuery,
        GeoQuery,
        QualityAssuranceQuery,
        AryQuery,
        AnalysisQuery,
        # --  End  --Project scopped entities
        ProjectType,
):
    # NOTE: To avoid circular import
    from analysis_framework.schema import AnalysisFrameworkDetailType

    class Meta:
        model = Project
        skip_registry = True
        only_fields = (
            'id',
            'title',
            'description',
            'start_date',
            'end_date',
            'analysis_framework',
            'category_editor',
            'assessment_template',
            'data',
            'created_at',
            'created_by',
            'modified_at',
            'modified_by',
            'is_default',
            'is_private',
            'is_visualization_enabled',
            'has_publicly_viewable_leads',
        )

    analysis_framework = graphene.Field(AnalysisFrameworkDetailType)
    activity_log = generic.GenericScalar()  # TODO: Need to define type
    recent_active_users = graphene.List(graphene.NonNull(UserEntityDateType))
    top_sourcers = graphene.List(graphene.NonNull(UserEntityCountType))
    top_taggers = graphene.List(graphene.NonNull(UserEntityCountType))

    user_members = DjangoPaginatedListObjectField(
        ProjectMembershipListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'))
    user_group_members = DjangoPaginatedListObjectField(
        ProjectUserGroupMembershipListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'))
    is_visualization_available = graphene.Boolean(
        required=True,
        description=
        'Checks if visualization is enabled and analysis framework is configured.',
    )
    viz_data = graphene.Field(ProjectVizDataType)
    # Other scoped queries
    unified_connector = graphene.Field(UnifiedConnectorQueryType)
    assisted_tagging = graphene.Field(AssistedTaggingQueryType)

    @staticmethod
    def resolve_user_members(root, info, **kwargs):
        if root.get_current_user_role(info.context.request.user) is not None:
            return ProjectMembership.objects.filter(project=root).all()
        return [
        ]  # NOTE: Always return empty array FIXME: without empty everything is returned

    @staticmethod
    def resolve_user_group_members(root, info, **kwargs):
        if root.get_current_user_role(info.context.request.user) is not None:
            return ProjectUserGroupMembership.objects.filter(
                project=root).all()
        return [
        ]  # NOTE: Always return empty array FIXME: without empty everything is returned

    @staticmethod
    def resolve_activity_log(root, info, **kwargs):
        return list(project_activity_log(root))

    @staticmethod
    def resolve_recent_active_users(root, info, **kwargs):
        return get_recent_active_users(root)

    @staticmethod
    def resolve_top_sourcers(root, info, **kwargs):
        return get_top_entity_contributor(root, Lead)

    @staticmethod
    def resolve_top_taggers(root, info, **kwargs):
        return get_top_entity_contributor(root, Entry)

    @staticmethod
    def resolve_viz_data(root, info, **kwargs):
        if root.get_current_user_role(
                info.context.request.user
        ) is not None and root.is_visualization_available:
            return root.project_stats

    @staticmethod
    def resolve_unified_connector(root, info, **kwargs):
        if root.get_current_user_role(info.context.request.user) is not None:
            return {}

    @staticmethod
    def resolve_assisted_tagging(root, info, **kwargs):
        if root.get_current_user_role(info.context.request.user) is not None:
            return {}
Beispiel #16
0
class Query:
    user_group = DjangoObjectField(UserGroupType)
    user_groups = DjangoPaginatedListObjectField(
        UserGroupListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'))