File tree Expand file tree Collapse file tree 2 files changed +29
-10
lines changed
rust/signed_doc/src/validator/rules/ownership Expand file tree Collapse file tree 2 files changed +29
-10
lines changed Original file line number Diff line number Diff line change @@ -51,15 +51,30 @@ impl DocumentOwnershipRule {
5151 "A latest version of the document must exist if a first version exists"
5252 ) ;
5353 } ;
54+
55+ // Create sets of authors for comparison, ensure that they are in the same form
56+ // (e.g. each `kid` is in `URI form`).
57+ //
5458 // Allowed authors for this document are the original author, and collaborators
5559 // defined in the last published version of the Document ID.
5660 let mut allowed_authors = first_doc
5761 . authors ( )
5862 . into_iter ( )
63+ . map ( CatalystId :: as_uri)
5964 . collect :: < HashSet < CatalystId > > ( ) ;
60- allowed_authors. extend ( last_doc. doc_meta ( ) . collaborators ( ) . iter ( ) . cloned ( ) ) ;
61-
62- let doc_authors = doc. authors ( ) . into_iter ( ) . collect :: < HashSet < CatalystId > > ( ) ;
65+ allowed_authors. extend (
66+ last_doc
67+ . doc_meta ( )
68+ . collaborators ( )
69+ . iter ( )
70+ . cloned ( )
71+ . map ( CatalystId :: as_uri) ,
72+ ) ;
73+ let doc_authors = doc
74+ . authors ( )
75+ . into_iter ( )
76+ . map ( CatalystId :: as_uri)
77+ . collect :: < HashSet < _ > > ( ) ;
6378
6479 let is_valid = allowed_authors. intersection ( & doc_authors) . count ( ) > 0 ;
6580
Original file line number Diff line number Diff line change @@ -49,17 +49,21 @@ fn doc_builder(
4949 authors : Authors ,
5050 collabs : Collabs ,
5151) -> ( UuidV7 , Authors , CatalystSignedDocument ) {
52- let _collaborators = collabs
53- . into_iter ( )
54- . map ( |c| c. kid )
55- . collect :: < Vec < CatalystId > > ( ) ;
5652 let mut doc_builder = Builder :: new ( )
5753 . with_metadata_field ( SupportedField :: Id ( doc_id) )
5854 . with_metadata_field ( SupportedField :: Ver ( doc_ver) )
5955 . with_metadata_field ( SupportedField :: Type ( UuidV4 :: new ( ) . into ( ) ) )
60- . with_metadata_field ( SupportedField :: ContentType ( ContentType :: Json ) )
61- //.with_metadata_field(SupportedField::Collaborators(collaborators.into()))
62- . with_content ( vec ! [ 1 , 2 , 3 ] ) ;
56+ . with_metadata_field ( SupportedField :: ContentType ( ContentType :: Json ) ) ;
57+
58+ if !collabs. is_empty ( ) {
59+ let collaborators = collabs
60+ . into_iter ( )
61+ . map ( |c| c. kid )
62+ . collect :: < Vec < CatalystId > > ( ) ;
63+ doc_builder =
64+ doc_builder. with_metadata_field ( SupportedField :: Collaborators ( collaborators. into ( ) ) ) ;
65+ }
66+
6367 for author in & authors {
6468 doc_builder = doc_builder
6569 . add_signature ( |m| author. sk . sign ( & m) . to_vec ( ) , author. kid . clone ( ) )
You can’t perform that action at this time.
0 commit comments