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",
|
||||
"hyper",
|
||||
"lexopt",
|
||||
"nonempty 0.8.1",
|
||||
"radicle",
|
||||
"radicle-cli",
|
||||
"radicle-crypto",
|
||||
|
|
|
|||
|
|
@ -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" }
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in New Issue