Skip to content

Commit 6ab8709

Browse files
committed
fix
1 parent 8ddf1da commit 6ab8709

File tree

1 file changed

+31
-26
lines changed
  • rust/signed_doc/src/validator/rules/ownership

1 file changed

+31
-26
lines changed

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

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -79,33 +79,40 @@ impl DocumentOwnershipRule {
7979
let mut allowed_authors = HashSet::new();
8080
match self {
8181
Self::OriginalAuthor => {
82-
let first_doc = provider
83-
.try_get_first_doc(doc_id)
84-
.await?
85-
.ok_or(anyhow::anyhow!("cannot get a first version document"))?;
86-
allowed_authors.extend(first_doc.authors());
82+
// only run check for the non first version of the document
83+
if doc_id != doc.doc_ver()? {
84+
let first_doc = provider
85+
.try_get_first_doc(doc_id)
86+
.await?
87+
.ok_or(anyhow::anyhow!("cannot get a first version document"))?;
88+
allowed_authors.extend(first_doc.authors());
89+
}
8790
},
8891
Self::CollaboratorsFieldBased => {
89-
let first_doc = provider
90-
.try_get_first_doc(doc_id)
91-
.await?
92-
.ok_or(anyhow::anyhow!("cannot get a first version document"))?;
93-
allowed_authors.extend(first_doc.authors());
94-
95-
let last_doc = provider
96-
.try_get_last_doc(doc_id)
97-
.await?
98-
.ok_or(anyhow::anyhow!(
92+
// only run check for the non first version of the document
93+
if doc_id != doc.doc_ver()? {
94+
let first_doc = provider
95+
.try_get_first_doc(doc_id)
96+
.await?
97+
.ok_or(anyhow::anyhow!("cannot get a first version document"))?;
98+
allowed_authors.extend(first_doc.authors());
99+
100+
let last_doc =
101+
provider
102+
.try_get_last_doc(doc_id)
103+
.await?
104+
.ok_or(anyhow::anyhow!(
99105
"A latest version of the document must exist if a first version exists"
100106
))?;
101107

102-
allowed_authors.extend(
103-
last_doc
104-
.doc_meta()
105-
.collaborators()
106-
.iter()
107-
.map(CatalystId::as_short_id),
108-
);
108+
allowed_authors.extend(
109+
last_doc
110+
.doc_meta()
111+
.collaborators()
112+
.iter()
113+
.map(CatalystId::as_short_id),
114+
);
115+
}
109116
},
110117
Self::RefFieldBased => {
111118
let Some(doc_ref) = doc.doc_meta().doc_ref() else {
@@ -146,10 +153,8 @@ impl DocumentOwnershipRule {
146153

147154
let doc_authors = doc.authors().into_iter().collect::<HashSet<_>>();
148155

149-
// all elements of the `doc_authors` should be intersecting with the `allowed_authors` OR
150-
// `allowed_authors` must be empty
151-
let is_valid = allowed_authors.is_empty()
152-
|| allowed_authors.intersection(&doc_authors).count() == doc_authors.len();
156+
// all elements of the `doc_authors` should be intersecting with the `allowed_authors`
157+
let is_valid = allowed_authors.intersection(&doc_authors).count() == doc_authors.len();
153158

154159
if !is_valid {
155160
doc.report().functional_validation(

0 commit comments

Comments
 (0)