Skip to content

Commit

Permalink
Add analysis-framework roles query
Browse files Browse the repository at this point in the history
 Update testcase of af roles query
  • Loading branch information
sudan45 committed May 2, 2024
1 parent 0c1dc33 commit e916fe3
Show file tree
Hide file tree
Showing 4 changed files with 67 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(models.Q(title__icontains=value))
return qs
18 changes: 17 additions & 1 deletion apps/analysis_framework/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,18 @@ 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',
'can_add_user',
'can_clone_framework',
'can_edit_framework',
'can_use_in_other_projects',
'is_default_role',
)

type = graphene.Field(AnalysisFrameworkRoleTypeEnum)


class AnalysisFrameworkFilterType(DjangoObjectType):
Expand Down Expand Up @@ -311,6 +322,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 +331,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()
28 changes: 28 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,29 @@ 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
canAddUser
canCloneFramework
canEditFramework
canUseInOtherProjects
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)
8 changes: 8 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,14 @@ type AnalysisFrameworkPropertiesType {
type AnalysisFrameworkRoleType {
id: ID!
title: String!
isPrivateRole: Boolean!
type: AnalysisFrameworkRoleTypeEnum
canAddUser: Boolean!
canCloneFramework: Boolean!
canEditFramework: Boolean!
canUseInOtherProjects: Boolean!
isDefaultRole: Boolean!
analysisframeworkmembershipSet: [AnalysisFrameworkMembershipType!]!
}

enum AnalysisFrameworkRoleTypeEnum {
Expand Down

0 comments on commit e916fe3

Please sign in to comment.