Skip to content

Commit 5272c11

Browse files
mmahroussfda-odoo
authored andcommitted
[IMP] update 5000s codes, their checks
1 parent a2b162f commit 5272c11

File tree

3 files changed

+131
-51
lines changed

3 files changed

+131
-51
lines changed

server/src/core/diagnostic_codes_list.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -332,13 +332,13 @@ OLS05025, DiagnosticSetting::Error, "Invalid attribute {0} in field node",
332332
*/
333333
OLS05026, DiagnosticSetting::Error, "Fields only allow 'record' children nodes",
334334
/**
335-
* The 'search' attribute cannot be used together with 'eval' or 'type' on a <value> node.
335+
* The 'search' attribute cannot be used together with 'eval', 'type', `file`, or text data on a <value> node.
336336
*/
337-
OLS05027, DiagnosticSetting::Error, "search attribute is not allowed when eval or type attribute is present",
337+
OLS05027, DiagnosticSetting::Error, "search attribute is not allowed when eval, type, file, or text content is present",
338338
/**
339-
* The 'eval' attribute cannot be used together with 'search' or 'type' on a <value> node.
339+
* The 'eval' attribute cannot be used together with 'search', 'type', `file`, or text data on a <value> node.
340340
*/
341-
OLS05028, DiagnosticSetting::Error, "eval attribute is not allowed when search or type attribute is present",
341+
OLS05028, DiagnosticSetting::Error, "eval attribute is not allowed when search, type, file, or text content is present",
342342
/**
343343
* The 'type' attribute cannot be used together with 'search' or 'eval' on a <value> node.
344344
*/
@@ -348,9 +348,9 @@ OLS05029, DiagnosticSetting::Error, "type attribute is not allowed when search o
348348
*/
349349
OLS05030, DiagnosticSetting::Error, "text content is not allowed on a value that contains a file attribute",
350350
/**
351-
* The 'file' attribute is only allowed on <value> nodes with a 'type' attribute.
351+
* The 'file' attribute cannot be used together with 'search' or 'eval' on a <value> node.
352352
*/
353-
OLS05031, DiagnosticSetting::Error, "file attribute is only allowed on value node with type attribute",
353+
OLS05031, DiagnosticSetting::Error, "file attribute is not allowed when search or eval attribute is present",
354354
/**
355355
* The attribute is not valid for <value> nodes.
356356
*/
@@ -368,21 +368,21 @@ OLS05034, DiagnosticSetting::Error, "delete node cannot have both id and search
368368
*/
369369
OLS05035, DiagnosticSetting::Error, "delete node must have either id or search attribute",
370370
/**
371-
* An <act_window> node must have the specified attribute (id, name, or res_model).
371+
* Empty Value data, text data or file attribute has to be provided on a <value> node.
372372
*/
373-
OLS05036, DiagnosticSetting::Error, "act_window node must contain a {0} attribute",
373+
OLS05036, DiagnosticSetting::Error, "Empty Value data, text data or file attribute has to be provided when `type` attribute is present",
374374
/**
375-
* The attribute is not valid for <act_window> nodes.
375+
* Empty Value data, one of text data, `file`, `eval`, or `search` has to be provided.
376376
*/
377-
OLS05037, DiagnosticSetting::Error, "Invalid attribute {0} in act_window node",
377+
OLS05037, DiagnosticSetting::Error, "Empty Value data, one of text data, `file`, `eval`, or `search` has to be provided",
378378
/**
379-
* <act_window> nodes cannot have text content.
379+
* Empty Function data, either of `eval` attribute , or one or more `value`, or `function` children have to be provided.
380380
*/
381-
OLS05038, DiagnosticSetting::Error, "act_window node cannot have text content",
381+
OLS05038, DiagnosticSetting::Error, "Empty Function data, either of `eval` attribute , or one or more `value`, or `function` children have to be provided",
382382
/**
383-
* The 'binding_type' attribute must be either 'action' or 'report'.
383+
* You provided an empty XML ID. Please provide a valid XML ID.
384384
*/
385-
OLS05039, DiagnosticSetting::Error, "binding_type attribute must be either 'action' or 'report', found {0}",
385+
OLS05039, DiagnosticSetting::Error, "Empty XML ID. Please provide a valid XML ID.",
386386
/**
387387
* The 'binding_views' attribute must match the required pattern.
388388
*/
@@ -440,11 +440,11 @@ OLS05053, DiagnosticSetting::Error, "Action with id '{0}' does not exist",
440440
/**
441441
* A menuitem is specifying a group that has not been declared before the menuitem
442442
*/
443-
OLS05054, DiagnosticSetting::Error, "Group with id '{0}' does not exist",
443+
OLS05054, DiagnosticSetting::Error, "Group(s) with id(s) '{0}' does not exist",
444444
/**
445-
* Model not found
445+
* Model not found in current module or its dependencies
446446
*/
447-
OLS05055, DiagnosticSetting::Error, "Model '{0}' not found in module '{1}'",
447+
OLS05055, DiagnosticSetting::Error, "Model '{0}' not found in module '{1}' or its dependencies",
448448
/**
449449
* Model not found
450450
*/

