diff --git a/apps/assets/api/asset/common.py b/apps/assets/api/asset/common.py index 007d7fbd0..fb949f7ef 100644 --- a/apps/assets/api/asset/common.py +++ b/apps/assets/api/asset/common.py @@ -37,17 +37,17 @@ class AssetViewSet(SuggestionMixin, FilterAssetByNodeMixin, OrgBulkModelViewSet) search_fields = ("hostname", "ip") ordering_fields = ("hostname", "ip", "port") ordering = ('hostname', ) - serializer_classes = { - 'default': serializers.AssetSerializer, - 'suggestion': serializers.MiniAssetSerializer, - 'platform': serializers.PlatformSerializer, - 'gateways': serializers.GatewayWithAuthSerializer - } - rbac_perms = { - 'match': 'assets.match_asset', - 'platform': 'assets.view_platform', - 'gateways': 'assets.view_gateway' - } + serializer_classes = ( + ('default', serializers.AssetSerializer), + ('suggestion', serializers.MiniAssetSerializer), + ('platform', serializers.PlatformSerializer), + ('gateways', serializers.GatewayWithAuthSerializer) + ) + rbac_perms = ( + ('match', 'assets.match_asset'), + ('platform', 'assets.view_platform'), + ('gateways', 'assets.view_gateway') + ) extra_filter_backends = [ FilterAssetByNodeFilterBackend, LabelFilterBackend, diff --git a/apps/assets/serializers/asset/category.py b/apps/assets/serializers/asset/category.py index 6d9ab1bf0..0b01bb0a2 100644 --- a/apps/assets/serializers/asset/category.py +++ b/apps/assets/serializers/asset/category.py @@ -52,17 +52,3 @@ class DatabaseSerializer(AssetSerializer): **AssetSerializer.Meta.extra_kwargs, 'db_name': {'required': True} } - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - if not self.instance: - self.set_port_default() - - def set_port_default(self): - port = self.fields['port'] - type_port_mapper = { - 'mysql': 3306, - 'postgresql': 5432, - 'oracle': 22 - } - port.default = '' diff --git a/apps/common/mixins/api/serializer.py b/apps/common/mixins/api/serializer.py index a416fa990..84cad19ff 100644 --- a/apps/common/mixins/api/serializer.py +++ b/apps/common/mixins/api/serializer.py @@ -16,28 +16,29 @@ class SerializerMixin: single_actions = ['put', 'retrieve', 'patch'] def get_serializer_classes(self): - return getattr(self, 'serializer_classes', None) + classes = getattr(self, 'serializer_classes', None) or {} + return dict(classes) def get_serializer_class_by_view_action(self): serializer_classes = self.get_serializer_classes() if serializer_classes is None: return None - if not isinstance(self.serializer_classes, dict): + if not isinstance(serializer_classes, dict): return None - + serializer_classes = dict(serializer_classes) view_action = self.request.query_params.get('action') or self.action or 'list' - serializer_class = self.serializer_classes.get(view_action) + serializer_class = serializer_classes.get(view_action) if serializer_class is None: view_method = self.request.method.lower() - serializer_class = self.serializer_classes.get(view_method) + serializer_class = serializer_classes.get(view_method) if serializer_class is None and view_action in self.single_actions: - serializer_class = self.serializer_classes.get('single') + serializer_class = serializer_classes.get('single') if serializer_class is None: - serializer_class = self.serializer_classes.get('display') + serializer_class = serializer_classes.get('display') if serializer_class is None: - serializer_class = self.serializer_classes.get('default') + serializer_class = serializer_classes.get('default') return serializer_class def get_serializer_class(self): diff --git a/apps/rbac/permissions.py b/apps/rbac/permissions.py index 3538246b7..286e5b935 100644 --- a/apps/rbac/permissions.py +++ b/apps/rbac/permissions.py @@ -93,7 +93,8 @@ class RBACPermission(permissions.DjangoModelPermissions): try: queryset = self._queryset(view) model_cls = queryset.model - except: + except Exception as e: + raise e model_cls = None return model_cls