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

[LLSC-28] Create user endpoint #7

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

mmiqball
Copy link
Collaborator

@mmiqball mmiqball commented Oct 31, 2024

Notion ticket link

[Create User endpoint (POST)] https://www.notion.so/uwblueprintexecs/Create-User-endpoint-POST-11410f3fb1dc8005b5e3f36238631399?pvs=4

Implementation description

User Creation Flow (app/services/implementations/user_service.py):

  • Implemented Firebase user creation with database integration
  • Added rollback handling if either Firebase or database operations fail
  • Proper role validation and mapping
    Schema and Model Updates (app/schemas/user.py, app/models/User.py)
  • Added Pydantic models with validation for user CRUD requests

Setup

To set this up, set up a Firebase console project > project settings > service accounts, generate a certificate and add in the fields used in utilities/firebase_init.py to the env

Checklist

  • My PR name is descriptive and in imperative tense
  • My commit messages are descriptive and in imperative tense. My commits are atomic and trivial commits are squashed or fixup'd into non-trivial commits
  • I have run the appropriate linter(s)
  • I have requested a review from the PL, as well as other devs who have background knowledge on this PR or who will be building on top of this PR

@mmiqball mmiqball force-pushed the mmiqball/LLSC-28-create-user-endpoint branch from 10bf32c to a564d75 Compare November 3, 2024 19:07
@mmiqball mmiqball changed the title [DRAFT] [LLSC-18] Create user endpoint [LLSC-28] Create user endpoint Nov 3, 2024
@mmiqball mmiqball force-pushed the mmiqball/LLSC-28-create-user-endpoint branch from 5cd9bf3 to 5f8fb34 Compare November 3, 2024 19:24
@mmiqball mmiqball requested a review from mslwang November 3, 2024 19:28
@mmiqball
Copy link
Collaborator Author

mmiqball commented Nov 3, 2024

Once we get a llsc@uwblueprint.com email, we can make an actual Firebase project instead of each person making their own for setup/testing

@mmiqball mmiqball requested a review from emma-x1 November 8, 2024 01:44
Copy link
Collaborator

@mslwang mslwang left a comment

Choose a reason for hiding this comment

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

First round of reviews, mostly naming and understanding.

backend/app/schemas/user.py Outdated Show resolved Hide resolved
backend/app/schemas/user.py Outdated Show resolved Hide resolved
backend/app/schemas/user.py Outdated Show resolved Hide resolved
backend/app/schemas/user.py Outdated Show resolved Hide resolved
backend/app/routes/user.py Outdated Show resolved Hide resolved
backend/app/schemas/user.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@mslwang mslwang left a comment

Choose a reason for hiding this comment

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

Another round of reviews, let me know when you can get around to this!

backend/app/schemas/user.py Show resolved Hide resolved
backend/app/utilities/firebase_init.py Outdated Show resolved Hide resolved
backend/app/schemas/user.py Outdated Show resolved Hide resolved
backend/app/schemas/user.py Show resolved Hide resolved
backend/app/schemas/user.py Show resolved Hide resolved
firebase_user = None
try:
# Create user in Firebase
firebase_user = firebase_admin.auth.create_user(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should eventually create another function or even another service to handle firebase interaction. The firebase error handling makes it hard to read this function.

backend/app/utilities/db_utils.py Show resolved Hide resolved
@@ -83,7 +83,7 @@ def get_users(self):
pass

@abstractmethod
def create_user(self, user, auth_id=None, signup_method="PASSWORD"):
def create_user(self, user, auth_id=None):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm assuming they added an option for adding SSO, let's actually keep this because imo SSO is easier and safer.

Copy link
Collaborator

@mslwang mslwang Nov 12, 2024

Choose a reason for hiding this comment

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

Or let's aim to add this back in if we decide to add SSO.

backend/tests/unit/test_user.py Show resolved Hide resolved
Request schema for user creation with conditional password validation
"""
password: Optional[str] = Field(None, min_length=8)
auth_id: Optional[str] = Field(None)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
auth_id: Optional[str] = Field(None)
auth_id: Optional[str] = Field(None) # for signup with google sso

Add a comment for clarity

from firebase_admin import credentials


def initialize_firebase():
Copy link
Collaborator

Choose a reason for hiding this comment

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

add INFO level logs for starting and successful initialization of firebase.

@mmiqball mmiqball force-pushed the mmiqball/LLSC-28-create-user-endpoint branch from c9fb7f0 to 43228b6 Compare November 15, 2024 00:45
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.

3 participants