From 08811b4b875530f11186763a11cc23da855c9973 Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Sun, 13 Nov 2022 17:41:43 +0100 Subject: [PATCH] Various fixes to COBs * Use the existing conventions for passing a signer to functions. * Allow replacing git refs when updating cobs. * Fix the parsing of a cob id. Signed-off-by: Alexis Sellier --- .../src/object/collaboration/create.rs | 8 ++--- .../src/object/collaboration/update.rs | 8 ++--- radicle-cob/src/tests.rs | 14 ++++----- radicle/src/cob.rs | 29 +++++++++++++++---- radicle/src/git.rs | 4 +-- radicle/src/lib.rs | 6 ++-- radicle/src/storage/git.rs | 2 +- 7 files changed, 44 insertions(+), 27 deletions(-) diff --git a/radicle-cob/src/object/collaboration/create.rs b/radicle-cob/src/object/collaboration/create.rs index ad623b5d..08caf974 100644 --- a/radicle-cob/src/object/collaboration/create.rs +++ b/radicle-cob/src/object/collaboration/create.rs @@ -48,19 +48,19 @@ impl Create { /// /// The `args` are the metadata for this [`CollaborativeObject`]. See /// [`Create`] for further information. -pub fn create( +pub fn create( storage: &S, - signer: Signer, + signer: &G, resource: &Resource, identifier: &S::Identifier, args: Create, ) -> Result where S: Store, + G: crypto::Signer, Author: Identity, Author::Identifier: Clone + PartialEq, Resource: Identity, - Signer: crypto::Signer, { let Create { author, @@ -81,7 +81,7 @@ where }; let init_change = storage - .create(content, resource.content_id(), &signer, args.create_spec()) + .create(content, resource.content_id(), signer, args.create_spec()) .map_err(error::Create::from)?; let history = History::new_from_root( diff --git a/radicle-cob/src/object/collaboration/update.rs b/radicle-cob/src/object/collaboration/update.rs index be888920..250cdc2c 100644 --- a/radicle-cob/src/object/collaboration/update.rs +++ b/radicle-cob/src/object/collaboration/update.rs @@ -42,19 +42,19 @@ pub struct Update { /// /// The `args` are the metadata for this [`CollaborativeObject`] /// udpate. See [`Update`] for further information. -pub fn update( +pub fn update( storage: &S, - signer: Signer, + signer: &G, resource: &Resource, identifier: &S::Identifier, args: Update, ) -> Result where S: Store, + G: crypto::Signer, Author: Identity, Author::Identifier: Clone + PartialEq, Resource: Identity, - Signer: crypto::Signer, { let Update { author, @@ -86,7 +86,7 @@ where let change = storage.create( content, resource.content_id(), - &signer, + signer, change::Create { tips: object.tips().iter().cloned().collect(), contents: changes.clone(), diff --git a/radicle-cob/src/tests.rs b/radicle-cob/src/tests.rs index d2699123..f8dc0262 100644 --- a/radicle-cob/src/tests.rs +++ b/radicle-cob/src/tests.rs @@ -22,7 +22,7 @@ fn roundtrip() { let typename = "xyz.rad.issue".parse::().unwrap(); let cob = create( &storage, - signer, + &signer, &proj, &proj.identifier(), Create { @@ -54,7 +54,7 @@ fn list_cobs() { let typename = "xyz.rad.issue".parse::().unwrap(); let issue_1 = create( &storage, - signer.clone(), + &signer, &proj, &proj.identifier(), Create { @@ -68,7 +68,7 @@ fn list_cobs() { let issue_2 = create( &storage, - signer, + &signer, &proj, &proj.identifier(), Create { @@ -103,7 +103,7 @@ fn update_cob() { let typename = "xyz.rad.issue".parse::().unwrap(); let cob = create( &storage, - signer.clone(), + &signer, &proj, &proj.identifier(), Create { @@ -121,7 +121,7 @@ fn update_cob() { let updated = update( &storage, - signer, + &signer, &proj, &proj.identifier(), Update { @@ -161,7 +161,7 @@ fn traverse_cobs() { let typename = "xyz.rad.issue".parse::().unwrap(); let cob = create( &storage, - terry_signer, + &terry_signer, &terry_proj, &terry_proj.identifier(), Create { @@ -183,7 +183,7 @@ fn traverse_cobs() { let updated = update( &storage, - neil_signer, + &neil_signer, &neil_proj, &neil_proj.identifier(), Update { diff --git a/radicle/src/cob.rs b/radicle/src/cob.rs index 5cd2dd55..c55080dd 100644 --- a/radicle/src/cob.rs +++ b/radicle/src/cob.rs @@ -5,8 +5,11 @@ pub use cob::{ use radicle_cob as cob; use radicle_git_ext::Oid; +pub use radicle_cob::*; + use crate::{ identity::{project::Identity, Did}, + node::NodeId, storage::git::Repository, }; @@ -21,6 +24,20 @@ pub struct Author { did: Did, } +impl From for Author { + fn from(did: Did) -> Self { + Self { did } + } +} + +impl From for Author { + fn from(node_id: NodeId) -> Self { + Self { + did: Did::from(node_id), + } + } +} + impl identity::Identity for Author { type Identifier = String; @@ -47,14 +64,14 @@ impl identity::Identity for Author { /// /// The `args` are the metadata for this [`CollaborativeObject`] /// udpate. See [`Update`] for further information. -pub fn create( +pub fn create( repository: &Repository, - signer: S, + signer: &G, project: &Identity, args: Create, ) -> Result where - S: crypto::Signer, + G: crypto::Signer, { let namespace = *signer.public_key(); cob::create(repository, signer, project, &namespace, args) @@ -103,14 +120,14 @@ pub fn list( /// /// The `args` are the metadata for this [`CollaborativeObject`] /// udpate. See [`Update`] for further information. -pub fn update( +pub fn update( repository: &Repository, - signer: S, + signer: &G, project: &Identity, args: Update, ) -> Result where - S: crypto::Signer, + G: crypto::Signer, { let namespace = *signer.public_key(); cob::update(repository, signer, project, &namespace, args) diff --git a/radicle/src/git.rs b/radicle/src/git.rs index a0346ff9..6740b261 100644 --- a/radicle/src/git.rs +++ b/radicle/src/git.rs @@ -151,9 +151,9 @@ pub mod refs { let (_refs, _cobs, typename, mut object_id) = cob.non_empty_components(); let object_id = object_id .next() - .and_then(|oid| oid.parse::().ok())?; + .and_then(|oid| oid.parse::().ok())?; let typename = typename.parse::().ok()?; - Some((typename, object_id)) + Some((typename, object_id.into())) } } diff --git a/radicle/src/lib.rs b/radicle/src/lib.rs index 83ad132a..9a211d8e 100644 --- a/radicle/src/lib.rs +++ b/radicle/src/lib.rs @@ -25,9 +25,9 @@ pub use storage::git::Storage; pub mod prelude { use super::*; - pub use crypto::{Signer, Verified}; - pub use identity::{Doc, Id}; + pub use crypto::{PublicKey, Signer, Verified}; + pub use identity::{Did, Doc, Id}; pub use node::NodeId; pub use profile::Profile; - pub use storage::BranchName; + pub use storage::{BranchName, ReadRepository, ReadStorage, WriteRepository, WriteStorage}; } diff --git a/radicle/src/storage/git.rs b/radicle/src/storage/git.rs index 320018e1..e53d60e4 100644 --- a/radicle/src/storage/git.rs +++ b/radicle/src/storage/git.rs @@ -771,7 +771,7 @@ impl cob::object::Storage for Repository { self.backend.reference( git::refs::storage::cob(identifier, typename, object_id).as_str(), (*change.id()).into(), - false, + true, &format!( "Updating collaborative object '{}/{}' with new change {}", typename,