diff --git a/radicle-httpd/src/api.rs b/radicle-httpd/src/api.rs index 498b052b..04bb9f33 100644 --- a/radicle-httpd/src/api.rs +++ b/radicle-httpd/src/api.rs @@ -17,11 +17,11 @@ use serde_json::json; use tokio::sync::RwLock; use tower_http::cors::{self, CorsLayer}; -use radicle::cob::issue; -use radicle::cob::patch; +use radicle::cob::{issue, patch, Author}; use radicle::identity::{DocAt, RepoId}; use radicle::node::policy::Scope; use radicle::node::routing::Store; +use radicle::node::AliasStore; use radicle::node::{Handle, NodeId}; use radicle::storage::{ReadRepository, ReadStorage}; use radicle::{Node, Profile}; @@ -65,7 +65,12 @@ impl Context { let id = repo.id(); let payload = doc.project()?; - let delegates = doc.delegates; + let aliases = self.profile.aliases(); + let delegates = doc + .delegates + .into_iter() + .map(|did| json::author(&Author::new(did), aliases.alias(did.as_key()))) + .collect::>(); let issues = self.profile.issues(repo)?.counts()?; let patches = self.profile.patches(repo)?.counts()?; let db = &self.profile.database()?; @@ -217,14 +222,13 @@ impl PatchState { } mod project { - use nonempty::NonEmpty; use serde::Serialize; + use serde_json::Value; use radicle::cob; use radicle::git::Oid; use radicle::identity::project::Project; use radicle::identity::{RepoId, Visibility}; - use radicle::prelude::Did; /// Project info. #[derive(Serialize)] @@ -233,7 +237,7 @@ mod project { /// Project metadata. #[serde(flatten)] pub payload: Project, - pub delegates: NonEmpty, + pub delegates: Vec, pub visibility: Visibility, pub head: Oid, pub patches: cob::patch::PatchCounts, diff --git a/radicle-httpd/src/api/json.rs b/radicle-httpd/src/api/json.rs index 60b8e72b..2686d306 100644 --- a/radicle-httpd/src/api/json.rs +++ b/radicle-httpd/src/api/json.rs @@ -184,7 +184,7 @@ fn reactions( } /// Returns JSON for an `author` and fills in `alias` when present. -fn author(author: &Author, alias: Option) -> Value { +pub(crate) fn author(author: &Author, alias: Option) -> Value { match alias { Some(alias) => json!({ "id": author.id, diff --git a/radicle-httpd/src/api/v1/delegates.rs b/radicle-httpd/src/api/v1/delegates.rs index fc5d27c2..e7cd6d5e 100644 --- a/radicle-httpd/src/api/v1/delegates.rs +++ b/radicle-httpd/src/api/v1/delegates.rs @@ -3,13 +3,16 @@ use axum::response::IntoResponse; use axum::routing::get; use axum::{Json, Router}; +use radicle::cob::Author; use radicle::identity::Did; use radicle::issue::cache::Issues as _; use radicle::node::routing::Store; +use radicle::node::AliasStore; use radicle::patch::cache::Patches as _; use radicle::storage::{ReadRepository, ReadStorage}; use crate::api::error::Error; +use crate::api::json; use crate::api::project::Info; use crate::api::Context; use crate::api::{PaginationQuery, ProjectQuery}; @@ -79,7 +82,13 @@ async fn delegates_projects_handler( return None; }; - let delegates = id.doc.delegates; + let aliases = ctx.profile.aliases(); + let delegates = id + .doc + .delegates + .into_iter() + .map(|did| json::author(&Author::new(did), aliases.alias(did.as_key()))) + .collect::>(); let seeding = db.count(&id.rid).unwrap_or_default(); Some(Info { @@ -135,7 +144,12 @@ mod routes { "name": "hello-world", "description": "Rad repository for tests", "defaultBranch": "master", - "delegates": ["did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi"], + "delegates": [ + { + "id": "did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi", + "alias": "seed" + } + ], "visibility": { "type": "public" }, @@ -179,7 +193,12 @@ mod routes { "name": "hello-world", "description": "Rad repository for tests", "defaultBranch": "master", - "delegates": ["did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi"], + "delegates": [ + { + "id": "did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi", + "alias": "seed" + } + ], "visibility": { "type": "public" }, diff --git a/radicle-httpd/src/api/v1/projects.rs b/radicle-httpd/src/api/v1/projects.rs index 4f525683..5dbb22d1 100644 --- a/radicle-httpd/src/api/v1/projects.rs +++ b/radicle-httpd/src/api/v1/projects.rs @@ -14,8 +14,8 @@ use serde_json::json; use tower_http::set_header::SetResponseHeaderLayer; use radicle::cob::{ - issue, issue::cache::Issues as _, patch, patch::cache::Patches as _, resolve_embed, Embed, - Label, Uri, + issue, issue::cache::Issues as _, patch, patch::cache::Patches as _, resolve_embed, Author, + Embed, Label, Uri, }; use radicle::identity::{Did, RepoId}; use radicle::node::routing::Store; @@ -141,7 +141,13 @@ async fn project_root_handler( let Ok(patches) = patches.counts() else { return None; }; - let delegates = info.doc.delegates; + let aliases = ctx.profile.aliases(); + let delegates = info + .doc + .delegates + .into_iter() + .map(|did| api::json::author(&Author::new(did), aliases.alias(did.as_key()))) + .collect::>(); let seeding = db.count(&info.rid).unwrap_or_default(); Some(Info { @@ -1003,7 +1009,12 @@ mod routes { "name": "hello-world", "description": "Rad repository for tests", "defaultBranch": "master", - "delegates": [DID], + "delegates": [ + { + "id": DID, + "alias": "seed" + } + ], "visibility": { "type": "public" }, @@ -1038,7 +1049,12 @@ mod routes { "name": "hello-world", "description": "Rad repository for tests", "defaultBranch": "master", - "delegates": [DID], + "delegates": [ + { + "id": DID, + "alias": "seed" + } + ], "visibility": { "type": "public" }, @@ -1073,7 +1089,12 @@ mod routes { "name": "hello-world", "description": "Rad repository for tests", "defaultBranch": "master", - "delegates": [DID], + "delegates": [ + { + "id": DID, + "alias": "seed" + } + ], "visibility": { "type": "public" },