|
|
|
@ -24,6 +24,8 @@ from orgs.mixins.api import RootOrgViewMixin
|
|
|
|
|
from perms.models import ActionChoices
|
|
|
|
|
from terminal.connect_methods import NativeClient, ConnectMethodUtil
|
|
|
|
|
from terminal.models import EndpointRule, Endpoint
|
|
|
|
|
from users.const import FileNameConflictResolution
|
|
|
|
|
from users.models import Preference
|
|
|
|
|
from ..models import ConnectionToken, date_expired_default
|
|
|
|
|
from ..serializers import (
|
|
|
|
|
ConnectionTokenSerializer, ConnectionTokenSecretSerializer,
|
|
|
|
@ -310,9 +312,20 @@ class ConnectionTokenViewSet(ExtraActionApiMixin, RootOrgViewMixin, JMSModelView
|
|
|
|
|
self.validate_serializer(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):
|
|
|
|
|
data = serializer.validated_data
|
|
|
|
|
user = self.get_user(serializer)
|
|
|
|
|
self._insert_connect_options(data)
|
|
|
|
|
asset = data.get('asset')
|
|
|
|
|
account_name = data.get('account')
|
|
|
|
|
_data = self._validate(user, asset, account_name)
|
|
|
|
|