-
Notifications
You must be signed in to change notification settings - Fork 82
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
chore(services/user): migrate user-team-list proto op #1650
base: main
Are you sure you want to change the base?
Conversation
How to use the Graphite Merge QueueAdd the label merge-queue to this PR to add it to the merge queue. You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
Deploying rivet with
|
Latest commit: |
742f6bc
|
Status: | ✅ Deploy successful! |
Preview URL: | https://f8f8b197.rivet.pages.dev |
Branch Preview URL: | https://12-18-chore-services-user-mi-7ha2.rivet.pages.dev |
06909a8
to
4c41e8e
Compare
4c41e8e
to
075a092
Compare
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.
I know this is still in progress, just providing some initial feedback. Feel free to ignore any changes you've already made. Really good stuff all around.
I only have nits to add on top of the comments i left:
- You can remove the leading
::
from all user pkg paths (::user::ops::get
->user::ops::get
) - Auto dereferencing should handle calls to
.op
in API services automatically, so you can change(*ctx)
to justctx
- The migration files from api-identity were moved to the wrong location, the entire folder at
packages/services/user-identity/db/user-identity
should be moved topackages/services/user/db/user-identity
- In the API layer we could change functions to accept an
OperationCtx
(new, from chirp-workflow) or aCtx
(from api-helper) instead of anOperationContext
(old) which would allow us to get rid ofcompat
calls and just do.op
. This is low priority though and isn't required
chirp_workflow::compat::op( | ||
&ctx, | ||
::user::ops::identity::create::Input { | ||
user_id: primary_user_id, | ||
identity: backend::user_identity::Identity { | ||
kind: Some(backend::user_identity::identity::Kind::Email(backend::user_identity::identity::Email { | ||
email: util::faker::email() | ||
})) | ||
} | ||
} | ||
) |
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.
Standalone services should be converted to use the new contexts as well, that way you dont have to use compat
. See cluster-gc
for an example. You'll have to change the ctx
variable above to use StandaloneCtx
chirp_workflow::compat::op( | ||
&ctx, | ||
::user::ops::identity::create::Input { | ||
user_id: primary_user_id, | ||
identity: backend::user_identity::Identity { | ||
kind: Some(backend::user_identity::identity::Kind::Email(backend::user_identity::identity::Email { | ||
email: util::faker::email() | ||
})) | ||
} | ||
} | ||
) |
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.
See above comment
|
||
#[derive(Debug)] | ||
pub struct Output { | ||
pub errors: Vec<common::ValidationError>, |
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.
Should be converted to rust type
#[derive(Debug)] | ||
pub struct Input { | ||
pub user_id: Uuid, | ||
pub client: backend::net::ClientInfo, |
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.
Should be converted to rust type
e508246
to
ec88581
Compare
ec88581
to
d8bc66a
Compare
d8bc66a
to
6fb3d05
Compare
b259e38
to
9a2121e
Compare
2519b6f
to
be1bf74
Compare
be1bf74
to
936d97d
Compare
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.
PR Summary
Based on the extensive changes shown, here's a concise summary of the key modifications in this PR:
Migrates user-related proto operations to a new consolidated structure in the user service, focusing on standardizing operation calls and improving code organization.
- Moved user identity database migrations from
/services/user-identity/db/user-identity
to/services/user/db/user-identity
- Added new user service operations in
/services/user/src/ops/
including identity management, profile validation, and token handling - Replaced individual user-related dependencies with consolidated
user.workspace
dependency across multiple packages - Added comprehensive test coverage for new user service operations in
/services/user/tests/
- Added
chirp-workflow
dependency to support new operation calling pattern usingctx.op()
instead ofop!
macro
77 file(s) reviewed, 49 comment(s)
Edit PR Review Bot Settings | Greptile
936d97d
to
f0811d0
Compare
f0811d0
to
742f6bc
Compare
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.
PR Summary
Based on the extensive changes shown, here's a concise summary of the most recent modifications in this PR:
Migrates user-team-list proto operation to use the new consolidated user service structure, with significant changes to authentication and operation calls.
- Replaced
op!
macro calls withchirp_workflow::compat::op
for user operations across auth.rs files in multiple API packages - Updated team membership checks to handle UUID conversions correctly in group-related operations
- Simplified user data retrieval in admin validation by reusing existing user calls
- Added new user service operations with proper caching and database interactions
- Introduced comprehensive test suite for new user operations including identity, profile, and token management
The changes maintain existing functionality while modernizing the API structure and improving code organization.
79 file(s) reviewed, 32 comment(s)
Edit PR Review Bot Settings | Greptile
let email_res = ctx.op(::user::ops::resolve_email::Input { | ||
emails: vec![res.email.clone()], | ||
}) | ||
.await?; |
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.
logic: ensure that email_res.users is properly ordered to prevent potential race conditions when multiple users have the same email
chirp_workflow::compat::op( | ||
&ctx, | ||
::user::ops::get::Input { | ||
user_ids: vec![user_ent.user_id], |
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.
logic: user_ids is passed without .into() here, but with .into() on line 112. These should be consistent.
let user_res = chirp_workflow::compat::op( | ||
&ctx, | ||
::user::ops::get::Input { | ||
user_ids: vec![user_ent.user_id], | ||
}, | ||
) |
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.
logic: The user_id type conversion may need to be checked here. Previously it was explicitly converted with .into(), but now it's passed directly. Verify that user_ent.user_id matches the expected type in the Input struct.
::user::ops::get::Input { | ||
user_ids: vec![user_ent.user_id], | ||
}, | ||
) | ||
.await?; | ||
|
||
let user = unwrap!(user_res.users.first(), "user not found"); |
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.
style: The error message 'user not found' is redundant since this code path should be unreachable - the user was already found in the first user_get call. Consider removing this check entirely.
let res = ctx.op(::user::ops::profile_validate::Input { | ||
user_id: user_ent.user_id, | ||
display_name: body.display_name.clone(), | ||
account_number: | ||
body.account_number | ||
.map(|n| n.api_try_into()) | ||
.transpose()?, | ||
account_number: body.account_number | ||
.map(|n| n.api_try_into()) | ||
.transpose()?, | ||
bio: body.bio.clone(), | ||
}) | ||
.await?; |
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.
style: The indentation here is inconsistent with the rest of the file - there's an extra space after res =
let user_res = op!([ctx] faker_user { }).await.unwrap(); | ||
let user_id = user_res.user_id.unwrap().as_uuid(); |
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.
style: consider adding error handling for faker_user failure case rather than just unwrap()
.find(|u| u.user_id.unwrap().as_uuid() == user.user_id.unwrap()) | ||
.expect("user not returned"); |
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.
style: consider more descriptive error message than 'user not returned', e.g. include the user ID that wasn't found
assert_eq!(1, res.users.len()); | ||
let user = res.users.first().unwrap(); | ||
assert_eq!(user_id, user.user_id); |
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.
style: consider adding assertions to verify that the non-existent email was not resolved to any user
|
||
let res = ctx.op(::user::ops::token_create::Input { | ||
user_id, | ||
client: backend::net::ClientInfo::default() |
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.
style: consider testing with non-default ClientInfo to ensure token creation works with different client configurations
assert_eq!(3, res.users.len()); | ||
let users_map = res | ||
.users | ||
.iter() | ||
.map(|u| (u.user_id, u.teams.len())) | ||
.collect::<HashMap<Uuid, usize>>(); |
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.
style: Consider adding error messages to assertions to make test failures more descriptive
Changes