franceconnect: maps FC gender to Publik title (#32876)
This commit is contained in:
parent
43a5061f5f
commit
cc5806edac
|
@ -14,6 +14,8 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import json
|
||||
|
||||
from django.core.urlresolvers import reverse_lazy
|
||||
from django.views.generic import FormView
|
||||
|
||||
|
@ -27,6 +29,21 @@ def get_variable(setting_name):
|
|||
setting_name,
|
||||
service=Authentic.objects.get(secondary=False))
|
||||
|
||||
PLATFORMS = {
|
||||
'test': {
|
||||
'A2_FC_AUTHORIZE_URL': 'https://fcp.integ01.dev-franceconnect.fr/api/v1/authorize',
|
||||
'A2_FC_TOKEN_URL': 'https://fcp.integ01.dev-franceconnect.fr/api/v1/token',
|
||||
'A2_FC_USERINFO_URL': 'https://fcp.integ01.dev-franceconnect.fr/api/v1/userinfo',
|
||||
'A2_FC_LOGOUT_URL': 'https://fcp.integ01.dev-franceconnect.fr/api/v1/logout',
|
||||
},
|
||||
'prod': {
|
||||
'A2_FC_AUTHORIZE_URL': 'https://app.franceconnect.gouv.fr/api/v1/authorize',
|
||||
'A2_FC_TOKEN_URL': 'https://app.franceconnect.gouv.fr/api/v1/token',
|
||||
'A2_FC_USERINFO_URL': 'https://app.franceconnect.gouv.fr/api/v1/userinfo',
|
||||
'A2_FC_LOGOUT_URL': 'https://app.franceconnect.gouv.fr/api/v1/logout',
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class HomeView(FormView):
|
||||
template_name = 'hobo/franceconnect_home.html'
|
||||
|
@ -47,22 +64,7 @@ class HomeView(FormView):
|
|||
return initial
|
||||
|
||||
def form_valid(self, form):
|
||||
platforms = {
|
||||
'test': {
|
||||
'A2_FC_AUTHORIZE_URL': 'https://fcp.integ01.dev-franceconnect.fr/api/v1/authorize',
|
||||
'A2_FC_TOKEN_URL': 'https://fcp.integ01.dev-franceconnect.fr/api/v1/token',
|
||||
'A2_FC_USERINFO_URL': 'https://fcp.integ01.dev-franceconnect.fr/api/v1/userinfo',
|
||||
'A2_FC_LOGOUT_URL': 'https://fcp.integ01.dev-franceconnect.fr/api/v1/logout',
|
||||
},
|
||||
'prod': {
|
||||
'A2_FC_AUTHORIZE_URL': 'https://app.franceconnect.gouv.fr/api/v1/authorize',
|
||||
'A2_FC_TOKEN_URL': 'https://app.franceconnect.gouv.fr/api/v1/token',
|
||||
'A2_FC_USERINFO_URL': 'https://app.franceconnect.gouv.fr/api/v1/userinfo',
|
||||
'A2_FC_LOGOUT_URL': 'https://app.franceconnect.gouv.fr/api/v1/logout',
|
||||
}
|
||||
}
|
||||
|
||||
for key, value in platforms[form.cleaned_data['platform']].items():
|
||||
for key, value in PLATFORMS[form.cleaned_data['platform']].items():
|
||||
variable = get_variable(key)
|
||||
variable.value = value
|
||||
variable.save()
|
||||
|
@ -79,6 +81,29 @@ class HomeView(FormView):
|
|||
variable.value = 'true'
|
||||
variable.save()
|
||||
|
||||
variable = get_variable('A2_FC_USER_INFO_MAPPINGS')
|
||||
variable.value = json.dumps({
|
||||
'last_name': {
|
||||
'ref': 'family_name',
|
||||
'verified': True,
|
||||
},
|
||||
'first_name': {
|
||||
'ref': 'given_name',
|
||||
'verified': True,
|
||||
},
|
||||
'title': {
|
||||
'ref': 'gender',
|
||||
'translation': 'simple',
|
||||
'translation_simple': {
|
||||
'male': 'Monsieur',
|
||||
'female': 'Madame',
|
||||
},
|
||||
'verified': True,
|
||||
},
|
||||
'email': 'email',
|
||||
})
|
||||
variable.save()
|
||||
|
||||
return super(HomeView, self).form_valid(form)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
# hobo - portal to configure and deploy applications
|
||||
# Copyright (C) 2015-2019 Entr'ouvert
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU Affero General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from test_manager import login
|
||||
|
||||
from hobo.environment.models import Variable, Authentic
|
||||
from hobo.franceconnect.views import PLATFORMS
|
||||
|
||||
|
||||
def test_franceconnect(app, admin_user):
|
||||
Authentic.objects.create(title='bar', slug='bar', base_url='http://bar.example.net')
|
||||
login(app)
|
||||
|
||||
assert Variable.objects.filter(name__startswith='SETTING_A2_FC').count() == 0
|
||||
|
||||
response = app.get('/franceconnect/')
|
||||
|
||||
assert Variable.objects.filter(name__startswith='SETTING_A2_FC').count() == 4
|
||||
assert Variable.objects.filter(name__startswith='SETTING_A2_FC_ENABLE', value='true').count() == 0
|
||||
|
||||
response = response.click('Enable')
|
||||
|
||||
assert Variable.objects.filter(name__startswith='SETTING_A2_FC').count() == 4
|
||||
assert Variable.objects.filter(name__startswith='SETTING_A2_FC_ENABLE', value='true').count() == 0
|
||||
|
||||
response = response.form.submit().follow()
|
||||
|
||||
assert Variable.objects.filter(name__startswith='SETTING_A2_FC').count() == 4
|
||||
assert Variable.objects.filter(name__startswith='SETTING_A2_FC_ENABLE', value='true').count() == 1
|
||||
|
||||
response.form.set('platform', 'prod')
|
||||
response.form.set('client_id', 'xyz')
|
||||
response.form.set('client_secret', '1234')
|
||||
response = response.form.submit().follow()
|
||||
|
||||
assert Variable.objects.filter(name__startswith='SETTING_A2_FC').count() == 9
|
||||
|
||||
for key, value in PLATFORMS['prod'].items():
|
||||
assert Variable.objects.filter(name='SETTING_' + key, value=value).count() == 1
|
||||
|
||||
assert Variable.objects.get(name='SETTING_A2_FC_USER_INFO_MAPPINGS').json == {
|
||||
"last_name": {
|
||||
"ref": "family_name",
|
||||
"verified": True
|
||||
},
|
||||
"first_name": {
|
||||
"ref": "given_name",
|
||||
"verified": True,
|
||||
},
|
||||
"title": {
|
||||
"ref": "gender",
|
||||
"translation": "simple",
|
||||
"translation_simple": {
|
||||
"male": "Monsieur",
|
||||
"female": "Madame"
|
||||
},
|
||||
"verified": True
|
||||
},
|
||||
"email": "email"
|
||||
}
|
Loading…
Reference in New Issue