mirror of https://github.com/jumpserver/jumpserver
fix: 修复 su-from-accounts API; 前端 Select2 组件初始化时 API 报错的问题;
修改原因: 前端使用 Select2 组件渲染更新账号的表单页面时,会默认先创建 spm 值, 后端调用 get_object 方法时,使用的queryset,就是spm所对应的queryset, 而 detail=True, 查询的值是当前 account_id,不在 queryset 中, 所以会导致调用父类的 get_object 方法报错,对象找不到pull/9169/head
parent
d252ee41ed
commit
58131a2b68
|
@ -1,13 +1,11 @@
|
|||
from django.shortcuts import get_object_or_404
|
||||
from rest_framework.decorators import action
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.generics import CreateAPIView, ListAPIView
|
||||
|
||||
from orgs.mixins.api import OrgBulkModelViewSet
|
||||
from rbac.permissions import RBACPermission
|
||||
|
||||
from common.mixins import RecordViewLogMixin
|
||||
from common.permissions import UserConfirmation
|
||||
from authentication.const import ConfirmType
|
||||
from assets.models import Account
|
||||
from assets.filters import AccountFilterSet
|
||||
from assets.tasks import verify_accounts_connectivity
|
||||
|
@ -32,7 +30,7 @@ class AccountViewSet(OrgBulkModelViewSet):
|
|||
|
||||
@action(methods=['get'], detail=True, url_path='su-from-accounts')
|
||||
def su_from_accounts(self, request, *args, **kwargs):
|
||||
account = super().get_object()
|
||||
account = get_object_or_404(Account, pk=self.kwargs['pk'])
|
||||
accounts = account.get_su_from_accounts()
|
||||
serializer = serializers.AccountSerializer(accounts, many=True)
|
||||
return Response(data=serializer.data)
|
||||
|
|
|
@ -60,7 +60,7 @@ class AccountSerializer(AccountSerializerCreateMixin, BaseAccountSerializer):
|
|||
)
|
||||
su_from = ObjectRelatedField(
|
||||
required=False, queryset=Account.objects, allow_null=True, allow_empty=True,
|
||||
label=_('Account'), attrs=('id', 'name', 'username')
|
||||
label=_('Su from'), attrs=('id', 'name', 'username')
|
||||
)
|
||||
|
||||
class Meta(BaseAccountSerializer.Meta):
|
||||
|
|
|
@ -8,6 +8,5 @@ from .. import api
|
|||
app_name = 'common'
|
||||
|
||||
urlpatterns = [
|
||||
path('resources/cache/',
|
||||
api.ResourcesIDCacheApi.as_view(), name='resources-cache'),
|
||||
path('resources/cache/', api.ResourcesIDCacheApi.as_view(), name='resources-cache'),
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue