Commit b4f23f97 authored by ibuler's avatar ibuler

Merge branch 'dev' of github.com:jumpserver/jumpserver into dev

parents 1cdcc66d 3f3cc635
......@@ -21,7 +21,7 @@ class Migration(migrations.Migration):
('org_id', models.CharField(blank=True, db_index=True, default='', max_length=36, verbose_name='Organization')),
('id', models.UUIDField(default=uuid.uuid4, primary_key=True, serialize=False)),
('name', models.CharField(max_length=128, verbose_name='Name')),
('type', models.CharField(choices=[('Browser', (('chrome', 'Chrome'),)), ('Database tools', (('mysql_workbench', 'MySQL Workbench'),)), ('Virtualization tools', (('vmware_client', 'VMware Client'),)), ('custom', 'Custom')], default='chrome', max_length=128, verbose_name='App type')),
('type', models.CharField(choices=[('Browser', (('chrome', 'Chrome'),)), ('Database tools', (('mysql_workbench', 'MySQL Workbench'),)), ('Virtualization tools', (('vmware_client', 'vSphere Client'),)), ('custom', 'Custom')], default='chrome', max_length=128, verbose_name='App type')),
('path', models.CharField(max_length=128, verbose_name='App path')),
('params', common.fields.model.EncryptJsonDictTextField(blank=True, default={}, max_length=4096, null=True, verbose_name='Parameters')),
('created_by', models.CharField(blank=True, max_length=32, null=True, verbose_name='Created by')),
......
......@@ -51,7 +51,7 @@ class AssetViewSet(IDInCacheFilterMixin, LabelFilter, BulkModelViewSet):
def set_assets_node(self, assets):
if not isinstance(assets, list):
assets = [assets]
node = Node.objects.get(value='Default')
node = Node.root()
node_id = self.request.query_params.get('node_id')
if node_id:
node = get_object_or_none(Node, pk=node_id)
......
......@@ -63,7 +63,8 @@
{% block content_bottom_left %}{% endblock %}
{% block custom_foot_js %}
<script>
$(document).ready(function(){
var admin_user_table = 0;
function initTable() {
var options = {
ele: $('#admin_user_list_table'),
columnDefs: [
......@@ -116,7 +117,12 @@ $(document).ready(function(){
columns: [{data: function(){return ""}}, {data: "name"}, {data: "username" }, {data: "assets_amount" },
{data: "reachable_amount"}, {data: "unreachable_amount"}, {data: "id"}, {data: "comment"}, {data: "id"}]
};
jumpserver.initServerSideDataTable(options)
admin_user_table = jumpserver.initServerSideDataTable(options);
return admin_user_table
}
$(document).ready(function(){
initTable()
})
.on('click', '.btn_admin_user_delete', function () {
......@@ -132,12 +138,7 @@ $(document).ready(function(){
})
.on('click', '.btn_export', function(){
var data_table = $('#admin_user_list_table').DataTable();
var rows = data_table.rows('.selected').data();
var admin_users = [];
$.each(rows, function (index, obj) {
admin_users.push(obj.id)
});
var admin_users = admin_user_table.selected;
var data = {
'resources': admin_users
};
......@@ -168,14 +169,7 @@ $(document).ready(function(){
});
})
.on('click', '#download_update_template', function () {
var $data_table = $('#admin_user_list_table').DataTable();
var rows = $data_table.rows('.selected').data();
var admin_users = [];
$.each(rows, function (index, obj) {
admin_users.push(obj.id)
});
var admin_users = admin_user_table.selected;
var data = {
'resources': admin_users
};
......
......@@ -469,14 +469,7 @@ $(document).ready(function(){
asset_table.search(val).draw();
})
.on('click', '.btn_export', function () {
var $data_table = $('#asset_list_table').DataTable();
var rows = $data_table.rows('.selected').data();
var assets = [];
$.each(rows, function (index, obj) {
assets.push(obj.id)
});
var assets = asset_table.selected;
var data = {
'resources': assets
};
......@@ -513,14 +506,7 @@ $(document).ready(function(){
});
})
.on('click', '#download_update_template', function () {
var $data_table = $('#asset_list_table').DataTable();
var rows = $data_table.rows('.selected').data();
var assets = [];
$.each(rows, function (index, obj) {
assets.push(obj.id)
});
var assets = asset_table.selected;
var data = {
'resources': assets
};
......@@ -639,11 +625,7 @@ $(document).ready(function(){
})
.on('click', '#btn_bulk_update', function () {
var action = $('#slct_bulk_update').val();
var $data_table = $('#asset_list_table').DataTable();
var id_list = [];
$data_table.rows({selected: true}).every(function(){
id_list.push(this.data().id);
});
var id_list = asset_table.selected;
if (id_list.length === 0) {
return false;
}
......
......@@ -68,6 +68,7 @@
{% endblock %}
{% block custom_foot_js %}
<script>
var system_user_table = 0;
function initTable() {
var options = {
ele: $('#system_user_list_table'),
......@@ -125,7 +126,8 @@ function initTable() {
],
op_html: $('#actions').html()
};
jumpserver.initServerSideDataTable(options);
system_user_table = jumpserver.initServerSideDataTable(options);
return system_user_table
}
$(document).ready(function(){
......@@ -198,12 +200,7 @@ $(document).ready(function(){
}
})
.on('click', '.btn_export', function () {
var data_table = $('#system_user_list_table').DataTable();
var rows = data_table.rows('.selected').data();
var system_users = [];
$.each(rows, function (index, obj) {
system_users.push(obj.id)
});
var system_users = system_user_table.selected;
var data = {
'resources': system_users
};
......@@ -235,12 +232,7 @@ $(document).ready(function(){
});
})
.on('click', '#download_update_template', function () {
var data_table = $('#system_user_list_table').DataTable();
var rows = data_table.rows('.selected').data();
var system_users = [];
$.each(rows, function (index, obj) {
system_users.push(obj.id)
});
var system_users = system_user_table.selected;
var data = {
'resources': system_users
};
......
# -*- coding: utf-8 -*-
#
VERSION = '1.4.10'
VERSION = '1.5.0'
......@@ -212,5 +212,7 @@ class OrgResourceSerializerMixin(serializers.Serializer):
"""
通过API批量操作资源时, 自动给每个资源添加所需属性org_id的值为current_org_id
(同时为serializer.is_valid()对Model的unique_together校验做准备)
由于HiddenField字段不可读,API获取资产信息时获取不到org_id,
但是coco需要资产的org_id字段,所以修改为CharField类型
"""
org_id = serializers.HiddenField(default=get_current_org_id)
org_id = serializers.CharField(default=get_current_org_id)
......@@ -102,10 +102,10 @@ class RemoteAppPermissionUserView(AdminUserRequiredMixin,
'app': _('Perms'),
'action': _('RemoteApp permission user list'),
'users_remain': current_org.get_org_users().exclude(
remoteapppermissions=self.object
remoteapppermission=self.object
),
'user_groups_remain': UserGroup.objects.exclude(
remoteapppermissions=self.object
remoteapppermission=self.object
)
}
kwargs.update(context)
......
......@@ -5,7 +5,9 @@ import os
import json
import jms_storage
from rest_framework import generics
from rest_framework.views import Response, APIView
from rest_framework.pagination import LimitOffsetPagination
from django.conf import settings
from django.core.mail import send_mail
from django.utils.translation import ugettext_lazy as _
......@@ -89,19 +91,55 @@ class LDAPTestingAPI(APIView):
return Response({"error": "Have user but attr mapping error"}, status=401)
class LDAPUserListApi(APIView):
class LDAPUserListApi(generics.ListAPIView):
pagination_class = LimitOffsetPagination
permission_classes = (IsOrgAdmin,)
def get(self, request):
def get_queryset(self):
util = LDAPUtil()
try:
users = util.search_user_items()
except Exception as e:
users = []
logger.error(e, exc_info=True)
# 前端data_table会根据row.id对table.selected值进行操作
for user in users:
user['id'] = user['username']
return users
def filter_queryset(self, queryset):
search = self.request.query_params.get('search')
if not search:
return queryset
search = search.lower()
queryset = [
q for q in queryset
if
search in q['username'].lower()
or search in q['name'].lower()
or search in q['email'].lower()
]
return queryset
def sort_queryset(self, queryset):
order_by = self.request.query_params.get('order')
if not order_by:
order_by = 'existing'
if order_by.startswith('-'):
order_by = order_by.lstrip('-')
reverse = True
else:
users = sorted(users, key=lambda u: (u['existing'], u['username']))
return Response(users)
reverse = False
queryset = sorted(queryset, key=lambda x: x[order_by], reverse=reverse)
return queryset
def list(self, request, *args, **kwargs):
queryset = self.filter_queryset(self.get_queryset())
queryset = self.sort_queryset(queryset)
page = self.paginate_queryset(queryset)
if page is not None:
return self.get_paginated_response(page)
return Response(queryset)
class LDAPUserSyncAPI(APIView):
......
......@@ -52,7 +52,7 @@
var ldap_users_table = 0;
function initLdapUsersTable() {
if(ldap_users_table){
return
return ldap_users_table
}
var options = {
ele: $('#ldap_list_users_table'),
......@@ -73,10 +73,10 @@ function initLdapUsersTable() {
{data: "username" },{data: "username" }, {data: "name" },
{data:"email"}, {data:'existing'}
],
pageLength: 10
pageLength: 15
};
ldap_users_table = jumpserver.initDataTable(options);
ldap_users_table = jumpserver.initServerSideDataTable(options);
return ldap_users_table
}
......
......@@ -110,10 +110,7 @@ $(document).ready(function () {
});
})
.on("click","#btn_ldap_modal_confirm",function () {
var username_list=[];
$("tbody input[type='checkbox']:checked").each(function () {
username_list.push($(this).attr('id'));
});
var username_list = ldap_users_table.selected;
if (username_list.length === 0){
var msg = "{% trans 'User is not currently selected, please check the user you want to import'%}";
......
......@@ -61,7 +61,6 @@ class LDAPUtil:
try:
user = User.objects.get(username=username)
except Exception as e:
logger.info(e)
return None
else:
return user
......
......@@ -21,13 +21,7 @@ class UserCheckOtpCodeForm(forms.Form):
otp_code = forms.CharField(label=_('MFA code'), max_length=6)
class UserCreateUpdateForm(OrgModelForm):
EMAIL_SET_PASSWORD = _('Reset link will be generated and sent to the user')
CUSTOM_PASSWORD = _('Set password')
PASSWORD_STRATEGY_CHOICES = (
(0, EMAIL_SET_PASSWORD),
(1, CUSTOM_PASSWORD)
)
class UserCreateUpdateFormMixin(OrgModelForm):
role_choices = ((i, n) for i, n in User.ROLE_CHOICES if i != User.ROLE_APP)
password = forms.CharField(
label=_('Password'), widget=forms.PasswordInput,
......@@ -42,10 +36,6 @@ class UserCreateUpdateForm(OrgModelForm):
widget=forms.Textarea(attrs={'placeholder': _('ssh-rsa AAAA...')}),
help_text=_('Paste user id_rsa.pub here.')
)
password_strategy = forms.ChoiceField(
choices=PASSWORD_STRATEGY_CHOICES, required=True, initial=0,
widget=forms.RadioSelect(), label=_('Password strategy')
)
class Meta:
model = User
......@@ -65,7 +55,7 @@ class UserCreateUpdateForm(OrgModelForm):
def __init__(self, *args, **kwargs):
self.request = kwargs.pop("request", None)
super(UserCreateUpdateForm, self).__init__(*args, **kwargs)
super(UserCreateUpdateFormMixin, self).__init__(*args, **kwargs)
roles = []
# Super admin user
......@@ -115,6 +105,23 @@ class UserCreateUpdateForm(OrgModelForm):
return user
class UserCreateForm(UserCreateUpdateFormMixin):
EMAIL_SET_PASSWORD = _('Reset link will be generated and sent to the user')
CUSTOM_PASSWORD = _('Set password')
PASSWORD_STRATEGY_CHOICES = (
(0, EMAIL_SET_PASSWORD),
(1, CUSTOM_PASSWORD)
)
password_strategy = forms.ChoiceField(
choices=PASSWORD_STRATEGY_CHOICES, required=True, initial=0,
widget=forms.RadioSelect(), label=_('Password strategy')
)
class UserUpdateForm(UserCreateUpdateFormMixin):
pass
class UserProfileForm(forms.ModelForm):
username = forms.CharField(disabled=True)
name = forms.CharField(disabled=True)
......
......@@ -46,7 +46,8 @@
{% block content_bottom_left %}{% endblock %}
{% block custom_foot_js %}
<script>
$(document).ready(function() {
var groups_table = 0;
function initTable() {
var options = {
ele: $('#group_list_table'),
buttons: [],
......@@ -84,7 +85,11 @@ $(document).ready(function() {
order: [],
op_html: $('#actions').html()
};
jumpserver.initServerSideDataTable(options);
groups_table = jumpserver.initServerSideDataTable(options);
return groups_table
}
$(document).ready(function() {
initTable()
}).on('click', '.btn_delete_user_group', function(){
var $this = $(this);
......@@ -136,12 +141,7 @@ $(document).ready(function() {
break;
}
}).on('click', '.btn_export', function(){
var data_table = $('#group_list_table').DataTable();
var rows = data_table.rows('.selected').data();
var groups = [];
$.each(rows, function (index, obj) {
groups.push(obj.id)
});
var groups = groups_table.selected;
var data = {
'resources': groups
};
......@@ -172,12 +172,7 @@ $(document).ready(function() {
});
})
.on('click', '#download_update_template', function(){
var data_table = $('#group_list_table').DataTable();
var rows = data_table.rows('.selected').data();
var groups = [];
$.each(rows, function (index, obj) {
groups.push(obj.id)
});
var groups = groups_table.selected;
var data = {
'resources': groups
};
......
......@@ -66,7 +66,7 @@
{% block custom_foot_js %}
<script src="{% static 'js/jquery.form.min.js' %}"></script>
<script>
var users_table = 0;
function initTable() {
var options = {
ele: $('#user_list_table'),
......@@ -122,23 +122,19 @@ function initTable() {
],
op_html: $('#actions').html()
};
var table = jumpserver.initServerSideDataTable(options);
return table
users_table = jumpserver.initServerSideDataTable(options);
return users_table
}
$(document).ready(function(){
var table = initTable();
initTable();
var fields = $('#fm_user_bulk_update .form-group');
$.each(fields, function (index, value) {
console.log(value)
});
$('.btn_export').click(function () {
var rows = table.rows('.selected').data();
var users = [];
$.each(rows, function (index, obj) {
users.push(obj.id)
});
var users = users_table.selected;
var data = {
'resources': users
};
......@@ -171,11 +167,7 @@ $(document).ready(function(){
});
});
$('#download_update_template').click(function () {
var rows = table.rows('.selected').data();
var users = [];
$.each(rows, function (index, obj) {
users.push(obj.id)
});
var users = users_table.selected;
var data = {
'resources': users
};
......@@ -209,11 +201,7 @@ $(document).ready(function(){
}).on('click', '#btn_bulk_update', function(){
var action = $('#slct_bulk_update').val();
var $data_table = $('#user_list_table').DataTable();
var id_list = [];
$data_table.rows({selected: true}).every(function(){
id_list.push(this.data().id);
});
var id_list = users_table.selected;
if (id_list.length === 0) {
return false;
}
......
......@@ -75,7 +75,7 @@ class UserListView(AdminUserRequiredMixin, TemplateView):
class UserCreateView(AdminUserRequiredMixin, SuccessMessageMixin, CreateView):
model = User
form_class = forms.UserCreateUpdateForm
form_class = forms.UserCreateForm
template_name = 'users/user_create.html'
success_url = reverse_lazy('users:user-list')
success_message = create_success_msg
......@@ -108,7 +108,7 @@ class UserCreateView(AdminUserRequiredMixin, SuccessMessageMixin, CreateView):
class UserUpdateView(AdminUserRequiredMixin, SuccessMessageMixin, UpdateView):
model = User
form_class = forms.UserCreateUpdateForm
form_class = forms.UserUpdateForm
template_name = 'users/user_update.html'
context_object_name = 'user_object'
success_url = reverse_lazy('users:user-list')
......
......@@ -60,7 +60,7 @@ pytz==2018.3
PyYAML==5.1
redis==2.10.6
requests==2.22.0
jms-storage==0.0.22
jms-storage==0.0.23
s3transfer==0.1.13
simplejson==3.13.2
six==1.11.0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment