Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlekSIS-App-LDAP
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AlekSIS®
Official
AlekSIS-App-LDAP
Commits
03bc1d06
Verified
Commit
03bc1d06
authored
5 years ago
by
Tom Teichler
Browse files
Options
Downloads
Patches
Plain Diff
Add code comments and docstring
parent
b64b75fd
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
aleksis/apps/ldap/util/ldap_sync.py
+7
-0
7 additions, 0 deletions
aleksis/apps/ldap/util/ldap_sync.py
with
7 additions
and
0 deletions
aleksis/apps/ldap/util/ldap_sync.py
+
7
−
0
View file @
03bc1d06
...
...
@@ -3,12 +3,16 @@ from django.contrib.auth import get_user_model
from
constance
import
config
def
ldap_create_user
(
sender
,
instance
,
created
,
raw
,
using
,
update_fields
,
**
kwargs
):
"""
Find ldap users by configurable matching fields and connect them to django users.
"""
Person
=
apps
.
get_model
(
"
core
"
,
"
Person
"
)
if
config
.
ENABLE_LDAP_SYNC
and
(
created
or
config
.
LDAP_SYNC_ON_UPDATE
):
# Check if there is an existing person connected to the user.
if
not
Person
.
objects
.
filter
(
user
=
instance
).
exists
():
if
config
.
LDAP_MATCHING_FIELDS
==
'
match-email
'
:
# Get or create a person matching to email field.
person
,
created
=
Person
.
objects
.
get_or_create
(
email
=
instance
.
email
,
defaults
=
{
...
...
@@ -17,6 +21,7 @@ def ldap_create_user(sender, instance, created, raw, using, update_fields, **kwa
}
)
elif
config
.
LDAP_MATCHING_FIELDS
==
'
match-name
'
:
# Get or create a person matching to the first and last name.
person
,
created
=
Person
.
objects
.
get_or_create
(
first_name
=
instance
.
first_name
,
last_name
=
instance
.
last_name
,
...
...
@@ -25,12 +30,14 @@ def ldap_create_user(sender, instance, created, raw, using, update_fields, **kwa
}
)
elif
config
.
LDAP_MATCHING_FIELDS
==
'
match-email-name
'
:
# Get or create a person matching to the email and the first and last name.
person
,
created
=
Person
.
objects
.
get_or_create
(
first_name
=
instance
.
first_name
,
last_name
=
instance
.
last_name
,
email
=
instance
.
email
)
# Save person if enabled in config or no new person was created.
if
config
.
LDAP_SYNC_CREATE
or
not
created
:
person
.
user
=
instance
person
.
save
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment