Browse Source

perf: 改造username_suggestions api 改为post请求 (#11110)

Co-authored-by: feng <1304903146@qq.com>
pull/11111/head
fit2bot 1 year ago committed by GitHub
parent
commit
99adb6ab7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      apps/accounts/api/account/account.py

17
apps/accounts/api/account/account.py

@ -52,20 +52,21 @@ class AccountViewSet(OrgBulkModelViewSet):
return Response(data=serializer.data)
@action(
methods=['get'], detail=False, url_path='username-suggestions',
methods=['post'], detail=False, url_path='username-suggestions',
permission_classes=[IsValidUser]
)
def username_suggestions(self, request, *args, **kwargs):
asset_ids = request.query_params.get('assets')
node_keys = request.query_params.get('keys')
username = request.query_params.get('username')
asset_ids = request.data.get('assets')
node_ids = request.data.get('nodes')
username = request.data.get('username')
assets = Asset.objects.all()
if asset_ids:
assets = assets.filter(id__in=asset_ids.split(','))
if node_keys:
patten = Node.get_node_all_children_key_pattern(node_keys.split(','))
assets = assets.filter(nodes__key__regex=patten)
assets = assets.filter(id__in=asset_ids)
if node_ids:
nodes = Node.objects.filter(id__in=node_ids)
node_asset_ids = Node.get_nodes_all_assets(*nodes).values_list('id', flat=True)
assets = assets.filter(id__in=set(list(asset_ids) + list(node_asset_ids)))
accounts = Account.objects.filter(asset__in=assets)
if username:

Loading…
Cancel
Save