Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: Allow using username in user queries #1221

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

Merged
merged 4 commits into from
Apr 29, 2022
Merged

Conversation

Emyrk
Copy link
Member

@Emyrk Emyrk commented Apr 29, 2022

The codersdk still accepts uuid for all user params. I added a UserByUsername ontop on User() func.

I was thinking we should either use generics, or an interface for a UserIdentifier and accept "me", uuid.UUID, or Username


I was writing the generic version, but you can't add Generics to methods on structs. 😢

@codecov
Copy link

codecov bot commented Apr 29, 2022

Codecov Report

Merging #1221 (290d1a3) into main (3ebe1d2) will increase coverage by 0.10%.
The diff coverage is 85.71%.

@@            Coverage Diff             @@
##             main    #1221      +/-   ##
==========================================
+ Coverage   65.60%   65.70%   +0.10%     
==========================================
  Files         269      269              
  Lines       17337    17365      +28     
  Branches      162      162              
==========================================
+ Hits        11374    11410      +36     
+ Misses       4772     4767       -5     
+ Partials     1191     1188       -3     
Flag Coverage Δ
unittest-go-macos-latest 52.96% <85.71%> (-0.02%) ⬇️
unittest-go-postgres- 64.75% <85.71%> (+0.08%) ⬆️
unittest-go-ubuntu-latest 55.42% <85.71%> (+0.13%) ⬆️
unittest-go-windows-2022 52.54% <85.71%> (+0.01%) ⬆️
unittest-js 68.85% <ø> (ø)
Impacted Files Coverage Δ
coderd/httpmw/userparam.go 85.71% <83.78%> (+7.58%) ⬆️
codersdk/users.go 64.95% <100.00%> (+0.66%) ⬆️
peer/conn.go 76.67% <0.00%> (-0.75%) ⬇️
provisionerd/provisionerd.go 76.30% <0.00%> (ø)
provisioner/terraform/provision.go 71.39% <0.00%> (+0.43%) ⬆️
coderd/provisionerdaemons.go 64.30% <0.00%> (+1.01%) ⬆️
peer/channel.go 85.54% <0.00%> (+2.31%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a3decc4...290d1a3. Read the comment docs.

})
return
}
} else if userID, err := uuid.Parse(userQuery); err == nil {
Copy link
Member

Choose a reason for hiding this comment

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

It might reduce complexity if we just disallow getting by UUID entirely. I'm not sure it provides a ton of value anyways, because you need to get the user to get the ID. You could of course list users to do that, but then just use the username.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not inclined to drop the functionality because usernames might be able to be changed. UUIDs never will.

It's really nice to have a ID, as you can assume that will be constant no matter what.

Copy link
Member

Choose a reason for hiding this comment

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

Fair enough fair enough

})
return
}
} else if userID, err := uuid.Parse(userQuery); err == nil {
Copy link
Member

Choose a reason for hiding this comment

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

Fair enough fair enough

@Emyrk Emyrk merged commit 69e26c4 into main Apr 29, 2022
@Emyrk Emyrk deleted the stevenmasley/user_by_username branch April 29, 2022 16:44
@misskniss misskniss added this to the V2 Beta milestone May 15, 2022
kylecarbs pushed a commit that referenced this pull request Jun 10, 2022
* feat: Allow using username in user queries
* Test needs a username/email to not match empty string
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