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
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
Mike Gabriel
AlekSIS-App-LDAP
Commits
7de21a31
Verified
Commit
7de21a31
authored
3 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Add hash to preference names to prevent double names
(cherry picked from commit
1459327b
)
parent
bb88b45d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
aleksis/apps/ldap/migrations/0001_preferences.py
+44
-0
44 additions, 0 deletions
aleksis/apps/ldap/migrations/0001_preferences.py
aleksis/apps/ldap/util/ldap_sync.py
+4
-1
4 additions, 1 deletion
aleksis/apps/ldap/util/ldap_sync.py
with
48 additions
and
1 deletion
aleksis/apps/ldap/migrations/0001_preferences.py
0 → 100644
+
44
−
0
View file @
7de21a31
from
django.db
import
migrations
from
aleksis.apps.ldap.util.ldap_sync
import
setting_name_from_field
from
aleksis.core.models
import
Person
from
django.contrib.sites.models
import
Site
_preference_suffixes
=
[
""
,
"
_re
"
,
"
_replace
"
]
def
_setting_name_old
(
model
,
field
):
part_1
=
model
.
_meta
.
label_lower
.
replace
(
"
.
"
,
"
_
"
).
replace
(
"
__
"
,
"
_
"
)
return
f
"
additional_field_
{
part_1
}
_
{
field
.
name
}
"
.
replace
(
"
__
"
,
"
_
"
)
def
_migrate_preferences
(
apps
,
schema_editor
):
SitePreferenceModel
=
apps
.
get_model
(
"
core
"
,
"
SitePreferenceModel
"
)
current_site
=
Site
.
objects
.
get_current
()
for
field
in
Person
.
syncable_fields
():
old_setting_name
=
_setting_name_old
(
Person
,
field
)
setting_name
=
setting_name_from_field
(
Person
,
field
)
for
suffix
in
_preference_suffixes
:
old_pref_name
=
old_setting_name
+
suffix
new_pref_name
=
setting_name
+
suffix
qs
=
SitePreferenceModel
.
objects
.
filter
(
section
=
"
ldap
"
,
name
=
old_pref_name
)
if
qs
.
exists
():
SitePreferenceModel
.
objects
.
update_or_create
(
instance
=
current_site
.
pk
,
section
=
"
ldap
"
,
name
=
new_pref_name
,
defaults
=
{
"
raw_value
"
:
qs
[
0
].
raw_value
},
)
class
Migration
(
migrations
.
Migration
):
initial
=
True
dependencies
=
[
(
"
core
"
,
"
0001_initial
"
),
(
"
sites
"
,
"
0002_alter_domain_unique
"
),
]
operations
=
[
migrations
.
RunPython
(
_migrate_preferences
)]
This diff is collapsed.
Click to expand it.
aleksis/apps/ldap/util/ldap_sync.py
+
4
−
1
View file @
7de21a31
import
io
import
logging
import
re
from
hashlib
import
shake_256
from
django.apps
import
apps
from
django.conf
import
settings
...
...
@@ -30,7 +31,9 @@ TQDM_DEFAULTS = {
def
setting_name_from_field
(
model
,
field
):
"""
Generate a setting name from a model field.
"""
name
=
f
"
additional_field_
{
model
.
_meta
.
label_lower
}
_
{
field
.
name
}
"
return
re
.
sub
(
r
"
[\._]+
"
,
"
_
"
,
name
)
name_hash
=
shake_256
(
name
.
encode
()).
hexdigest
(
5
)
cleaned_name
=
re
.
sub
(
r
"
[\._]+
"
,
"
_
"
,
name
)
return
f
"
{
cleaned_name
}{
name_hash
}
"
def
ldap_field_to_filename
(
dn
,
fieldname
):
...
...
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