Skip to content

Commit

Permalink
Rename MCP fields on user model and add read only admin view for migr…
Browse files Browse the repository at this point in the history
…ation testing
  • Loading branch information
hfroot committed Nov 26, 2024
1 parent 69fee18 commit 5eb98f4
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 15 deletions.
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",
)
},
),
)
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
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
16 changes: 8 additions & 8 deletions web/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ def get_or_create_user(user_data):

# Attempt with id provided by Identity Provider
try:
user = get_user_model().objects.get(mcp_id=user_id)
user.mcp_organizations = organizations
user = get_user_model().objects.get(proconnect_id=user_id)
user.proconnect_organizations = organizations
user.save()
logger.info(f"ProConnect user {user_id} (ID Ma Cantine: {user.id}) was found.")
return user
Expand All @@ -244,8 +244,8 @@ def get_or_create_user(user_data):
# Attempt with email
try:
user = get_user_model().objects.get(email=email)
user.mcp_id = user_id
user.mcp_organizations = organizations
user.proconnect_id = user_id
user.proconnect_organizations = organizations
user.save()
logger.info(f"ProConnect user {user_id} was already registered in MaCantine with email {email}.")
return user
Expand All @@ -259,11 +259,11 @@ def get_or_create_user(user_data):
first_name=user_data.get("given_name"),
last_name=last_name,
email=email,
mcp_id=user_id,
# phone_number=mcp_data.get("phone"),
proconnect_id=user_id,
# phone_number=proconnect_data.get("phone"),
username=f"{last_name}-proconnect-{user_id}",
mcp_organizations=organizations,
created_with_mcp=True,
proconnect_organizations=organizations,
created_with_proconnect=True,
)
return user

Expand Down

0 comments on commit 5eb98f4

Please sign in to comment.