From 3a9c8b7144d42183f82462807345f3c88bdacc16 Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Wed, 26 Apr 2023 11:06:55 +0200 Subject: [PATCH] radicle: Remove `delegate` from `Remote` type It wasn't being set correctly, and it's not the place for it, so we remove it and set it in `httpd`. Note that `Remote` is now simply a wrapper around `SignedRefs`. If we want to remove the type or turn it into an alias, it will require touching lots of different parts of the codebase. I opted not to do that here as it's lower priority. --- radicle-cli/src/commands/patch/list.rs | 6 ------ radicle-httpd/src/api/v1/projects.rs | 10 ++++++---- radicle/src/storage.rs | 18 +++--------------- radicle/src/test/storage.rs | 15 ++------------- 4 files changed, 11 insertions(+), 38 deletions(-) diff --git a/radicle-cli/src/commands/patch/list.rs b/radicle-cli/src/commands/patch/list.rs index e9f60fe4..87083261 100644 --- a/radicle-cli/src/commands/patch/list.rs +++ b/radicle-cli/src/commands/patch/list.rs @@ -149,9 +149,6 @@ pub fn timeline( let peer = repository.remote(&merge.node)?; let mut badges = Vec::new(); - if peer.delegate { - badges.push(term::format::secondary("(delegate)").into()); - } if peer.id == *whoami { badges.push(term::format::primary("(you)").into()); } @@ -185,9 +182,6 @@ pub fn timeline( let peer = repository.remote(reviewer)?; let mut badges = Vec::new(); - if peer.delegate { - badges.push(term::format::secondary("(delegate)").into()); - } if peer.id == *whoami { badges.push(term::format::primary("(you)").into()); } diff --git a/radicle-httpd/src/api/v1/projects.rs b/radicle-httpd/src/api/v1/projects.rs index 7e04d972..14b98619 100644 --- a/radicle-httpd/src/api/v1/projects.rs +++ b/radicle-httpd/src/api/v1/projects.rs @@ -318,6 +318,7 @@ async fn tree_handler( async fn remotes_handler(State(ctx): State, Path(project): Path) -> impl IntoResponse { let storage = &ctx.profile.storage; let repo = storage.repository(project)?; + let delegates = repo.delegates()?; let remotes = repo .remotes()? .filter_map(|r| r.map(|r| r.1).ok()) @@ -335,7 +336,7 @@ async fn remotes_handler(State(ctx): State, Path(project): Path) -> json!({ "id": remote.id, "heads": refs, - "delegate": remote.delegate, + "delegate": delegates.contains(&remote.id.into()), }) }) .collect::>(); @@ -351,6 +352,7 @@ async fn remote_handler( ) -> impl IntoResponse { let storage = &ctx.profile.storage; let repo = storage.repository(project)?; + let delegates = repo.delegates()?; let remote = repo.remote(&node_id)?; let refs = remote .refs @@ -364,7 +366,7 @@ async fn remote_handler( let remote = json!({ "id": remote.id, "heads": refs, - "delegate": remote.delegate, + "delegate": delegates.contains(&remote.id.into()), }); Ok::<_, Error>(Json(remote)) @@ -1251,7 +1253,7 @@ mod routes { "heads": { "master": HEAD }, - "delegate": false + "delegate": true } ]) ); @@ -1275,7 +1277,7 @@ mod routes { "heads": { "master": HEAD }, - "delegate": false + "delegate": true }) ); } diff --git a/radicle/src/storage.rs b/radicle/src/storage.rs index 4bcd0068..f68c3800 100644 --- a/radicle/src/storage.rs +++ b/radicle/src/storage.rs @@ -208,17 +208,12 @@ pub struct Remote { /// Git references published under this remote, and their hashes. #[serde(flatten)] pub refs: SignedRefs, - /// Whether this remote is a delegate for the project. - pub delegate: bool, } impl Remote { /// Create a new unverified remotes object. pub fn new(refs: impl Into>) -> Self { - Self { - refs: refs.into(), - delegate: false, - } + Self { refs: refs.into() } } } @@ -226,26 +221,19 @@ impl Remote { pub fn verified(self) -> Result, crypto::Error> { let refs = self.refs.verified()?; - Ok(Remote { - refs, - delegate: self.delegate, - }) + Ok(Remote { refs }) } } impl Remote { /// Create a new unverified remotes object. pub fn new(refs: impl Into>) -> Self { - Self { - refs: refs.into(), - delegate: false, - } + Self { refs: refs.into() } } pub fn unverified(self) -> Remote { Remote { refs: self.refs.unverified(), - delegate: self.delegate, } } } diff --git a/radicle/src/test/storage.rs b/radicle/src/test/storage.rs index cd4e51d9..ca4eb38d 100644 --- a/radicle/src/test/storage.rs +++ b/radicle/src/test/storage.rs @@ -154,10 +154,7 @@ impl ReadRepository for MockRepository { fn remote(&self, id: &RemoteId) -> Result, refs::Error> { self.remotes .get(id) - .map(|refs| Remote { - refs: refs.clone(), - delegate: false, - }) + .map(|refs| Remote { refs: refs.clone() }) .ok_or(refs::Error::InvalidRef) } @@ -165,15 +162,7 @@ impl ReadRepository for MockRepository { Ok(self .remotes .iter() - .map(|(id, refs)| { - ( - *id, - Remote { - refs: refs.clone(), - delegate: false, - }, - ) - }) + .map(|(id, refs)| (*id, Remote { refs: refs.clone() })) .collect()) }