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 ..models import Domain, Gateway
|
||||
from .base import AuthSerializerMixin
|
||||
|
||||
|
||||
class DomainSerializer(BulkOrgResourceModelSerializer):
|
||||
|
@ -26,14 +27,14 @@ class DomainSerializer(BulkOrgResourceModelSerializer):
|
|||
return obj.gateway_set.all().count()
|
||||
|
||||
|
||||
class GatewaySerializer(BulkOrgResourceModelSerializer):
|
||||
class GatewaySerializer(AuthSerializerMixin, BulkOrgResourceModelSerializer):
|
||||
class Meta:
|
||||
model = Gateway
|
||||
list_serializer_class = AdaptedBulkListSerializer
|
||||
fields = [
|
||||
'id', 'name', 'ip', 'port', 'protocol', 'username',
|
||||
'domain', 'is_active', 'date_created', 'date_updated',
|
||||
'created_by', 'comment',
|
||||
'id', 'name', 'ip', 'port', 'protocol', 'username', 'password',
|
||||
'private_key', 'public_key', 'domain', 'is_active', 'date_created',
|
||||
'date_updated', 'created_by', 'comment',
|
||||
]
|
||||
|
||||
|
||||
|
|
|
@ -95,6 +95,32 @@ function protocolChange() {
|
|||
$(document).ready(function(){
|
||||
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(){
|
||||
protocolChange();
|
||||
});
|
||||
|
|
|
@ -132,6 +132,7 @@ class DomainGatewayCreateView(PermissionsMixin, CreateView):
|
|||
context = {
|
||||
'app': _('Assets'),
|
||||
'action': _('Create gateway'),
|
||||
'type': 'create'
|
||||
}
|
||||
kwargs.update(context)
|
||||
return super().get_context_data(**kwargs)
|
||||
|
@ -152,6 +153,7 @@ class DomainGatewayUpdateView(PermissionsMixin, UpdateView):
|
|||
context = {
|
||||
'app': _('Assets'),
|
||||
'action': _('Update gateway'),
|
||||
"type": "update"
|
||||
}
|
||||
kwargs.update(context)
|
||||
return super().get_context_data(**kwargs)
|
||||
|
|
Loading…
Reference in New Issue