Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration vers ProConnect (MAJ variables d'env necessaire) #4620

Draft
wants to merge 22 commits into
base: staging
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
3c3871e
Start renaming variables
hfroot Oct 3, 2024
b00dd44
Update button style
hfroot Oct 3, 2024
e50e3a6
Merge branch 'staging' into 4482-migration-bouton-moncompte-pro
hfroot Nov 4, 2024
0979571
Debugging
hfroot Nov 5, 2024
dc0e510
Ability to attach VSCode debug session to Docker server
hfroot Nov 5, 2024
8483ed7
Formatting changes
hfroot Nov 5, 2024
002941c
Revert "Update button style"
hfroot Nov 5, 2024
01108a7
Revert "Start renaming variables"
hfroot Nov 5, 2024
d9e132e
Get it working again with MCP
hfroot Nov 5, 2024
559b752
Write custom userinfo method to parse user data from token
hfroot Nov 6, 2024
dd660da
Update user get/create for new ProConnect data structure
hfroot Nov 6, 2024
a3e4d71
Rename some variables
hfroot Nov 6, 2024
473bf8c
Reapply "Update button style"
hfroot Nov 6, 2024
95cf5f8
Fix spacing on registration page before new ProConnect button
hfroot Nov 6, 2024
09c6fd2
Update docs
hfroot Nov 6, 2024
564ed99
More variable renaming
hfroot Nov 6, 2024
cf65695
Merge branch 'staging' into 4482-migration-bouton-moncompte-pro
hfroot Nov 13, 2024
74381f4
Configure leeway to be shorter to allow for the 60s expiration time o…
hfroot Nov 26, 2024
69fee18
Merge branch 'staging' into 4482-migration-bouton-moncompte-pro
hfroot Nov 26, 2024
5eb98f4
Rename MCP fields on user model and add read only admin view for migr…
hfroot Nov 26, 2024
4cdb3b5
Remove outdated comment
hfroot Nov 26, 2024
7461474
Revert "Ability to attach VSCode debug session to Docker server"
hfroot Nov 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .env.docker
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ALLOWED_HOSTS=localhost
ALLOWED_HOSTS=localhost,127.0.0.1
SECRET=my local secret
DEBUG=True
DEBUG_FRONT=True
Expand Down Expand Up @@ -32,9 +32,9 @@ REDIS_PREPEND_KEY=LOCAL
OVERRIDE_TEST_SEED=
SIRET_API_KEY=
SIRET_API_SECRET=
MONCOMPTEPRO_CLIENT_ID=
MONCOMPTEPRO_SECRET=
MONCOMPTEPRO_CONFIG=
PROCONNECT_CLIENT_ID=
PROCONNECT_SECRET=
PROCONNECT_CONFIG=
MAX_DAYS_HISTORICAL_RECORDS=
CSV_PURCHASE_CHUNK_LINES=
ENABLE_XP_RESERVATION=True
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ repos:
args: [--line-length=119]
exclude: ^migrations/
- repo: https://github.com/pycqa/flake8
rev: 3.8.3
rev: 7.1.0
hooks:
- id: flake8
args: [--config=.flake8]
Expand Down
2 changes: 1 addition & 1 deletion api/serializers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Meta:
"other_source_description",
"has_mtm_data",
"reviews",
"mcp_organizations",
"proconnect_organizations",
"departments",
)

Expand Down
13 changes: 13 additions & 0 deletions data/admin/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ class MaCanteenUserAdmin(UserAdmin):
"creation_mtm_source",
"creation_mtm_campaign",
"creation_mtm_medium",
"created_with_proconnect",
"proconnect_id",
"proconnect_organizations",
)

