From 7a5e5ec86524afbd372ed14b7f8c9c16b64bb4d7 Mon Sep 17 00:00:00 2001 From: cloudhead Date: Thu, 25 Jan 2024 16:31:28 +0100 Subject: [PATCH] httpd: Don't show unseeded repos --- radicle-httpd/src/api/v1/projects.rs | 18 +++++++++++------- radicle-httpd/src/test.rs | 9 ++++++--- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/radicle-httpd/src/api/v1/projects.rs b/radicle-httpd/src/api/v1/projects.rs index e10bfdb6..f2734a06 100644 --- a/radicle-httpd/src/api/v1/projects.rs +++ b/radicle-httpd/src/api/v1/projects.rs @@ -89,6 +89,7 @@ async fn project_root_handler( let storage = &ctx.profile.storage; let db = &ctx.profile.database()?; let pinned = &ctx.profile.config.web.pinned; + let policies = ctx.profile.policies()?; let mut projects = match show { ProjectQuery::All => storage @@ -105,14 +106,17 @@ async fn project_root_handler( let infos = projects .into_iter() - .filter_map(|id| { - let Ok(repo) = storage.repository(id.rid) else { + .filter_map(|info| { + if !policies.is_seeding(&info.rid).unwrap_or_default() { + return None; + } + let Ok(repo) = storage.repository(info.rid) else { return None; }; let Ok((_, head)) = repo.head() else { return None; }; - let Ok(payload) = id.doc.project() else { + let Ok(payload) = info.doc.project() else { return None; }; let Ok(issues) = issue::Issues::open(&repo) else { @@ -127,17 +131,17 @@ async fn project_root_handler( let Ok(patches) = patches.counts() else { return None; }; - let delegates = id.doc.delegates; - let seeding = db.count(&id.rid).unwrap_or_default(); + let delegates = info.doc.delegates; + let seeding = db.count(&info.rid).unwrap_or_default(); Some(Info { payload, delegates, head, - visibility: id.doc.visibility, + visibility: info.doc.visibility, issues, patches, - id: id.rid, + id: info.rid, seeding, }) }) diff --git a/radicle-httpd/src/test.rs b/radicle-httpd/src/test.rs index 7579d9c7..96c0a75c 100644 --- a/radicle-httpd/src/test.rs +++ b/radicle-httpd/src/test.rs @@ -97,6 +97,7 @@ fn seed_with_signer(dir: &Path, profile: radicle::Profile, signer: &G profile.policies_mut().unwrap(); profile.database_mut().unwrap(); // Create the database. + let mut policies = profile.policies_mut().unwrap(); let workdir = dir.join("hello-world-private"); fs::create_dir_all(&workdir).unwrap(); @@ -125,7 +126,7 @@ fn seed_with_signer(dir: &Path, profile: radicle::Profile, signer: &G let visibility = Visibility::Private { allow: BTreeSet::default(), }; - radicle::rad::init( + let (rid, _, _) = radicle::rad::init( &repo, &name, &description, @@ -135,6 +136,7 @@ fn seed_with_signer(dir: &Path, profile: radicle::Profile, signer: &G &profile.storage, ) .unwrap(); + policies.seed(&rid, node::policy::Scope::All).unwrap(); let workdir = dir.join("hello-world"); @@ -215,7 +217,7 @@ fn seed_with_signer(dir: &Path, profile: radicle::Profile, signer: &G let description = "Rad repository for tests".to_string(); let branch = RefString::try_from(DEFAULT_BRANCH).unwrap(); let visibility = Visibility::default(); - let (id, _, _) = radicle::rad::init( + let (rid, _, _) = radicle::rad::init( &repo, &name, &description, @@ -225,9 +227,10 @@ fn seed_with_signer(dir: &Path, profile: radicle::Profile, signer: &G &profile.storage, ) .unwrap(); + policies.seed(&rid, node::policy::Scope::All).unwrap(); let storage = &profile.storage; - let repo = storage.repository(id).unwrap(); + let repo = storage.repository(rid).unwrap(); let mut issues = Issues::open(&repo).unwrap(); let issue = issues .create(