Skip to content

Commit 1e304b8

Browse files
mmahroussfda-odoo
authored andcommitted
[IMP] validate module name in xml module names
1 parent 928defc commit 1e304b8

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

server/src/core/csv_arch_builder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ impl CsvArchBuilder {
9595
start: start as usize,
9696
end: end as usize,
9797
}),
98+
ref_key: None,
9899
}
99100
);
100101
start = end + 1;

server/src/core/xml_arch_builder_rng_validation.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,8 @@ impl XmlArchBuilder {
244244
}
245245

246246
let has_type = node.attribute("type").is_some();
247-
let has_ref = node.attribute("ref").is_some();
247+
let ref_key = node.attribute_node("ref").map(|rk| (rk.value().to_string(), rk.range()));
248+
let has_ref = ref_key.is_some();
248249
let has_eval = node.attribute("eval").is_some();
249250
let has_search = node.attribute("search").is_some();
250251
if [has_type, has_ref, has_eval, has_search].iter().filter(|b| **b).count() > 1 {
@@ -377,6 +378,7 @@ impl XmlArchBuilder {
377378
range: node.attribute_node("name").unwrap().range(),
378379
text: text,
379380
text_range: text_range,
381+
ref_key,
380382
})
381383
}
382384

server/src/core/xml_data.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub struct OdooDataField {
2525
pub name: OYarn,
2626
pub range: Range<usize>,
2727
pub text: Option<String>,
28+
pub ref_key: Option<(String, Range<usize>)>,
2829
pub text_range: Option<Range<usize>>,
2930
}
3031

server/src/core/xml_validation.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{cell::RefCell, cmp::Ordering, collections::{HashMap, HashSet}, rc::Rc}
33
use lsp_types::{Diagnostic, Position, Range};
44
use tracing::{info, trace};
55

6-
use crate::{constants::{BuildSteps, OYarn, DEBUG_STEPS}, core::{diagnostics::{create_diagnostic, DiagnosticCode}, entry_point::{EntryPoint, EntryPointType}, evaluation::ContextValue, file_mgr::FileInfo, model::Model, odoo::SyncOdoo, symbols::symbol::Symbol, xml_data::{OdooData, XmlDataDelete, XmlDataMenuItem, OdooDataRecord, XmlDataTemplate}}, oyarn, threads::SessionInfo, utils::compare_semver, Sy};
6+
use crate::{Sy, constants::{BuildSteps, DEBUG_STEPS, OYarn}, core::{diagnostics::{DiagnosticCode, create_diagnostic}, entry_point::{EntryPoint, EntryPointType}, evaluation::ContextValue, file_mgr::{FileInfo, FileMgr}, model::Model, odoo::SyncOdoo, symbols::symbol::Symbol, xml_data::{OdooData, OdooDataRecord, XmlDataDelete, XmlDataMenuItem, XmlDataTemplate}}, oyarn, threads::SessionInfo, utils::compare_semver};
77

88

99

@@ -128,6 +128,21 @@ impl XmlValidator {
128128
//TODO check that the language exists
129129
}
130130
}
131+
// Validate field ref_key
132+
if let Some((ref_key_val, ref_key_range)) = field.ref_key.as_ref(){
133+
let xml_id_split: Vec<_> = ref_key_val.split('.').collect();
134+
if xml_id_split.len() > 1 {
135+
let module_name = xml_id_split[0];
136+
if session.sync_odoo.modules.get(module_name).is_none() {
137+
if let Some(diagnostic) = create_diagnostic(session, DiagnosticCode::OLS05003, &[]) {
138+
diagnostics.push(Diagnostic {
139+
range: Range { start: Position::new(ref_key_range.start.try_into().unwrap(), 0), end: Position::new(ref_key_range.end.try_into().unwrap(), 0) },
140+
..diagnostic
141+
});
142+
}
143+
}
144+
}
145+
}
131146
//Check that the field belong to the model
132147
if all_fields.contains_key(&field_name) {
133148
mandatory_fields.retain(|f| f != &field_name.to_string());

0 commit comments

Comments
 (0)