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
ef2c9630
Verified
Commit
ef2c9630
authored
5 years ago
by
Tom Teichler
Browse files
Options
Downloads
Patches
Plain Diff
Add basic ldap group sync
parent
a01789a3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1
Resolve "Sync user groups after login"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
aleksis/apps/ldap/util/ldap_sync.py
+20
-0
20 additions, 0 deletions
aleksis/apps/ldap/util/ldap_sync.py
with
20 additions
and
0 deletions
aleksis/apps/ldap/util/ldap_sync.py
+
20
−
0
View file @
ef2c9630
...
...
@@ -7,6 +7,7 @@ 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
"
)
Group
=
apps
.
get_model
(
"
core
"
,
"
Group
"
)
if
config
.
ENABLE_LDAP_SYNC
and
(
created
or
config
.
LDAP_SYNC_ON_UPDATE
):
# Check if there is an existing person connected to the user.
...
...
@@ -39,3 +40,22 @@ def ldap_create_user(sender, instance, created, raw, using, update_fields, **kwa
if
config
.
LDAP_SYNC_CREATE
or
not
created
:
person
.
user
=
instance
person
.
save
()
if
config
.
ENABLE_LDAP_GROUP_SYNC
:
group_objects
=
[]
groups
=
instance
.
ldap_user
.
_get_groups
()
group_infos
=
list
(
groups
.
_get_group_infos
())
for
ldap_group
in
group_infos
:
group
,
created
=
Group
.
objects
.
get_or_create
(
import_ref
=
ldap_group
[
0
],
defaults
=
{
"
short_name
"
:
ldap_group
[
1
][
config
.
LDAP_GROUP_SYNC_FIELD_SHORT_NAME
][
0
][
-
16
:],
"
name
"
:
ldap_group
[
1
][
config
.
LDAP_GROUP_SYNC_FIELD_NAME
][
0
][:
60
]
}
)
if
config
.
LDAP_SYNC_CREATE_GROUPS
or
not
created
:
group
.
save
()
group_objects
.
append
(
group
)
instance
.
person
.
member_of
.
set
(
group_objects
)
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