Skip to content

Commit

Permalink
chore(users/pending-delete-toggle): migrate proto ops & refs
Browse files Browse the repository at this point in the history
  • Loading branch information
ABCxFF committed Dec 21, 2024
1 parent 9545b63 commit a0b09cc
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/api/identity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ user.workspace = true
user-avatar-upload-complete.workspace = true
user-get.workspace = true
user-identity-get.workspace = true
user-pending-delete-toggle.workspace = true
rivet-config.workspace = true
rivet-env.workspace = true

Expand Down
8 changes: 4 additions & 4 deletions packages/api/identity/src/route/identities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ pub async fn mark_deletion(
) -> GlobalResult<serde_json::Value> {
let user_ent = ctx.auth().user(ctx.op_ctx()).await?;

op!([ctx] user_pending_delete_toggle {
user_id: Some(user_ent.user_id.into()),
(*ctx).op(::user::ops::pending_delete_toggle::Input {
user_id: user_ent.user_id,
active: true,
})
.await?;
Expand All @@ -319,8 +319,8 @@ pub async fn mark_deletion(
pub async fn unmark_deletion(ctx: Ctx<Auth>) -> GlobalResult<serde_json::Value> {
let user_ent = ctx.auth().user(ctx.op_ctx()).await?;

op!([ctx] user_pending_delete_toggle {
user_id: Some(user_ent.user_id.into()),
(*ctx).op(::user::ops::pending_delete_toggle::Input {
user_id: user_ent.user_id,
active: false,
})
.await?;
Expand Down
1 change: 1 addition & 0 deletions packages/services/user/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ rivet-config.workspace = true
rivet-operation.workspace = true
token-create.workspace = true
user-get.workspace = true
user-identity-get.workspace = true

[dependencies.sqlx]
workspace = true
Expand Down
1 change: 1 addition & 0 deletions packages/services/user/src/ops/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod pending_delete_toggle;
pub mod profile_validate;
pub mod resolve_display_name;
pub mod resolve_email;
Expand Down
47 changes: 47 additions & 0 deletions packages/services/user/src/ops/pending_delete_toggle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use chirp_workflow::prelude::*;
use proto::backend::{self, pkg::*};
use rivet_operation::prelude::proto;

#[derive(Debug)]
pub struct Input {
pub user_id: Uuid,
pub active: bool
}

#[derive(Debug)]
pub struct Output {
}


#[operation]
pub async fn pending_delete_toggle(
ctx: &OperationCtx,
input: &Input
) -> GlobalResult<Output> {
let user_id = input.user_id;

// Verify the user is registered
let identity = op!([ctx] user_identity_get {
user_ids: vec![user_id.into()],
})
.await?;
let identities = &unwrap_ref!(identity.users.first()).identities;
ensure_with!(!identities.is_empty(), IDENTITY_NOT_REGISTERED);

sql_execute!(
[ctx]
"UPDATE db_user.users SET delete_request_ts = $2 WHERE user_id = $1",
user_id,
input.active.then(util::timestamp::now),
)
.await?;

ctx.cache().purge("user", [user_id]).await?;

msg!([ctx] user::msg::update(user_id) {
user_id: Some(user_id.into()),
})
.await?;

Ok(Output {})
}

0 comments on commit a0b09cc

Please sign in to comment.