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 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());
}

View File

@ -318,6 +318,7 @@ async fn tree_handler(
async fn remotes_handler(State(ctx): State<Context>, Path(project): Path<Id>) -> 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<Context>, Path(project): Path<Id>) ->
json!({
"id": remote.id,
"heads": refs,
"delegate": remote.delegate,
"delegate": delegates.contains(&remote.id.into()),
})
})
.collect::<Vec<_>>();
@ -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
})
);
}

View File

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