server/src/core/xml_arch_builder_rng_validation.rs

Lines changed: 60 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,16 @@ impl XmlArchBuilder {
7373
}
7474
},
7575
"groups" => {
76-
for group in attr.value().split(",") {
77-
let group = group.trim_start_matches("-");
78-
if self.get_group_ids(session, group, &attr, diagnostics).is_empty() {
79-
if let Some(diagnostic) = create_diagnostic(session, DiagnosticCode::OLS05054, &[group]) {
80-
diagnostics.push(Diagnostic {
81-
range: Range { start: Position::new(attr.range().start as u32, 0), end: Position::new(attr.range().end as u32, 0) },
82-
..diagnostic.clone()
83-
});
84-
}
76+
let missing_groups = attr.value().split(",")
77+
.filter(|group| self.get_group_ids(session, group.trim_start_matches("-"), &attr, diagnostics).is_empty())
78+
.collect::<Vec<&str>>()
79+
.join(",");
80+
if missing_groups.len() > 0 {
81+
if let Some(diagnostic) = create_diagnostic(session, DiagnosticCode::OLS05054, &[&missing_groups]) {
82+
diagnostics.push(Diagnostic {
83+
range: Range { start: Position::new(attr.range().start as u32, 0), end: Position::new(attr.range().end as u32, 0) },
84+
..diagnostic.clone()
85+
});
8586
}
8687
}
8788
},
@@ -177,6 +178,7 @@ impl XmlArchBuilder {
177178
true
178179
}
179180

181+
/// Load a <record> node, returning true if node is a record node
180182
fn load_record(&mut self, session: &mut SessionInfo, node: &Node, diagnostics: &mut Vec<Diagnostic>) -> bool {
181183
if node.tag_name().name() != "record" { return false; }
182184
let mut found_model = false;
@@ -206,7 +208,7 @@ impl XmlArchBuilder {
206208
..diagnostic.clone()
207209
});
208210
}
209-
return false;
211+
return true;
210212
}
211213
let mut data = OdooDataRecord {
212214
file_symbol: Rc::downgrade(&self.xml_symbol),
@@ -218,7 +220,8 @@ impl XmlArchBuilder {
218220
for child in node.children().filter(|n| n.is_element()) {
219221
if let Some(field) = self.load_field(session, &child, diagnostics) {
220222
data.fields.push(field);
221-
} else {
223+
} else if child.tag_name().name() != "field" {
224+
// Diagnostic only for non-field tags, not for invalid ones
222225
if let Some(diagnostic) = create_diagnostic(session, DiagnosticCode::OLS05015, &[child.tag_name().name()]) {
223226
diagnostics.push(Diagnostic {
224227
range: Range { start: Position::new(child.range().start as u32, 0), end: Position::new(child.range().end as u32, 0) },
@@ -234,14 +237,15 @@ impl XmlArchBuilder {
234237

235238
fn load_field(&mut self, session: &mut SessionInfo, node: &Node, diagnostics: &mut Vec<Diagnostic>) -> Option<OdooDataField> {
236239
if node.tag_name().name() != "field" { return None; }
237-
if node.attribute("name").is_none() {
240+
let Some(node_name_node) = node.attribute_node("name") else {
238241
if let Some(diagnostic) = create_diagnostic(session, DiagnosticCode::OLS05016, &[]) {
239242
diagnostics.push(Diagnostic {
240243
range: Range { start: Position::new(node.range().start as u32, 0), end: Position::new(node.range().end as u32, 0) },
241244
..diagnostic.clone()
242245
});
243246
}
244-
}
247+
return None;
248+
};
245249

246250
let has_type = node.attribute("type").is_some();
247251
let ref_key = node.attribute_node("ref").map(|rk| (rk.value().to_string(), rk.range()));
@@ -258,6 +262,7 @@ impl XmlArchBuilder {
258262
return None;
259263
}
260264
let mut is_xml_or_html = false;
265+
let mut iterable_child_node = false;
261266
if let Some(field_type) = node.attribute("type") {
262267
match field_type {
263268
"int" => {
@@ -283,6 +288,7 @@ impl XmlArchBuilder {
283288
}
284289
}
285290
"list" | "tuple" => {
291+
iterable_child_node = true;
286292
for child in node.children() {
287293
if !self.load_value(session, &child, diagnostics) {
288294
if let Some(diagnostic) = create_diagnostic(session, DiagnosticCode::OLS05020, &[child.tag_name().name()]) {
@@ -356,7 +362,7 @@ impl XmlArchBuilder {
356362
}
357363
}
358364
for child in node.children() {
359-
if !self.load_record(session, &child, diagnostics) && !child.is_text() && !child.is_comment() && !is_xml_or_html {
365+
if !self.load_record(session, &child, diagnostics) && !child.is_text() && !child.is_comment() && !is_xml_or_html && !iterable_child_node{
360366
if let Some(diagnostic) = create_diagnostic(session, DiagnosticCode::OLS05026, &[]) {
361367
diagnostics.push(Diagnostic {
362368
range: Range { start: Position::new(child.range().start as u32, 0), end: Position::new(child.range().end as u32, 0) },
@@ -374,8 +380,8 @@ impl XmlArchBuilder {
374380
}
375381
}
376382
Some(OdooDataField {
377-
name: oyarn!("{}", node.attribute("name").unwrap()),
378-
range: node.attribute_node("name").unwrap().range(),
383+
name: oyarn!("{}", node_name_node.value()),
384+
range: node_name_node.range(),
379385
text: text,
380386
text_range: text_range,
381387
ref_key,
@@ -386,13 +392,13 @@ impl XmlArchBuilder {
386392
if node.tag_name().name() != "value" { return false; }
387393
let mut has_search = false;
388394
let mut has_eval = false;
389-
let has_type = node.has_attribute("type");
395+
let mut has_type_or_file_or_text = node.text().is_some();
390396
for attr in node.attributes() {
391397
match attr.name() {
392398
"name" | "model" | "use" => {},
393399
"search" => {
394400
has_search = true;
395-
if has_eval || has_type {
401+
if has_eval || has_type_or_file_or_text {
396402
if let Some(diagnostic) = create_diagnostic(session, DiagnosticCode::OLS05027, &[]) {
397403
diagnostics.push(Diagnostic {
398404
range: Range { start: Position::new(attr.range().start as u32, 0), end: Position::new(attr.range().end as u32, 0) },
@@ -403,7 +409,7 @@ impl XmlArchBuilder {
403409
},
404410
"eval" => {
405411
has_eval = true;
406-
if has_search || has_type {
412+
if has_search || has_type_or_file_or_text {
407413
if let Some(diagnostic) = create_diagnostic(session, DiagnosticCode::OLS05028, &[]) {
408414
diagnostics.push(Diagnostic {
409415
range: Range { start: Position::new(attr.range().start as u32, 0), end: Position::new(attr.range().end as u32, 0) },
@@ -413,16 +419,18 @@ impl XmlArchBuilder {
413419
}
414420
},
415421
"type" => {
422+
has_type_or_file_or_text = true;
416423
if has_search || has_eval {
417424
if let Some(diagnostic) = create_diagnostic(session, DiagnosticCode::OLS05029, &[]) {
418425
diagnostics.push(Diagnostic {
419426
range: Range { start: Position::new(attr.range().start as u32, 0), end: Position::new(attr.range().end as u32, 0) },
420427
..diagnostic.clone()
421428
});
429+
continue;
422430
}
423431
}
424-
if node.has_attribute("file") && node.text().is_some() {
425-
if let Some(diagnostic) = create_diagnostic(session, DiagnosticCode::OLS05030, &[]) {
432+
if !node.has_attribute("file") && !node.text().is_some() {
433+
if let Some(diagnostic) = create_diagnostic(session, DiagnosticCode::OLS05036, &[]) {
426434
diagnostics.push(Diagnostic {
427435
range: Range { start: Position::new(attr.range().start as u32, 0), end: Position::new(attr.range().end as u32, 0) },
428436
..diagnostic.clone()
@@ -431,7 +439,17 @@ impl XmlArchBuilder {
431439
}
432440
},
433441
"file" => {
434-
if !has_type {
442+
has_type_or_file_or_text = true;
443+
if node.text().is_some() {
444+
if let Some(diagnostic) = create_diagnostic(session, DiagnosticCode::OLS05030, &[]) {
445+
diagnostics.push(Diagnostic {
446+
range: Range { start: Position::new(attr.range().start as u32, 0), end: Position::new(attr.range().end as u32, 0) },
447+
..diagnostic.clone()
448+
});
449+
continue;
450+
}
451+
}
452+
if has_search || has_eval {
435453
if let Some(diagnostic) = create_diagnostic(session, DiagnosticCode::OLS05031, &[]) {
436454
diagnostics.push(Diagnostic {
437455
range: Range { start: Position::new(attr.range().start as u32, 0), end: Position::new(attr.range().end as u32, 0) },
@@ -450,6 +468,14 @@ impl XmlArchBuilder {
450468
}
451469
}
452470
}
471+
if !has_search && !has_eval && !has_type_or_file_or_text {
472+
if let Some(diagnostic) = create_diagnostic(session, DiagnosticCode::OLS05037, &[]) {
473+
diagnostics.push(Diagnostic {
474+
range: Range { start: Position::new(node.range().start as u32, 0), end: Position::new(node.range().end as u32, 0) },
475+
..diagnostic.clone()
476+
});
477+
}
478+
}
453479
true
454480
}
455481

@@ -475,6 +501,7 @@ impl XmlArchBuilder {
475501
..diagnostic.clone()
476502
});
477503
}
504+
return true;
478505
}
479506
let found_id = node.attribute("id").map(|s| s.to_string());
480507
let has_search = node.attribute("search").is_some();
@@ -535,8 +562,10 @@ impl XmlArchBuilder {
535562
}
536563
}
537564
}
565+
let mut has_value_or_function_child = false;
538566
for child in node.children().filter(|n| n.is_element()) {
539567
if self.load_value(session, &child, diagnostics) {
568+
has_value_or_function_child = true;
540569
if has_eval {
541570
if let Some(diagnostic) = create_diagnostic(session, DiagnosticCode::OLS05045, &[]) {
542571
diagnostics.push(Diagnostic {
@@ -546,6 +575,7 @@ impl XmlArchBuilder {
546575
}
547576
}
548577
} else if self.load_function(session, &child, diagnostics) {
578+
has_value_or_function_child = true;
549579
if has_eval {
550580
if let Some(diagnostic) = create_diagnostic(session, DiagnosticCode::OLS05047, &[]) {
551581
diagnostics.push(Diagnostic {
@@ -563,6 +593,14 @@ impl XmlArchBuilder {
563593
}
564594
}
565595
}
596+
if !has_eval && !has_value_or_function_child {
597+
if let Some(diagnostic) = create_diagnostic(session, DiagnosticCode::OLS05038, &[]) {
598+
diagnostics.push(Diagnostic {
599+
range: Range { start: Position::new(node.range().start as u32, 0), end: Position::new(node.range().end as u32, 0) },
600+
..diagnostic.clone()
601+
});
602+
}
603+
}
566604
true
567605
}
568606
}

0 commit comments

Comments
 (0)