From 17cf9bc5c7b98d012690bcea659b2b2b09a1a6b3 Mon Sep 17 00:00:00 2001 From: PramUkesh Date: Tue, 23 Jan 2024 01:38:14 +0530 Subject: [PATCH] ws::events > append missing user site data for siteChanged event --- src/plugins/websocket/handlers/sites.rs | 42 ++++++++++++++++--------- src/plugins/websocket/mod.rs | 3 +- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/src/plugins/websocket/handlers/sites.rs b/src/plugins/websocket/handlers/sites.rs index 1924ad9..07a9748 100644 --- a/src/plugins/websocket/handlers/sites.rs +++ b/src/plugins/websocket/handlers/sites.rs @@ -10,6 +10,7 @@ use super::{ users::{get_current_user, handle_cert_set}, }; use crate::{ + core::site::models::SiteInfo, environment::SITE_PERMISSIONS_DETAILS, plugins::site_server::handlers::{ sites::{DBQueryRequest, SiteInfoListRequest, SiteInfoRequest}, @@ -259,18 +260,37 @@ pub fn handle_site_info(ws: &ZeruWebsocket, command: &Command) -> Result( + ws: &ZeruWebsocket, + site_info: &'a mut SiteInfo, +) -> Option<&'a mut SiteInfo> { if let Some(map) = block_on(ws.user_controller.send(UserSiteData { user_addr: String::from("current"), - site_addr: ws.address.address.clone(), + site_addr: site_info.address.clone(), })) .unwrap() { let user_site_data = map.values().last().unwrap(); - let mut site_info = result.unwrap(); if let Some(provider) = user_site_data.get_cert_provider() { - let user = get_current_user(ws)?; - let user_name = &user.certs.get(&provider).unwrap().auth_user_name; - site_info.cert_user_id = Some(format!("{}@{}", user_name, provider)); + let user = get_current_user(ws).unwrap(); + if let Some(cert) = &user.certs.get(&provider) { + site_info.cert_user_id = Some(format!("{}@{}", cert.auth_user_name, provider)); + } } if let Some(auth) = user_site_data.get_auth_pair() { site_info.auth_address = auth.auth_address; @@ -280,22 +300,14 @@ pub fn handle_site_info(ws: &ZeruWebsocket, command: &Command) -> Result Result { diff --git a/src/plugins/websocket/mod.rs b/src/plugins/websocket/mod.rs index 5a227ef..721a1a9 100644 --- a/src/plugins/websocket/mod.rs +++ b/src/plugins/websocket/mod.rs @@ -489,8 +489,9 @@ impl ZeruWebsocket { let mut site_info = block_on(self.site_addr.send(SiteInfoRequest())) .unwrap() .unwrap(); + let site_info = append_user_site_data(&self, &mut site_info).unwrap(); site_info.event = Some(add_params.clone()); - self.send_event(EventType::SiteInfo(site_info))?; + self.send_event(EventType::SiteInfo(site_info.clone()))?; } else if listener == "serverChanged" { let server_info = server_info(self)?; if params.len() > 0 {