summaryrefslogtreecommitdiffstats
path: root/django/sp_sso/invite/utils.py
diff options
context:
space:
mode:
authorPaul Marillonnet <pmarillonnet@entrouvert.com>2017-06-28 20:16:05 (GMT)
committerPaul Marillonnet <pmarillonnet@entrouvert.com>2017-06-28 20:37:17 (GMT)
commite3238650273dd708a9022fc77fad02ee0d4d2a2c (patch)
treec123bef9ac544a25f28b8951fc1ffe07f01d0cdd /django/sp_sso/invite/utils.py
parent574904e80bf147f5b969c339174b5c7a78307ead (diff)
downloadpaul-synchro-e3238650273dd708a9022fc77fad02ee0d4d2a2c.zip
paul-synchro-e3238650273dd708a9022fc77fad02ee0d4d2a2c.tar.gz
paul-synchro-e3238650273dd708a9022fc77fad02ee0d4d2a2c.tar.bz2
POC Campus Condorcet : mise à jour du formulaire d'invitation
Diffstat (limited to 'django/sp_sso/invite/utils.py')
-rw-r--r--django/sp_sso/invite/utils.py31
1 files changed, 28 insertions, 3 deletions
diff --git a/django/sp_sso/invite/utils.py b/django/sp_sso/invite/utils.py
index d9921f5..dbe2ac5 100644
--- a/django/sp_sso/invite/utils.py
+++ b/django/sp_sso/invite/utils.py
@@ -1,6 +1,6 @@
import json
-from urllib2 import build_opener, HTTPHandler, Request
+from urllib2 import build_opener, HTTPHandler, Request, urlopen
pocform = 'invitation'
wcs = 'http://forms-condorcet.dev.entrouvert.org/'
@@ -8,11 +8,20 @@ posturl = wcs+'/api/formdefs/'+pocform+'/submit'
INVITATION_ATTRIBUTES_MAPPING = {
'ep_principal_name': 'hote_identite',
- 'email': 'hote_courriel'
+ 'email': 'hote_courriel',
+ 'prenom': 'hote_prenom',
+ 'nom': 'hote_nom'
}
+ADDITIONAL_PREFILLED_FIELDS = ['hote_etablissement', 'hote_unite']
+
+PASSERELLE_PEOPLE_QUERY = 'http://dir-condorcet.dev.entrouvert.org/ldapquery/condorcet/run/6/'
+
def get_invitaton_attributes_mapping():
- return INVITATION_ATTRIBUTES_MAPPING
+ return INVITATION_ATTRIBUTES_MAPPING.copy()
+
+def get_additional_prefilled_fields():
+ return ADDITIONAL_PREFILLED_FIELDS[:]
def do_invite(invitation):
opener = build_opener(HTTPHandler)
@@ -33,3 +42,19 @@ def do_invite(invitation):
ret = -1
return ret
+
+
+def get_affectations_from_eppn(eppn):
+ if eppn:
+ try:
+ ldapquery = urlopen(PASSERELLE_PEOPLE_QUERY)
+ jsonresult = json.loads(ldapquery.read())
+
+ for user in jsonresult['content']:
+ if user.get('attributes', {}).get('eduPersonPrincipalName') == eppn:
+ return (user['attributes'].get('supannEtablissement', [''])[0],
+ user['attributes'].get('supannEntiteAffectation', [''])[0])
+ raise Exception('Invalid user')
+ # fall back in except block
+ except:
+ return ('', '')