fieldsets = (
Expand Down Expand Up @@ -113,6 +116,16 @@ class MaCanteenUserAdmin(UserAdmin):
)
},
),
(
"Données ProConnect",
{
"fields": (
"created_with_proconnect",
"proconnect_id",
"proconnect_organizations",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

j'ai rajouté ces données pour qu'on puisse s'assurer que la migration des comptes créés avec MonComptePro a bien reussi

)
},
),
)
add_fieldsets = (
(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Generated by Django 5.0.8 on 2024-11-26 12:10

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("data", "0158_merge_20241106_1432"),
]

operations = [
migrations.RenameField(
model_name="user",
old_name="created_with_mcp",
new_name="created_with_proconnect",
),
migrations.RenameField(
model_name="user",
old_name="mcp_id",
new_name="proconnect_id",
),
migrations.RenameField(
model_name="user",
old_name="mcp_organizations",
new_name="proconnect_organizations",
),
migrations.AlterField(
model_name="user",
name="created_with_proconnect",
field=models.BooleanField(
default="False",
verbose_name="Compte créé avec ProConnect (ex. MonComptePro)",
),
),
migrations.AlterField(
model_name="user",
name="proconnect_id",
field=models.TextField(
blank=True, null=True, verbose_name="ID ProConnect (ex. MonComptePro)"
),
),
migrations.AlterField(
model_name="user",
name="proconnect_organizations",
field=models.JSONField(
blank=True,
null=True,
verbose_name="Organisations sous ProConnect (ex. MonComptePro)",
),
),
]
12 changes: 8 additions & 4 deletions data/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,14 @@ class Sources(models.TextChoices):
is_dev = models.BooleanField(default="False", verbose_name="Compte développeur / technique")
is_elected_official = models.BooleanField(default="False", verbose_name="Compte élu·e")

# MonComptePro
created_with_mcp = models.BooleanField(default="False", verbose_name="Compte créé avec MonComptePro")
mcp_id = models.TextField(blank=True, null=True, verbose_name="ID MonComptePro")
mcp_organizations = models.JSONField(blank=True, null=True, verbose_name="Organisations sous MonComptePro")
# ProConnect
created_with_proconnect = models.BooleanField(
default="False", verbose_name="Compte créé avec ProConnect (ex. MonComptePro)"
)
proconnect_id = models.TextField(blank=True, null=True, verbose_name="ID ProConnect (ex. MonComptePro)")
proconnect_organizations = models.JSONField(
blank=True, null=True, verbose_name="Organisations sous ProConnect (ex. MonComptePro)"
)

# Email campaigns
email_no_canteen_first_reminder = models.DateTimeField(
Expand Down
6 changes: 3 additions & 3 deletions docs/ONBOARDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ REDIS_PREPEND_KEY= Optionnel - Ajout ce string au début de chaque clé Redis. U
OVERRIDE_TEST_SEED= Optionnel - `seed` utilisé par les tests pour les éléments aléatoires. Utile lors qu'un test échoue et qu'on veut reproduire exactement ce qu'il s'est passé.
SIRET_API_KEY= Optionnel - pour utiliser l'API INSEE Sirene. Pour générer : accèder votre compte https://api.insee.fr/catalogue/ > My applications > Add application
SIRET_API_SECRET= Optionnel - pour utiliser l'API INSEE Sirene
MONCOMPTEPRO_CLIENT_ID= Optionnel - Client ID utilisé pour l'authentification via [MonComptePro](https://github.com/betagouv/moncomptepro).
MONCOMPTEPRO_SECRET= Optionnel - Secret utilisé pour l'authentification via [MonComptePro](https://github.com/betagouv/moncomptepro).
MONCOMPTEPRO_CONFIG= Optionnel - Url de configuration utilisé pour l'authentification via [MonComptePro](https://github.com/betagouv/moncomptepro). Par exemple : `https://app-test.moncomptepro.beta.gouv.fr/.well-known/openid-configuration`
PROCONNECT_CLIENT_ID= Optionnel - Client ID utilisé pour l'authentification via [ProConnect](https://github.com/numerique-gouv/proconnect-documentation).
PROCONNECT_SECRET= Optionnel - Secret utilisé pour l'authentification via [ProConnect](https://github.com/numerique-gouv/proconnect-documentation).
PROCONNECT_CONFIG= Optionnel - Url de configuration utilisé pour l'authentification via [ProConnect](https://github.com/numerique-gouv/proconnect-documentation/blob/main/resources/valeur_ac_domain.md). Par exemple : `https://[PROCONNECT_DOMAIN]/api/v2/.well-known/openid-configuration`
MAX_DAYS_HISTORICAL_RECORDS= Optionnel - Flag pour indiquer le nombre de jours pendant lequels on garde l'historique des modèles. Utilisé lors d'une tâche Celery.
CSV_PURCHASE_CHUNK_LINES= Optionnel - Définit le nombre de lignes dans chaque chunk pour l'import des achats. Le choix par défaut est de 81920 ce qui représente en moyenne des chunks de 3Mb.
```
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/views/ManagementPage/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
</div>
<CanteenCreationDialog
v-if="showCanteenCreationPrompt !== null"
:organizations="loggedUser.mcpOrganizations"
:organizations="loggedUser.proconnectOrganizations"
v-model="showCanteenCreationPrompt"
/>
</div>
Expand Down Expand Up @@ -182,7 +182,7 @@ export default {
},
watch: {
canteenCount(count) {
if (this.loggedUser.mcpOrganizations && count === 0 && this.showCanteenCreationPrompt === null) {
if (this.loggedUser.proconnectOrganizations && count === 0 && this.showCanteenCreationPrompt === null) {
this.showCanteenCreationPrompt = true
}
},
Expand Down
12 changes: 6 additions & 6 deletions macantine/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,14 +563,14 @@
REDIS_PREPEND_KEY = os.getenv("REDIS_PREPEND_KEY", "")

AUTHLIB_OAUTH_CLIENTS = {
"moncomptepro": {
"client_id": os.getenv("MONCOMPTEPRO_CLIENT_ID"),
"client_secret": os.getenv("MONCOMPTEPRO_SECRET"),
"proconnect": {
"client_id": os.getenv("PROCONNECT_CLIENT_ID"),
"client_secret": os.getenv("PROCONNECT_SECRET"),
}
}
MONCOMPTEPRO_CONFIG = os.getenv("MONCOMPTEPRO_CONFIG")
USES_MONCOMPTEPRO = (
os.getenv("MONCOMPTEPRO_CLIENT_ID") and os.getenv("MONCOMPTEPRO_SECRET") and os.getenv("MONCOMPTEPRO_CONFIG")
PROCONNECT_CONFIG = os.getenv("PROCONNECT_CONFIG")
USES_PROCONNECT = (
os.getenv("PROCONNECT_CLIENT_ID") and os.getenv("PROCONNECT_SECRET") and os.getenv("PROCONNECT_CONFIG")
)
MAX_DAYS_HISTORICAL_RECORDS = (
int(os.getenv("MAX_DAYS_HISTORICAL_RECORDS")) if os.getenv("MAX_DAYS_HISTORICAL_RECORDS", None) else None
Expand Down
27 changes: 27 additions & 0 deletions web/static/css/auth.css

Large diffs are not rendered by default.

16 changes: 0 additions & 16 deletions web/static/images/button-moncomptepro.svg

This file was deleted.

21 changes: 15 additions & 6 deletions web/templates/auth/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% block title %}S'identifier{% endblock %}

{% load static %}
{% load moncomptepro %}
{% load proconnect %}

{% block content %}

Expand Down Expand Up @@ -60,11 +60,20 @@
</form>
<a href="{% url 'register' %}">Créer mon compte</a>
<hr aria-hidden="true" role="presentation" style="margin-top: 22px;" />
{% uses_moncomptepro as show_mcp_button %}
{% if show_mcp_button %}
<a href="{% url 'oidc-login' %}">
<img src="{% static 'images/button-moncomptepro.svg' %}" alt="S'identifier avec MonComptePro" />
</a>
{% uses_proconnect as show_proconnect_button %}
{% if show_proconnect_button %}
<div>
<form method="get" action="{% url 'oidc-login' %}">
<button class="proconnect-button">
<span class="proconnect-sr-only">S'identifier avec ProConnect</span>
</button>
</form>
<p>
<a href="https://www.proconnect.gouv.fr/" target="_blank" rel="noopener noreferrer" title="Qu’est-ce que ProConnect ? - nouvelle fenêtre">
Qu’est-ce que ProConnect ?
</a>
</p>
</div>
{% endif %}
<p style="font-size: 0.85em; margin-top: 20px;"><a href="{% url 'password_reset' %}">J'ai perdu mon mot de passe</a></p>
<p style="font-size: 0.85em; margin-top: 20px;"><a href="{% url 'magicauth-login' %}">Recevoir un lien de connexion par email</a></p>
Expand Down
23 changes: 15 additions & 8 deletions web/templates/auth/register.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends 'base.html' %}
{% block title %}Créer mon compte{% endblock %}
{% load moncomptepro %}
{% load proconnect %}
{% load static %}

{% block content %}
Expand Down Expand Up @@ -189,14 +189,21 @@

</form>
<div>
<a href="{% url 'login' %}">J'ai déjà un compte</a>
<p><a href="{% url 'login' %}">J'ai déjà un compte</a></p>
</div>
{% uses_moncomptepro as show_mcp_button %}
{% if show_mcp_button %}
<div style="margin-top: 16px;">
<a href="{% url 'oidc-login' %}">
<img src="{% static 'images/button-moncomptepro.svg' %}" alt="S'identifier avec MonComptePro" />
</a>
{% uses_proconnect as show_proconnect_button %}
{% if show_proconnect_button %}
<div>
<form method="get" action="{% url 'oidc-login' %}">
<button class="proconnect-button">
<span class="proconnect-sr-only">S'identifier avec ProConnect</span>
</button>
</form>
<p>
<a href="https://www.proconnect.gouv.fr/" target="_blank" rel="noopener noreferrer" title="Qu’est-ce que ProConnect ? - nouvelle fenêtre">
Qu’est-ce que ProConnect ?
</a>
</p>
</div>
{% endif %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@


@register.simple_tag
def uses_moncomptepro():
return getattr(settings, "USES_MONCOMPTEPRO", "")
def uses_proconnect():
return getattr(settings, "USES_PROCONNECT", "")
2 changes: 1 addition & 1 deletion web/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
),
]

if settings.USES_MONCOMPTEPRO:
if settings.USES_PROCONNECT:
urlpatterns.append(
path(
"oidc-login",
Expand Down
Loading
Loading