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

chore(services/user): migrate user-team-list proto op #1650

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

ABCxFF
Copy link
Contributor

@ABCxFF ABCxFF commented Dec 18, 2024

Changes

Copy link
Contributor Author

ABCxFF commented Dec 18, 2024


How to use the Graphite Merge Queue

Add 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.

Copy link

cloudflare-workers-and-pages bot commented Dec 18, 2024

Deploying rivet with  Cloudflare Pages  Cloudflare Pages

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

View logs

@ABCxFF ABCxFF force-pushed the 12-18-chore_services_user_migrate_user_proto_ops branch from 06909a8 to 4c41e8e Compare December 21, 2024 00:45
@ABCxFF ABCxFF force-pushed the 12-18-chore_services_user_migrate_user_proto_ops branch from 4c41e8e to 075a092 Compare December 30, 2024 23:07
Copy link
Contributor

@MasterPtato MasterPtato left a 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 just ctx
  • 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 to packages/services/user/db/user-identity
  • In the API layer we could change functions to accept an OperationCtx (new, from chirp-workflow) or a Ctx (from api-helper) instead of an OperationContext (old) which would allow us to get rid of compat calls and just do .op. This is low priority though and isn't required

Comment on lines +47 to +57
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()
}))
}
}
)
Copy link
Contributor

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

Comment on lines +47 to +57
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()
}))
}
}
)
Copy link
Contributor

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>,
Copy link
Contributor

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,
Copy link
Contributor

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

@ABCxFF ABCxFF force-pushed the 12-18-chore_services_user_migrate_user_proto_ops branch from e508246 to ec88581 Compare January 7, 2025 15:45
@ABCxFF ABCxFF force-pushed the 12-18-chore_services_user_migrate_user_proto_ops branch from ec88581 to d8bc66a Compare January 14, 2025 22:47
@ABCxFF ABCxFF force-pushed the 12-18-chore_services_user_migrate_user_proto_ops branch from d8bc66a to 6fb3d05 Compare January 22, 2025 03:35
@ABCxFF ABCxFF force-pushed the 12-18-chore_services_user_migrate_user_proto_ops branch 4 times, most recently from b259e38 to 9a2121e Compare January 28, 2025 19:50
@ABCxFF ABCxFF force-pushed the 12-18-chore_services_user_migrate_user_proto_ops branch 2 times, most recently from 2519b6f to be1bf74 Compare January 28, 2025 22:35
@ABCxFF ABCxFF force-pushed the 12-18-chore_services_user_migrate_user_proto_ops branch from be1bf74 to 936d97d Compare February 6, 2025 21:51
@ABCxFF ABCxFF marked this pull request as ready for review February 10, 2025 19:37
Copy link

@greptile-apps greptile-apps bot left a 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 using ctx.op() instead of op! macro

77 file(s) reviewed, 49 comment(s)
Edit PR Review Bot Settings | Greptile

@ABCxFF ABCxFF force-pushed the 12-18-chore_services_user_migrate_user_proto_ops branch from 936d97d to f0811d0 Compare February 10, 2025 23:08
@ABCxFF ABCxFF force-pushed the 12-18-chore_services_user_migrate_user_proto_ops branch from f0811d0 to 742f6bc Compare February 14, 2025 14:31
@ABCxFF
Copy link
Contributor Author

ABCxFF commented Feb 14, 2025

@greptileai

Copy link

@greptile-apps greptile-apps bot left a 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 with chirp_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

Comment on lines +100 to 103
let email_res = ctx.op(::user::ops::resolve_email::Input {
emails: vec![res.email.clone()],
})
.await?;
Copy link

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],
Copy link

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.

Comment on lines +119 to +124
let user_res = chirp_workflow::compat::op(
&ctx,
::user::ops::get::Input {
user_ids: vec![user_ent.user_id],
},
)
Copy link

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");
Copy link

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.

Comment on lines +220 to 228
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?;
Copy link

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 =

Comment on lines +37 to +38
let user_res = op!([ctx] faker_user { }).await.unwrap();
let user_id = user_res.user_id.unwrap().as_uuid();
Copy link

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()

Comment on lines +65 to +66
.find(|u| u.user_id.unwrap().as_uuid() == user.user_id.unwrap())
.expect("user not returned");
Copy link

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

Comment on lines +32 to +34
assert_eq!(1, res.users.len());
let user = res.users.first().unwrap();
assert_eq!(user_id, user.user_id);
Copy link

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()
Copy link

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

Comment on lines +40 to +45
assert_eq!(3, res.users.len());
let users_map = res
.users
.iter()
.map(|u| (u.user_id, u.teams.len()))
.collect::<HashMap<Uuid, usize>>();
Copy link

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

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.

2 participants