File tree Expand file tree Collapse file tree 4 files changed +26
-6
lines changed
catalyst-signed-doc-spec/src/signers
signed_doc/src/validator/rules Expand file tree Collapse file tree 4 files changed +26
-6
lines changed Original file line number Diff line number Diff line change 11//! 'signers' field definition
22
33pub 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) ]
89pub struct Signers {
910 pub roles : roles:: Roles ,
11+ pub update : update:: Update ,
1012}
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -5,6 +5,8 @@ mod tests;
55
66use std:: collections:: HashSet ;
77
8+ use anyhow:: ensure;
9+ use catalyst_signed_doc_spec:: signers:: update:: Update ;
810use catalyst_types:: catalyst_id:: CatalystId ;
911
1012use crate :: { providers:: CatalystSignedDocumentProvider , CatalystSignedDocument } ;
@@ -28,10 +30,19 @@ fn single_author_check(doc: &CatalystSignedDocument) -> bool {
2830#[ derive( Debug ) ]
2931pub ( crate ) struct DocumentOwnershipRule {
3032 /// Collaborators are allowed.
31- pub ( crate ) allow_collaborators : bool ,
33+ allow_collaborators : bool ,
3234}
3335
3436impl 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 ,
You can’t perform that action at this time.
0 commit comments