Radish alpha
r
Radicle web interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
httpd: Add delegates to project routes
Sebastian Martinez committed 3 years ago
commit 95dca98a4306168a53a4bc766615702f6a5a799e
parent 43f32c8360c4461f6990980509eedc74b5513ed4
5 files changed +23 -3
modified 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" }
modified 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<Did>,
        pub head: Oid,
        pub patches: usize,
        pub issues: usize,
modified 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),
modified 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,
modified 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,