diff --git a/Cargo.lock b/Cargo.lock index b97052e8..55ca8f0c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1963,6 +1963,7 @@ dependencies = [ "flate2", "hyper", "lexopt", + "nonempty 0.8.1", "radicle", "radicle-cli", "radicle-crypto", diff --git a/radicle-httpd/Cargo.toml b/radicle-httpd/Cargo.toml index a6b76933..c727b661 100644 --- a/radicle-httpd/Cargo.toml +++ b/radicle-httpd/Cargo.toml @@ -25,6 +25,7 @@ flate2 = { version = "1" } hyper = { version = "0.14.17", default-features = false } lexopt = { version = "0.2.1" } radicle-surf = { version = "0.9.0", default-features = false, features = ["serde"] } +nonempty = { version = "0.8.1", features = ["serialize"] } serde = { version = "1", features = ["derive"] } serde_json = { version = "1", features = ["preserve_order"] } thiserror = { version = "1" } diff --git a/radicle-httpd/src/api.rs b/radicle-httpd/src/api.rs index cd819bc9..91027b31 100644 --- a/radicle-httpd/src/api.rs +++ b/radicle-httpd/src/api.rs @@ -48,11 +48,14 @@ impl Context { let storage = &self.profile.storage; let repo = storage.repository(id)?; let (_, head) = repo.head()?; - let payload = repo.project_of(self.profile.id())?; + let doc = repo.identity_of(self.profile.id())?; + let payload = doc.project()?; + let delegates = doc.delegates; let issues = (Issues::open(self.profile.public_key, &repo)?).count()?; Ok(project::Info { payload, + delegates, head, issues, patches: 0, @@ -126,10 +129,13 @@ pub struct PaginationQuery { } mod project { + use nonempty::NonEmpty; + use serde::Serialize; + use radicle::git::Oid; use radicle::identity::project::Project; use radicle::identity::Id; - use serde::Serialize; + use radicle::prelude::Did; /// Project info. #[derive(Serialize)] @@ -138,6 +144,7 @@ mod project { /// Project metadata. #[serde(flatten)] pub payload: Project, + pub delegates: NonEmpty, pub head: Oid, pub patches: usize, pub issues: usize, diff --git a/radicle-httpd/src/api/error.rs b/radicle-httpd/src/api/error.rs index b6b48d7d..e8bdef7c 100644 --- a/radicle-httpd/src/api/error.rs +++ b/radicle-httpd/src/api/error.rs @@ -42,6 +42,10 @@ pub enum Error { #[error(transparent)] GitProject(#[from] radicle::storage::git::ProjectError), + /// Project doc error. + #[error(transparent)] + ProjectDoc(#[from] radicle::identity::doc::PayloadError), + /// Surf directory error. #[error(transparent)] SurfDir(#[from] radicle_surf::fs::error::Directory), diff --git a/radicle-httpd/src/api/v1/delegates.rs b/radicle-httpd/src/api/v1/delegates.rs index d72c91bb..e8b3d09d 100644 --- a/radicle-httpd/src/api/v1/delegates.rs +++ b/radicle-httpd/src/api/v1/delegates.rs @@ -42,7 +42,8 @@ async fn delegates_projects_handler( let Ok(doc) = repo.identity_of(ctx.profile.id()) else { return None }; let Ok(payload) = doc.project() else { return None }; - if !doc.delegates.iter().any(|d| *d == delegate) { + let delegates = doc.delegates; + if !delegates.iter().any(|d| *d == delegate) { return None; } @@ -51,6 +52,7 @@ async fn delegates_projects_handler( Some(Info { payload, + delegates, head, issues, patches: 0, @@ -89,6 +91,7 @@ mod routes { "name": "hello-world", "description": "Rad repository for tests", "defaultBranch": "master", + "delegates": ["did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi"], "head": HEAD, "patches": 0, "issues": 1, diff --git a/radicle-httpd/src/api/v1/projects.rs b/radicle-httpd/src/api/v1/projects.rs index 3e7cbd6b..a012c311 100644 --- a/radicle-httpd/src/api/v1/projects.rs +++ b/radicle-httpd/src/api/v1/projects.rs @@ -78,11 +78,14 @@ async fn project_root_handler( let Ok(repo) = storage.repository(id) else { return None }; let Ok((_, head)) = repo.head() else { return None }; let Ok(payload) = repo.project_of(ctx.profile.id()) else { return None }; + let Ok(doc) = repo.identity_of(ctx.profile.id()) else { return None }; let Ok(issues) = Issues::open(ctx.profile.public_key, &repo) else { return None }; let Ok(issues) = (*issues).count() else { return None }; + let delegates = doc.delegates; Some(Info { payload, + delegates, head, issues, patches: 0, @@ -574,6 +577,7 @@ mod routes { "name": "hello-world", "description": "Rad repository for tests", "defaultBranch": "master", + "delegates": ["did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi"], "head": HEAD, "patches": 0, "issues": 1, @@ -596,6 +600,7 @@ mod routes { "name": "hello-world", "description": "Rad repository for tests", "defaultBranch": "master", + "delegates": ["did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi"], "head": HEAD, "patches": 0, "issues": 1,