mirror of https://github.com/jumpserver/jumpserver
Finish form ajax submmit
parent
301e02bcd8
commit
0907f5021e
|
@ -38,14 +38,6 @@ class Terminal(models.Model):
|
|||
self.save()
|
||||
return user, access_key
|
||||
|
||||
@property
|
||||
def is_superuser(self):
|
||||
return False
|
||||
|
||||
@property
|
||||
def is_terminal(self):
|
||||
return True
|
||||
|
||||
def __unicode__(self):
|
||||
active = 'Active' if self.user and self.user.is_active else 'Disabled'
|
||||
return '%s: %s' % (self.name, active)
|
||||
|
|
|
@ -91,6 +91,18 @@ $(document).ready(function(){
|
|||
};
|
||||
jumpserver.initDataTable(options);
|
||||
|
||||
$('#btn_terminal_accept').click(function () {
|
||||
var $form = $('#form_terminal_accept');
|
||||
function success(data, textStatus, jqXHR) {
|
||||
if (data.success === true) {
|
||||
window.location.reload()
|
||||
} else {
|
||||
$('#modal-error').html(data.msg).css('display', 'block');
|
||||
}
|
||||
}
|
||||
$form.ajaxSubmit({success: success});
|
||||
})
|
||||
|
||||
}).on('click', '.btn_delete', function(){
|
||||
var $this = $(this);
|
||||
var uid = $this.data('uid');
|
||||
|
@ -119,16 +131,6 @@ $(document).ready(function(){
|
|||
$('#modal_terminal_accept').modal({
|
||||
show: true
|
||||
});
|
||||
}).on('click', '#btn_terminal_accept', function () {
|
||||
var $form = $('#form_terminal_accept');
|
||||
function success (data, textStatus, jqXHR) {
|
||||
if (data.success === true) {
|
||||
window.location.reload()
|
||||
} else {
|
||||
$('#modal-error').html(data.msg).css('display', 'block');
|
||||
}
|
||||
}
|
||||
$form.ajaxSubmit({success: success});
|
||||
})
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
{% block modal_title%}{% trans "Accept terminal registration" %}{% endblock %}
|
||||
{% block modal_body %}
|
||||
{% load bootstrap %}
|
||||
<form action="{% url 'applications:terminal-modal-accept' pk="99991937" %}" method="post" class="form-horizontal" id="form_terminal_accept">
|
||||
<form action="{% url 'applications:terminal-modal-accept' pk="99991937" %}" method="post" class="form-horizontal" id="form_terminal_accept" enctype="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
<p class="alert alert-danger" id="modal-error" style="display: none"></p>
|
||||
{{ form.name|bootstrap_horizontal }}
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
<form action="" method="post">
|
||||
{% csrf_token %}
|
||||
{{ form }}
|
||||
<input type="submit" value="Submit">
|
||||
</form>
|
|
@ -18,4 +18,4 @@ urlpatterns = [
|
|||
# url(r'^v1/terminal/heatbeat/$', api.TestHeatbeat.as_view())
|
||||
]
|
||||
|
||||
urlpatterns += router.urls
|
||||
urlpatterns += router.urls
|
||||
|
|
|
@ -45,9 +45,10 @@ class TerminalDeleteView(DeleteView):
|
|||
success_url = reverse_lazy('applications:applications-list')
|
||||
|
||||
|
||||
class TerminalModelAccept(AdminUserRequiredMixin, JSONResponseMixin, BaseUpdateView):
|
||||
class TerminalModelAccept(AdminUserRequiredMixin, JSONResponseMixin, UpdateView):
|
||||
model = Terminal
|
||||
form_class = TerminalForm
|
||||
template_name = 'applications/terminal_modal_test.html'
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
print(request.POST)
|
||||
|
|
|
@ -3,11 +3,22 @@
|
|||
|
||||
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from rest_framework import generics, viewsets
|
||||
from rest_framework.views import APIView, Response
|
||||
|
||||
from . import models, serializers
|
||||
from .hands import IsSuperUserOrAppUser, Terminal
|
||||
from .hands import IsSuperUserOrAppUser, Terminal, IsAppUser
|
||||
|
||||
|
||||
class ProxyLogReceiveView(generics.CreateAPIView):
|
||||
queryset = models.ProxyLog.objects.all()
|
||||
serializer_class = serializers.ProxyLogSerializer
|
||||
permission_classes = (IsAppUser,)
|
||||
|
||||
def get_serializer(self, *args, **kwargs):
|
||||
kwargs['data']['terminal'] = self.request.user.terminal.name
|
||||
return super(ProxyLogReceiveView, self).get_serializer(*args, **kwargs)
|
||||
|
||||
|
||||
class ProxyLogViewSet(viewsets.ModelViewSet):
|
||||
|
@ -18,7 +29,7 @@ class ProxyLogViewSet(viewsets.ModelViewSet):
|
|||
"name": "",
|
||||
"hostname": "",
|
||||
"ip": "",
|
||||
"applications", "",
|
||||
"terminal": "",
|
||||
"login_type": "",
|
||||
"system_user": "",
|
||||
"was_failed": "",
|
||||
|
|
|
@ -4,5 +4,5 @@
|
|||
from users.utils import AdminUserRequiredMixin
|
||||
from users.models import User
|
||||
from assets.models import Asset, SystemUser
|
||||
from users.permissions import IsSuperUserOrAppUser
|
||||
from users.permissions import IsSuperUserOrAppUser, IsAppUser
|
||||
from applications.models import Terminal
|
||||
|
|
|
@ -45,7 +45,7 @@ class ProxyLog(models.Model):
|
|||
log_file = models.CharField(max_length=1000, blank=True, null=True)
|
||||
was_failed = models.BooleanField(default=False, verbose_name=_('Did connect failed'))
|
||||
is_finished = models.BooleanField(default=False, verbose_name=_('Is finished'))
|
||||
date_start = models.DateTimeField(verbose_name=_('Date start'))
|
||||
date_start = models.DateTimeField(auto_created=True, verbose_name=_('Date start'))
|
||||
date_finished = models.DateTimeField(null=True, verbose_name=_('Date finished'))
|
||||
|
||||
def __unicode__(self):
|
||||
|
@ -54,16 +54,14 @@ class ProxyLog(models.Model):
|
|||
@property
|
||||
def commands_dict(self):
|
||||
commands = self.command_log.all()
|
||||
return [
|
||||
{
|
||||
"command_no": command.command_no,
|
||||
"command": command.command,
|
||||
"output": command.output_decode,
|
||||
"datetime": command.datetime,
|
||||
return [{
|
||||
"command_no": command.command_no,
|
||||
"command": command.command,
|
||||
"output": command.output_decode,
|
||||
"datetime": command.datetime,
|
||||
} for command in commands]
|
||||
|
||||
class Meta:
|
||||
db_table = 'proxy_log'
|
||||
ordering = ['-date_start', 'username']
|
||||
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ class ProxyLogSerializer(serializers.ModelSerializer):
|
|||
|
||||
class Meta:
|
||||
model = models.ProxyLog
|
||||
fields = ['id', 'name', 'username', 'hostname', 'ip', 'system_user', 'login_type', 'applications',
|
||||
fields = ['id', 'name', 'username', 'hostname', 'ip', 'system_user', 'login_type', 'terminal',
|
||||
'log_file', 'was_failed', 'is_finished', 'date_start', 'date_finished', 'time',
|
||||
'command_length', "commands_dict"]
|
||||
|
||||
|
|
|
@ -5,10 +5,12 @@ from .. import api
|
|||
|
||||
app_name = 'audits'
|
||||
|
||||
|
||||
router = routers.DefaultRouter()
|
||||
router.register(r'v1/proxy-log/', api.ProxyLogViewSet, 'proxy-log')
|
||||
router.register(r'v1/command-log/', api.CommandLogViewSet, 'command-log')
|
||||
router.register(r'v1/proxy-log', api.ProxyLogViewSet, 'proxy-log')
|
||||
router.register(r'v1/command-log', api.CommandLogViewSet, 'command-log')
|
||||
|
||||
urlpatterns = router.urls
|
||||
urlpatterns = [
|
||||
url(r'^v1/proxy-log/receive/$', api.ProxyLogReceiveView.as_view(), name='proxy-log-receive'),
|
||||
]
|
||||
|
||||
urlpatterns += router.urls
|
||||
|
|
|
@ -2,7 +2,7 @@ Django==1.10
|
|||
django-bootstrap-form==3.2.1
|
||||
logging==0.4.9.6
|
||||
Pillow==3.3.1
|
||||
djangorestframework==3.4.5
|
||||
djangorestframework==3.5.3
|
||||
ForgeryPy==0.1
|
||||
openpyxl==2.4.0
|
||||
celery==3.1.23
|
||||
|
|
Loading…
Reference in New Issue