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

fix: Improve edit profile function so it handles errors correctly #56

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

maryycarrera
Copy link

This pull request modifies the edit profile functionality. All changes were implemented by María de la Salud Carrera Talaverón and David Vargas Jorba.

Previously, the edit_profile() function in the app/modules/profile/routes.py file obtained the user profile using the get_authenticated_user_profile method in AuthenticationService. However, this made the profile variable be a function object, which resulted in en error later when we tried to obtain the user profile ID. To fix this issue, we decided to instead obtain the user profile using the current_user method imported from flask.

Moreover, the form did not handle the validation errors properly, due to various reasons. Firstly, we decided to refactor the update_profile(self, user_profile_id, form) function in UserProfileService so it returns only the updated profile, instead of the profile plus the possible errors. The errors are then raised as an exception. This way, the aforementioned edit_profile() function had to be refactored too, so it handles the exception when needed. Continuing with the changes implemented in the service, we also decided to check every validation in the update method. Before this, the form allowed the user to save their profile even when the validations were not met. Once all the data is valid, the changes are commited; otherwise, the transaction is rolled back.

Finally, the HTML code for the edit profile form did not show the possible errors properly. This was due to a missing </p> label in line 113 of the app/modules/profile/templates/profile/edit.html file.

@maryycarrera maryycarrera changed the title fix: improve edit profile function so it handles errors correctly fix: Improve edit profile function so it handles errors correctly Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant