Radish alpha
h
rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
Radicle Heartwood Protocol & Stack
Radicle
Git
httpd: Add alias to project delegates
Merged did:key:z6MkkfM3...sVz5 opened 2 years ago
4 files changed +69 -16 a9b94b0a d04d9d7d
modified 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::<Vec<_>>();
        let issues = self.profile.issues(repo)?.counts()?;
        let patches = self.profile.patches(repo)?.counts()?;
        let db = &self.profile.database()?;
@@ -74,6 +79,7 @@ impl Context {
        Ok(project::Info {
            payload,
            delegates,
+
            threshold: doc.threshold,
            visibility: doc.visibility,
            head,
            issues,
@@ -217,14 +223,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 +238,8 @@ mod project {
        /// Project metadata.
        #[serde(flatten)]
        pub payload: Project,
-
        pub delegates: NonEmpty<Did>,
+
        pub delegates: Vec<Value>,
+
        pub threshold: usize,
        pub visibility: Visibility,
        pub head: Oid,
        pub patches: cob::patch::PatchCounts,
modified radicle-httpd/src/api/json.rs
@@ -185,7 +185,7 @@ fn reactions(
}

/// 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 {
        Some(alias) => json!({
            "id": author.id,
modified 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,12 +82,19 @@ 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::<Vec<_>>();
            let seeding = db.count(&id.rid).unwrap_or_default();

            Some(Info {
                payload,
                delegates,
+
                threshold: id.doc.threshold,
                visibility: id.doc.visibility,
                head,
                issues,
@@ -135,7 +145,13 @@ mod routes {
                "name": "hello-world",
                "description": "Rad repository for tests",
                "defaultBranch": "master",
-
                "delegates": ["did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi"],
+
                "delegates": [
+
                  {
+
                    "id": "did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi",
+
                    "alias": "seed"
+
                  }
+
                ],
+
                "threshold": 1,
                "visibility": {
                  "type": "public"
                },
@@ -179,7 +195,13 @@ mod routes {
                "name": "hello-world",
                "description": "Rad repository for tests",
                "defaultBranch": "master",
-
                "delegates": ["did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi"],
+
                "delegates": [
+
                  {
+
                    "id": "did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi",
+
                    "alias": "seed"
+
                  }
+
                ],
+
                "threshold": 1,
                "visibility": {
                  "type": "public"
                },
modified 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;
@@ -137,13 +137,20 @@ 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::<Vec<_>>();
            let seeding = db.count(&info.rid).unwrap_or_default();

            Some(Info {
                payload,
                delegates,
                head,
+
                threshold: info.doc.threshold,
                visibility: info.doc.visibility,
                issues,
                patches,
@@ -992,7 +999,13 @@ mod routes {
                "name": "hello-world",
                "description": "Rad repository for tests",
                "defaultBranch": "master",
-
                "delegates": [DID],
+
                "delegates": [
+
                  {
+
                    "id": DID,
+
                    "alias": "seed"
+
                  }
+
                ],
+
                "threshold": 1,
                "visibility": {
                  "type": "public"
                },
@@ -1027,7 +1040,13 @@ mod routes {
                "name": "hello-world",
                "description": "Rad repository for tests",
                "defaultBranch": "master",
-
                "delegates": [DID],
+
                "delegates": [
+
                  {
+
                    "id": DID,
+
                    "alias": "seed"
+
                  }
+
                ],
+
                "threshold": 1,
                "visibility": {
                  "type": "public"
                },
@@ -1062,7 +1081,13 @@ mod routes {
               "name": "hello-world",
               "description": "Rad repository for tests",
               "defaultBranch": "master",
-
               "delegates": [DID],
+
               "delegates": [
+
                 {
+
                   "id": DID,
+
                   "alias": "seed"
+
                 }
+
               ],
+
               "threshold": 1,
               "visibility": {
                 "type": "public"
               },