CALL gql.list_users() YIELD username, email, active, created_at, roles Lists all users in the security catalog
(&self, _args: Vec<Value>)
| 686 | /// CALL gql.list_users() YIELD username, email, active, created_at, roles |
| 687 | /// Lists all users in the security catalog |
| 688 | fn list_users(&self, _args: Vec<Value>) -> Result<QueryResult, ExecutionError> { |
| 689 | let mut catalog_manager = self.catalog_manager.write().map_err(|_| { |
| 690 | ExecutionError::RuntimeError("Failed to acquire catalog manager lock".to_string()) |
| 691 | })?; |
| 692 | |
| 693 | let response = catalog_manager |
| 694 | .execute( |
| 695 | "security", |
| 696 | CatalogOperation::Query { |
| 697 | query_type: QueryType::ListUsers, |
| 698 | params: json!({}), |
| 699 | }, |
| 700 | ) |
| 701 | .map_err(|e| ExecutionError::CatalogError(format!("Failed to list users: {}", e)))?; |
| 702 | |
| 703 | let mut rows = Vec::new(); |
| 704 | let columns = vec![ |
| 705 | "username".to_string(), |
| 706 | "email".to_string(), |
| 707 | "active".to_string(), |
| 708 | "created_at".to_string(), |
| 709 | "roles".to_string(), |
| 710 | ]; |
| 711 | |
| 712 | if let CatalogResponse::Query { results } = response { |
| 713 | if let Some(users) = results.as_array() { |
| 714 | for user_value in users { |
| 715 | if let Some(user) = user_value.as_object() { |
| 716 | let mut row_values = HashMap::new(); |
| 717 | row_values.insert( |
| 718 | "username".to_string(), |
| 719 | user.get("id") |
| 720 | .and_then(|id| id.as_object()) |
| 721 | .and_then(|id_obj| id_obj.get("name")) |
| 722 | .and_then(|v| v.as_str()) |
| 723 | .map(|s| Value::String(s.to_string())) |
| 724 | .unwrap_or(Value::Null), |
| 725 | ); |
| 726 | row_values.insert( |
| 727 | "email".to_string(), |
| 728 | user.get("properties") |
| 729 | .and_then(|props| props.as_object()) |
| 730 | .and_then(|props_obj| props_obj.get("email")) |
| 731 | .and_then(|v| v.as_str()) |
| 732 | .map(|s| Value::String(s.to_string())) |
| 733 | .unwrap_or(Value::Null), |
| 734 | ); |
| 735 | row_values.insert( |
| 736 | "active".to_string(), |
| 737 | user.get("enabled") |
| 738 | .and_then(|v| v.as_bool()) |
| 739 | .map(Value::Boolean) |
| 740 | .unwrap_or(Value::Boolean(true)), |
| 741 | ); |
| 742 | row_values.insert( |
| 743 | "created_at".to_string(), |
| 744 | user.get("created_at") |
| 745 | .and_then(|v| v.as_str()) |
no test coverage detected