From 4cbf6dd5e6f024f94910b186b4a23dcd7acf29c4 Mon Sep 17 00:00:00 2001 From: Michael Bai Date: Tue, 14 Dec 2021 19:00:28 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E7=94=A8=E6=88=B7=E8=AE=A4=E8=AF=81=E4=BF=A1?= =?UTF-8?q?=E6=81=AFAPI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assets/api/system_user.py | 3 ++- apps/assets/models/user.py | 11 ++++++++++- apps/authentication/api/connection_token.py | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/apps/assets/api/system_user.py b/apps/assets/api/system_user.py index 581800bec..912630b79 100644 --- a/apps/assets/api/system_user.py +++ b/apps/assets/api/system_user.py @@ -138,7 +138,8 @@ class SystemUserAppAuthInfoApi(generics.RetrieveAPIView): instance = super().get_object() app_id = self.kwargs.get('app_id') user_id = self.request.query_params.get("user_id") - instance.load_app_more_auth(app_id, user_id) + username = self.request.query_params.get("username") + instance.load_app_more_auth(app_id, username, user_id) return instance diff --git a/apps/assets/models/user.py b/apps/assets/models/user.py index 5e0384d01..7677c3f08 100644 --- a/apps/assets/models/user.py +++ b/apps/assets/models/user.py @@ -129,12 +129,21 @@ class AuthMixin: if password: self.password = password - def load_app_more_auth(self, app_id=None, user_id=None): + def load_app_more_auth(self, app_id=None, username=None, user_id=None): self._clean_auth_info_if_manual_login_mode() # 加载临时认证信息 if self.login_mode == self.LOGIN_MANUAL: self._load_tmp_auth_if_has(app_id, user_id) return + # 更新用户名 + from users.models import User + user = get_object_or_none(User, pk=user_id) if user_id else None + if self.username_same_with_user: + if user and not username: + _username = user.username + else: + _username = username + self.username = _username def load_asset_special_auth(self, asset, username=''): """ diff --git a/apps/authentication/api/connection_token.py b/apps/authentication/api/connection_token.py index 9001e8650..4adaa1942 100644 --- a/apps/authentication/api/connection_token.py +++ b/apps/authentication/api/connection_token.py @@ -294,7 +294,7 @@ class SecretDetailMixin: data.update(asset_detail) else: app_detail = self._get_application_secret_detail(app) - system_user.load_app_more_auth(app.id, user.id) + system_user.load_app_more_auth(app.id, user.username, user.id) data['type'] = 'application' data.update(app_detail)