mirror of https://github.com/jumpserver/jumpserver
perf: connectiontoken 添加 connect_options file_name_conflict_resolution参数 给koko处理冲冲突文件名 (#11535)
Co-authored-by: feng <1304903146@qq.com>pull/11519/head^2
parent
04e341a1bb
commit
d7ca1a09d4
|
@ -24,6 +24,8 @@ from orgs.mixins.api import RootOrgViewMixin
|
||||||
from perms.models import ActionChoices
|
from perms.models import ActionChoices
|
||||||
from terminal.connect_methods import NativeClient, ConnectMethodUtil
|
from terminal.connect_methods import NativeClient, ConnectMethodUtil
|
||||||
from terminal.models import EndpointRule, Endpoint
|
from terminal.models import EndpointRule, Endpoint
|
||||||
|
from users.const import FileNameConflictResolution
|
||||||
|
from users.models import Preference
|
||||||
from ..models import ConnectionToken, date_expired_default
|
from ..models import ConnectionToken, date_expired_default
|
||||||
from ..serializers import (
|
from ..serializers import (
|
||||||
ConnectionTokenSerializer, ConnectionTokenSecretSerializer,
|
ConnectionTokenSerializer, ConnectionTokenSecretSerializer,
|
||||||
|
@ -310,9 +312,20 @@ class ConnectionTokenViewSet(ExtraActionApiMixin, RootOrgViewMixin, JMSModelView
|
||||||
self.validate_serializer(serializer)
|
self.validate_serializer(serializer)
|
||||||
return super().perform_create(serializer)
|
return super().perform_create(serializer)
|
||||||
|
|
||||||
|
def _insert_connect_options(self, data):
|
||||||
|
name = 'file_name_conflict_resolution'
|
||||||
|
connect_options = data.pop('connect_options', {})
|
||||||
|
preference = Preference.objects.filter(
|
||||||
|
name=name, user=self.request.user, category='koko'
|
||||||
|
).first()
|
||||||
|
value = preference.value if preference else FileNameConflictResolution.REPLACE
|
||||||
|
connect_options[name] = value
|
||||||
|
data['connect_options'] = connect_options
|
||||||
|
|
||||||
def validate_serializer(self, serializer):
|
def validate_serializer(self, serializer):
|
||||||
data = serializer.validated_data
|
data = serializer.validated_data
|
||||||
user = self.get_user(serializer)
|
user = self.get_user(serializer)
|
||||||
|
self._insert_connect_options(data)
|
||||||
asset = data.get('asset')
|
asset = data.get('asset')
|
||||||
account_name = data.get('account')
|
account_name = data.get('account')
|
||||||
_data = self._validate(user, asset, account_name)
|
_data = self._validate(user, asset, account_name)
|
||||||
|
|
Loading…
Reference in New Issue