hackforla / HomeUniteUs

We're working with community non-profits who have a Host Home or empty bedrooms initiative to develop a workflow management tool to make the process scalable (across all providers), reduce institutional bias, and effectively capture data.
https://homeunite.us/
GNU General Public License v2.0
35 stars 21 forks source link

655 Add User Roles and Basic User Data to Db #668

Closed Joshua-Douglas closed 1 month ago

Joshua-Douglas commented 1 month ago

Closes #655.

What changes did you make?

Added user roles (Guest, Host, Coordinator, Admin) and updated the user model to include first, middle, and last name. PR #661 made an update that passes the first and last name to the backend, so I was also able to update the frontend app to begin receiving and storing the user names as well (video below).

The user name initials are now displayed on the user avatar menu after logging in, and the user's name is accessible from all authenticated components.

Making this change required refactoring our alembic migration scripts, the API test project, and the API itself. The following detailed changes were required:

Before this PR there was no mechanism for determining user type and there was no mechanism for storing basic user information. We can now differentiate between guests, hosts, and coordinators. This will allow us to begin creating different views for each user type, and to begin restricting portions of the API that require elevated access.

This PR does not implement any data model relationships between user types, and it does not implement role-specific user data.

Testing done for these changes

What did you learn or can share that is new?(optional)

I learned how to write and test alembic database migrations. The steps are documented in api/openapi_server/models/README.md.

New Data Model

classDiagram
class alembic_version{
   *VARCHAR<32> version_num NOT NULL
}
class housing_program{
   *INTEGER id NOT NULL
   VARCHAR program_name NOT NULL
   INTEGER service_provider NOT NULL
}
class housing_program_service_provider{
   *INTEGER id NOT NULL
   VARCHAR provider_name NOT NULL
}
class role{
   *INTEGER id NOT NULL
   VARCHAR name NOT NULL
}
class user{
   *INTEGER id NOT NULL
   VARCHAR email NOT NULL
   VARCHAR<255> firstName NOT NULL
   VARCHAR<255> lastName NOT NULL
   VARCHAR<255> middleName
   INTEGER role_id NOT NULL
}
housing_program_service_provider "1" -- "0..n" housing_program
role "1" -- "0..n" user

Video of new Sign In User Initials

Visuals after changes are applied https://github.com/hackforla/HomeUniteUs/assets/22138019/9bdf0326-269e-432b-be1f-335f64605367 ![image](Paste_Your_Image_Link_Here_After_Attaching_Files)
paulespinosa commented 1 month ago
  • (e.g. don't allow spaces in names)

Some people have spaces in their names. Here's some resources to understand more about names:

https://github.com/kdeldycke/awesome-falsehood

paulespinosa commented 1 month ago

Looking good. Is there a PM created issue this can relate back to?

Joshua-Douglas commented 1 month ago
  • (e.g. don't allow spaces in names)

Some people have spaces in their names. Here's some resources to understand more about names:

https://github.com/kdeldycke/awesome-falsehood

That's a great illustration of why I did not validate the names. Great sources, thanks!

After reading through them I realized two things and corrected both in 6ad02dd:

  1. Last names should not be required. I updated the database model to only require first names.
  2. First names should be at least one character in length. The data model now validates that the name is at least one non-space character.
Joshua-Douglas commented 1 month ago

Hey @erikguntner and @paulespinosa,

Thank you so much for taking the time to do a detailed review. I've updated the PR in response to your comments.

Since I had to modify the migration script, it is probably best for you to downgrade and re-upgrade if your local db is on the current head.

Here are all the changes from the review:

I also noticed that #602 broke our e2e tests, so I submitted a fix for this in 74f861e.

Joshua-Douglas commented 1 month ago

@paulespinosa, I saw your question but I don't see any requested changes. Does this PR require more work?

paulespinosa commented 1 month ago

@paulespinosa, I saw your question but I don't see any requested changes. Does this PR require more work?

Code seems fine. @sanya301, @rpradheap this feature adds ~fields to the sign up page~ (sorry for the confusion) the user initials as shown in the video above. Look good to you?