-
-
Notifications
You must be signed in to change notification settings - Fork 21
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
655 Add User Roles and Basic User Data to Db #668
Conversation
… were autogenerated by the api.
… table and replace with the host user type.
…that upgrade our in-memory test database
…ase as part of the test project setup. Also, add a test suite to test the migration.
…a tests, and replace old host schema tests. Add user schema validation to enforce valid role.
…g a UserSchema. The updated endpoint now requires email and user_name. Fix test cases by updating the app fixture to use an upgraded database, allow the DataAccessLayer to be configured by the test project, and remove the Host model class
…st and last name and updating MockAWS test users to be Admin role.
…ng the upgrade/downgrade process idempotent
…uests. Also, Update UserSchema to allow extra fields. This will allow us to parse User models directly from request JSON.
2. Add test case to verify all fields are required during signup. 3. Update SignUp e2e test to add a no mocking version. This tests against the acutal running backend.
…ts were throwing 'db not up to date' errors on CI pipeline.
…rn it in the user data response.
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.
Everything looks great! Thanks for the detailed steps for updating the data model. Approving. Only question is regarding the workflow_dispatch
property in the test workflow.
* There is no way to map host users back to the user table. We would need a user id foreign | ||
key, or at least an email address. | ||
''' | ||
role_table = op.create_table('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.
This means there can be duplicate role names. The id
column isn't strictly necessary. The name
column can be the primary key.
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.
Correct, the id
isn't strictly necessary, but it does provide us the flexibility to rename the roles at any time. I think being able to easily rename our roles is worth storing 4-10 extra integers in the db.
To your point about duplicate names, I added a safeguard against this in 6ad02dd by adding the unique=True
constraint to the role.name
field.
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.
Using on update cascade
can also be considered easy when defining a table. What other reasons are there to use a surrogate key?
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.
Using surrogate keys like an id field offers several advantages beyond the ease of updates provided by ON UPDATE CASCADE
. Surrogate keys are unique and stable, providing an abstraction layer that decouples database structure from business logic, thus reducing the need for changes due to business modifications. They enhance performance with quicker indexing and simplify relational management by avoiding the complexities and potential performance issues of cascading updates. Additionally, surrogate keys maintain data integrity by minimizing risks associated with data duplication and erroneous updates, making them ideal for robust, scalable database architectures.
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.
Is that a chatgpt response? 😄 Do these reasons apply to this data model?
Some people have spaces in their names. Here's some resources to understand more about names: |
Looking good. Is there a PM created issue this can relate back to? |
…racter long, add additional user repo tests, and make last names optional per US Web Design System Guidance: https://designsystem.digital.gov/patterns/create-a-user-profile/name/
…pt is added. Our instructions were missing the increment step, but it is more reliable to simply auto-increment. The downside is that we'll need to bundle our migration scripts with the API.
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:
|
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. |
f73415a
to
4a1ac90
Compare
@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 |
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:
roles
table).marshmallow-sqlalchemy
to the latest release. I needed a bug fix from the latest release.signUpHost
andsignUpCoordinator
endpoints to 1) assign a role to their created users and 2) require the user first and last name.user
andsignIn
endpoints to return the user first and last name as part of theuser
data.api/openapi_server/models/README.md
, and include instructions on how to update the database model. Turns out there are a lot of steps!User
model (de)serialization json schema, complete with a test suite. We could add some name validation here (e.g. don't allow spaces in names) and filter the json requests through the schema, but it didn't seem worth while.Host
model object. This is now replaced by theUser
model with aHost
role.create_host
endpoint. This is now completely replaced bysignUpHost
3ceec084158f_.py
, to work with unversioned local databases. This will allow other devs to runalembic upgrade head
even if they've been working off of an API-generated database.guest
role and will be given the names "unknown".run-tests.yml
to include aworkflow_dispatch
trigger to allow manual triggering.cypress:run:mock
andcypress:run:nomock
configurations to allow more easily running the full e2e test suites.Rationale behind the changes?
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
pytest-alembic
.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 inapi/openapi_server/models/README.md
.New Data Model
Video of new Sign In User Initials
Visuals after changes are applied
UserNameDemo.mp4