mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-12 21:39:18 +00:00
perf(application): 优化一些小细节
This commit is contained in:
@@ -41,16 +41,17 @@ class ApplicationViewSet(OrgBulkModelViewSet):
|
||||
if self.action in [
|
||||
'create', 'update', 'partial_update', 'bulk_update', 'partial_bulk_update'
|
||||
] and not app_type:
|
||||
# action: create / update ...
|
||||
# action: create / update
|
||||
raise JMSException(
|
||||
'The `{}` action must take the `type` query parameter'.format(self.action)
|
||||
)
|
||||
|
||||
if app_type:
|
||||
# action: create / update / list / retrieve / metadata
|
||||
attrs_cls = models.Category.get_type_serializer_cls(app_type)
|
||||
elif app_category:
|
||||
# action: list / retrieve / metadata
|
||||
attrs_cls = models.Category.get_category_serializer_cls(app_category)
|
||||
else:
|
||||
attrs_cls = serializers.CommonCategorySerializer
|
||||
attrs_cls = models.Category.get_no_password_serializer_cls()
|
||||
return type('ApplicationDynamicSerializer', (serializer_class,), {'attrs': attrs_cls()})
|
||||
|
@@ -39,11 +39,11 @@ class SerializeApplicationToTreeNodeMixin:
|
||||
'meta': {'type': 'k8s_app'}
|
||||
}
|
||||
|
||||
def dispatch_serialize(self, application):
|
||||
def _serialize(self, application):
|
||||
method_name = f'_serialize_{application.category}'
|
||||
data = getattr(self, method_name)(application)
|
||||
return data
|
||||
|
||||
def serialize_applications(self, applications):
|
||||
data = [self.dispatch_serialize(application) for application in applications]
|
||||
data = [self._serialize(application) for application in applications]
|
||||
return data
|
||||
|
@@ -27,8 +27,14 @@ class RemoteAppConnectionInfoApi(generics.RetrieveAPIView):
|
||||
permission_classes = (IsAppUser, )
|
||||
serializer_class = RemoteAppConnectionInfoSerializer
|
||||
|
||||
@staticmethod
|
||||
def check_category_allowed(obj):
|
||||
if not obj.category_is_remote_app:
|
||||
raise JMSException(
|
||||
'The request instance(`{}`) is not of category `remote_app`'.format(obj.category)
|
||||
)
|
||||
|
||||
def get_object(self):
|
||||
obj = super().get_object()
|
||||
if not models.Category.is_remote_app(obj.category):
|
||||
raise JMSException('The request instance is not of category `remote_app`')
|
||||
self.check_category_allowed(obj)
|
||||
return obj
|
||||
|
Reference in New Issue
Block a user