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

feat: add authentication and validate DB results with Pydantic schemas #60

Merged
merged 9 commits into from
Jul 7, 2024

Conversation

Pradip-p
Copy link
Collaborator

@Pradip-p Pradip-p commented Jul 6, 2024

The pull request I created here encountered numerous merge conflicts and merge commits, which made the codebase difficult to manage and review. In order to ensure a clean and manageable integration, I decided to create a new pull request.

This new PR consolidates all the necessary changes without the clutter of previous conflicts. I
@nrjadkry @spwoodcock Please review this PR.

What type of PR is this? (check all applicable)

  • 🍕 Feature
  • 🐛 Bug Fix
  • 📝 Documentation
  • 🧑‍💻 Refactor
  • ✅ Test
  • 🤖 Build or CI
  • ❓ Other (please specify)

Describe this PR

This PR introduces the following features:

  • Implemented user authentication to enhance security.
  • Added UUID generation for project creation to ensure unique project identifiers.
  • Validated database query results using Pydantic schemas to ensure data integrity and consistency.
  • Removed the register_user code as it was no longer required.

Screenshots

Review Guide

To test this change:

  1. Verify that user authentication works as expected during project creation.
  2. Check that UUIDs are being correctly generated and assigned to new projects.
  3. Ensure that database query results are being validated using Pydantic schemas without any errors.

@Pradip-p Pradip-p requested review from nrjadkry and spwoodcock July 6, 2024 09:31
Copy link
Member

@spwoodcock spwoodcock left a comment

Choose a reason for hiding this comment

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

Looks a lot cleaner 👍

Just some minor fixes to do

@@ -58,96 +52,62 @@ async def create_project_with_project_info(
},
)

if not new_project_id:
if not project_id:
raise HTTPException(status_code=500, detail="Project could not be created")
# Fetch the newly created project using the returned ID
select_query = f"""
Copy link
Member

Choose a reason for hiding this comment

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

This seems unnecessary after the insert above.

You could just add the fields you need to the RETURNING clause and save a database call 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thank you for the suggestion! I have updated the query to include only the necessary fields in the RETURNING clause, eliminating the extra database call. Appreciate the feedback! 👍

projects.name,
projects.short_description,
projects.description,
projects.per_task_instructions,
Copy link
Member

Choose a reason for hiding this comment

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

More of a db schema related question, but I don't understand this variable name.

Isn't it just the instructions for the project?
It could probably just be projects.instructions?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@spwoodcock I am returning only the necessary fields of the projects model instead of the whole model, and those fields are also validated using Pydantic schemas.

Regarding the variable name, I agree it could probably be just projects.instructions instead of projects.per_task_instructions.

def delete_project_by_id(
project_id: uuid.UUID,
db: Session = Depends(database.get_db),
AuthUser=Depends(login_required),
Copy link
Member

Choose a reason for hiding this comment

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

This is missing a param name:

user: AuthUser = Depends(login_required)

as auth user is just the param type

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@spwoodcock I have just fixed it by adding the missing parameter name. Thanks for pointing that out!

@@ -83,6 +93,7 @@ async def upload_project_task_boundaries(
project_id: uuid.UUID,
task_geojson: UploadFile = File(...),
db: Database = Depends(database.encode_db),
AuthUser=Depends(login_required),
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

Another endpoint has it right with

user_data: AuthUser =

project_geojson: UploadFile = File(...), dimension: int = Form(100)
project_geojson: UploadFile = File(...),
dimension: int = Form(100),
AuthUser=(login_required),
Copy link
Member

Choose a reason for hiding this comment

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

Same again

@nrjadkry nrjadkry merged commit d0fddb4 into hotosm:main Jul 7, 2024
1 check passed
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