Skip to content
Snippets Groups Projects
Commit c3a8de35 authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Merge branch 'prepare-release-2.0rc2' into 'release/2.0'

Prepare release 2.0rc2

See merge request AlekSIS/official/AlekSIS-App-LDAP!79
parents b3b948af 5f75f1b3
No related branches found
Tags 2.0rc2
No related merge requests found
......@@ -6,6 +6,14 @@ All notable changes to this project will be documented in this file.
The format is based on `Keep a Changelog`_,
and this project adheres to `Semantic Versioning`_.
`2.0rc2`_ - 2021-09-16
----------------------
Fixed
~~~~~
* Names of preferences contained `__` in some rare cases which is forbidden.
`2.0rc1`_ - 2021-06-23
----------------------
......@@ -55,3 +63,4 @@ Added
.. _2.0a2: https://edugit.org/AlekSIS/official/AlekSIS-App-LDAP/-/tags/2.0a2
.. _2.0b0: https://edugit.org/AlekSIS/Official/AlekSIS-App-LDAP/-/tags/2.0b0
.. _2.0rc1: https://edugit.org/AlekSIS/Official/AlekSIS-App-LDAP/-/tags/2.0rc1
.. _2.0rc2: https://edugit.org/AlekSIS/Official/AlekSIS-App-LDAP/-/tags/2.0rc2
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)]
import io
import logging
import re
from hashlib import shake_256
from django.apps import apps
from django.conf import settings
......@@ -29,8 +30,10 @@ TQDM_DEFAULTS = {
def setting_name_from_field(model, field):
"""Generate a setting name from a model field."""
part_1 = model._meta.label_lower.replace(".", "_").replace("__", "_")
return f"additional_field_{part_1}_{field.name}".replace("__", "_")
name = f"additional_field_{model._meta.label_lower}_{field.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.
[tool.poetry]
name = "AlekSIS-App-LDAP"
version = "2.0rc1"
version = "2.0rc2"
packages = [
{ include = "aleksis" }
]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment