Merge pull request #2695 from jumpserver/dev_bugfix

[Bugfix] 修复AssetUserManager.get获取username为""的AuthBook对象时,返回多个结果的bug
pull/2702/head
老广 6 years ago committed by GitHub
commit 1ca1e519b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -39,6 +39,8 @@ __all__ = [
class NodeViewSet(viewsets.ModelViewSet): class NodeViewSet(viewsets.ModelViewSet):
filter_fields = ('value', 'key', )
search_fields = filter_fields
queryset = Node.objects.all() queryset = Node.objects.all()
permission_classes = (IsOrgAdmin,) permission_classes = (IsOrgAdmin,)
serializer_class = serializers.NodeSerializer serializer_class = serializers.NodeSerializer

@ -11,7 +11,7 @@ class AuthBookBackend(BaseBackend):
@classmethod @classmethod
def filter(cls, username=None, asset=None, latest=True): def filter(cls, username=None, asset=None, latest=True):
queryset = AuthBook.objects.all() queryset = AuthBook.objects.all()
if username: if username is not None:
queryset = queryset.filter(username=username) queryset = queryset.filter(username=username)
if asset: if asset:
queryset = queryset.filter(asset=asset) queryset = queryset.filter(asset=asset)

@ -27,7 +27,7 @@ class AdminUserBackend(BaseBackend):
instances = [] instances = []
assets = cls._get_assets(asset) assets = cls._get_assets(asset)
for asset in assets: for asset in assets:
if username and asset.admin_user.username != username: if username is not None and asset.admin_user.username != username:
continue continue
instance = construct_authbook_object(asset.admin_user, asset) instance = construct_authbook_object(asset.admin_user, asset)
instances.append(instance) instances.append(instance)

@ -30,7 +30,7 @@ class SystemUserBackend(BaseBackend):
@classmethod @classmethod
def _filter_system_users_by_username(cls, system_users, username): def _filter_system_users_by_username(cls, system_users, username):
_system_users = cls._distinct_system_users_by_username(system_users) _system_users = cls._distinct_system_users_by_username(system_users)
if username: if username is not None:
_system_users = [su for su in _system_users if username == su.username] _system_users = [su for su in _system_users if username == su.username]
return _system_users return _system_users

Loading…
Cancel
Save