jumpserver/apps/assets/api/platform.py

31 lines
992 B
Python
Raw Normal View History

2022-04-02 10:35:46 +00:00
2022-04-28 14:54:18 +00:00
from common.drf.api import JMSModelViewSet
2022-09-13 02:41:49 +00:00
from common.drf.serializers import GroupedChoiceSerializer
2022-04-02 10:35:46 +00:00
from assets.models import Platform
2022-09-29 12:44:45 +00:00
from assets.serializers import PlatformSerializer
2022-04-02 10:35:46 +00:00
__all__ = ['AssetPlatformViewSet']
2022-04-28 14:54:18 +00:00
class AssetPlatformViewSet(JMSModelViewSet):
2022-04-02 10:35:46 +00:00
queryset = Platform.objects.all()
2022-04-28 14:54:18 +00:00
serializer_classes = {
'default': PlatformSerializer,
2022-09-13 02:41:49 +00:00
'categories': GroupedChoiceSerializer
2022-04-28 14:54:18 +00:00
}
2022-08-22 05:25:57 +00:00
filterset_fields = ['name', 'category', 'type']
2022-04-02 10:35:46 +00:00
search_fields = ['name']
2022-04-28 14:54:18 +00:00
rbac_perms = {
2022-05-05 08:18:05 +00:00
'categories': 'assets.view_platform',
2022-08-29 07:50:25 +00:00
'type_constraints': 'assets.view_platform',
'ops_methods': 'assets.view_platform'
2022-04-28 14:54:18 +00:00
}
2022-04-02 10:35:46 +00:00
def check_object_permissions(self, request, obj):
if request.method.lower() in ['delete', 'put', 'patch'] and obj.internal:
self.permission_denied(
request, message={"detail": "Internal platform"}
)
return super().check_object_permissions(request, obj)