cob: Add actor to `Entry`
Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
This commit is contained in:
parent
e83d47ff45
commit
f140c6d28e
|
|
@ -66,6 +66,7 @@ fn evaluate_change(
|
|||
|
||||
Ok(history::Entry::new(
|
||||
*change.id(),
|
||||
change.signature.key,
|
||||
*change.author(),
|
||||
change.resource,
|
||||
child_commits.iter().cloned(),
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ use std::{
|
|||
|
||||
use git_ext::Oid;
|
||||
use petgraph::visit::Walker as _;
|
||||
use radicle_crypto::PublicKey;
|
||||
|
||||
use crate::pruning_fold;
|
||||
|
||||
|
|
@ -50,6 +51,7 @@ pub enum CreateError {
|
|||
impl History {
|
||||
pub(crate) fn new_from_root<Id>(
|
||||
id: Id,
|
||||
actor: PublicKey,
|
||||
author: Option<Oid>,
|
||||
resource: Oid,
|
||||
contents: Contents,
|
||||
|
|
@ -60,6 +62,7 @@ impl History {
|
|||
let id = id.into();
|
||||
let root_entry = Entry {
|
||||
id,
|
||||
actor,
|
||||
author,
|
||||
resource,
|
||||
children: vec![],
|
||||
|
|
@ -126,6 +129,7 @@ impl History {
|
|||
pub(crate) fn extend<Id>(
|
||||
&mut self,
|
||||
new_id: Id,
|
||||
new_actor: PublicKey,
|
||||
new_author: Option<Oid>,
|
||||
new_resource: Oid,
|
||||
new_contents: Contents,
|
||||
|
|
@ -136,6 +140,7 @@ impl History {
|
|||
let new_id = new_id.into();
|
||||
let new_entry = Entry::new(
|
||||
new_id,
|
||||
new_actor,
|
||||
new_author,
|
||||
new_resource,
|
||||
std::iter::empty::<git2::Oid>(),
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
|
||||
use git_ext::Oid;
|
||||
|
||||
use radicle_crypto::PublicKey;
|
||||
|
||||
use crate::pruning_fold;
|
||||
|
||||
/// Entry contents.
|
||||
|
|
@ -41,6 +43,8 @@ impl From<EntryId> for Oid {
|
|||
pub struct Entry {
|
||||
/// The identifier for this entry
|
||||
pub(super) id: EntryId,
|
||||
/// The actor that authored this entry.
|
||||
pub(super) actor: PublicKey,
|
||||
/// The content-address for this entry's author.
|
||||
/// TODO: This shouldn't be here?
|
||||
pub(super) author: Option<Oid>,
|
||||
|
|
@ -55,6 +59,7 @@ pub struct Entry {
|
|||
impl Entry {
|
||||
pub fn new<Id1, Id2, ChildIds>(
|
||||
id: Id1,
|
||||
actor: PublicKey,
|
||||
author: Option<Oid>,
|
||||
resource: Oid,
|
||||
children: ChildIds,
|
||||
|
|
@ -67,6 +72,7 @@ impl Entry {
|
|||
{
|
||||
Self {
|
||||
id: id.into(),
|
||||
actor,
|
||||
author,
|
||||
resource,
|
||||
children: children.into_iter().map(|id| id.into()).collect(),
|
||||
|
|
@ -84,9 +90,14 @@ impl Entry {
|
|||
self.resource
|
||||
}
|
||||
|
||||
/// The public key of the actor.
|
||||
pub fn actor(&self) -> &PublicKey {
|
||||
&self.actor
|
||||
}
|
||||
|
||||
/// The `Oid` of the author that made this change.
|
||||
pub fn author(&self) -> &Option<Oid> {
|
||||
&self.author
|
||||
pub fn author(&self) -> Option<&Oid> {
|
||||
self.author.as_ref()
|
||||
}
|
||||
|
||||
/// The contents of this change
|
||||
|
|
|
|||
|
|
@ -89,6 +89,7 @@ where
|
|||
|
||||
let history = History::new_from_root(
|
||||
*init_change.id(),
|
||||
init_change.signature.key,
|
||||
content,
|
||||
resource.content_id(),
|
||||
contents.clone(),
|
||||
|
|
|
|||
|
|
@ -67,9 +67,10 @@ where
|
|||
message,
|
||||
} = args;
|
||||
|
||||
let content = match author {
|
||||
let author = match author {
|
||||
None => None,
|
||||
Some(author) => {
|
||||
// TODO: Remove?
|
||||
if !author.is_delegate(signer.public_key()) {
|
||||
return Err(error::Update::SignerIsNotAuthor);
|
||||
} else {
|
||||
|
|
@ -87,7 +88,7 @@ where
|
|||
.ok_or(error::Update::NoSuchObject)?;
|
||||
|
||||
let change = storage.create(
|
||||
content,
|
||||
author,
|
||||
resource.content_id(),
|
||||
signer,
|
||||
change::Create {
|
||||
|
|
@ -98,10 +99,13 @@ where
|
|||
message,
|
||||
},
|
||||
)?;
|
||||
|
||||
object
|
||||
.history
|
||||
.extend(change.id, content, change.resource, changes);
|
||||
object.history.extend(
|
||||
change.id,
|
||||
change.signature.key,
|
||||
author,
|
||||
change.resource,
|
||||
changes,
|
||||
);
|
||||
storage
|
||||
.update(identifier, typename, &object_id, &change)
|
||||
.map_err(|err| error::Update::Refs { err: Box::new(err) })?;
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@ pub mod error;
|
|||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct Signature {
|
||||
key: PublicKey,
|
||||
sig: crypto::Signature,
|
||||
pub(super) key: PublicKey,
|
||||
pub(super) sig: crypto::Signature,
|
||||
}
|
||||
|
||||
impl Signature {
|
||||
|
|
|
|||
Loading…
Reference in New Issue