httpd: Add alias to project delegates

This commit is contained in:
Sebastian Martinez 2024-04-29 10:59:55 +02:00 committed by cloudhead
parent 854fc9af8e
commit c4d4ad7008
No known key found for this signature in database
4 changed files with 60 additions and 16 deletions

View File

@ -17,11 +17,11 @@ use serde_json::json;
use tokio::sync::RwLock; use tokio::sync::RwLock;
use tower_http::cors::{self, CorsLayer}; use tower_http::cors::{self, CorsLayer};
use radicle::cob::issue; use radicle::cob::{issue, patch, Author};
use radicle::cob::patch;
use radicle::identity::{DocAt, RepoId}; use radicle::identity::{DocAt, RepoId};
use radicle::node::policy::Scope; use radicle::node::policy::Scope;
use radicle::node::routing::Store; use radicle::node::routing::Store;
use radicle::node::AliasStore;
use radicle::node::{Handle, NodeId}; use radicle::node::{Handle, NodeId};
use radicle::storage::{ReadRepository, ReadStorage}; use radicle::storage::{ReadRepository, ReadStorage};
use radicle::{Node, Profile}; use radicle::{Node, Profile};
@ -65,7 +65,12 @@ impl Context {
let id = repo.id(); let id = repo.id();
let payload = doc.project()?; 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::<Vec<_>>();
let issues = self.profile.issues(repo)?.counts()?; let issues = self.profile.issues(repo)?.counts()?;
let patches = self.profile.patches(repo)?.counts()?; let patches = self.profile.patches(repo)?.counts()?;
let db = &self.profile.database()?; let db = &self.profile.database()?;
@ -217,14 +222,13 @@ impl PatchState {
} }
mod project { mod project {
use nonempty::NonEmpty;
use serde::Serialize; use serde::Serialize;
use serde_json::Value;
use radicle::cob; use radicle::cob;
use radicle::git::Oid; use radicle::git::Oid;
use radicle::identity::project::Project; use radicle::identity::project::Project;
use radicle::identity::{RepoId, Visibility}; use radicle::identity::{RepoId, Visibility};
use radicle::prelude::Did;
/// Project info. /// Project info.
#[derive(Serialize)] #[derive(Serialize)]
@ -233,7 +237,7 @@ mod project {
/// Project metadata. /// Project metadata.
#[serde(flatten)] #[serde(flatten)]
pub payload: Project, pub payload: Project,
pub delegates: NonEmpty<Did>, pub delegates: Vec<Value>,
pub visibility: Visibility, pub visibility: Visibility,
pub head: Oid, pub head: Oid,
pub patches: cob::patch::PatchCounts, pub patches: cob::patch::PatchCounts,

View File

@ -184,7 +184,7 @@ fn reactions(
} }
/// Returns JSON for an `author` and fills in `alias` when present. /// Returns JSON for an `author` and fills in `alias` when present.
fn author(author: &Author, alias: Option<Alias>) -> Value { pub(crate) fn author(author: &Author, alias: Option<Alias>) -> Value {
match alias { match alias {
Some(alias) => json!({ Some(alias) => json!({
"id": author.id, "id": author.id,

View File

@ -3,13 +3,16 @@ use axum::response::IntoResponse;
use axum::routing::get; use axum::routing::get;
use axum::{Json, Router}; use axum::{Json, Router};
use radicle::cob::Author;
use radicle::identity::Did; use radicle::identity::Did;
use radicle::issue::cache::Issues as _; use radicle::issue::cache::Issues as _;
use radicle::node::routing::Store; use radicle::node::routing::Store;
use radicle::node::AliasStore;
use radicle::patch::cache::Patches as _; use radicle::patch::cache::Patches as _;
use radicle::storage::{ReadRepository, ReadStorage}; use radicle::storage::{ReadRepository, ReadStorage};
use crate::api::error::Error; use crate::api::error::Error;
use crate::api::json;
use crate::api::project::Info; use crate::api::project::Info;
use crate::api::Context; use crate::api::Context;
use crate::api::{PaginationQuery, ProjectQuery}; use crate::api::{PaginationQuery, ProjectQuery};
@ -79,7 +82,13 @@ async fn delegates_projects_handler(
return None; 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::<Vec<_>>();
let seeding = db.count(&id.rid).unwrap_or_default(); let seeding = db.count(&id.rid).unwrap_or_default();
Some(Info { Some(Info {
@ -135,7 +144,12 @@ mod routes {
"name": "hello-world", "name": "hello-world",
"description": "Rad repository for tests", "description": "Rad repository for tests",
"defaultBranch": "master", "defaultBranch": "master",
"delegates": ["did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi"], "delegates": [
{
"id": "did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi",
"alias": "seed"
}
],
"visibility": { "visibility": {
"type": "public" "type": "public"
}, },
@ -179,7 +193,12 @@ mod routes {
"name": "hello-world", "name": "hello-world",
"description": "Rad repository for tests", "description": "Rad repository for tests",
"defaultBranch": "master", "defaultBranch": "master",
"delegates": ["did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi"], "delegates": [
{
"id": "did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi",
"alias": "seed"
}
],
"visibility": { "visibility": {
"type": "public" "type": "public"
}, },

View File

@ -14,8 +14,8 @@ use serde_json::json;
use tower_http::set_header::SetResponseHeaderLayer; use tower_http::set_header::SetResponseHeaderLayer;
use radicle::cob::{ use radicle::cob::{
issue, issue::cache::Issues as _, patch, patch::cache::Patches as _, resolve_embed, Embed, issue, issue::cache::Issues as _, patch, patch::cache::Patches as _, resolve_embed, Author,
Label, Uri, Embed, Label, Uri,
}; };
use radicle::identity::{Did, RepoId}; use radicle::identity::{Did, RepoId};
use radicle::node::routing::Store; use radicle::node::routing::Store;
@ -141,7 +141,13 @@ async fn project_root_handler(
let Ok(patches) = patches.counts() else { let Ok(patches) = patches.counts() else {
return None; 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::<Vec<_>>();
let seeding = db.count(&info.rid).unwrap_or_default(); let seeding = db.count(&info.rid).unwrap_or_default();
Some(Info { Some(Info {
@ -1003,7 +1009,12 @@ mod routes {
"name": "hello-world", "name": "hello-world",
"description": "Rad repository for tests", "description": "Rad repository for tests",
"defaultBranch": "master", "defaultBranch": "master",
"delegates": [DID], "delegates": [
{
"id": DID,
"alias": "seed"
}
],
"visibility": { "visibility": {
"type": "public" "type": "public"
}, },
@ -1038,7 +1049,12 @@ mod routes {
"name": "hello-world", "name": "hello-world",
"description": "Rad repository for tests", "description": "Rad repository for tests",
"defaultBranch": "master", "defaultBranch": "master",
"delegates": [DID], "delegates": [
{
"id": DID,
"alias": "seed"
}
],
"visibility": { "visibility": {
"type": "public" "type": "public"
}, },
@ -1073,7 +1089,12 @@ mod routes {
"name": "hello-world", "name": "hello-world",
"description": "Rad repository for tests", "description": "Rad repository for tests",
"defaultBranch": "master", "defaultBranch": "master",
"delegates": [DID], "delegates": [
{
"id": DID,
"alias": "seed"
}
],
"visibility": { "visibility": {
"type": "public" "type": "public"
}, },