diff --git a/src/models/menu.rs b/src/models/menu.rs index bbe06d9..2e9041c 100644 --- a/src/models/menu.rs +++ b/src/models/menu.rs @@ -4,7 +4,7 @@ use std::{io::ErrorKind, io::Error}; use crate::models::{menu_item::menu_items_from_role, menu_tree::menu_tree_from_id, role::role_from_id}; -use super::{menu_item::MenuItem, menu_tree::MenuTree}; +use super::{menu_item::MenuItem, menu_tree::MenuTree, role::Role}; #[derive(Deserialize, Extractible, Debug, Clone)] #[salvo(extract(default_source(from = "body")))] @@ -128,14 +128,14 @@ impl Menu { } pub async fn allowed_menu(_language: Option<&String>, _client_id: Option<&String>, _role_id: Option<&String>, _dictionary_code: Option<&String>) -> Result { - let _expected_role = role_from_id(_role_id, _client_id, _dictionary_code).await; - let _role = match _expected_role { + let _expected_role: Result = role_from_id(_role_id, _client_id, _dictionary_code).await; + let _role: Role = match _expected_role { Ok(role) => role, Err(error) => return Err(Error::new(ErrorKind::InvalidData.into(), error)) }; - let _menu_items = menu_items_from_role(_role.to_owned(), _language, _dictionary_code, None, None).await; - let _menu_items = match _menu_items { + let _menu_items: Result, Error> = menu_items_from_role(_role.to_owned(), _language, _dictionary_code, None, None).await; + let _menu_items: Vec = match _menu_items { Ok(menu) => menu, Err(error) => return Err(Error::new(ErrorKind::InvalidData.into(), error)) }; @@ -144,8 +144,8 @@ pub async fn allowed_menu(_language: Option<&String>, _client_id: Option<&String return Err(Error::new(ErrorKind::InvalidData.into(), "Tree ID not found")) } - let _tree_result = menu_tree_from_id(_role.tree_uuid, _dictionary_code).await; - let _tree = match _tree_result { + let _tree_result: Result = menu_tree_from_id(_role.tree_uuid, _dictionary_code).await; + let _tree: MenuTree = match _tree_result { Ok(tree) => tree, Err(error) => return Err(Error::new(ErrorKind::InvalidData.into(), error)) }; diff --git a/src/models/menu_item.rs b/src/models/menu_item.rs index d27d499..2e83960 100644 --- a/src/models/menu_item.rs +++ b/src/models/menu_item.rs @@ -93,39 +93,59 @@ impl Default for MenuItem { } impl MenuItem { - pub fn from_id(_id: Option) -> Self { - let mut menu = MenuItem::default(); + pub fn from_id(_id: Option) -> Self { + let mut menu: MenuItem = MenuItem::default(); menu.id = _id; menu } fn get_find_body_from_role(_role: Role) -> serde_json::Value { - // "W" Window - // "X" Form - // "S" Smart Browser - // "R" Report - // "P" Process - // "F" Workflow + // "W" Window let _window_access: Vec = match _role.to_owned().window_access { - Some(value) => value, - None => Vec::new() - }; + Some(value) => { + // remove none values into vector + value.into_iter().flatten().collect() + }, + None => Vec::new() + }; + + // "X" Form let _form_access: Vec = match _role.to_owned().form_access { - Some(value) => value, - None => Vec::new() - }; + Some(value) => { + // remove none values into vector + value.into_iter().flatten().collect() + }, + None => Vec::new() + }; + + // "S" Smart Browser let _browser_access: Vec = match _role.to_owned().browser_access { - Some(value) => value, - None => Vec::new() - }; + Some(value) => { + // remove none values into vector + value.into_iter().flatten().collect() + }, + None => Vec::new() + }; + + // "R" Report + // "P" Process let _process_access: Vec = match _role.to_owned().process_access { - Some(value) => value, - None => Vec::new() - }; + Some(value) => { + // remove none values into vector + value.into_iter().flatten().collect() + }, + None => Vec::new() + }; + + // "F" Workflow let _workflow_access: Vec = match _role.to_owned().workflow_access { - Some(value) => value, - None => Vec::new() - }; + Some(value) => { + // remove none values into vector + value.into_iter().flatten().collect() + }, + None => Vec::new() + }; + json!({ "query": { "bool": { @@ -135,7 +155,7 @@ impl MenuItem { "must": [ { "match": { - "is_summary": true + "is_summary": true } } ] @@ -145,13 +165,13 @@ impl MenuItem { "bool": { "must": [ { - "terms": { - "action_uuid": _window_access + "match": { + "action": "W" } }, { - "match": { - "action": "W" + "terms": { + "action_uuid": _window_access } } ] @@ -161,13 +181,13 @@ impl MenuItem { "bool": { "must": [ { - "terms": { - "action_uuid": _form_access + "match": { + "action": "X" } }, { - "match": { - "action": "X" + "terms": { + "action_uuid": _form_access } } ] @@ -177,13 +197,13 @@ impl MenuItem { "bool": { "must": [ { - "terms": { - "action_uuid": _browser_access + "match": { + "action": "S" } }, { - "match": { - "action": "S" + "terms": { + "action_uuid": _browser_access } } ] @@ -193,13 +213,13 @@ impl MenuItem { "bool": { "must": [ { - "terms": { - "action_uuid": _process_access + "match": { + "action": "P" } }, { - "match": { - "action": "P" + "terms": { + "action_uuid": _process_access } } ] @@ -209,13 +229,13 @@ impl MenuItem { "bool": { "must": [ { - "terms": { - "action_uuid": _process_access + "match": { + "action": "R" } }, { - "match": { - "action": "R" + "terms": { + "action_uuid": _process_access } } ] @@ -225,13 +245,13 @@ impl MenuItem { "bool": { "must": [ { - "terms": { - "action_uuid": _workflow_access + "match": { + "action": "F" } }, { - "match": { - "action": "F" + "terms": { + "action_uuid": _workflow_access } } ] @@ -241,7 +261,7 @@ impl MenuItem { } } }) - } + } pub fn to_string(&self) -> String { format!("Menu Item: UUID {:?}, ID {:?}, Name {:?}, Index: {:?}", self.uuid, self.internal_id, self.name, self.index_value) diff --git a/src/models/role.rs b/src/models/role.rs index ae010d3..57e2203 100644 --- a/src/models/role.rs +++ b/src/models/role.rs @@ -47,12 +47,12 @@ pub struct Role { pub role_id: Option, pub user_id: Option, // Access - pub window_access: Option>, - pub process_access: Option>, - pub form_access: Option>, - pub browser_access: Option>, - pub workflow_access: Option>, - pub dashboard_access: Option> + pub window_access: Option>>, + pub process_access: Option>>, + pub form_access: Option>>, + pub browser_access: Option>>, + pub workflow_access: Option>>, + pub dashboard_access: Option>> } impl Default for Role { @@ -83,14 +83,14 @@ impl Default for Role { } impl Role { - pub fn from_id(_id: Option<&String>) -> Self { - let mut menu = Role::default(); - menu.uuid = _id.cloned(); - menu - } + pub fn from_id(_id: Option<&String>) -> Self { + let mut role: Role = Role::default(); + role.uuid = _id.cloned(); + role + } pub fn to_string(&self) -> String { - format!("Form: UUID {:?}, ID {:?}, Name {:?}, Index: {:?}", self.uuid, self.internal_id, self.name, self.index_value) + format!("Role: UUID {:?}, ID {:?}, Name {:?}, Index: {:?}", self.uuid, self.internal_id, self.name, self.index_value) } } @@ -115,7 +115,7 @@ impl IndexDocument for Role { } fn id(self: &Self) -> String { - self.id.to_owned().unwrap_or_else(|| { + self.uuid.to_owned().unwrap_or_else(|| { log::error!("{}", self.to_string()); "".to_string() }) @@ -166,7 +166,7 @@ pub async fn role_from_id(_uuid: Option<&String>, _client_uuid: Option<&String>, Ok(value) => { match serde_json::from_value::(value) { Ok(role) => { - log::info!("Finded Role Value: {:?}", role.id); + log::info!("Finded Role {:?} Value: {:?}", role.name, role.id); Ok(role) }, Err(error) => {