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

#129: Promote User to Artist #331

Merged

Conversation

berkaykrc
Copy link
Contributor

Description

This pull request includes multiple changes across various files in the backend of the project. The most important changes introduce the ability to promote a user to an artist, enhance password handling, and add new fields to user and artist schemas.

User Promotion and Authorization:

  • Added a new endpoint promote_user_to_artist in Backend/app/spotify_electron/user/base_user_controller.py to promote a user to an artist.
  • Implemented the promote_user_to_artist function in Backend/app/spotify_electron/user/user/user_service.py to handle the promotion logic and validation.
  • Added a new error type BaseUserRepositoryError in Backend/app/spotify_electron/user/base_user_controller.py to handle repository-related errors.

Password Handling:

  • Modified hash_password and create_artist functions in Backend/app/auth/auth_service.py and Backend/app/spotify_electron/user/artist/artist_service.py respectively, to accept both str and bytes types for passwords. [1] [2]
  • Enhanced the hash_password function to handle both string and byte inputs correctly.

User and Artist Schema Changes:

  • Added new fields _id and id to UserDAO and UserDTO classes in Backend/app/spotify_electron/user/user/user_schema.py and ArtistDAO and ArtistDTO classes in Backend/app/spotify_electron/user/artist/artist_schema.py. [1] [2]
  • Updated the functions get_user_dao_from_document and get_user_dto_from_dao to include the new _id and id fields. [1] [2]

Testing Enhancements:

  • Added a new test function test_promote_user_to_artist in Backend/tests/test__base_users.py to verify the promotion of a user to an artist.
  • Added a new helper function promote_user_to_artist in Backend/tests/test_API/api_base_users.py for testing the promotion endpoint.

Minor Fixes and Improvements:

  • Corrected the docstring in verify_password in Backend/app/auth/auth_service.py.
  • Added print statements to Backend/tests/conftest.py to log environment variables during test setup.
  • Fixed minor typos and formatting issues in various files. [1] [2]

Commit type

  • feat: indicates the addition of a new feature or functionality to the project.

Issue

#129

Solution

Ability to promote User to Artist with existing data.

Proposed Changes

  • User can be promoted to Artist with same information.
  • When retrieving user password, logs user type and username to clarify
  • New endpoint exposed as promote_user_to_artist
  • JWT Token needed to promote user for now to ensure non-authorized requests are blocked
  • Not needed hash password again if it's provided as hashed when creating user or artist

Potential Impact

  • User IDs are visible on API side
  • Password hashing not done when creating user, artist if password already provided as hashed.

Additional Changes needed

  • Expose getting user by id as an endpoint if necessary

Assigned

@AntonioMrtz

@AntonioMrtz
Copy link
Owner

Hi @berkaykrc thanks for your work.

Can we check the OpenAPI pipeline? It ensures OpenAPI.json is updated in the repo with the latest code. More on how to generate the updated OpenAPI schema here

Let me know if you need anything :)

@AntonioMrtz AntonioMrtz linked an issue Feb 13, 2025 that may be closed by this pull request
@berkaykrc
Copy link
Contributor Author

Hi @berkaykrc thanks for your work.

Can we check the OpenAPI pipeline? It ensures OpenAPI.json is updated in the repo with the latest code. More on how to generate the updated OpenAPI schema here

Let me know if you need anything :)

Hi @AntonioMrtz.
Yes, I would like to ask before making and committing changes. Since I was only working on backend, I checked how to generate OpenAPI Schema (backend), but there is also generate OpenAPI Schema (frontend). Should I generate both or just backend?

@AntonioMrtz
Copy link
Owner

Hi @berkaykrc thanks for your work.
Can we check the OpenAPI pipeline? It ensures OpenAPI.json is updated in the repo with the latest code. More on how to generate the updated OpenAPI schema here
Let me know if you need anything :)

Hi @AntonioMrtz. Yes, I would like to ask before making and committing changes. Since I was only working on backend, I checked how to generate OpenAPI Schema (backend), but there is also generate OpenAPI Schema (frontend). Should I generate both or just backend?

