Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gyuricska Milán
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
35ae5cdc
authored
8 years ago
by
Czémán Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: Rework ldap utils
parent
2de30027
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
13 deletions
+14
-13
circle/dashboard/ldap_utils.py
+14
-13
No files found.
circle/dashboard/ldap_utils.py
View file @
35ae5cdc
...
...
@@ -4,12 +4,14 @@ from django.contrib.auth.models import Group
from
.models
import
GroupProfile
,
FutureMember
,
Profile
import
ldap
from
django_auth_ldap.backend
import
LDAPSettings
from
django_auth_ldap.config
import
LDAPSearch
logger
=
logging
.
getLogger
(
__name__
)
def
ldap_connect
(
ldap_settings
):
def
ldap_connect
():
ldap_settings
=
LDAPSettings
()
conn
=
ldap
.
initialize
(
ldap_settings
.
SERVER_URI
)
for
opt
,
value
in
ldap_settings
.
CONNECTION_OPTIONS
.
items
():
conn
.
set_option
(
opt
,
value
)
...
...
@@ -17,13 +19,14 @@ def ldap_connect(ldap_settings):
return
conn
def
owns
(
conn
,
ldap_settings
,
ownerattr
,
user_dn
,
group_name
):
group
=
ldap_settings
.
GROUP_SEARCH
.
search_with_additional_term_string
(
"(cn=
%
s)"
%
group_name
)
.
execute
(
conn
)
def
owns
(
conn
,
user_dn
,
group_dn
):
ownerattr
=
settings
.
LDAP_GROUP_OWNER_ATTRIBUTE
group
=
LDAPSearch
(
group_dn
.
lower
(),
ldap
.
SCOPE_BASE
,
"cn=*"
)
.
execute
(
conn
)
if
len
(
group
)
==
0
:
return
False
group
=
group
[
0
]
owners
=
group
[
1
]
.
get
(
ownerattr
,
[])
logger
.
error
(
owners
)
return
user_dn
in
map
(
unicode
.
upper
,
owners
)
...
...
@@ -60,22 +63,20 @@ def ldap_save_org_id(sender, user, ldap_user, **kwargs):
i
.
group
.
user_set
.
add
(
user
)
i
.
delete
()
ownerattr
=
settings
.
LDAP_GROUP_OWNER_ATTRIBUTE
ldap_settings
=
LDAPSettings
()
# connection will close, when object destroys
# https://www.python-ldap.org/doc/html/ldap.html#ldap-objects
conn
=
ldap_connect
(
ldap_settings
)
for
group
in
zip
(
group_dns
,
ldap_user
.
group_names
)
:
conn
=
ldap_connect
()
for
group
in
group_dns
:
try
:
g
=
GroupProfile
.
search
(
group
[
0
]
)
g
=
GroupProfile
.
search
(
group
)
except
Group
.
DoesNotExist
:
logger
.
debug
(
'cant find ownergroup
%
s'
,
group
[
0
]
)
logger
.
debug
(
'cant find ownergroup
%
s'
,
group
)
else
:
if
owns
(
conn
,
ldap_settings
,
ownerattr
,
user_dn
,
group
[
1
]
):
if
owns
(
conn
,
user_dn
,
group
):
logger
.
debug
(
'could find ownergroup
%
s (
%
s)'
,
group
[
0
]
,
unicode
(
g
))
group
,
unicode
(
g
))
g
.
profile
.
set_level
(
user
,
'owner'
)
else
:
logger
.
debug
(
'cant find ownergroup
%
s'
,
group
[
0
]
)
logger
.
debug
(
'cant find ownergroup
%
s'
,
group
)
return
False
# User did not change
This diff is collapsed.
Click to expand it.
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