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)