httpd: Don't show unseeded repos

This commit is contained in:
cloudhead 2024-01-25 16:31:28 +01:00
parent aa9c6542ab
commit 7a5e5ec865
No known key found for this signature in database
2 changed files with 17 additions and 10 deletions

View File

@ -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,
})
})

View File

@ -97,6 +97,7 @@ fn seed_with_signer<G: 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<G: 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<G: 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<G: 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<G: 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(