mirror of https://github.com/jumpserver/jumpserver
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
803 B
28 lines
803 B
# -*- coding: utf-8 -*-
|
|
#
|
|
from rest_framework_bulk import BulkModelViewSet
|
|
|
|
from common.permissions import IsValidUser
|
|
from orgs.utils import tmp_to_root_org
|
|
from ..models import FavoriteAsset
|
|
from ..serializers import FavoriteAssetSerializer
|
|
|
|
__all__ = ['FavoriteAssetViewSet']
|
|
|
|
|
|
class FavoriteAssetViewSet(BulkModelViewSet):
|
|
serializer_class = FavoriteAssetSerializer
|
|
permission_classes = (IsValidUser,)
|
|
filterset_fields = ['asset']
|
|
|
|
def dispatch(self, request, *args, **kwargs):
|
|
with tmp_to_root_org():
|
|
return super().dispatch(request, *args, **kwargs)
|
|
|
|
def get_queryset(self):
|
|
queryset = FavoriteAsset.objects.filter(user=self.request.user)
|
|
return queryset
|
|
|
|
def allow_bulk_destroy(self, qs, filtered):
|
|
return filtered.count() == 1
|