-
Notifications
You must be signed in to change notification settings - Fork 1
Finish Up Restructuring User System #84
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
base: main
Are you sure you want to change the base?
Conversation
backend/python/migrations/versions/01f342ea9ad6_add_cascade_delete_to_driver_and_admin.py
Fixed
Show fixed
Hide fixed
backend/python/migrations/versions/01f342ea9ad6_add_cascade_delete_to_driver_and_admin.py
Fixed
Show fixed
Hide fixed
Code ReviewOverall this is a good cleanup PR — re-enabling role-based authorization and adding cascade deletes are both solid improvements. I found a few issues that should be addressed before merging. Critical Bug: Role Case MismatchThere is a case inconsistency across the codebase that will break driver authorization silently.
When a driver tries to access a protected route, Suggestion: Pick one convention (e.g. all lowercase) and apply it consistently. The admin route already uses # auth.py — should match what Firebase claims actually store
require_driver = require_authorization_by_role({"driver"})
|
PR Review: Finish Up Restructuring User SystemOverall this is a solid cleanup PR — removing unused OAuth code, re-enabling role-based authorization, and adding cascade deletes are all good improvements. A few things to address: Bugs / Issues1. HTTP 401 used for authorization failures (should be 403) In raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN,
detail="You are not authorized to make this request.",
)This applies to both the re-enabled 2. The admin email from app.config import settings
admin_email = settings.admin_email # or similar3. Migration downgrade uses In the downgrade path of op.drop_constraint(None, 'drivers', type_='foreignkey')This will fail at runtime if the downgrade is ever needed. The generated constraint names should be explicitly named in both Design Question (from PR description)
Yes, if the design intent is that a driver/admin record cannot exist without a user, then deleting through the user (and relying on cascade) is the correct approach. You can keep Minor / Style
What's working well
|
|
@claude review |
Pull Request Review: Finish Up Restructuring User SystemSummaryThis PR successfully completes the user system restructuring by re-enabling role-based authorization, removing unused OAuth routes, and adding cascade delete functionality to driver and admin relationships. The implementation is solid with a few areas that could be improved. Positive Changes ✅
Issues & Concerns 🔴1. Security: Hardcoded Admin EmailLocation: backend/python/app/update_firebase.py:5 admin_email = "[email protected]"Issue: The admin email is hardcoded in the migration script. This creates several problems:
Recommendation: Either:
2. Inconsistent Error Handling in auth.pyLocation: backend/python/app/dependencies/auth.py:86-99 The Recommendation: # Line 90 and 97 should use HTTP_403_FORBIDDEN instead of HTTP_401_UNAUTHORIZED
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN, # Changed from 401
detail="You are not authorized to make this request.",
)3. Role Case Sensitivity MismatchLocation: backend/python/app/dependencies/auth.py:131 require_driver = require_authorization_by_role({"driver"})Issue: The role is now lowercase Recommendation: Search for all role string comparisons and ensure consistent casing. The Firebase custom claims use lowercase "admin" and "driver" (from update_firebase.py), so all checks should be lowercase. 4. Missing Error Handling in Migration ScriptLocation: backend/python/app/update_firebase.py:21-32 Issue: The script catches exceptions per-user but doesn't:
Recommendation: Add proper error tracking and exit codes for CI/CD integration. Code Quality Issues
|
|
|
||
| # Common authorization dependencies | ||
| require_driver = require_authorization_by_role({"Driver"}) | ||
| require_driver = require_authorization_by_role({"driver"}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a quick food for thought, in our codebase, there are two roles drivers and admin, and some routes are admin only. This means that by default, admin should be able to access all routes, so it might not make sense to have a require driver.
This gives 2 solutions:
- Simpler: Delete the require driver entirely and only use require_admin, and only require valid auth checks for some api routes.
- More Complex but better: delete require_driver, and use ID-based checks for driver self-service (e.g., driver can only update their own profile)
Admin ID bypasses all id checks or has access to all IDs
Lmk which one you would prefer and your thoughts!
ludavidca
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great Job making these changes! User System is definitely one of the most critical and important and complex parts of the project and I'm really happy with how much work you've put into this. There are still a couple of small comments and nice to haves. Lmk your thoughts!
|
|
||
| admin_email = "[email protected]" | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be best to have this as an env variable to avoid hardcoded values
|
|
||
| def update_all_users_role(role_name: str) -> None: | ||
| """ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job on implementing a way to update all roles!
I realize that I should have probably better specified this in the ticket, but can we add another function to update only one user to admin or driver instead? This way, we won't have people changing other people's roles in the middle of development. Thanks!
| # NOTE: This overwrites preexisting roles so be careful! | ||
| new_role = "driver" | ||
| update_all_users_role(new_role) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once the update_your_user_role is implemented (with input param being your email). Please feel free to make that the default main function that runs, and make a variable your_email = "" to be used by the function!
JIRA ticket link
Finish Up Restructuring User System
Implementation description
Steps to test
What should reviewers focus on?
Checklist