Skip to content

Commit

Permalink
Merge pull request #42 from Holo-Host/feat/categories
Browse files Browse the repository at this point in the history
feat/categories
  • Loading branch information
zeeshan595 authored May 24, 2024
2 parents 0debe13 + f461ba5 commit cf9a5d7
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/host_zome_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub struct HappBundle {
pub special_installed_app_id: Option<String>,
pub jurisdictions: Vec<String>,
pub exclude_jurisdictions: bool,
pub categories: Vec<String>,
}

#[derive(Clone)]
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/install_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/transaction_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub struct InvoiceNote {
}

#[derive(Clone, serde::Serialize, serde::Deserialize, Debug)]
pub struct JurisdictionPreferences {
pub struct JurisdictionAndCategoryPreferences {
pub value: Vec<String>,
pub is_exclusion: bool,
}
Expand All @@ -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)]
Expand Down
34 changes: 29 additions & 5 deletions src/uninstall_apps.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashMap;
use std::collections::{HashMap, HashSet};

pub use crate::config;
pub use crate::host_zome_calls::HappBundle;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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<String> = 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)
Expand Down

0 comments on commit cf9a5d7

Please sign in to comment.