Skip to content

Commit

Permalink
Merge pull request #1678 from st1020/feat/add-project-group-in-projec…
Browse files Browse the repository at this point in the history
…t-list-api

feat: add project group name field in project list api
  • Loading branch information
Bidaya0 authored Jul 28, 2023
2 parents 57f0480 + c620c04 commit 1abb9f5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
9 changes: 9 additions & 0 deletions dongtai_web/serializers/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def __init__(self, *args, **kwargs):
agent_count = serializers.SerializerMethodField(help_text="Agent Count")
owner = serializers.SerializerMethodField(help_text="Project owner")
agent_language = serializers.SerializerMethodField(help_text="Agent language currently included in the project")
project_group_name = serializers.SerializerMethodField(help_text="项目组名称列表")
USER_MAP = {}

class Meta:
Expand All @@ -81,6 +82,7 @@ class Meta:
"agent_language",
"vul_validation",
"status",
"project_group_name",
]

def get_agents(self, obj):
Expand Down Expand Up @@ -126,3 +128,10 @@ def get_agent_count(self, obj) -> int:
else:
res = obj.iastagent_set.count()
return res

def get_project_group_name(self, obj: IastProject) -> list:
if "project_group_name" in self.context:
res = self.context["project_group_name"][obj.id]
else:
res = obj.iastprojectgroup_set.values_list("name", flat=True)
return list(res)
7 changes: 6 additions & 1 deletion dongtai_web/views/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from dongtai_common.endpoint import R, UserEndPoint
from dongtai_common.models.project import ProjectStatus
from dongtai_common.utils.request_type import Request
from dongtai_web.serializers.project import (
ProjectSerializer,
get_agent_count,
Expand Down Expand Up @@ -39,6 +40,7 @@ class _ProjectsArgsSerializer(serializers.Serializer):
max_value=10,
help_text=_("The exclude vulnerability status."),
)
project_group_name = serializers.CharField(default=None, help_text="项目组名称")


_SuccessSerializer = get_response_serializer(ProjectSerializer(many=True))
Expand All @@ -55,7 +57,7 @@ class Projects(UserEndPoint):
description=_("Get the item corresponding to the user, support fuzzy search based on name."),
response_schema=_SuccessSerializer,
)
def get(self, request):
def get(self, request: Request):
ser = _ProjectsArgsSerializer(data=request.GET)
try:
if ser.is_valid(True):
Expand All @@ -64,6 +66,7 @@ def get(self, request):
name: str = ser.validated_data.get("name")
status: int | None = ser.validated_data.get("status")
exclude_vul_status: int | None = ser.validated_data.get("exclude_vul_status")
project_group_name: str | None = ser.validated_data.get("project_group_name")
else:
return R.failure(data="Can not validation data.")
except ValidationError as e:
Expand All @@ -74,6 +77,8 @@ def get(self, request):
queryset = queryset.filter(name__icontains=name)
if status is not None:
queryset = queryset.filter(status=status)
if project_group_name is not None:
queryset = queryset.filter(iastprojectgroup__name__icontains=project_group_name)
queryset = queryset.select_related("user")
page_summary, page_data = self.get_paginator(queryset, page, page_size)
vul_levels_dict = get_vul_levels_dict(page_data, exclude_vul_status=exclude_vul_status)
Expand Down

0 comments on commit 1abb9f5

Please sign in to comment.