From 615dcf31b1670783c4e796fa7250bee4e2d520c5 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Mon, 27 Jan 2020 13:22:04 +0100 Subject: [PATCH] franceconnect: add scopes setting (#39286) --- hobo/franceconnect/forms.py | 19 +++++++++++++++++++ hobo/franceconnect/views.py | 5 +++++ tests/test_franceconnect.py | 8 ++++---- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/hobo/franceconnect/forms.py b/hobo/franceconnect/forms.py index 6ed5d98..a8b5b98 100644 --- a/hobo/franceconnect/forms.py +++ b/hobo/franceconnect/forms.py @@ -33,6 +33,25 @@ class SettingsForm(forms.Form): client_secret = forms.CharField( label=_('Client Secret'), widget=forms.TextInput(attrs={'size': 64})) + scopes = forms.MultipleChoiceField( + label=_('Scopes'), + choices=[ + ('given_name', _('given name (given_name)')), + ('gender', _('gender (gender)')), + ('birthdate', _('birthdate (birthdate)')), + ('birthcountry', _('birthcountry (birthcountry)')), + ('birthplace', _('birthplace (birthplace)')), + ('family_name', _('family name (family_name)')), + ('email', _('email (email)')), + ('preferred_username', _('usual family name (preferred_username)')), + ('address', _('address (address)')), + ('phone', _('phone (phone)')), + ('identite_pivot', _('identite_pivot (identite_pivot)')), + ('profile', _('profile (profile)')), + ('birth', _('birth profile (birth)')), + ], + widget=forms.CheckboxSelectMultiple, + help_text=_('These scopes will be requested in addition to openid')) class EnableForm(forms.Form): diff --git a/hobo/franceconnect/views.py b/hobo/franceconnect/views.py index 9bf7dff..63dc93b 100644 --- a/hobo/franceconnect/views.py +++ b/hobo/franceconnect/views.py @@ -60,6 +60,7 @@ class HomeView(FormView): initial['client_id'] = get_variable('A2_FC_CLIENT_ID').value initial['client_secret'] = get_variable('A2_FC_CLIENT_SECRET').value + initial['scopes'] = get_variable('A2_FC_SCOPES').json or ['profile'] return initial @@ -104,6 +105,10 @@ class HomeView(FormView): }) variable.save() + variable = get_variable('A2_FC_SCOPES') + variable.json = form.cleaned_data['scopes'] + variable.save() + return super(HomeView, self).form_valid(form) def get_context_data(self, **kwargs): diff --git a/tests/test_franceconnect.py b/tests/test_franceconnect.py index 767f0b4..58e968c 100644 --- a/tests/test_franceconnect.py +++ b/tests/test_franceconnect.py @@ -28,17 +28,17 @@ def test_franceconnect(app, admin_user): response = app.get('/franceconnect/') - assert Variable.objects.filter(name__startswith='SETTING_A2_FC').count() == 4 + assert Variable.objects.filter(name__startswith='SETTING_A2_FC').count() == 5 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').count() == 5 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').count() == 5 assert Variable.objects.filter(name__startswith='SETTING_A2_FC_ENABLE', value='true').count() == 1 response.form.set('platform', 'prod') @@ -46,7 +46,7 @@ def test_franceconnect(app, admin_user): response.form.set('client_secret', '1234') response = response.form.submit().follow() - assert Variable.objects.filter(name__startswith='SETTING_A2_FC').count() == 9 + assert Variable.objects.filter(name__startswith='SETTING_A2_FC').count() == 10 for key, value in PLATFORMS['prod'].items(): assert Variable.objects.filter(name='SETTING_' + key, value=value).count() == 1 -- 2.24.0