From 6bde31cdd0cdbe462e405c2e9b3990bf1ed28fad Mon Sep 17 00:00:00 2001 From: "Jiangjie.Bai" Date: Tue, 22 Mar 2022 18:42:11 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E8=BF=9C=E7=A8=8B=E5=BA=94=E7=94=A8=E8=AE=A4=E8=AF=81=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/applications/models/application.py | 9 +++++---- apps/assets/models/user.py | 13 +++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/apps/applications/models/application.py b/apps/applications/models/application.py index a6552fffd..4cb488e23 100644 --- a/apps/applications/models/application.py +++ b/apps/applications/models/application.py @@ -8,6 +8,7 @@ from django.conf import settings from orgs.mixins.models import OrgModelMixin from common.mixins import CommonModelMixin from common.tree import TreeNode +from common.utils import is_uuid from assets.models import Asset, SystemUser from ..utils import KubernetesTree @@ -267,12 +268,12 @@ class Application(CommonModelMixin, OrgModelMixin, ApplicationTreeNodeMixin): 'parameters': parameters } - def get_remote_app_asset(self): + def get_remote_app_asset(self, raise_exception=True): asset_id = self.attrs.get('asset') - if not asset_id: + if is_uuid(asset_id): + return Asset.objects.filter(id=asset_id).first() + if raise_exception: raise ValueError("Remote App not has asset attr") - asset = Asset.objects.filter(id=asset_id).first() - return asset class ApplicationUser(SystemUser): diff --git a/apps/assets/models/user.py b/apps/assets/models/user.py index 678e5f8cf..ce0029768 100644 --- a/apps/assets/models/user.py +++ b/apps/assets/models/user.py @@ -133,6 +133,14 @@ class AuthMixin: self.password = password def load_app_more_auth(self, app_id=None, username=None, user_id=None): + from applications.models import Application + app = get_object_or_none(Application, pk=app_id) + if app and app.category_remote_app: + # Remote app + self._load_remoteapp_more_auth(app, username, user_id) + return + + # Other app self._clean_auth_info_if_manual_login_mode() # 加载临时认证信息 if self.login_mode == self.LOGIN_MANUAL: @@ -148,6 +156,11 @@ class AuthMixin: _username = username self.username = _username + def _load_remoteapp_more_auth(self, app, username, user_id): + asset = app.get_remote_app_asset(raise_exception=False) + if asset: + self.load_asset_more_auth(asset_id=asset.id, username=username, user_id=user_id) + def load_asset_special_auth(self, asset, username=''): """ AuthBook 的数据状态