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

Implements findUserByMe endpoint + trimmings #19

Merged
merged 7 commits into from
Sep 14, 2023
Merged

Implements findUserByMe endpoint + trimmings #19

merged 7 commits into from
Sep 14, 2023

Conversation

gbdubs
Copy link
Contributor

@gbdubs gbdubs commented Sep 11, 2023

No description provided.

@gbdubs gbdubs requested a review from bcspragu September 11, 2023 21:49
@gbdubs gbdubs linked an issue Sep 12, 2023 that may be closed by this pull request
@@ -26,17 +26,32 @@ func initiativeToOAPI(i *pacta.Initiative) (*api.Initiative, error) {
}, nil
}

func userToOAPI(user *pacta.User) (*api.User, error) {
if user == nil {
return nil, errorInternal(fmt.Errorf("userToOAPI: can't convert nil pointer"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

I hear your point about keeping all the conv stuff in the pactasrv package so you can access these, but my counterpoint would be that determining the 'type' of an error truly is a concern of the server, and this should just return a fmt.Errorf(...) or some conv-specific error that the srv layer then converts into an errorWhatever

Functionally, it probably doesn't matter, just cleaner abstractions and easier testing

Comment on lines +29 to +31
func userToOAPI(user *pacta.User) (*api.User, error) {
if user == nil {
return nil, errorInternal(fmt.Errorf("userToOAPI: can't convert nil pointer"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

I remember you had a reason for using *api.Whatever and dereference instead of just using structs directly, but it seems like a lot of contorting to be using pointers, but having to check for errors/disallow them, only to convert them back into not-pointers later

if authnID == "" {
return nil, fmt.Errorf("couldn't find authn id in jwt")
}
user, err := s.DB.GetOrCreateUserByAuthn(s.DB.NoTxn(ctx), pacta.AuthnMechanism_EmailAndPass, authnID, emails[0])
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would not use a GetOrCreate endpoint for something like this. GetOrCreate-ing a user should happen on a dedicated login or similar endpoint, it should be an error if a user tries to do anything else without an account in the DB.

There's a bunch of reasons to do this, but the main one is to have a single location where we create accounts in the DB.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What are the other reasons? We can remove the other CreateUser method trivially.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The other reasons are something like:

  1. We shouldn't have exported methods that nobody is using, it increases the package's surface area unnecessarily
  2. Given the way our login system works ('get token, send to server'), the only way of account creation that makes sense is GetOrCreateUser[...], we shouldn't make it tempting to create accounts any other way

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wait I might be misunderstanding. When does the token from Azure get sent directly to the server? Aren't we always facilitating that exchange through the Frontend? If so wouldn't just having getOrCreateUser make sense at the FE layer too?

Agreed on the idea of one method at the DB layer. - I'll make CreateUser testonly.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copying image from Slack:
image

Copy link
Collaborator

@bcspragu bcspragu Sep 14, 2023

Choose a reason for hiding this comment

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

The token that would go to a PACTA /login endpoint would be the RMI-specific token from step 4, and that would get or create the user account in the PACTA database

db/sqldb/user.go Outdated Show resolved Hide resolved
db/sqldb/user.go Outdated Show resolved Hide resolved
pacta/email.go Outdated Show resolved Hide resolved
pacta/email.go Outdated Show resolved Hide resolved
pacta/email.go Outdated Show resolved Hide resolved
pacta/email.go Outdated Show resolved Hide resolved
scripts/run_db.sh Outdated Show resolved Hide resolved
@gbdubs gbdubs merged commit a8ca9f5 into main Sep 14, 2023
1 of 2 checks 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.

Error Yields Hundreds of Requests
2 participants