Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
radicle: Remove `delegate` from `Remote` type
Alexis Sellier committed 3 years ago
commit 3a9c8b7144d42183f82462807345f3c88bdacc16
parent df25e9a2a58d47c026de236a46bd48444d0025f4
4 files changed +11 -38
modified 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());
            }
modified radicle-httpd/src/api/v1/projects.rs
@@ -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
            })
        );
    }
modified radicle/src/storage.rs
@@ -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,
        }
    }
}
modified radicle/src/test/storage.rs
@@ -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())
    }