mirror of https://github.com/jumpserver/jumpserver
[Update] 创建/更新 网关使用api (#2911)
* [Update] 创建/更新 网关使用api * [Update] 修改小问题 * [Update] 修改小问题 * [Update] 修改网关一些信息可读pull/2926/head
parent
cedf0e4532
commit
6e86e3f118
|
@ -6,6 +6,7 @@ from common.serializers import AdaptedBulkListSerializer
|
||||||
from orgs.mixins import BulkOrgResourceModelSerializer
|
from orgs.mixins import BulkOrgResourceModelSerializer
|
||||||
|
|
||||||
from ..models import Domain, Gateway
|
from ..models import Domain, Gateway
|
||||||
|
from .base import AuthSerializerMixin
|
||||||
|
|
||||||
|
|
||||||
class DomainSerializer(BulkOrgResourceModelSerializer):
|
class DomainSerializer(BulkOrgResourceModelSerializer):
|
||||||
|
@ -26,14 +27,14 @@ class DomainSerializer(BulkOrgResourceModelSerializer):
|
||||||
return obj.gateway_set.all().count()
|
return obj.gateway_set.all().count()
|
||||||
|
|
||||||
|
|
||||||
class GatewaySerializer(BulkOrgResourceModelSerializer):
|
class GatewaySerializer(AuthSerializerMixin, BulkOrgResourceModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Gateway
|
model = Gateway
|
||||||
list_serializer_class = AdaptedBulkListSerializer
|
list_serializer_class = AdaptedBulkListSerializer
|
||||||
fields = [
|
fields = [
|
||||||
'id', 'name', 'ip', 'port', 'protocol', 'username',
|
'id', 'name', 'ip', 'port', 'protocol', 'username', 'password',
|
||||||
'domain', 'is_active', 'date_created', 'date_updated',
|
'private_key', 'public_key', 'domain', 'is_active', 'date_created',
|
||||||
'created_by', 'comment',
|
'date_updated', 'created_by', 'comment',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -95,6 +95,32 @@ function protocolChange() {
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
protocolChange();
|
protocolChange();
|
||||||
})
|
})
|
||||||
|
.on("submit", "form", function (evt) {
|
||||||
|
evt.preventDefault();
|
||||||
|
var form = $("form");
|
||||||
|
var data = form.serializeObject();
|
||||||
|
data["private_key"] = $("#id_private_key_file").data('file');
|
||||||
|
var method = "POST";
|
||||||
|
var the_url = '{% url "api-assets:gateway-list" %}';
|
||||||
|
var redirect_to = '{% url "assets:domain-gateway-list" pk=DEFAULT_PK %}'.replace("{{ DEFAULT_PK }}", data.domain);
|
||||||
|
{% if type == "update" %}
|
||||||
|
the_url = '{% url 'api-assets:gateway-detail' pk=object.id %}';
|
||||||
|
method = "PUT";
|
||||||
|
{% endif %}
|
||||||
|
var props = {
|
||||||
|
url:the_url,
|
||||||
|
data:data,
|
||||||
|
method:method,
|
||||||
|
form:form,
|
||||||
|
redirect_to:redirect_to
|
||||||
|
};
|
||||||
|
formSubmit(props);
|
||||||
|
})
|
||||||
|
.on('change', '#id_private_key_file', function () {
|
||||||
|
readFile($(this)).on("onload", function (evt, data) {
|
||||||
|
$(this).attr("data-file", data)
|
||||||
|
})
|
||||||
|
})
|
||||||
.on('change', protocol_id, function(){
|
.on('change', protocol_id, function(){
|
||||||
protocolChange();
|
protocolChange();
|
||||||
});
|
});
|
||||||
|
|
|
@ -132,6 +132,7 @@ class DomainGatewayCreateView(PermissionsMixin, CreateView):
|
||||||
context = {
|
context = {
|
||||||
'app': _('Assets'),
|
'app': _('Assets'),
|
||||||
'action': _('Create gateway'),
|
'action': _('Create gateway'),
|
||||||
|
'type': 'create'
|
||||||
}
|
}
|
||||||
kwargs.update(context)
|
kwargs.update(context)
|
||||||
return super().get_context_data(**kwargs)
|
return super().get_context_data(**kwargs)
|
||||||
|
@ -152,6 +153,7 @@ class DomainGatewayUpdateView(PermissionsMixin, UpdateView):
|
||||||
context = {
|
context = {
|
||||||
'app': _('Assets'),
|
'app': _('Assets'),
|
||||||
'action': _('Update gateway'),
|
'action': _('Update gateway'),
|
||||||
|
"type": "update"
|
||||||
}
|
}
|
||||||
kwargs.update(context)
|
kwargs.update(context)
|
||||||
return super().get_context_data(**kwargs)
|
return super().get_context_data(**kwargs)
|
||||||
|
|
Loading…
Reference in New Issue