|
1 | 1 | //! This piece of the project exposes a GraphQL endpoint that allows one to access DAILP data in a federated manner with specific queries. |
2 | 2 |
|
| 3 | +use aws_sdk_cognitoidentityprovider::Client; |
3 | 4 | use dailp::{ |
4 | 5 | auth::{AuthGuard, GroupGuard, UserGroup, UserInfo}, |
5 | 6 | comment::{CommentParent, CommentUpdate, DeleteCommentInput, PostCommentInput}, |
@@ -648,39 +649,28 @@ impl Mutation { |
648 | 649 | } |
649 | 650 |
|
650 | 651 | // Deletes a user |
| 652 | + #[graphql(guard = "AuthGuard")] |
651 | 653 | 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"))?; |
658 | 657 |
|
659 | 658 | 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()) |
662 | 662 | .send() |
663 | 663 | .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))?; |
678 | 665 |
|
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?) |
684 | 674 | } |
685 | 675 |
|
686 | 676 | /// Decide if a piece of word audio should be included in edited collection |
|
0 commit comments