Skip to content

Commit 25c3728

Browse files
DocumentOwnershipRule validation rule initialisation (#587)
1 parent 641b076 commit 25c3728

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
//! 'signers' field definition
22
33
pub mod roles;
4+
pub mod update;
45

56
/// Document's 'signers' fields definition
67
#[derive(serde::Deserialize)]
78
#[allow(clippy::missing_docs_in_private_items)]
89
pub struct Signers {
910
pub roles: roles::Roles,
11+
pub update: update::Update,
1012
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//! 'updates' field definition
2+
3+
/// Document's 'updates' fields definition.
4+
#[derive(serde::Deserialize)]
5+
#[allow(clippy::missing_docs_in_private_items)]
6+
pub struct Update {
7+
pub author: bool,
8+
#[serde(default)]
9+
pub collaborators: bool,
10+
}

rust/signed_doc/src/validator/rules/mod.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ impl Rules {
116116
/// - `signed_doc.json` filed loading and JSON parsing errors.
117117
/// - `catalyst-signed-doc-spec` crate version doesn't align with the latest version
118118
/// of the `signed_doc.json`.
119-
pub(crate) fn documents_rules(
120-
) -> anyhow::Result<impl Iterator<Item = (crate::DocType, crate::validator::rules::Rules)>>
119+
pub(crate) fn documents_rules() -> anyhow::Result<impl Iterator<Item = (crate::DocType, Rules)>>
121120
{
122121
let spec = catalyst_signed_doc_spec::CatalystSignedDocSpec::load_signed_doc_spec()?;
123122

@@ -141,9 +140,7 @@ impl Rules {
141140
content: ContentRule::new(&doc_spec.payload)?,
142141
kid: SignatureKidRule::new(&doc_spec.signers.roles)?,
143142
signature: SignatureRule { mutlisig: false },
144-
ownership: DocumentOwnershipRule {
145-
allow_collaborators: false,
146-
},
143+
ownership: DocumentOwnershipRule::new(&doc_spec.signers.update)?,
147144
};
148145
let doc_type = doc_spec.doc_type.parse()?;
149146

rust/signed_doc/src/validator/rules/ownership/mod.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ mod tests;
55

66
use std::collections::HashSet;
77

8+
use anyhow::ensure;
9+
use catalyst_signed_doc_spec::signers::update::Update;
810
use catalyst_types::catalyst_id::CatalystId;
911

1012
use crate::{providers::CatalystSignedDocumentProvider, CatalystSignedDocument};
@@ -28,10 +30,19 @@ fn single_author_check(doc: &CatalystSignedDocument) -> bool {
2830
#[derive(Debug)]
2931
pub(crate) struct DocumentOwnershipRule {
3032
/// Collaborators are allowed.
31-
pub(crate) allow_collaborators: bool,
33+
allow_collaborators: bool,
3234
}
3335

3436
impl DocumentOwnershipRule {
37+
/// Creates `DocumentOwnershipRule` from specs.
38+
pub(crate) fn new(spec: &Update) -> anyhow::Result<Self> {
39+
ensure!(spec.author, "'author' field must always be equal to `true`");
40+
41+
Ok(Self {
42+
allow_collaborators: spec.collaborators,
43+
})
44+
}
45+
3546
/// Check document ownership rule
3647
pub(crate) async fn check<Provider>(
3748
&self,

0 commit comments

Comments
 (0)