openfun / joanie

👛 A headless ERP for education to manage course enrollment/subscription, payment and certificates delivery.
MIT License
22 stars 2 forks source link

Moodle Backend - User creation failure with email conflict #710

Closed jbpenrath closed 5 months ago

jbpenrath commented 6 months ago

Bug Report

Problematic behavior With the Moodle backend, we have implemented a logic to create a user on the fly if it does not exist on Moodle side. We are looking for moodle user_id through user.username of the related enrollment.

But unfortunately, this logic encounts some conflict. Indeed, Moodle seems to accept only one account per email. But we can have cases where an account has been previously created on Moodle with a given email (e.g: for administrator). At this stage, this account is not sync with Joanie so username for those accounts can be different. Then when this kind of user wants to enroll to a course run, Joanie is not able to retrieve a Moodle user_id through user.username so we try to create a new user and then BOOM ! Moodle refuses to create the user as already one exists with the provided email ...

Expected behavior/code If a Moodle account exists for a given email, we should not try to create a new user. Are we able to update it ?

Additional context/Screenshots https://gip-fun-mooc.sentry.io/issues/5098652962/?project=6599941&query=is:unresolved&statsPeriod=7d&stream_index=4

kernicPanel commented 6 months ago

https://sandbox.moodledemo.net/admin/webservice/documentation.php

image

kernicPanel commented 6 months ago

We well need to do the same steps than https://github.com/openfun/joanie/issues/732#issuecomment-2044294817