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..f8b1c54 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,11 @@ 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); + if suspended_happs.contains(running_happ_id) { trace!("Disabling suspended happ {}", running_happ_id); return false; @@ -145,10 +150,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 +174,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)