httpd: Add delegates to project routes
Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
This commit is contained in:
parent
72c99b7939
commit
867eea5c38
|
|
@ -1963,6 +1963,7 @@ dependencies = [
|
||||||
"flate2",
|
"flate2",
|
||||||
"hyper",
|
"hyper",
|
||||||
"lexopt",
|
"lexopt",
|
||||||
|
"nonempty 0.8.1",
|
||||||
"radicle",
|
"radicle",
|
||||||
"radicle-cli",
|
"radicle-cli",
|
||||||
"radicle-crypto",
|
"radicle-crypto",
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ flate2 = { version = "1" }
|
||||||
hyper = { version = "0.14.17", default-features = false }
|
hyper = { version = "0.14.17", default-features = false }
|
||||||
lexopt = { version = "0.2.1" }
|
lexopt = { version = "0.2.1" }
|
||||||
radicle-surf = { version = "0.9.0", default-features = false, features = ["serde"] }
|
radicle-surf = { version = "0.9.0", default-features = false, features = ["serde"] }
|
||||||
|
nonempty = { version = "0.8.1", features = ["serialize"] }
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
serde_json = { version = "1", features = ["preserve_order"] }
|
serde_json = { version = "1", features = ["preserve_order"] }
|
||||||
thiserror = { version = "1" }
|
thiserror = { version = "1" }
|
||||||
|
|
|
||||||
|
|
@ -48,11 +48,14 @@ impl Context {
|
||||||
let storage = &self.profile.storage;
|
let storage = &self.profile.storage;
|
||||||
let repo = storage.repository(id)?;
|
let repo = storage.repository(id)?;
|
||||||
let (_, head) = repo.head()?;
|
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()?;
|
let issues = (Issues::open(self.profile.public_key, &repo)?).count()?;
|
||||||
|
|
||||||
Ok(project::Info {
|
Ok(project::Info {
|
||||||
payload,
|
payload,
|
||||||
|
delegates,
|
||||||
head,
|
head,
|
||||||
issues,
|
issues,
|
||||||
patches: 0,
|
patches: 0,
|
||||||
|
|
@ -126,10 +129,13 @@ pub struct PaginationQuery {
|
||||||
}
|
}
|
||||||
|
|
||||||
mod project {
|
mod project {
|
||||||
|
use nonempty::NonEmpty;
|
||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
use radicle::git::Oid;
|
use radicle::git::Oid;
|
||||||
use radicle::identity::project::Project;
|
use radicle::identity::project::Project;
|
||||||
use radicle::identity::Id;
|
use radicle::identity::Id;
|
||||||
use serde::Serialize;
|
use radicle::prelude::Did;
|
||||||
|
|
||||||
/// Project info.
|
/// Project info.
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
|
|
@ -138,6 +144,7 @@ mod project {
|
||||||
/// Project metadata.
|
/// Project metadata.
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub payload: Project,
|
pub payload: Project,
|
||||||
|
pub delegates: NonEmpty<Did>,
|
||||||
pub head: Oid,
|
pub head: Oid,
|
||||||
pub patches: usize,
|
pub patches: usize,
|
||||||
pub issues: usize,
|
pub issues: usize,
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,10 @@ pub enum Error {
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
GitProject(#[from] radicle::storage::git::ProjectError),
|
GitProject(#[from] radicle::storage::git::ProjectError),
|
||||||
|
|
||||||
|
/// Project doc error.
|
||||||
|
#[error(transparent)]
|
||||||
|
ProjectDoc(#[from] radicle::identity::doc::PayloadError),
|
||||||
|
|
||||||
/// Surf directory error.
|
/// Surf directory error.
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
SurfDir(#[from] radicle_surf::fs::error::Directory),
|
SurfDir(#[from] radicle_surf::fs::error::Directory),
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,8 @@ async fn delegates_projects_handler(
|
||||||
let Ok(doc) = repo.identity_of(ctx.profile.id()) else { return None };
|
let Ok(doc) = repo.identity_of(ctx.profile.id()) else { return None };
|
||||||
let Ok(payload) = doc.project() 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;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -51,6 +52,7 @@ async fn delegates_projects_handler(
|
||||||
|
|
||||||
Some(Info {
|
Some(Info {
|
||||||
payload,
|
payload,
|
||||||
|
delegates,
|
||||||
head,
|
head,
|
||||||
issues,
|
issues,
|
||||||
patches: 0,
|
patches: 0,
|
||||||
|
|
@ -89,6 +91,7 @@ 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"],
|
||||||
"head": HEAD,
|
"head": HEAD,
|
||||||
"patches": 0,
|
"patches": 0,
|
||||||
"issues": 1,
|
"issues": 1,
|
||||||
|
|
|
||||||
|
|
@ -78,11 +78,14 @@ async fn project_root_handler(
|
||||||
let Ok(repo) = storage.repository(id) else { return None };
|
let Ok(repo) = storage.repository(id) else { return None };
|
||||||
let Ok((_, head)) = repo.head() 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(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::open(ctx.profile.public_key, &repo) else { return None };
|
||||||
let Ok(issues) = (*issues).count() else { return None };
|
let Ok(issues) = (*issues).count() else { return None };
|
||||||
|
let delegates = doc.delegates;
|
||||||
|
|
||||||
Some(Info {
|
Some(Info {
|
||||||
payload,
|
payload,
|
||||||
|
delegates,
|
||||||
head,
|
head,
|
||||||
issues,
|
issues,
|
||||||
patches: 0,
|
patches: 0,
|
||||||
|
|
@ -574,6 +577,7 @@ 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"],
|
||||||
"head": HEAD,
|
"head": HEAD,
|
||||||
"patches": 0,
|
"patches": 0,
|
||||||
"issues": 1,
|
"issues": 1,
|
||||||
|
|
@ -596,6 +600,7 @@ 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"],
|
||||||
"head": HEAD,
|
"head": HEAD,
|
||||||
"patches": 0,
|
"patches": 0,
|
||||||
"issues": 1,
|
"issues": 1,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue