Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
jumpserver
Commits
00e986a6
Commit
00e986a6
authored
May 29, 2019
by
BaiJiangJie
Committed by
老广
May 29, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 优化LDAP用户导入功能,可导入跨页选取的所有用户 (#2745)
parent
dc4bf669
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
12 deletions
+46
-12
api.py
apps/settings/api.py
+42
-4
_ldap_list_users_modal.html
apps/settings/templates/settings/_ldap_list_users_modal.html
+3
-3
ldap_setting.html
apps/settings/templates/settings/ldap_setting.html
+1
-4
utils.py
apps/settings/utils.py
+0
-1
No files found.
apps/settings/api.py
View file @
00e986a6
...
...
@@ -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
):
...
...
apps/settings/templates/settings/_ldap_list_users_modal.html
View file @
00e986a6
...
...
@@ -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
:
1
0
pageLength
:
1
5
};
ldap_users_table
=
jumpserver
.
initDataTable
(
options
);
ldap_users_table
=
jumpserver
.
init
ServerSide
DataTable
(
options
);
return
ldap_users_table
}
...
...
apps/settings/templates/settings/ldap_setting.html
View file @
00e986a6
...
...
@@ -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'%}"
;
...
...
apps/settings/utils.py
View file @
00e986a6
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment