Projet

Général

Profil

0004-authentic2-agent-manage-profile-fields-7185.patch

Frédéric Péters, 08 mai 2015 13:03

Télécharger (3,86 ko)

Voir les différences:

Subject: [PATCH 4/4] authentic2 agent: manage profile fields (#7185)

 .../authentic2/management/commands/hobo_deploy.py    | 15 +++++++++++++++
 hobo/multitenant/settings_loaders.py                 | 20 +++++++++++++++++++-
 2 files changed, 34 insertions(+), 1 deletion(-)
hobo/agent/authentic2/management/commands/hobo_deploy.py
10 10
from authentic2 import app_settings
11 11
from authentic2.compat import get_user_model
12 12
from authentic2.compat_lasso import lasso
13
from authentic2.models import Attribute
13 14
from authentic2.saml.models import LibertyProvider, SPOptionsIdPPolicy, SAMLAttribute
14 15
from django.contrib.contenttypes.models import ContentType
15 16
from django.contrib.auth.models import Group
......
64 65
                    user.is_superuser = True
65 66
                    user.save()
66 67

  
68
            # create/update user attributes
69
            for attribute in hobo_environment.get('profile', {}).get('fields'):
70
                if attribute['name'] in ('first_name', 'last_name', 'email'):
71
                    # those fields are hardcoded in the user model
72
                    continue
73
                attr, created = Attribute.objects.get_or_create(name=attribute['name'])
74
                for key in ('label', 'description', 'asked_on_registration',
75
                        'user_editable', 'user_visible', 'kind'):
76
                    setattr(attr, key, attribute[key])
77
                if attribute['disabled']:
78
                    # don't actively remove attribute, just mark it as not visible
79
                    attr.user_visible = False
80
                attr.save()
81

  
67 82
            # creation of IdpPolicy
68 83
            policy, created = SPOptionsIdPPolicy.objects.get_or_create(name='Default')
69 84
            if created:
hobo/multitenant/settings_loaders.py
82 82
#
83 83

  
84 84
class Authentic(FileBaseSettingsLoader):
85
    FILENAME = 'hobo.json' # for get_new_time() only
85
    FILENAME = 'hobo.json'
86 86

  
87 87
    def update_settings(self, tenant_settings, tenant):
88
        # update SAML certicates and keys
88 89
        tenant_dir = os.path.join(settings.TENANT_BASE, tenant.domain_url)
89 90
        saml_crt = os.path.join(tenant_dir, 'saml.crt')
90 91
        saml_key = os.path.join(tenant_dir, 'saml.key')
......
95 96
        else:
96 97
            tenant_settings.A2_IDP_SAML2_ENABLE = False
97 98

  
99
        # then other things
100
        path = os.path.join(tenant_dir, self.FILENAME)
101
        if os.path.exists(path):
102
            self.update_settings_from_path(tenant_settings, path)
103

  
104
    def update_settings_from_path(self, tenant_settings, path):
105
        # profile fields
106
        with file(path) as f:
107
            hobo_json = json.load(f)
108

  
109
        fields = hobo_json.get('profile', {}).get('fields')
110
        if fields:
111
            fields.sort(lambda x, y: cmp(x.get('order'), y.get('order')))
112
            tenant_settings.A2_PROFILE_FIELDS = [x['name'] for x in fields if not x['disabled']]
113
            tenant_settings.A2_REQUIRED_FIELDS = [x['name'] for x in fields if x['required']]
114
            tenant_settings.A2_REGISTRATION_FIELDS = [x['name'] for x in fields if x['asked_on_registration']]
115

  
98 116

  
99 117
#
100 118
# Generic loaders (not recommended)
101
-