mirror of https://github.com/jumpserver/jumpserver
Finish terminal accept
parent
775cd523eb
commit
d56f030dc4
|
@ -14,4 +14,6 @@ class TerminalForm(forms.ModelForm):
|
|||
help_texts = {
|
||||
'url': 'Example: ssh://192.168.1.1:22 or http://jms.jumpserver.org, that user login'
|
||||
}
|
||||
|
||||
widgets = {
|
||||
'name': forms.TextInput(attrs={'readonly': 'readonly'})
|
||||
}
|
|
@ -13,7 +13,7 @@ class Terminal(models.Model):
|
|||
)
|
||||
name = models.CharField(max_length=30, unique=True, verbose_name=_('Name'))
|
||||
remote_addr = models.GenericIPAddressField(verbose_name=_('Remote address'), blank=True, null=True)
|
||||
type = models.CharField(choices=TYPE_CHOICES, max_length=2, blank=True, verbose_name=_('Terminal type'))
|
||||
type = models.CharField(choices=TYPE_CHOICES, max_length=3, blank=True, verbose_name=_('Terminal type'))
|
||||
user = models.OneToOneField(User, verbose_name='Application user', null=True)
|
||||
url = models.CharField(max_length=100, blank=True, verbose_name=_('URL to login'))
|
||||
is_accepted = models.BooleanField(default=False, verbose_name='Is Accepted')
|
||||
|
@ -53,7 +53,7 @@ class Terminal(models.Model):
|
|||
__str__ = __unicode__
|
||||
|
||||
class Meta:
|
||||
db_table = 'applications'
|
||||
ordering = ('is_accepted',)
|
||||
|
||||
|
||||
class TerminalHeatbeat(models.Model):
|
||||
|
|
|
@ -2,15 +2,17 @@
|
|||
{% load i18n static %}
|
||||
{% block custom_head_css_js %}
|
||||
{{ block.super }}
|
||||
|
||||
<style>
|
||||
div.dataTables_wrapper div.dataTables_filter,
|
||||
.dataTables_length {
|
||||
float: right !important;
|
||||
}
|
||||
|
||||
div.dataTables_wrapper div.dataTables_filter {
|
||||
margin-left: 15px;
|
||||
}
|
||||
|
||||
#modal .modal-body { max-height: 200px; }
|
||||
</style>
|
||||
{% endblock %}
|
||||
{% block table_search %}{% endblock %}
|
||||
|
@ -36,6 +38,8 @@
|
|||
<tbody>
|
||||
</tbody>
|
||||
</table>
|
||||
{% include 'applications/terminal_modal_accept.html' %}
|
||||
|
||||
{% endblock %}
|
||||
{% block custom_foot_js %}
|
||||
<script src="{% static 'js/jquery.form.min.js' %}"></script>
|
||||
|
@ -70,7 +74,7 @@ $(document).ready(function(){
|
|||
var delete_btn = '<a class="btn btn-xs btn-danger m-l-xs btn_delete" data-uid="99991937" data-name="99991938">{% trans "Delete" %}</a>'
|
||||
.replace('99991937', cellData)
|
||||
.replace('99991938', rowData.name);
|
||||
var accept_btn = '<a href="" class="btn btn-xs btn-primary">{% trans "Accept" %}</a> '
|
||||
var accept_btn = '<a class="btn btn-xs btn-primary btn-accept" data-id="99991937">{% trans "Accept" %}</a> '
|
||||
.replace('99991937', cellData);
|
||||
var reject_btn = '<a href="" class="btn btn-xs btn-danger">{% trans "Reject" %}</a>'
|
||||
if (rowData.is_accepted) {
|
||||
|
@ -86,12 +90,47 @@ $(document).ready(function(){
|
|||
op_html: $('#actions').html()
|
||||
};
|
||||
jumpserver.initDataTable(options);
|
||||
|
||||
}).on('click', '.btn_delete', function(){
|
||||
var $this = $(this);
|
||||
var uid = $this.data('uid');
|
||||
var name = $(this).data('name');
|
||||
var the_url = '{% url "api-applications:terminal-detail" pk=99991937 %}'.replace('99991937', uid);
|
||||
objectDelete($this, name, the_url)
|
||||
|
||||
}).on('click', '.btn-accept', function () {
|
||||
var $this = $(this);
|
||||
var terminal_id = $this.data('id');
|
||||
var the_url = "{% url 'api-applications:terminal-detail' pk=99991937 %}".replace('99991937', terminal_id);
|
||||
var post_url = $('#form_terminal_accept').attr('action').replace('99991937', terminal_id);
|
||||
console.log(post_url);
|
||||
$.ajax({
|
||||
url: the_url,
|
||||
method: 'GET',
|
||||
success: function (data) {
|
||||
$('#id_name').val(data.name);
|
||||
$('#id_remote_addr').val(data.remote_addr);
|
||||
$('#id_type').val(data.type);
|
||||
$('#id_url').val(data.url);
|
||||
$('#id_comment').val(data.comment);
|
||||
$('#form_terminal_accept').attr('action', post_url)
|
||||
}
|
||||
});
|
||||
$('#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 === false) {
|
||||
console.log(data.msg);
|
||||
window.location.reload()
|
||||
|
||||
} else {
|
||||
console.log(data.msg);
|
||||
}
|
||||
}
|
||||
$form.ajaxSubmit({success: success});
|
||||
})
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
{% extends '_modal.html' %}
|
||||
{% load static %}
|
||||
{% load bootstrap %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block modal_body %}
|
||||
<form action="" method="post" class="form-horizontal">
|
||||
{% csrf_token %}
|
||||
{{ form.name|bootstrap_horizontal }}
|
||||
{{ form.remote_addr|bootstrap_horizontal }}
|
||||
{{ form.type|bootstrap_horizontal }}
|
||||
{{ form.url|bootstrap_horizontal }}
|
||||
{{ form.comment|bootstrap_horizontal }}
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-4 col-sm-offset-2">
|
||||
<button class="btn btn-default" type="reset"> {% trans 'Reset' %}</button>
|
||||
<button id="submit_button" class="btn btn-primary" type="submit">{% trans 'Submit' %}</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
||||
{% block custom_foot_js %}
|
||||
{% endblock %}
|
|
@ -0,0 +1,18 @@
|
|||
{% extends '_modal.html' %}
|
||||
{% load i18n %}
|
||||
{% block modal_id %}modal_terminal_accept{% endblock %}
|
||||
{% block modal_class %}modal-lg{% endblock %}
|
||||
{% 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">
|
||||
{% csrf_token %}
|
||||
{{ form.name|bootstrap_horizontal }}
|
||||
{{ form.remote_addr|bootstrap_horizontal }}
|
||||
{{ form.type|bootstrap_horizontal }}
|
||||
{{ form.url|bootstrap_horizontal }}
|
||||
{{ form.comment|bootstrap_horizontal }}
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
||||
{% block modal_confirm_id %}btn_terminal_accept{% endblock %}
|
|
@ -11,4 +11,5 @@ app_name = 'applications'
|
|||
urlpatterns = [
|
||||
url(r'^terminal$', views.TerminalListView.as_view(), name='terminal-list'),
|
||||
url(r'^terminal/(?P<pk>\d+)/update$', views.TerminalUpdateView.as_view(), name='terminal-update'),
|
||||
url(r'^terminal/(?P<pk>\d+)/modal/accept$', views.TerminalModelAccept.as_view(), name='terminal-modal-accept'),
|
||||
]
|
||||
|
|
|
@ -1,21 +1,28 @@
|
|||
# ~*~ coding: utf-8 ~*~
|
||||
#
|
||||
|
||||
from django.views.generic import ListView, UpdateView, DeleteView
|
||||
from django.views.generic import ListView, UpdateView, DeleteView, FormView
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.urls import reverse_lazy
|
||||
|
||||
from .models import Terminal
|
||||
from users.utils import AdminUserRequiredMixin
|
||||
from common.mixins import JSONResponseMixin
|
||||
from .forms import TerminalForm
|
||||
|
||||
|
||||
class TerminalListView(ListView):
|
||||
model = Terminal
|
||||
template_name = 'applications/terminal_list.html'
|
||||
form_class = TerminalForm
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(TerminalListView, self).get_context_data(**kwargs)
|
||||
context.update({'app': _('Terminal'), 'action': _('Terminal list')})
|
||||
context.update({
|
||||
'app': _('Terminal'),
|
||||
'action': _('Terminal list'),
|
||||
'form': self.form_class()
|
||||
})
|
||||
return context
|
||||
|
||||
|
||||
|
@ -34,4 +41,30 @@ class TerminalUpdateView(UpdateView):
|
|||
class TerminalDeleteView(DeleteView):
|
||||
model = Terminal
|
||||
template_name = 'assets/delete_confirm.html'
|
||||
success_url = reverse_lazy('applications:applications-list')
|
||||
success_url = reverse_lazy('applications:applications-list')
|
||||
|
||||
|
||||
class TerminalModelAccept(AdminUserRequiredMixin, JSONResponseMixin, UpdateView):
|
||||
model = Terminal
|
||||
form_class = TerminalForm
|
||||
|
||||
def form_valid(self, form):
|
||||
terminal = form.save()
|
||||
terminal.is_accepted = True
|
||||
terminal.save()
|
||||
data = {
|
||||
'success': True,
|
||||
'msg': 'success'
|
||||
}
|
||||
print('Valid')
|
||||
return self.render_json_response(data)
|
||||
|
||||
def form_invalid(self, form):
|
||||
print(form.errors)
|
||||
data = {
|
||||
'success': False,
|
||||
'msg': ','.join(form.errors)
|
||||
}
|
||||
return self.render_json_response(data)
|
||||
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
<body>
|
||||
<div id="wrapper">
|
||||
|
||||
{% include '_left_side_bar.html' %}
|
||||
<div id="page-wrapper" class="gray-bg">
|
||||
{% include '_header_bar.html' %}
|
||||
|
|
|
@ -132,8 +132,7 @@ $(document).ready(function(){
|
|||
$form.ajaxSubmit({success: success});
|
||||
})
|
||||
|
||||
})
|
||||
.on('click', '#btn_bulk_update', function(){
|
||||
}).on('click', '#btn_bulk_update', function(){
|
||||
var action = $('#slct_bulk_update').val();
|
||||
var $data_table = $('#user_list_table').DataTable();
|
||||
var id_list = [];
|
||||
|
@ -205,15 +204,13 @@ $(document).ready(function(){
|
|||
default:
|
||||
break;
|
||||
}
|
||||
})
|
||||
.on('click', '.btn_user_delete', function(){
|
||||
}).on('click', '.btn_user_delete', function(){
|
||||
var $this = $(this);
|
||||
var name = $this.data('name');
|
||||
var uid = $this.data('uid');
|
||||
var the_url = '{% url "api-users:user-detail" pk=99991937 %}'.replace('99991937', uid);
|
||||
objectDelete($this, name, the_url);
|
||||
})
|
||||
.on('click', '#btn_user_bulk_update', function(){
|
||||
}).on('click', '#btn_user_bulk_update', function(){
|
||||
var json_data = $('#fm_user_bulk_update').serializeObject();
|
||||
var body = {};
|
||||
body.enable_otp = (json_data.enable_otp === 'on')? true: false;
|
||||
|
|
Loading…
Reference in New Issue