Skip to content

Commit

Permalink
Add analysis-framework roles query
Browse files Browse the repository at this point in the history
  • Loading branch information
sudan45 committed May 2, 2024
1 parent 0c1dc33 commit 283076e
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
14 changes: 14 additions & 0 deletions apps/analysis_framework/filter_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from .models import (
AnalysisFramework,
AnalysisFrameworkRole,
AnalysisFrameworkTag,
)
from entry.models import Entry
Expand Down Expand Up @@ -86,3 +87,16 @@ def filter_recently_used(self, queryset, name, value):
entries_qs = Entry.objects.filter(modified_at__gte=recent_usage_cutoff)
return queryset.filter(id__in=entries_qs.values('analysis_framework'))
return queryset


class AnalysisFrameworkRoleGqFilterSet(UserResourceGqlFilterSet):
search = django_filters.CharFilter(method='search_filter')

class Meta:
model = AnalysisFrameworkRole
fields = ('__all__')

def search_filter(self, qs, _, value):
if value:
return qs.filter(title__icontains=value)
return qs
14 changes: 13 additions & 1 deletion apps/analysis_framework/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,14 @@ def resolve_used_in_project_count(root, info):
class AnalysisFrameworkRoleType(DjangoObjectType):
class Meta:
model = AnalysisFrameworkRole
only_fields = ('id', 'title',)
only_fields = (
'id',
'title',
'is_private_role',
'is_default_role',
)

type = graphene.Field(AnalysisFrameworkRoleTypeEnum)


class AnalysisFrameworkFilterType(DjangoObjectType):
Expand Down Expand Up @@ -311,6 +318,7 @@ class Query:
page_size_query_param='pageSize'
)
)
analysis_framework_roles = graphene.List(graphene.NonNull(AnalysisFrameworkRoleType), required=True)

@staticmethod
def resolve_analysis_frameworks(root, info, **kwargs) -> QuerySet:
Expand All @@ -319,3 +327,7 @@ def resolve_analysis_frameworks(root, info, **kwargs) -> QuerySet:
@staticmethod
def resolve_public_analysis_frameworks(root, info, **kwargs) -> QuerySet:
return AnalysisFramework.objects.filter(is_private=False).distinct()

@staticmethod
def resolve_analysis_framework_roles(root, info, **kwargs) -> QuerySet:
return AnalysisFrameworkRole.objects.all()
24 changes: 24 additions & 0 deletions apps/analysis_framework/tests/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from utils.graphene.tests import GraphQLSnapShotTestCase

from analysis_framework.models import AnalysisFrameworkRole

from user.factories import UserFactory
from project.factories import ProjectFactory
from lead.factories import LeadFactory
Expand Down Expand Up @@ -323,3 +325,25 @@ def test_recent_analysis_framework(self):
content['data']['projectExploreStats']['topActiveFrameworks'][4]['analysisFrameworkId'],
str(analysis_framework4.id)
)

def test_analysis_framework_roles(self):
query = '''
query MyQuery {
analysisFrameworkRoles {
title
type
isPrivateRole
id
isDefaultRole
}
}
'''
user = UserFactory.create()
# without login
self.query_check(query, assert_for_error=True)

# with normal login
self.force_login(user)
content = self.query_check(query)
af_roles_count = AnalysisFrameworkRole.objects.all().count()
self.assertEqual(len(content['data']['analysisFrameworkRoles']), af_roles_count)
4 changes: 4 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ type AnalysisFrameworkPropertiesType {
type AnalysisFrameworkRoleType {
id: ID!
title: String!
isPrivateRole: Boolean!
isDefaultRole: Boolean!
type: AnalysisFrameworkRoleTypeEnum
}

enum AnalysisFrameworkRoleTypeEnum {
Expand Down Expand Up @@ -5694,6 +5697,7 @@ type Query {
analysisFrameworks(id: Float, createdAt: DateTime, createdAtGte: DateTime, createdAtLte: DateTime, modifiedAt: DateTime, modifiedAtGte: DateTime, modifiedAtLte: DateTime, createdBy: [ID!], modifiedBy: [ID!], search: String, isCurrentUserMember: Boolean, recentlyUsed: Boolean, tags: [ID!], page: Int = 1, ordering: String, pageSize: Int): AnalysisFrameworkListType
publicAnalysisFrameworks(id: Float, createdAt: DateTime, createdAtGte: DateTime, createdAtLte: DateTime, modifiedAt: DateTime, modifiedAtGte: DateTime, modifiedAtLte: DateTime, createdBy: [ID!], modifiedBy: [ID!], search: String, isCurrentUserMember: Boolean, recentlyUsed: Boolean, tags: [ID!], page: Int = 1, ordering: String, pageSize: Int): PublicAnalysisFrameworkListType
analysisFrameworkTags(id: Float, search: String, page: Int = 1, ordering: String, pageSize: Int): AnalysisFrameworkTagListType
analysisFrameworkRoles: [AnalysisFrameworkRoleType!]!
project(id: ID!): ProjectDetailType
projects(createdAt: DateTime, createdAtGte: DateTime, createdAtLte: DateTime, modifiedAt: DateTime, modifiedAtGte: DateTime, modifiedAtLte: DateTime, createdBy: [ID!], modifiedBy: [ID!], ids: [ID!], excludeIds: [ID!], status: ProjectStatusEnum, organizations: [ID!], analysisFrameworks: [ID!], regions: [ID!], search: String, isCurrentUserMember: Boolean, hasPermissionAccess: ProjectPermission, ordering: [ProjectOrderingEnum!], isTest: Boolean, page: Int = 1, pageSize: Int): ProjectListType
recentProjects: [ProjectDetailType!]
Expand Down

0 comments on commit 283076e

Please sign in to comment.