Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add project group name field in project list api #1678

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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