policies: add additional filters to create flow charts on frontend
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
f76c1a6f93
commit
f62786e58b
|
@ -2,6 +2,8 @@
|
||||||
from typing import OrderedDict
|
from typing import OrderedDict
|
||||||
|
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
|
from django_filters.filters import BooleanFilter, ModelMultipleChoiceFilter
|
||||||
|
from django_filters.filterset import FilterSet
|
||||||
from rest_framework.serializers import ModelSerializer, PrimaryKeyRelatedField, ValidationError
|
from rest_framework.serializers import ModelSerializer, PrimaryKeyRelatedField, ValidationError
|
||||||
from rest_framework.viewsets import ModelViewSet
|
from rest_framework.viewsets import ModelViewSet
|
||||||
from structlog.stdlib import get_logger
|
from structlog.stdlib import get_logger
|
||||||
|
@ -96,6 +98,22 @@ class PolicyBindingSerializer(ModelSerializer):
|
||||||
return attrs
|
return attrs
|
||||||
|
|
||||||
|
|
||||||
|
class PolicyBindingFilter(FilterSet):
|
||||||
|
"""Filter for PolicyBindings"""
|
||||||
|
|
||||||
|
target_in = ModelMultipleChoiceFilter(
|
||||||
|
field_name="target__pbm_uuid",
|
||||||
|
to_field_name="pbm_uuid",
|
||||||
|
queryset=PolicyBindingModel.objects.select_subclasses(),
|
||||||
|
)
|
||||||
|
policy__isnull = BooleanFilter("policy", "isnull")
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
|
||||||
|
model = PolicyBinding
|
||||||
|
fields = ["policy", "policy__isnull", "target", "target_in", "enabled", "order", "timeout"]
|
||||||
|
|
||||||
|
|
||||||
class PolicyBindingViewSet(UsedByMixin, ModelViewSet):
|
class PolicyBindingViewSet(UsedByMixin, ModelViewSet):
|
||||||
"""PolicyBinding Viewset"""
|
"""PolicyBinding Viewset"""
|
||||||
|
|
||||||
|
@ -105,5 +123,6 @@ class PolicyBindingViewSet(UsedByMixin, ModelViewSet):
|
||||||
.prefetch_related("policy")
|
.prefetch_related("policy")
|
||||||
) # prefetching policy so we resolve the subclass
|
) # prefetching policy so we resolve the subclass
|
||||||
serializer_class = PolicyBindingSerializer
|
serializer_class = PolicyBindingSerializer
|
||||||
filterset_fields = ["policy", "target", "enabled", "order", "timeout"]
|
|
||||||
search_fields = ["policy__name"]
|
search_fields = ["policy__name"]
|
||||||
|
filterset_class = PolicyBindingFilter
|
||||||
|
ordering = ["target", "order"]
|
||||||
|
|
14
schema.yml
14
schema.yml
|
@ -7033,6 +7033,10 @@ paths:
|
||||||
schema:
|
schema:
|
||||||
type: string
|
type: string
|
||||||
format: uuid
|
format: uuid
|
||||||
|
- in: query
|
||||||
|
name: policy__isnull
|
||||||
|
schema:
|
||||||
|
type: boolean
|
||||||
- name: search
|
- name: search
|
||||||
required: false
|
required: false
|
||||||
in: query
|
in: query
|
||||||
|
@ -7044,6 +7048,15 @@ paths:
|
||||||
schema:
|
schema:
|
||||||
type: string
|
type: string
|
||||||
format: uuid
|
format: uuid
|
||||||
|
- in: query
|
||||||
|
name: target_in
|
||||||
|
schema:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
format: uuid
|
||||||
|
explode: true
|
||||||
|
style: form
|
||||||
- in: query
|
- in: query
|
||||||
name: timeout
|
name: timeout
|
||||||
schema:
|
schema:
|
||||||
|
@ -29418,6 +29431,7 @@ components:
|
||||||
- SUCCESSFUL
|
- SUCCESSFUL
|
||||||
- WARNING
|
- WARNING
|
||||||
- ERROR
|
- ERROR
|
||||||
|
- UNKNOWN
|
||||||
type: string
|
type: string
|
||||||
SubModeEnum:
|
SubModeEnum:
|
||||||
enum:
|
enum:
|
||||||
|
|
Reference in New Issue