mirror of
				https://github.com/nitnelave/lldap.git
				synced 2023-04-12 14:25:13 +00:00 
			
		
		
		
	api: add the rest of the fields to User
This commit is contained in:
		
							parent
							
								
									ee21c2f5fc
								
							
						
					
					
						commit
						0cf7b76c1c
					
				| @ -2,8 +2,9 @@ query ListUsersQuery($filters: RequestFilter) { | |||||||
|   users(filters: $filters) { |   users(filters: $filters) { | ||||||
|     id |     id | ||||||
|     email |     email | ||||||
|     groups { |     displayName | ||||||
|       id |     firstName | ||||||
|     } |     lastName | ||||||
|  |     creationDate | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,8 +0,0 @@ | |||||||
| use graphql_client::GraphQLQuery; |  | ||||||
| 
 |  | ||||||
| #[derive(GraphQLQuery)] |  | ||||||
| #[graphql(
 |  | ||||||
|     schema_path = "../schema.graphql", |  | ||||||
|     query_path = "queries/list_users.graphql" |  | ||||||
| )] |  | ||||||
| pub struct ListUsersQuery; |  | ||||||
| @ -4,7 +4,6 @@ mod api; | |||||||
| mod app; | mod app; | ||||||
| mod cookies; | mod cookies; | ||||||
| mod create_user; | mod create_user; | ||||||
| mod graphql_api; |  | ||||||
| mod login; | mod login; | ||||||
| mod logout; | mod logout; | ||||||
| mod user_details; | mod user_details; | ||||||
|  | |||||||
| @ -1,19 +1,24 @@ | |||||||
| use crate::{ | use crate::api::HostService; | ||||||
|     api::HostService, |  | ||||||
|     graphql_api::{ |  | ||||||
|         list_users_query::{self, RequestFilter, ResponseData}, |  | ||||||
|         ListUsersQuery, |  | ||||||
|     }, |  | ||||||
| }; |  | ||||||
| use anyhow::{anyhow, Result}; | use anyhow::{anyhow, Result}; | ||||||
| use lldap_model::*; | use graphql_client::GraphQLQuery; | ||||||
| use yew::format::Json; | use yew::format::Json; | ||||||
| use yew::prelude::*; | use yew::prelude::*; | ||||||
| use yew::services::{fetch::FetchTask, ConsoleService}; | use yew::services::{fetch::FetchTask, ConsoleService}; | ||||||
| 
 | 
 | ||||||
|  | #[derive(GraphQLQuery)] | ||||||
|  | #[graphql(
 | ||||||
|  |     schema_path = "../schema.graphql", | ||||||
|  |     query_path = "queries/list_users.graphql", | ||||||
|  |     response_derives = "Debug", | ||||||
|  |     custom_scalars_module = "chrono" | ||||||
|  | )] | ||||||
|  | pub struct ListUsersQuery; | ||||||
|  | 
 | ||||||
|  | use list_users_query::{RequestFilter, ResponseData}; | ||||||
|  | 
 | ||||||
| pub struct UserTable { | pub struct UserTable { | ||||||
|     link: ComponentLink<Self>, |     link: ComponentLink<Self>, | ||||||
|     users: Option<Result<Vec<User>>>, |     users: Option<Result<Vec<list_users_query::ListUsersQueryUsers>>>, | ||||||
|     // Used to keep the request alive long enough.
 |     // Used to keep the request alive long enough.
 | ||||||
|     _task: Option<FetchTask>, |     _task: Option<FetchTask>, | ||||||
| } | } | ||||||
| @ -54,15 +59,7 @@ impl Component for UserTable { | |||||||
|     fn update(&mut self, msg: Self::Message) -> ShouldRender { |     fn update(&mut self, msg: Self::Message) -> ShouldRender { | ||||||
|         match msg { |         match msg { | ||||||
|             Msg::ListUsersResponse(Ok(users)) => { |             Msg::ListUsersResponse(Ok(users)) => { | ||||||
|                 self.users = Some(Ok(users |                 self.users = Some(Ok(users.users.into_iter().collect())); | ||||||
|                     .users |  | ||||||
|                     .into_iter() |  | ||||||
|                     .map(|u| User { |  | ||||||
|                         user_id: u.id, |  | ||||||
|                         email: u.email, |  | ||||||
|                         ..Default::default() |  | ||||||
|                     }) |  | ||||||
|                     .collect())); |  | ||||||
|                 ConsoleService::log(format!("Response: {:?}", Json(&self.users)).as_str()); |                 ConsoleService::log(format!("Response: {:?}", Json(&self.users)).as_str()); | ||||||
|                 true |                 true | ||||||
|             } |             } | ||||||
| @ -87,7 +84,7 @@ impl Component for UserTable { | |||||||
|                     .map(|u| { |                     .map(|u| { | ||||||
|                         html! { |                         html! { | ||||||
|                             <tr> |                             <tr> | ||||||
|                                 <td>{&u.user_id}</td> |                                 <td>{&u.id}</td> | ||||||
|                                 <td>{&u.email}</td> |                                 <td>{&u.email}</td> | ||||||
|                                 <td>{&u.display_name.as_ref().unwrap_or(&String::new())}</td> |                                 <td>{&u.display_name.as_ref().unwrap_or(&String::new())}</td> | ||||||
|                                 <td>{&u.first_name.as_ref().unwrap_or(&String::new())}</td> |                                 <td>{&u.first_name.as_ref().unwrap_or(&String::new())}</td> | ||||||
|  | |||||||
| @ -26,9 +26,16 @@ type Query { | |||||||
|   users(filters: RequestFilter): [User!]! |   users(filters: RequestFilter): [User!]! | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | "NaiveDateTime" | ||||||
|  | scalar NaiveDateTime | ||||||
|  | 
 | ||||||
| type User { | type User { | ||||||
|   id: String! |   id: String! | ||||||
|   email: String! |   email: String! | ||||||
|  |   displayName: String | ||||||
|  |   firstName: String | ||||||
|  |   lastName: String | ||||||
|  |   creationDate: NaiveDateTime! | ||||||
|   "The groups to which this user belongs." |   "The groups to which this user belongs." | ||||||
|   groups: [Group!]! |   groups: [Group!]! | ||||||
| } | } | ||||||
|  | |||||||
| @ -145,6 +145,22 @@ impl<Handler: BackendHandler + Sync> User<Handler> { | |||||||
|         &self.user.email |         &self.user.email | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     fn display_name(&self) -> Option<&String> { | ||||||
|  |         self.user.display_name.as_ref() | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     fn first_name(&self) -> Option<&String> { | ||||||
|  |         self.user.first_name.as_ref() | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     fn last_name(&self) -> Option<&String> { | ||||||
|  |         self.user.last_name.as_ref() | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     fn creation_date(&self) -> chrono::NaiveDateTime { | ||||||
|  |         self.user.creation_date | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     /// The groups to which this user belongs.
 |     /// The groups to which this user belongs.
 | ||||||
|     async fn groups(&self, context: &Context<Handler>) -> FieldResult<Vec<Group<Handler>>> { |     async fn groups(&self, context: &Context<Handler>) -> FieldResult<Vec<Group<Handler>>> { | ||||||
|         Ok(context |         Ok(context | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Valentin Tolmer
						Valentin Tolmer