INGInious icon indicating copy to clipboard operation
INGInious copied to clipboard

Use of the Beanie model for user handling

Open AlexandreDoneux opened this issue 11 months ago • 0 comments

This PR draft is to display a possible way to use beanie as an ODM for DB interactions. Using an ODM would allow us the handle data more easily as objects and handle errors in a more secure way for the app. It would in a greater measure improve the code quality. Beanie being based on Pydantic also serves data validation purposes.

This first PR focuses on the handling of users as it is one of the simplest structures we have so far. It includes for the moment :

  • An additional asyncio loop specifically for Motor calls (the python drive Beanie is based on).
  • A User model and a couple of validators whose job it is to validate the data when creating a new document or fetching one from the database.
  • Data validation and DB queries for the install script and user registration/password reset

As the work was done exploring the capabilities of Beanie and Pydantic, multiple things still need to be implemented before considering changing this draft in a finished PR :

  • [ ] Implementing testing for the model
  • [ ] Using Beanie for Validation and queries at the other places in the app
    • [ ] ...
  • [ ] Using a more appropriate way to run the beanie queries on the sayncio loop. As the loop already exists and it is endlessly running, I had to settle on asyncio.run_coroutine_threadsafe(). A better way is surely possible.

The broader purpose for this User model is also to get rid of the UserManager singleton and move all their methods inside the use model if possible.

AlexandreDoneux avatar Mar 12 '25 16:03 AlexandreDoneux