diff --git a/apps/assets/api/asset/permission.py b/apps/assets/api/asset/permission.py index cab75bc17..5981d1105 100644 --- a/apps/assets/api/asset/permission.py +++ b/apps/assets/api/asset/permission.py @@ -1,18 +1,18 @@ # -*- coding: utf-8 -*- # -from rest_framework.generics import ListAPIView -from django.shortcuts import get_object_or_404 from django.db.models import Q +from django.shortcuts import get_object_or_404 +from rest_framework.generics import ListAPIView +from assets.models import Asset from common.utils import get_logger -from users.models import User, UserGroup -from users.serializers import UserSerializer, UserGroupSerializer -from users.filters import UserFilter +from orgs.mixins import generics +from perms.filters import AssetPermissionFilter from perms.models import AssetPermission from perms.serializers import AssetPermissionSerializer -from perms.filters import AssetPermissionFilter -from orgs.mixins import generics -from assets.models import Asset +from users.filters import UserFilter +from users.models import User, UserGroup +from users.serializers import UserSerializer, UserGroupSerializer logger = get_logger(__file__) __all__ = [ @@ -56,6 +56,7 @@ class AssetPermUserListApi(BaseAssetPermUserOrUserGroupListApi): class AssetPermUserGroupListApi(BaseAssetPermUserOrUserGroupListApi): serializer_class = UserGroupSerializer + queryset = UserGroup.objects.none() def get_queryset(self): perms = self.get_asset_related_perms() @@ -124,4 +125,3 @@ class AssetPermUserGroupPermissionsListApi(BaseAssetRelatedPermissionListApi): user_group_id = self.kwargs.get('perm_user_group_id') user_group = get_object_or_404(UserGroup, pk=user_group_id) return user_group - diff --git a/apps/assets/models/asset/common.py b/apps/assets/models/asset/common.py index 23ff26488..fba640e2f 100644 --- a/apps/assets/models/asset/common.py +++ b/apps/assets/models/asset/common.py @@ -21,12 +21,9 @@ logger = logging.getLogger(__name__) def default_node(): - try: - from assets.models import Node - root = Node.org_root() - return Node.objects.filter(id=root.id) - except: - return None + from orgs.utils import current_org + from ..node import Node + return Node(id=current_org.id) class AssetManager(OrgManager): diff --git a/apps/assets/serializers/asset/common.py b/apps/assets/serializers/asset/common.py index 137a2ae3c..ded10161d 100644 --- a/apps/assets/serializers/asset/common.py +++ b/apps/assets/serializers/asset/common.py @@ -11,7 +11,7 @@ from accounts.serializers import AccountSerializerCreateValidateMixin from accounts.serializers import AuthValidateMixin from common.serializers import WritableNestedModelSerializer, SecretReadableMixin, CommonModelSerializer from common.serializers.fields import LabeledChoiceField -from common.utils import lazyproperty, decrypt_password +from common.utils import lazyproperty from orgs.mixins.serializers import BulkOrgResourceModelSerializer from ...const import Category, AllTypes from ...models import Asset, Node, Platform, Label, Protocol @@ -25,6 +25,8 @@ __all__ = [ class AssetProtocolsSerializer(serializers.ModelSerializer): + port = serializers.IntegerField(required=False, allow_null=True, max_value=65535, min_value=1) + class Meta: model = Protocol fields = ['name', 'port'] diff --git a/apps/audits/api.py b/apps/audits/api.py index 4c2b5dc76..d1915206a 100644 --- a/apps/audits/api.py +++ b/apps/audits/api.py @@ -12,8 +12,8 @@ from common.api import JMSGenericViewSet from common.drf.filters import DatetimeRangeFilter from common.plugins.es import QuerySet as ESQuerySet from orgs.mixins.api import OrgGenericViewSet, OrgBulkModelViewSet -from orgs.utils import current_org, tmp_to_root_org from orgs.models import Organization +from orgs.utils import current_org, tmp_to_root_org from users.models import User from .backends import TYPE_ENGINE_MAPPING from .const import ActivityChoices @@ -135,8 +135,11 @@ class OperateLogViewSet(RetrieveModelMixin, ListModelMixin, OrgGenericViewSet): date_range_filter_fields = [ ('datetime', ('date_from', 'date_to')) ] - filterset_fields = ['user', 'action', 'resource_type', 'resource', 'remote_addr'] - search_fields = ['resource'] + filterset_fields = [ + 'user', 'action', 'resource_type', 'resource', + 'remote_addr' + ] + search_fields = ['resource', 'user'] ordering = ['-datetime'] def get_serializer_class(self): diff --git a/apps/terminal/backends/command/models.py b/apps/terminal/backends/command/models.py index 39637aab3..da535a17c 100644 --- a/apps/terminal/backends/command/models.py +++ b/apps/terminal/backends/command/models.py @@ -1,7 +1,8 @@ # -*- coding: utf-8 -*- # -from datetime import datetime import uuid +from datetime import datetime + from django.db import models from django.utils.translation import ugettext_lazy as _