@@ -77,45 +77,21 @@ impl DocumentOwnershipRule {
7777 }
7878
7979 let mut allowed_authors = HashSet :: new ( ) ;
80- if let DocumentOwnershipRule :: RefFieldBased = self {
81- let Some ( doc_ref) = doc. doc_meta ( ) . doc_ref ( ) else {
82- doc. report ( ) . missing_field ( "ref" , REPORT_CONTEXT ) ;
83- return Ok ( false ) ;
84- } ;
85- let & [ ref doc_ref] = doc_ref. as_slice ( ) else {
86- doc. report ( )
87- . other ( "'ref' field cannot have multiple values" , REPORT_CONTEXT ) ;
88- return Ok ( false ) ;
89- } ;
90- let Some ( first_ref_doc) = provider. try_get_first_doc ( * doc_ref. id ( ) ) . await ? else {
91- doc. report ( ) . other (
92- "Cannot find a first version of the referenced document" ,
93- REPORT_CONTEXT ,
94- ) ;
95- return Ok ( false ) ;
96- } ;
97- allowed_authors. extend ( first_ref_doc. authors ( ) ) ;
98-
99- let last_doc =
100- provider
101- . try_get_last_doc ( * doc_ref. id ( ) )
80+ match self {
81+ Self :: OriginalAuthor => {
82+ let first_doc = provider
83+ . try_get_first_doc ( doc_id)
10284 . await ?
103- . ok_or ( anyhow:: anyhow!(
104- "A latest version of the document must exist if a first version exists"
105- ) ) ?;
106-
107- allowed_authors. extend (
108- last_doc
109- . doc_meta ( )
110- . collaborators ( )
111- . iter ( )
112- . map ( CatalystId :: as_short_id) ,
113- ) ;
114- } else if let Some ( first_doc) = provider. try_get_first_doc ( doc_id) . await ? {
115- allowed_authors. extend ( first_doc. authors ( ) ) ;
85+ . ok_or ( anyhow:: anyhow!( "cannot get a first version document" ) ) ?;
86+ allowed_authors. extend ( first_doc. authors ( ) ) ;
87+ } ,
88+ 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 ( ) ) ;
11694
117- if let DocumentOwnershipRule :: CollaboratorsFieldBased = self {
118- // This a new version of an existing `doc_id`
11995 let last_doc = provider
12096 . try_get_last_doc ( doc_id)
12197 . await ?
@@ -130,7 +106,42 @@ impl DocumentOwnershipRule {
130106 . iter ( )
131107 . map ( CatalystId :: as_short_id) ,
132108 ) ;
133- }
109+ } ,
110+ Self :: RefFieldBased => {
111+ let Some ( doc_ref) = doc. doc_meta ( ) . doc_ref ( ) else {
112+ doc. report ( ) . missing_field ( "ref" , REPORT_CONTEXT ) ;
113+ return Ok ( false ) ;
114+ } ;
115+ let & [ ref doc_ref] = doc_ref. as_slice ( ) else {
116+ doc. report ( )
117+ . other ( "'ref' field cannot have multiple values" , REPORT_CONTEXT ) ;
118+ return Ok ( false ) ;
119+ } ;
120+ let Some ( first_ref_doc) = provider. try_get_first_doc ( * doc_ref. id ( ) ) . await ? else {
121+ doc. report ( ) . other (
122+ "Cannot find a first version of the referenced document" ,
123+ REPORT_CONTEXT ,
124+ ) ;
125+ return Ok ( false ) ;
126+ } ;
127+ allowed_authors. extend ( first_ref_doc. authors ( ) ) ;
128+
129+ let last_doc =
130+ provider
131+ . try_get_last_doc ( * doc_ref. id ( ) )
132+ . await ?
133+ . ok_or ( anyhow:: anyhow!(
134+ "A latest version of the document must exist if a first version exists"
135+ ) ) ?;
136+
137+ allowed_authors. extend (
138+ last_doc
139+ . doc_meta ( )
140+ . collaborators ( )
141+ . iter ( )
142+ . map ( CatalystId :: as_short_id) ,
143+ ) ;
144+ } ,
134145 }
135146
136147 let doc_authors = doc. authors ( ) . into_iter ( ) . collect :: < HashSet < _ > > ( ) ;
0 commit comments