If you feel confident you can also generate frontend OpenAPI schema. The backend OpenAPI schema is only needed at the time to generate frontend boilerplate for requests. I would suggest doing it at the end of the PR when endpoints parameters/names are not going to change more.

@berkaykrc
Copy link
Contributor Author

Hi @berkaykrc thanks for your work.
Can we check the OpenAPI pipeline? It ensures OpenAPI.json is updated in the repo with the latest code. More on how to generate the updated OpenAPI schema here
Let me know if you need anything :)

Hi @AntonioMrtz. Yes, I would like to ask before making and committing changes. Since I was only working on backend, I checked how to generate OpenAPI Schema (backend), but there is also generate OpenAPI Schema (frontend). Should I generate both or just backend?

If you feel confident you can also generate frontend OpenAPI schema. The backend OpenAPI schema is only needed at the time to generate frontend boilerplate for requests. I would suggest doing it at the end of the PR when endpoints parameters/names are not going to change more.

Roger that. I fixed things as you suggested, and marked as resolved comment. Generated both I'm still waiting things to discuss .nvmrc and validations.

Copy link
Owner

@AntonioMrtz AntonioMrtz left a comment

Choose a reason for hiding this comment

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

Looks good to me but there's a few adjustments to do :)

@berkaykrc berkaykrc force-pushed the feat/129-promote-user-to-artist branch from 34ccfe1 to ac73d66 Compare February 24, 2025 21:10
@AntonioMrtz
Copy link
Owner

Hi @berkaykrc I would try to review it ASAP :)

@berkaykrc
Copy link
Contributor Author

berkaykrc commented Feb 25, 2025

Hi @berkaykrc I would try to review it ASAP :)

Thank you, take your time! I just did rebase from main branch instead of merge (wanted to try it), so last two commit is what your last requested.

Copy link
Owner

@AntonioMrtz AntonioMrtz left a comment

Choose a reason for hiding this comment

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

Great job! Just a few adjustments need to be done. After that I will merge it :)

Copy link
Owner

@AntonioMrtz AntonioMrtz left a comment

Choose a reason for hiding this comment

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

The things pointed out in the comments

@berkaykrc
Copy link
Contributor Author

The things pointed out in the comments

Okay I will check them out now.

@AntonioMrtz
Copy link
Owner

Hi @berkaykrc I did some changes to the way JWTBearer dependency is injected into the endpoints. Do you need help integrating that with your PR?

@berkaykrc
Copy link
Contributor Author

berkaykrc commented Feb 28, 2025

Hi @berkaykrc I did some changes to the way JWTBearer dependency is injected into the endpoints. Do you need help integrating that with your PR?

Oh, yeah I checked it, on my promote_user_to_artist endpoint just type annotated like you did on your last commit and how it's on file on general. Do I need to make anything other than that? I just started looking into your requests. I run ruff and tests, looking fine for now.

@AntonioMrtz
Copy link
Owner

AntonioMrtz commented Feb 28, 2025

Hi @berkaykrc I did some changes to the way JWTBearer dependency is injected into the endpoints. Do you need help integrating that with your PR?

Oh, yeah I checked it, on my promote_user_to_artist endpoint just type annotated like you did on your last commit and how it's on file on general. Do I need to make anything other than that? I just started looking into your requests. I run ruff and tests, looking fine for now.

I suppose that only replace token: Depends... with token: Token should do the work. If tests are working you can push it to your branch

@berkaykrc berkaykrc requested a review from AntonioMrtz March 1, 2025 17:31
Copy link
Owner

@AntonioMrtz AntonioMrtz left a comment

Choose a reason for hiding this comment

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

lgtm :). Great job 🎉

@berkaykrc
Copy link
Contributor Author

lgtm :). Great job 🎉

Thanks much 🥳

@AntonioMrtz AntonioMrtz merged commit 885d5d6 into AntonioMrtz:master Mar 2, 2025
8 checks passed
@berkaykrc berkaykrc deleted the feat/129-promote-user-to-artist branch March 2, 2025 12:42
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.

Promote User to Artist
2 participants