From ea79c7358235980f328113767f092834b8deb21a Mon Sep 17 00:00:00 2001 From: Zeeshan Abid Date: Fri, 24 May 2024 15:47:23 +0100 Subject: [PATCH 1/3] feat: categories filtering implemented --- src/host_zome_calls.rs | 2 ++ src/install_app.rs | 1 + src/transaction_types.rs | 5 +++-- src/uninstall_apps.rs | 33 ++++++++++++++++++++++++++++----- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/host_zome_calls.rs b/src/host_zome_calls.rs index febf27e..5dcf23e 100644 --- a/src/host_zome_calls.rs +++ b/src/host_zome_calls.rs @@ -23,6 +23,7 @@ pub struct HappBundle { pub special_installed_app_id: Option, pub jurisdictions: Vec, pub exclude_jurisdictions: bool, + pub categories: Vec, } #[derive(Clone)] @@ -177,6 +178,7 @@ pub async fn get_all_published_hosted_happs( special_installed_app_id: happ.special_installed_app_id, jurisdictions: happ.jurisdictions, exclude_jurisdictions: happ.exclude_jurisdictions, + categories: happ.categories, } }) .collect(); diff --git a/src/install_app.rs b/src/install_app.rs index 8da62fd..e64f477 100644 --- a/src/install_app.rs +++ b/src/install_app.rs @@ -68,6 +68,7 @@ pub async fn install_holo_hosted_happs( special_installed_app_id, exclude_jurisdictions: _, jurisdictions: _, + categories: _, } in happs { // Check if special happ is installed and do nothing if it is installed diff --git a/src/transaction_types.rs b/src/transaction_types.rs index aa82223..f19e17d 100644 --- a/src/transaction_types.rs +++ b/src/transaction_types.rs @@ -88,7 +88,7 @@ pub struct InvoiceNote { } #[derive(Clone, serde::Serialize, serde::Deserialize, Debug)] -pub struct JurisdictionPreferences { +pub struct JurisdictionAndCategoryPreferences { pub value: Vec, pub is_exclusion: bool, } @@ -101,7 +101,8 @@ pub struct HostingPreferences { pub price_bandwidth: Fuel, pub max_time_before_invoice: Duration, pub invoice_due_in_days: u8, - pub jurisdiction_prefs: JurisdictionPreferences, + pub jurisdiction_prefs: JurisdictionAndCategoryPreferences, + pub categories_prefs: JurisdictionAndCategoryPreferences, } #[derive(serde::Serialize, serde::Deserialize, Debug)] diff --git a/src/uninstall_apps.rs b/src/uninstall_apps.rs index f05c6ca..ccec31d 100644 --- a/src/uninstall_apps.rs +++ b/src/uninstall_apps.rs @@ -1,4 +1,4 @@ -use std::collections::HashMap; +use std::collections::{HashMap, HashSet}; pub use crate::config; pub use crate::host_zome_calls::HappBundle; @@ -103,6 +103,10 @@ pub async fn should_be_installed( return true; } + let published_happ = published_happs + .iter() + .find(|&happ| happ.happ_id.to_string() == *running_happ_id); + if suspended_happs.contains(running_happ_id) { trace!("Disabling suspended happ {}", running_happ_id); return false; @@ -145,10 +149,7 @@ pub async fn should_be_installed( // jurisdiction is taken from mongodb and compared against hApps jurisdictions match jurisdiction { Some(jurisdiction) => { - if let Some(happ) = published_happs - .iter() - .find(|&happ| happ.happ_id.to_string() == *running_happ_id) - { + if let Some(happ) = published_happ { let mut is_jurisdiction_in_list = false; if let Some(_happ_jurisdiction) = happ .jurisdictions @@ -172,6 +173,28 @@ pub async fn should_be_installed( } } + // verify the happ matches the hosting categories preferences + if let Some(happ) = published_happ { + let categories_prefs: HashSet = hosting_preferences + .categories_prefs + .value + .iter() + .cloned() + .collect(); + + let contains_category = happ + .categories + .iter() + .any(|category| categories_prefs.contains(category)); + + if contains_category && hosting_preferences.categories_prefs.is_exclusion { + return false; + } + if !contains_category && !hosting_preferences.categories_prefs.is_exclusion { + return false; + } + } + // The running happ is an instance of an expected happ let expected_happ = published_happs.iter().find(|published_happ| { is_instance_of_happ(&published_happ.happ_id.to_string(), running_happ_id) From 5a6b58b65f94d29e33ab059671ef5981fd169b6f Mon Sep 17 00:00:00 2001 From: Zeeshan Abid <6005448+zeeshan595@users.noreply.github.com> Date: Fri, 24 May 2024 16:57:11 +0100 Subject: [PATCH 2/3] Update src/uninstall_apps.rs Co-authored-by: Joel Ulahanna --- src/uninstall_apps.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/uninstall_apps.rs b/src/uninstall_apps.rs index ccec31d..e309eae 100644 --- a/src/uninstall_apps.rs +++ b/src/uninstall_apps.rs @@ -103,6 +103,7 @@ pub async fn should_be_installed( return true; } + // checks if published happ is still running let published_happ = published_happs .iter() .find(|&happ| happ.happ_id.to_string() == *running_happ_id); From f461ba5ce2b59500ad3f49c141cf3de46068bec1 Mon Sep 17 00:00:00 2001 From: Zeeshan Abid Date: Fri, 24 May 2024 16:59:37 +0100 Subject: [PATCH 3/3] fixed formatting issues --- src/uninstall_apps.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uninstall_apps.rs b/src/uninstall_apps.rs index e309eae..f8b1c54 100644 --- a/src/uninstall_apps.rs +++ b/src/uninstall_apps.rs @@ -103,7 +103,7 @@ pub async fn should_be_installed( return true; } - // checks if published happ is still running + // checks if published happ is still running let published_happ = published_happs .iter() .find(|&happ| happ.happ_id.to_string() == *running_happ_id);