Projet

Général

Profil

0001-franceconnect-add-scopes-setting-39286.patch

Benjamin Dauvergne, 05 mars 2020 11:19

Télécharger (4,15 ko)

Voir les différences:

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(-)
hobo/franceconnect/forms.py
33 33
    client_secret = forms.CharField(
34 34
            label=_('Client Secret'),
35 35
            widget=forms.TextInput(attrs={'size': 64}))
36
    scopes = forms.MultipleChoiceField(
37
        label=_('Scopes'),
38
        choices=[
39
            ('given_name', _('given name (given_name)')),
40
            ('gender', _('gender (gender)')),
41
            ('birthdate', _('birthdate (birthdate)')),
42
            ('birthcountry', _('birthcountry (birthcountry)')),
43
            ('birthplace', _('birthplace (birthplace)')),
44
            ('family_name', _('family name (family_name)')),
45
            ('email', _('email (email)')),
46
            ('preferred_username', _('usual family name (preferred_username)')),
47
            ('address', _('address (address)')),
48
            ('phone', _('phone (phone)')),
49
            ('identite_pivot', _('identite_pivot (identite_pivot)')),
50
            ('profile', _('profile (profile)')),
51
            ('birth', _('birth profile (birth)')),
52
        ],
53
        widget=forms.CheckboxSelectMultiple,
54
        help_text=_('These scopes will be requested in addition to openid'))
36 55

  
37 56

  
38 57
class EnableForm(forms.Form):
hobo/franceconnect/views.py
60 60

  
61 61
        initial['client_id'] = get_variable('A2_FC_CLIENT_ID').value
62 62
        initial['client_secret'] = get_variable('A2_FC_CLIENT_SECRET').value
63
        initial['scopes'] = get_variable('A2_FC_SCOPES').json or []
63 64

  
64 65
        return initial
65 66

  
......
104 105
        })
105 106
        variable.save()
106 107

  
108
        variable = get_variable('A2_FC_SCOPES')
109
        variable.json = form.cleaned_data['scopes']
110
        variable.save()
111

  
107 112
        return super(HomeView, self).form_valid(form)
108 113

  
109 114
    def get_context_data(self, **kwargs):
tests/test_franceconnect.py
28 28

  
29 29
    response = app.get('/franceconnect/')
30 30

  
31
    assert Variable.objects.filter(name__startswith='SETTING_A2_FC').count() == 4
31
    assert Variable.objects.filter(name__startswith='SETTING_A2_FC').count() == 5
32 32
    assert Variable.objects.filter(name__startswith='SETTING_A2_FC_ENABLE', value='true').count() == 0
33 33

  
34 34
    response = response.click('Enable')
35 35

  
36
    assert Variable.objects.filter(name__startswith='SETTING_A2_FC').count() == 4
36
    assert Variable.objects.filter(name__startswith='SETTING_A2_FC').count() == 5
37 37
    assert Variable.objects.filter(name__startswith='SETTING_A2_FC_ENABLE', value='true').count() == 0
38 38

  
39 39
    response = response.form.submit().follow()
40 40

  
41
    assert Variable.objects.filter(name__startswith='SETTING_A2_FC').count() == 4
41
    assert Variable.objects.filter(name__startswith='SETTING_A2_FC').count() == 5
42 42
    assert Variable.objects.filter(name__startswith='SETTING_A2_FC_ENABLE', value='true').count() == 1
43 43

  
44 44
    response.form.set('platform', 'prod')
......
46 46
    response.form.set('client_secret', '1234')
47 47
    response = response.form.submit().follow()
48 48

  
49
    assert Variable.objects.filter(name__startswith='SETTING_A2_FC').count() == 9
49
    assert Variable.objects.filter(name__startswith='SETTING_A2_FC').count() == 10
50 50

  
51 51
    for key, value in PLATFORMS['prod'].items():
52 52
        assert Variable.objects.filter(name='SETTING_' + key, value=value).count() == 1
53
-