From 42c3a461c5168e2801f4feb10773d7339bc54924 Mon Sep 17 00:00:00 2001 From: EdwinBetanc0urt Date: Tue, 28 May 2024 10:58:52 -0400 Subject: [PATCH] fix: Index name with all values. --- src/models/browser.rs | 31 +++++-------------------------- src/models/form.rs | 19 ++++--------------- src/models/menu.rs | 31 +++++-------------------------- src/models/mod.rs | 12 +++++------- src/models/process.rs | 31 +++++-------------------------- src/models/window.rs | 31 +++++-------------------------- 6 files changed, 29 insertions(+), 126 deletions(-) diff --git a/src/models/browser.rs b/src/models/browser.rs index c8dcc2b..e04425b 100644 --- a/src/models/browser.rs +++ b/src/models/browser.rs @@ -3,7 +3,7 @@ use salvo::prelude::*; use serde_json::json; use std::{io::ErrorKind, io::Error}; -use crate::{controller::opensearch::{IndexDocument, get_by_id, find, exists_index}, models::{user_index, role_index, default_index, language_index, client_index}}; +use crate::{controller::opensearch::{IndexDocument, get_by_id, find, exists_index}, models::{user_index, role_index}}; #[derive(Deserialize, Extractible, Debug, Clone)] #[salvo(extract(default_source(from = "body")))] @@ -317,9 +317,6 @@ async fn get_index_name(_language: Option<&String>, _client_id: Option<&String>, let _user_index = user_index(_index.to_owned(), _language, _client_id, _role_id, _user_id); let _role_index = role_index(_index.to_owned(), _language, _client_id, _role_id); - let _client_index = client_index(_index.to_owned(), _language, _client_id); - let _language_index = language_index(_index.to_owned(), _language); - let _default_index = default_index(_index.to_owned()); // Find index match exists_index(_user_index.to_owned()).await { @@ -328,33 +325,15 @@ async fn get_index_name(_language: Option<&String>, _client_id: Option<&String>, Ok(_user_index) }, Err(_) => { - log::info!("No user index `{:}`", _user_index); + log::warn!("No user index `{:}`", _user_index); match exists_index(_role_index.to_owned()).await { Ok(_) => { log::info!("Find with role index `{:}`", _role_index); Ok(_role_index) }, - Err(_) => { - log::info!("No role index `{:}`", _role_index); - match exists_index(_client_index.to_owned()).await { - Ok(_) => { - log::info!("Find with client index `{:}`", _client_index); - Ok(_client_index) - }, - Err(_) => { - log::warn!("No client index `{:}`", _client_index); - match exists_index(_language_index.to_owned()).await { - Ok(_) => { - log::info!("Find with language index `{:}`", _language_index); - Ok(_language_index) - }, - Err(_) => { - log::warn!("No language index `{:}`. Find with default index `{:}`.", _language_index, _default_index); - Ok(_default_index) - } - } - } - } + Err(error) => { + log::error!("No role index `{:}`", _role_index); + return Err(Error::new(ErrorKind::InvalidData.into(), error)) } } } diff --git a/src/models/form.rs b/src/models/form.rs index 31a7b14..d586c10 100644 --- a/src/models/form.rs +++ b/src/models/form.rs @@ -3,7 +3,7 @@ use salvo::prelude::*; use serde_json::json; use std::{io::ErrorKind, io::Error}; -use crate::{controller::opensearch::{IndexDocument, get_by_id, find, exists_index}, models::{client_index, default_index, language_index}}; +use crate::{controller::opensearch::{IndexDocument, get_by_id, find, exists_index}, models::client_index}; #[derive(Deserialize, Extractible, Debug, Clone)] #[salvo(extract(default_source(from = "body")))] @@ -167,8 +167,6 @@ async fn get_index_name(_language: Option<&String>, _client_id: Option<&String>, let _index: String = "form".to_string(); let _client_index = client_index(_index.to_owned(), _language, _client_id); - let _language_index = language_index(_index.to_owned(), _language); - let _default_index = default_index(_index.to_owned()); // Find index match exists_index(_client_index.to_owned()).await { @@ -176,18 +174,9 @@ async fn get_index_name(_language: Option<&String>, _client_id: Option<&String>, log::info!("Find with client index `{:}`", _client_index); Ok(_client_index) }, - Err(_) => { - log::warn!("No client index `{:}`", _client_index); - match exists_index(_language_index.to_owned()).await { - Ok(_) => { - log::info!("Find with language index `{:}`", _language_index); - Ok(_language_index) - }, - Err(_) => { - log::warn!("No language index `{:}`. Find with default index `{:}`.", _language_index, _default_index); - Ok(_default_index) - } - } + Err(error) => { + log::error!("No client index `{:}`", _client_index); + return Err(Error::new(ErrorKind::InvalidData.into(), error)) } } } diff --git a/src/models/menu.rs b/src/models/menu.rs index fdb9499..9434988 100644 --- a/src/models/menu.rs +++ b/src/models/menu.rs @@ -3,7 +3,7 @@ use salvo::prelude::*; use serde_json::json; use std::{io::ErrorKind, io::Error}; -use crate::{controller::opensearch::{IndexDocument, get_by_id, find, exists_index}, models::{user_index, role_index, client_index, language_index, default_index}}; +use crate::{controller::opensearch::{IndexDocument, get_by_id, find, exists_index}, models::{user_index, role_index}}; #[derive(Deserialize, Extractible, Debug, Clone)] #[salvo(extract(default_source(from = "body")))] @@ -242,9 +242,6 @@ async fn get_index_name(_language: Option<&String>, _client_id: Option<&String>, let _user_index = user_index(_index.to_owned(), _language, _client_id, _role_id, _user_id); let _role_index = role_index(_index.to_owned(), _language, _client_id, _role_id); - let _client_index = client_index(_index.to_owned(), _language, _client_id); - let _language_index = language_index(_index.to_owned(), _language); - let _default_index = default_index(_index.to_owned()); // Find index match exists_index(_user_index.to_owned()).await { @@ -253,33 +250,15 @@ async fn get_index_name(_language: Option<&String>, _client_id: Option<&String>, Ok(_user_index) }, Err(_) => { - log::info!("No user index `{:}`", _user_index); + log::warn!("No user index `{:}`", _user_index); match exists_index(_role_index.to_owned()).await { Ok(_) => { log::info!("Find with role index `{:}`", _role_index); Ok(_role_index) }, - Err(_) => { - log::info!("No role index `{:}`", _role_index); - match exists_index(_client_index.to_owned()).await { - Ok(_) => { - log::info!("Find with client index `{:}`", _client_index); - Ok(_client_index) - }, - Err(_) => { - log::info!("No client index `{:}`", _client_index); - match exists_index(_language_index.to_owned()).await { - Ok(_) => { - log::info!("Find with language index `{:}`", _language_index); - Ok(_language_index) - }, - Err(_) => { - log::info!("No language index `{:}`. Find with default index `{:}`.", _language_index, _default_index); - Ok(_default_index) - } - } - } - } + Err(error) => { + log::error!("No role index `{:}`", _role_index); + return Err(Error::new(ErrorKind::InvalidData.into(), error)) } } } diff --git a/src/models/mod.rs b/src/models/mod.rs index 8e472ea..7b8caf1 100644 --- a/src/models/mod.rs +++ b/src/models/mod.rs @@ -25,10 +25,8 @@ fn default_index(_index_name: String) -> String { fn language_index(_index_name: String, _language: Option<&String>) -> String { let mut _index_to_find: String = default_index(_index_name); if let Some(language) = _language { - if language != "en_US" { - _index_to_find.push_str("_"); - _index_to_find.push_str(language); - } + _index_to_find.push_str("_"); + _index_to_find.push_str(language); } _index_to_find.to_lowercase() } @@ -37,7 +35,7 @@ fn client_index(_index_name: String, _language: Option<&String>, _client_id: Opt let mut _index_to_find: String = language_index(_index_name, _language); if let Some(client_id) = _client_id { if let Ok(id) = client_id.parse::() { - if id > 0 { + if id >= 0 { _index_to_find.push_str("_"); _index_to_find.push_str(client_id); } @@ -50,7 +48,7 @@ fn role_index(_index_name: String, _language: Option<&String>, _client_id: Optio let mut _index_to_find: String = client_index(_index_name, _language, _client_id); if let Some(role_id) = _role_id { if let Ok(id) = role_id.parse::() { - if id > 0 { + if id >= 0 { _index_to_find.push_str("_"); _index_to_find.push_str(role_id); } @@ -63,7 +61,7 @@ fn user_index(_index_name: String, _language: Option<&String>, _client_id: Optio let mut _index_to_find: String = role_index(_index_name, _language, _client_id, _role_id); if let Some(user_id) = _user_id { if let Ok(id) = user_id.parse::() { - if id > 0 { + if id >= 0 { _index_to_find.push_str("_"); _index_to_find.push_str(user_id); } diff --git a/src/models/process.rs b/src/models/process.rs index 85c99d2..9d5aea3 100644 --- a/src/models/process.rs +++ b/src/models/process.rs @@ -3,7 +3,7 @@ use salvo::prelude::*; use serde_json::json; use std::{io::ErrorKind, io::Error}; -use crate::{controller::opensearch::{IndexDocument, get_by_id, find, exists_index}, models::{user_index, role_index, default_index, language_index, client_index}}; +use crate::{controller::opensearch::{IndexDocument, get_by_id, find, exists_index}, models::{user_index, role_index}}; #[derive(Deserialize, Extractible, Debug, Clone)] #[salvo(extract(default_source(from = "body")))] @@ -285,9 +285,6 @@ async fn get_index_name(_language: Option<&String>, _client_id: Option<&String>, let _user_index = user_index(_index.to_owned(), _language, _client_id, _role_id, _user_id); let _role_index = role_index(_index.to_owned(), _language, _client_id, _role_id); - let _client_index = client_index(_index.to_owned(), _language, _client_id); - let _language_index = language_index(_index.to_owned(), _language); - let _default_index = default_index(_index.to_owned()); // Find index match exists_index(_user_index.to_owned()).await { @@ -296,33 +293,15 @@ async fn get_index_name(_language: Option<&String>, _client_id: Option<&String>, Ok(_user_index) }, Err(_) => { - log::info!("No user index `{:}`", _user_index); + log::warn!("No user index `{:}`", _user_index); match exists_index(_role_index.to_owned()).await { Ok(_) => { log::info!("Find with role index `{:}`", _role_index); Ok(_role_index) }, - Err(_) => { - log::info!("No role index `{:}`", _role_index); - match exists_index(_client_index.to_owned()).await { - Ok(_) => { - log::info!("Find with client index `{:}`", _client_index); - Ok(_client_index) - }, - Err(_) => { - log::warn!("No client index `{:}`", _client_index); - match exists_index(_language_index.to_owned()).await { - Ok(_) => { - log::info!("Find with language index `{:}`", _language_index); - Ok(_language_index) - }, - Err(_) => { - log::warn!("No language index `{:}`. Find with default index `{:}`.", _language_index, _default_index); - Ok(_default_index) - } - } - } - } + Err(error) => { + log::error!("No role index `{:}`", _role_index); + return Err(Error::new(ErrorKind::InvalidData.into(), error)) } } } diff --git a/src/models/window.rs b/src/models/window.rs index 9de02ba..08e37e1 100644 --- a/src/models/window.rs +++ b/src/models/window.rs @@ -3,7 +3,7 @@ use salvo::prelude::*; use serde_json::json; use std::{io::ErrorKind, io::Error}; -use crate::{controller::opensearch::{IndexDocument, get_by_id, find, exists_index}, models::{user_index, role_index, default_index, language_index, client_index}}; +use crate::{controller::opensearch::{IndexDocument, get_by_id, find, exists_index}, models::{user_index, role_index}}; #[derive(Deserialize, Extractible, Debug, Clone)] #[salvo(extract(default_source(from = "body")))] @@ -325,9 +325,6 @@ async fn get_index_name(_language: Option<&String>, _client_id: Option<&String>, let _user_index = user_index(_index.to_owned(), _language, _client_id, _role_id, _user_id); let _role_index = role_index(_index.to_owned(), _language, _client_id, _role_id); - let _client_index = client_index(_index.to_owned(), _language, _client_id); - let _language_index = language_index(_index.to_owned(), _language); - let _default_index = default_index(_index.to_owned()); // Find index match exists_index(_user_index.to_owned()).await { @@ -336,33 +333,15 @@ async fn get_index_name(_language: Option<&String>, _client_id: Option<&String>, Ok(_user_index) }, Err(_) => { - log::info!("No user index `{:}`", _user_index); + log::warn!("No user index `{:}`", _user_index); match exists_index(_role_index.to_owned()).await { Ok(_) => { log::info!("Find with role index `{:}`", _role_index); Ok(_role_index) }, - Err(_) => { - log::info!("No role index `{:}`", _role_index); - match exists_index(_client_index.to_owned()).await { - Ok(_) => { - log::info!("Find with client index `{:}`", _client_index); - Ok(_client_index) - }, - Err(_) => { - log::warn!("No client index `{:}`", _client_index); - match exists_index(_language_index.to_owned()).await { - Ok(_) => { - log::info!("Find with language index `{:}`", _language_index); - Ok(_language_index) - }, - Err(_) => { - log::warn!("No language index `{:}`. Find with default index `{:}`.", _language_index, _default_index); - Ok(_default_index) - } - } - } - } + Err(error) => { + log::error!("No role index `{:}`", _role_index); + return Err(Error::new(ErrorKind::InvalidData.into(), error)) } } }