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.
This commit is contained in:
Alexis Sellier 2023-04-26 11:06:55 +02:00
parent df25e9a2a5
commit 3a9c8b7144
No known key found for this signature in database
4 changed files with 11 additions and 38 deletions

View File

@ -149,9 +149,6 @@ pub fn timeline(
let peer = repository.remote(&merge.node)?; let peer = repository.remote(&merge.node)?;
let mut badges = Vec::new(); let mut badges = Vec::new();
if peer.delegate {
badges.push(term::format::secondary("(delegate)").into());
}
if peer.id == *whoami { if peer.id == *whoami {
badges.push(term::format::primary("(you)").into()); badges.push(term::format::primary("(you)").into());
} }
@ -185,9 +182,6 @@ pub fn timeline(
let peer = repository.remote(reviewer)?; let peer = repository.remote(reviewer)?;
let mut badges = Vec::new(); let mut badges = Vec::new();
if peer.delegate {
badges.push(term::format::secondary("(delegate)").into());
}
if peer.id == *whoami { if peer.id == *whoami {
badges.push(term::format::primary("(you)").into()); badges.push(term::format::primary("(you)").into());
} }

View File

@ -318,6 +318,7 @@ async fn tree_handler(
async fn remotes_handler(State(ctx): State<Context>, Path(project): Path<Id>) -> impl IntoResponse { async fn remotes_handler(State(ctx): State<Context>, Path(project): Path<Id>) -> impl IntoResponse {
let storage = &ctx.profile.storage; let storage = &ctx.profile.storage;
let repo = storage.repository(project)?; let repo = storage.repository(project)?;
let delegates = repo.delegates()?;
let remotes = repo let remotes = repo
.remotes()? .remotes()?
.filter_map(|r| r.map(|r| r.1).ok()) .filter_map(|r| r.map(|r| r.1).ok())
@ -335,7 +336,7 @@ async fn remotes_handler(State(ctx): State<Context>, Path(project): Path<Id>) ->
json!({ json!({
"id": remote.id, "id": remote.id,
"heads": refs, "heads": refs,
"delegate": remote.delegate, "delegate": delegates.contains(&remote.id.into()),
}) })
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
@ -351,6 +352,7 @@ async fn remote_handler(
) -> impl IntoResponse { ) -> impl IntoResponse {
let storage = &ctx.profile.storage; let storage = &ctx.profile.storage;
let repo = storage.repository(project)?; let repo = storage.repository(project)?;
let delegates = repo.delegates()?;
let remote = repo.remote(&node_id)?; let remote = repo.remote(&node_id)?;
let refs = remote let refs = remote
.refs .refs
@ -364,7 +366,7 @@ async fn remote_handler(
let remote = json!({ let remote = json!({
"id": remote.id, "id": remote.id,
"heads": refs, "heads": refs,
"delegate": remote.delegate, "delegate": delegates.contains(&remote.id.into()),
}); });
Ok::<_, Error>(Json(remote)) Ok::<_, Error>(Json(remote))
@ -1251,7 +1253,7 @@ mod routes {
"heads": { "heads": {
"master": HEAD "master": HEAD
}, },
"delegate": false "delegate": true
} }
]) ])
); );
@ -1275,7 +1277,7 @@ mod routes {
"heads": { "heads": {
"master": HEAD "master": HEAD
}, },
"delegate": false "delegate": true
}) })
); );
} }

View File

@ -208,17 +208,12 @@ pub struct Remote<V = Verified> {
/// Git references published under this remote, and their hashes. /// Git references published under this remote, and their hashes.
#[serde(flatten)] #[serde(flatten)]
pub refs: SignedRefs<V>, pub refs: SignedRefs<V>,
/// Whether this remote is a delegate for the project.
pub delegate: bool,
} }
impl Remote<Unverified> { impl Remote<Unverified> {
/// Create a new unverified remotes object. /// Create a new unverified remotes object.
pub fn new(refs: impl Into<SignedRefs<Unverified>>) -> Self { pub fn new(refs: impl Into<SignedRefs<Unverified>>) -> Self {
Self { Self { refs: refs.into() }
refs: refs.into(),
delegate: false,
}
} }
} }
@ -226,26 +221,19 @@ impl Remote<Unverified> {
pub fn verified(self) -> Result<Remote<Verified>, crypto::Error> { pub fn verified(self) -> Result<Remote<Verified>, crypto::Error> {
let refs = self.refs.verified()?; let refs = self.refs.verified()?;
Ok(Remote { Ok(Remote { refs })
refs,
delegate: self.delegate,
})
} }
} }
impl Remote<Verified> { impl Remote<Verified> {
/// Create a new unverified remotes object. /// Create a new unverified remotes object.
pub fn new(refs: impl Into<SignedRefs<Verified>>) -> Self { pub fn new(refs: impl Into<SignedRefs<Verified>>) -> Self {
Self { Self { refs: refs.into() }
refs: refs.into(),
delegate: false,
}
} }
pub fn unverified(self) -> Remote<Unverified> { pub fn unverified(self) -> Remote<Unverified> {
Remote { Remote {
refs: self.refs.unverified(), refs: self.refs.unverified(),
delegate: self.delegate,
} }
} }
} }

View File

@ -154,10 +154,7 @@ impl ReadRepository for MockRepository {
fn remote(&self, id: &RemoteId) -> Result<Remote<Verified>, refs::Error> { fn remote(&self, id: &RemoteId) -> Result<Remote<Verified>, refs::Error> {
self.remotes self.remotes
.get(id) .get(id)
.map(|refs| Remote { .map(|refs| Remote { refs: refs.clone() })
refs: refs.clone(),
delegate: false,
})
.ok_or(refs::Error::InvalidRef) .ok_or(refs::Error::InvalidRef)
} }
@ -165,15 +162,7 @@ impl ReadRepository for MockRepository {
Ok(self Ok(self
.remotes .remotes
.iter() .iter()
.map(|(id, refs)| { .map(|(id, refs)| (*id, Remote { refs: refs.clone() }))
(
*id,
Remote {
refs: refs.clone(),
delegate: false,
},
)
})
.collect()) .collect())
} }