Skip to content

Commit fbcfab3

Browse files
committed
merged with delete user query
1 parent 2e5307f commit fbcfab3

4 files changed

Lines changed: 59 additions & 2 deletions

File tree

graphql/src/query.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
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
async_graphql::InputType,
56
auth::{AuthGuard, GroupGuard, NotGroupGuard, UserGroup, UserInfo},
67
collection,
78
comment::{CommentParent, CommentUpdate, DeleteCommentInput, PostCommentInput},
89
page::{NewPageInput, Page},
910
slugify_ltree,
10-
user::{User, UserUpdate},
11+
user::{User, UserId, UserUpdate},
1112
AnnotatedForm, AnnotatedSeg, AttachAudioToDocumentInput, AttachAudioToWordInput,
1213
CollectionChapter, Contributor, ContributorRole, CreateEditedCollectionInput,
1314
CurateDocumentAudioInput, CurateWordAudioInput, Date, DeleteContributorAttribution,
@@ -643,6 +644,29 @@ impl Mutation {
643644
.ok_or_else(|| anyhow::format_err!("Failed to load document"))?)
644645
}
645646

647+
// Deletes a user
648+
#[graphql(guard = "AuthGuard")]
649+
async fn delete_user(&self, context: &Context<'_>, user_id: Uuid) -> FieldResult<UserId> {
650+
// let cognito = context.data::<aws_sdk_cognitoidentityprovider::Client>()?;
651+
// let user_pool_id = std::env::var("DAILP_USER_POOL")
652+
// .map_err(|_| anyhow::format_err!("DAILP_USER_POOL not set"))?;
653+
654+
// let identity_result = cognito
655+
// .admin_delete_user()
656+
// .user_pool_id(std::env::var("DAILP_USER_POOL"))
657+
// .username(user_id.to_string())
658+
// .send()
659+
// .await
660+
// .map_err(|e| anyhow::format_err!("Failed to delete user: {}", e))?;
661+
662+
// log::info!("admin_delete_user result: {:?}", identity_result);
663+
Ok(context
664+
.data::<DataLoader<Database>>()?
665+
.loader()
666+
.delete_user(&user_id)
667+
.await?)
668+
}
669+
646670
/// Decide if a piece of word audio should be included in edited collection
647671
#[graphql(guard = "GroupGuard::new(UserGroup::Editors)")]
648672
async fn curate_word_audio(

types/.sqlx/query-15e338c47089a2352b2470c60da5784405b2f8de49d56f119d3d98fe8d4dc4db.json

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

types/queries/remove_user.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
DELETE FROM dailp_user
2+
WHERE id = $1
3+
RETURNING id

types/src/database_sql.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,15 @@ impl Database {
921921
})
922922
.collect();
923923

924-
Ok(users) // come back to see if list conversions are needed
924+
Ok(users)
925+
}
926+
927+
pub async fn delete_user(&self, user_id: &Uuid) -> Result<UserId> {
928+
let row = query_file!("queries/remove_user.sql", user_id)
929+
.fetch_one(&self.client)
930+
.await?;
931+
932+
Ok(UserId(row.id.to_string()))
925933
}
926934

927935
pub async fn bookmarked_documents(&self, user_id: &Uuid) -> Result<Vec<Uuid>> {

0 commit comments

Comments
 (0)