Skip to content

Commit f8455ca

Browse files
committed
Changes to graphql mutation using 'admin_delete_user' instead
1 parent 5d25e96 commit f8455ca

1 file changed

Lines changed: 17 additions & 27 deletions

File tree

graphql/src/query.rs

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! This piece of the project exposes a GraphQL endpoint that allows one to access DAILP data in a federated manner with specific queries.
22
3+
use aws_sdk_cognitoidentityprovider::Client;
34
use dailp::{
45
auth::{AuthGuard, GroupGuard, UserGroup, UserInfo},
56
comment::{CommentParent, CommentUpdate, DeleteCommentInput, PostCommentInput},
@@ -648,39 +649,28 @@ impl Mutation {
648649
}
649650

650651
// Deletes a user
652+
#[graphql(guard = "AuthGuard")]
651653
async fn delete_user(&self, context: &Context<'_>, user_id: Uuid) -> FieldResult<UserId> {
652-
let cognito = context.data::<aws_sdk_cognitoidentity::Client>()?;
653-
let region = std::env::var("DAILP_AWS_REGION")
654-
.map_err(|_| anyhow::format_err!("DAILP_AWS_REGION not set"))?;
655-
let region = "us-east-1";
656-
// formats into recognizable Cognito identity ID (ex. "us-east-1:550e8400-e29b-41d4-a716-446655440000")
657-
let identity_id = format!("{}:{}", region, user_id);
654+
let cognito = context.data::<aws_sdk_cognitoidentityprovider::Client>()?;
655+
let user_pool_id = std::env::var("DAILP_USER_POOL")
656+
.map_err(|_| anyhow::format_err!("DAILP_USER_POOL not set"))?;
658657

659658
let identity_result = cognito
660-
.delete_identities()
661-
.identity_ids_to_delete(identity_id)
659+
.admin_delete_user()
660+
.user_pool_id(std::env::var("DAILP_USER_POOL"))
661+
.username(user_id.to_string())
662662
.send()
663663
.await
664-
.map_err(|e| anyhow::format_err!("Failed to delete Cognito identity: {}", e))?;
665-
666-
// if let Some(unprocessed) = identity_result.unprocessed_identity_ids() {
667-
// if !unprocessed.is_empty() {
668-
// let ids = unprocessed
669-
// .iter()
670-
// .map(|u| u.identity_id().unwrap_or_default())
671-
// .collect::<Vec<_>>()
672-
// .join(", ");
673-
// return Err(anyhow::format_err!(
674-
// "Cognito could not process some identities: {}",
675-
// ids
676-
// ).into());
677-
// }
664+
.map_err(|e| anyhow::format_err!("Failed to delete user: {}", e))?;
678665

679-
Ok(context
680-
.data::<DataLoader<Database>>()?
681-
.loader()
682-
.delete_user(&user_id)
683-
.await?)
666+
log::info!("admin_delete_user result: {:?}", identity_result);
667+
668+
Ok(UserId(user_id.to_string()))
669+
// Ok(context
670+
// .data::<DataLoader<Database>>()?
671+
// .loader()
672+
// .delete_user(&user_id)
673+
// .await?)
684674
}
685675

686676
/// Decide if a piece of word audio should be included in edited collection

0 commit comments

Comments
 (0)