From 98633e880bd679cef1bc3880176bfaf1a9fd48a2 Mon Sep 17 00:00:00 2001 From: Chris Carlon Date: Sun, 8 Dec 2024 17:20:59 +0000 Subject: [PATCH] fix: fixed workspace memebers showing correct roles in frontend [2024-12-08] --- gridwalk-backend/src/data/dynamodb/config.rs | 4 ++ gridwalk-backend/src/routes/workspace.rs | 41 ++++++++++---------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/gridwalk-backend/src/data/dynamodb/config.rs b/gridwalk-backend/src/data/dynamodb/config.rs index 40b63ea..2c50cbc 100644 --- a/gridwalk-backend/src/data/dynamodb/config.rs +++ b/gridwalk-backend/src/data/dynamodb/config.rs @@ -418,6 +418,8 @@ impl UserStore for Dynamodb { return Ok(vec![]); } + println!("{:?}", member_items); + // Extract user IDs and create batch get request let keys: Vec> = member_items .iter() @@ -485,6 +487,8 @@ impl UserStore for Dynamodb { }) .collect(); + println!("{:?}", members); + Ok(members) } diff --git a/gridwalk-backend/src/routes/workspace.rs b/gridwalk-backend/src/routes/workspace.rs index 9fea54c..a15b3f3 100644 --- a/gridwalk-backend/src/routes/workspace.rs +++ b/gridwalk-backend/src/routes/workspace.rs @@ -1,5 +1,5 @@ use crate::auth::AuthUser; -use crate::core::{Profile, User, Workspace, WorkspaceRole}; +use crate::core::{User, Workspace, WorkspaceRole}; use crate::{app_state::AppState, core::get_unix_timestamp}; use axum::{ extract::{Extension, Path, State}, @@ -141,7 +141,7 @@ pub async fn get_workspace_members( State(state): State>, Extension(auth_user): Extension, Path(workspace_id): Path, -) -> Response { +) -> impl IntoResponse { if let Some(req_user) = auth_user.user { // Get the workspace let workspace = match Workspace::from_id(&state.app_data, &workspace_id).await { @@ -158,30 +158,29 @@ pub async fn get_workspace_members( // Get all members and transform to simplified response match workspace.get_members(&state.app_data).await { Ok(members) => { - let users: Vec> = futures::stream::iter(members) + let users: Vec = futures::stream::iter(members) .then(|m| { let state_clone = state.clone(); - async move { User::from_id(&state_clone.app_data, &m.user_id).await } + async move { + if let Ok(user) = + User::from_id(&state_clone.app_data, &m.user_id).await + { + SimpleMemberResponse { + role: m.role, + email: user.email, + } + } else { + SimpleMemberResponse { + role: m.role, + email: "Uknown".to_string(), + } + } + } }) .collect() .await; - match users.into_iter().collect::, _>>() { - Ok(users) => { - let profiles = users - .into_iter() - .map(Profile::from) - .collect::>(); - Json(profiles).into_response() - } - Err(_) => { - let error = ErrorResponse { - error: "Failed to fetch some user details".to_string(), - }; - Json(error).into_response() - } - } - - //Json(users).into_response() + + Json(users).into_response() } Err(_) => { let error = ErrorResponse {