diff --git a/apps/assets/api/account/template.py b/apps/assets/api/account/template.py index dd9ee1d00..aa3be6b4f 100644 --- a/apps/assets/api/account/template.py +++ b/apps/assets/api/account/template.py @@ -1,9 +1,6 @@ from assets import serializers from assets.models import AccountTemplate -from rbac.permissions import RBACPermission -from authentication.const import ConfirmType from common.mixins import RecordViewLogMixin -from common.permissions import UserConfirmation from orgs.mixins.api import OrgBulkModelViewSet diff --git a/apps/assets/models/account.py b/apps/assets/models/account.py index b3742682d..68a6fa47e 100644 --- a/apps/assets/models/account.py +++ b/apps/assets/models/account.py @@ -82,6 +82,10 @@ class Account(AbsConnectivity, BaseAccount): def __str__(self): return '{}'.format(self.username) + @lazyproperty + def has_secret(self): + return bool(self.secret) + @classmethod def get_manual_account(cls): """ @INPUT 手动登录的账号(any) """ diff --git a/apps/assets/serializers/account/base.py b/apps/assets/serializers/account/base.py index c0e3553e8..becfd4df9 100644 --- a/apps/assets/serializers/account/base.py +++ b/apps/assets/serializers/account/base.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- from django.utils.translation import gettext_lazy as _ +from rest_framework import serializers from assets.models import BaseAccount from assets.serializers.base import AuthValidateMixin @@ -9,6 +10,8 @@ __all__ = ['BaseAccountSerializer'] class BaseAccountSerializer(AuthValidateMixin, BulkOrgResourceModelSerializer): + has_secret = serializers.BooleanField(label=_("Has secret"), read_only=True) + class Meta: model = BaseAccount fields_mini = ['id', 'name', 'username'] diff --git a/apps/assets/serializers/account/template.py b/apps/assets/serializers/account/template.py index 7a7de7f11..9227b5585 100644 --- a/apps/assets/serializers/account/template.py +++ b/apps/assets/serializers/account/template.py @@ -1,5 +1,5 @@ -from common.drf.serializers import SecretReadableMixin from assets.models import AccountTemplate +from common.drf.serializers import SecretReadableMixin from .base import BaseAccountSerializer