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
22075b9e
Verified
Commit
22075b9e
authored
4 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
Correct use of get_ldap_value_for_field
parent
f62a49db
No related branches found
No related tags found
1 merge request
!28
Resolve "Allow match of users to persons by other fields in AlekSIS and LDAP"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
aleksis/apps/ldap/util/ldap_sync.py
+6
-4
6 additions, 4 deletions
aleksis/apps/ldap/util/ldap_sync.py
with
6 additions
and
4 deletions
aleksis/apps/ldap/util/ldap_sync.py
+
6
−
4
View file @
22075b9e
...
@@ -128,7 +128,7 @@ def apply_templates(value, patterns, templates, separator="|"):
...
@@ -128,7 +128,7 @@ def apply_templates(value, patterns, templates, separator="|"):
return
value
return
value
def
get_ldap_value_for_field
(
model
,
field
,
attrs
,
dn
,
instance
=
None
):
def
get_ldap_value_for_field
(
model
,
field
,
attrs
,
dn
,
instance
=
None
,
allow_missing
=
False
):
"""
Get the value of a field in LDAP attributes.
"""
Get the value of a field in LDAP attributes.
Looks at the site preference for sync fields to determine which LDAP field is
Looks at the site preference for sync fields to determine which LDAP field is
...
@@ -152,7 +152,8 @@ def get_ldap_value_for_field(model, field, attrs, dn, instance=None):
...
@@ -152,7 +152,8 @@ def get_ldap_value_for_field(model, field, attrs, dn, instance=None):
value
=
from_ldap
(
value
,
field
,
dn
,
ldap_field
,
instance
)
value
=
from_ldap
(
value
,
field
,
dn
,
ldap_field
,
instance
)
return
value
return
value
else
:
if
not
allow_missing
:
raise
KeyError
(
f
"
Matching field
{
ldap_field
}
not in attributes of
{
dn
}
"
)
raise
KeyError
(
f
"
Matching field
{
ldap_field
}
not in attributes of
{
dn
}
"
)
...
@@ -228,8 +229,9 @@ def ldap_sync_from_user(user, dn, attrs):
...
@@ -228,8 +229,9 @@ def ldap_sync_from_user(user, dn, attrs):
defaults
=
{}
defaults
=
{}
# Match on all fields selected in preferences
# Match on all fields selected in preferences
fields_map
=
{
f
.
name
:
f
for
f
in
Person
.
syncable_fields
()}
for
field_name
in
get_site_preferences
()[
"
ldap__matching_fields
"
]:
for
field_name
in
get_site_preferences
()[
"
ldap__matching_fields
"
]:
value
=
get_ldap_value_for_field
(
Person
,
field
,
attrs
,
dn
)
value
=
get_ldap_value_for_field
(
Person
,
field
s_map
[
field_name
]
,
attrs
,
dn
)
matches
[
field_name
]
=
value
matches
[
field_name
]
=
value
# Pre-fill all mandatory non-matching fields from User object
# Pre-fill all mandatory non-matching fields from User object
for
missing_key
in
(
"
first_name
"
,
"
last_name
"
,
"
email
"
):
for
missing_key
in
(
"
first_name
"
,
"
last_name
"
,
"
email
"
):
...
@@ -254,7 +256,7 @@ def ldap_sync_from_user(user, dn, attrs):
...
@@ -254,7 +256,7 @@ def ldap_sync_from_user(user, dn, attrs):
# Synchronise additional fields if enabled
# Synchronise additional fields if enabled
for
field
in
Person
.
syncable_fields
():
for
field
in
Person
.
syncable_fields
():
value
=
get_ldap_value_for_field
(
Person
,
field
,
attrs
,
dn
,
person
)
value
=
get_ldap_value_for_field
(
Person
,
field
,
attrs
,
dn
,
person
,
allow_missing
=
True
)
setattr
(
person
,
field
.
name
,
value
)
setattr
(
person
,
field
.
name
,
value
)
logger
.
debug
(
f
"
Field
{
field
.
name
}
set to
{
value
}
for
{
person
}
"
)
logger
.
debug
(
f
"
Field
{
field
.
name
}
set to
{
value
}
for
{
person
}
"
)
...
...
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