* policies/expression: migrate to raw python instead of jinja2 * lib/expression: create base evaluator, custom subclass for policies * core: rewrite propertymappings to use python * providers/saml: update to new PropertyMappings * sources/ldap: update to new PropertyMappings * docs: update docs for new propertymappings * root: remove jinja2 * root: re-add jinja to lock file as its implicitly required
		
			
				
	
	
		
			36 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			36 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
# Generated by Django 3.0.6 on 2020-05-23 19:30
 | 
						|
 | 
						|
from django.apps.registry import Apps
 | 
						|
from django.db import migrations
 | 
						|
 | 
						|
 | 
						|
def create_default_ad_property_mappings(apps: Apps, schema_editor):
 | 
						|
    LDAPPropertyMapping = apps.get_model("passbook_sources_ldap", "LDAPPropertyMapping")
 | 
						|
    mapping = {
 | 
						|
        "name": "return ldap.get('name')",
 | 
						|
        "first_name": "return ldap.get('givenName')",
 | 
						|
        "last_name": "return ldap.get('sn')",
 | 
						|
        "username": "return ldap.get('sAMAccountName')",
 | 
						|
        "email": "return ldap.get('mail')",
 | 
						|
    }
 | 
						|
    db_alias = schema_editor.connection.alias
 | 
						|
    for object_field, expression in mapping.items():
 | 
						|
        LDAPPropertyMapping.objects.using(db_alias).get_or_create(
 | 
						|
            expression=expression,
 | 
						|
            object_field=object_field,
 | 
						|
            defaults={
 | 
						|
                "name": f"Autogenerated LDAP Mapping: {expression} -> {object_field}"
 | 
						|
            },
 | 
						|
        )
 | 
						|
 | 
						|
 | 
						|
class Migration(migrations.Migration):
 | 
						|
 | 
						|
    dependencies = [
 | 
						|
        ("passbook_sources_ldap", "0002_ldapsource_sync_users"),
 | 
						|
    ]
 | 
						|
 | 
						|
    operations = [
 | 
						|
        migrations.RunPython(create_default_ad_property_mappings),
 | 
						|
    ]
 |