diff --git a/hobo/franceconnect/forms.py b/hobo/franceconnect/forms.py
deleted file mode 100644
index e4d392a..0000000
--- a/hobo/franceconnect/forms.py
+++ /dev/null
@@ -1,61 +0,0 @@
-# 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 .
-
-from django import forms
-from django.utils.translation import ugettext_lazy as _
-
-
-class SettingsForm(forms.Form):
- platform = forms.ChoiceField(
- label=_('Platform'),
- choices=[
- ('prod', _('Production')),
- ('test', _('Integration')),
- ],
- )
- client_id = forms.CharField(
- label=_('Client ID'),
- help_text=_(
- 'See '
- 'FranceConnect partners site for getting client ID and secret.'
- ),
- widget=forms.TextInput(attrs={'size': 64}),
- )
- 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):
- pass
diff --git a/hobo/franceconnect/templates/hobo/franceconnect_disable.html b/hobo/franceconnect/templates/hobo/franceconnect_disable.html
deleted file mode 100644
index eea69e3..0000000
--- a/hobo/franceconnect/templates/hobo/franceconnect_disable.html
+++ /dev/null
@@ -1,20 +0,0 @@
-{% extends "hobo/franceconnect_home.html" %}
-{% load i18n %}
-
-{% block appbar %}
-
FranceConnect
-{% endblock %}
-
-{% block content %}
-
-
-{% endblock %}
diff --git a/hobo/franceconnect/templates/hobo/franceconnect_enable.html b/hobo/franceconnect/templates/hobo/franceconnect_enable.html
deleted file mode 100644
index b59f4ff..0000000
--- a/hobo/franceconnect/templates/hobo/franceconnect_enable.html
+++ /dev/null
@@ -1,20 +0,0 @@
-{% extends "hobo/franceconnect_home.html" %}
-{% load i18n %}
-
-{% block appbar %}
- FranceConnect
-{% endblock %}
-
-{% block content %}
-
-
-{% endblock %}
diff --git a/hobo/franceconnect/templates/hobo/franceconnect_home.html b/hobo/franceconnect/templates/hobo/franceconnect_home.html
index b819199..f22dca7 100644
--- a/hobo/franceconnect/templates/hobo/franceconnect_home.html
+++ b/hobo/franceconnect/templates/hobo/franceconnect_home.html
@@ -8,40 +8,12 @@
{% block appbar %}
{% trans 'FranceConnect' %}
- {% if enabled %}
-
- {% trans 'Disable' %}
-
- {% endif %}
{% endblock %}
{% block content %}
-
- {% blocktrans %}
- FranceConnect is the solution proposed by the French state to streamline
- logging in online services.
- {% endblocktrans %}
+
-{% if not enabled %}
-
- {% trans "Support is currently disabled." %}
-
-
- {% trans 'Enable' %}
-
-{% else %}
-
-
-
-{% endif %}
-
{% endblock %}
diff --git a/hobo/franceconnect/urls.py b/hobo/franceconnect/urls.py
index b0bc813..0602bc3 100644
--- a/hobo/franceconnect/urls.py
+++ b/hobo/franceconnect/urls.py
@@ -20,6 +20,4 @@ from . import views
urlpatterns = [
url(r'^$', views.home, name='franceconnect-home'),
- url(r'^enable$', views.enable, name='franceconnect-enable'),
- url(r'^disable$', views.disable, name='franceconnect-disable'),
]
diff --git a/hobo/franceconnect/views.py b/hobo/franceconnect/views.py
index 82ee891..4c3c0b4 100644
--- a/hobo/franceconnect/views.py
+++ b/hobo/franceconnect/views.py
@@ -14,139 +14,11 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see
.
-import json
-
-from django.urls import reverse_lazy
-from django.views.generic import FormView
-
-from hobo.environment.models import Authentic
-from hobo.environment.utils import get_setting_variable
-
-from .forms import EnableForm, SettingsForm
+from django.views.generic import TemplateView
-def get_variable(setting_name):
- return get_setting_variable(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):
+class HomeView(TemplateView):
template_name = 'hobo/franceconnect_home.html'
- form_class = SettingsForm
- success_url = reverse_lazy('franceconnect-home')
-
- def get_initial(self):
- initial = super(HomeView, self).get_initial()
- authorize_url = get_variable('A2_FC_AUTHORIZE_URL').value
- if authorize_url == 'https://fcp.integ01.dev-franceconnect.fr/api/v1/authorize':
- initial['platform'] = 'test'
- elif authorize_url == 'https://app.franceconnect.gouv.fr/api/v1/authorize':
- initial['platform'] = 'prod'
-
- 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', 'email']
-
- return initial
-
- def form_valid(self, form):
- for key, value in PLATFORMS[form.cleaned_data['platform']].items():
- variable = get_variable(key)
- variable.value = value
- variable.save()
-
- variable = get_variable('A2_FC_CLIENT_ID')
- variable.value = form.cleaned_data['client_id']
- variable.save()
-
- variable = get_variable('A2_FC_CLIENT_SECRET')
- variable.value = form.cleaned_data['client_secret']
- variable.save()
-
- variable = get_variable('A2_FC_VERIFY_CERTIFICATE')
- 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()
-
- 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):
- context = super(HomeView, self).get_context_data(**kwargs)
- context['enabled'] = bool(get_variable('A2_FC_ENABLE').json)
- return context
home = HomeView.as_view()
-
-
-class EnableView(FormView):
- form_class = EnableForm
- template_name = 'hobo/franceconnect_enable.html'
- success_url = reverse_lazy('franceconnect-home')
-
- def form_valid(self, form):
- variable = get_variable('A2_FC_ENABLE')
- variable.value = 'true'
- variable.save()
- return super(EnableView, self).form_valid(form)
-
-
-enable = EnableView.as_view()
-
-
-class DisableView(FormView):
- form_class = EnableForm
- template_name = 'hobo/franceconnect_disable.html'
- success_url = reverse_lazy('franceconnect-home')
-
- def form_valid(self, form):
- variable = get_variable('A2_FC_ENABLE')
- variable.value = 'false'
- variable.save()
- return super(DisableView, self).form_valid(form)
-
-
-disable = DisableView.as_view()
diff --git a/tests/test_franceconnect.py b/tests/test_franceconnect.py
deleted file mode 100644
index b2a5e5f..0000000
--- a/tests/test_franceconnect.py
+++ /dev/null
@@ -1,67 +0,0 @@
-# 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
.
-
-from test_manager import login
-
-from hobo.environment.models import Authentic, Variable
-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() == 0
- 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() == 0
- 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() == 1
- 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() == 10
-
- 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",
- }