Skip to content

Commit

Permalink
feat(sync task): support filter category (#1087)
Browse files Browse the repository at this point in the history
  • Loading branch information
nannan00 authored Jul 21, 2023
1 parent 3d1ce2e commit e86facc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/api/bkuser_core/api/web/sync_task/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class Meta:
fields = ("id", "display_name")


class SyncTaskInputSLZ(serializers.Serializer):
category_id = serializers.IntegerField(required=False)


class SyncTaskOutputSLZ(serializers.Serializer):
id = serializers.CharField()
category = CategoryForSyncTaskSerializer()
Expand Down
9 changes: 8 additions & 1 deletion src/api/bkuser_core/api/web/sync_task/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from django.conf import settings
from rest_framework import generics

from .serializers import SyncTaskOutputSLZ, SyncTaskProcessOutputSLZ
from .serializers import SyncTaskInputSLZ, SyncTaskOutputSLZ, SyncTaskProcessOutputSLZ
from bkuser_core.api.web.utils import get_operator
from bkuser_core.api.web.viewset import CustomPagination
from bkuser_core.bkiam.constants import IAMAction
Expand All @@ -27,8 +27,15 @@ class SyncTaskListApi(generics.ListAPIView):

def get_queryset(self):
operator = get_operator(self.request)
slz = SyncTaskInputSLZ(data=self.request.query_params)
slz.is_valid(raise_exception=True)
data = slz.validated_data

queryset = SyncTask.objects.all().order_by("-create_time")
category_id = data.get("category_id")
if category_id:
queryset = queryset.filter(category_id=category_id)

if settings.ENABLE_IAM:
fs = Permission().make_filter_of_category(operator, IAMAction.VIEW_CATEGORY)
queryset = queryset.filter(fs)
Expand Down

0 comments on commit e86facc

Please sign in to comment.