powerplatform_dataverse_client/dataverse/
requestparameters.rs1use reqwest::RequestBuilder;
2
3#[derive(Debug, Clone, Default)]
5pub struct RequestParameters {
6 pub bypass_business_logic_execution_custom_sync: bool,
8 pub bypass_business_logic_execution_custom_async: bool,
10 pub bypass_custom_plugin_execution: bool,
12 pub suppress_callback_registration_expander_job: bool,
14 }
19
20impl RequestParameters {
21 pub fn headers(&self) -> Vec<(&'static str, &'static str)> {
23 let mut headers = Vec::new();
24
25 if let Some(value) = self.bypass_business_logic_execution_value() {
26 headers.push(("MSCRM.BypassBusinessLogicExecution", value));
27 }
28
29 if self.bypass_custom_plugin_execution {
30 headers.push(("MSCRM.BypassCustomPluginExecution", "true"));
31 }
32
33 if self.suppress_callback_registration_expander_job {
34 headers.push(("MSCRM.SuppressCallbackRegistrationExpanderJob", "true"));
35 }
36
37 headers
38 }
39
40 pub fn apply(&self, mut request: RequestBuilder) -> RequestBuilder {
42 for (header, value) in self.headers() {
43 request = request.header(header, value);
44 }
45
46 request
56 }
57
58 fn bypass_business_logic_execution_value(&self) -> Option<&'static str> {
60 match (
61 self.bypass_business_logic_execution_custom_sync,
62 self.bypass_business_logic_execution_custom_async,
63 ) {
64 (true, true) => Some("CustomSync,CustomAsync"),
65 (true, false) => Some("CustomSync"),
66 (false, true) => Some("CustomAsync"),
67 (false, false) => None,
68 }
69 }
70}
71
72#[cfg(test)]
73mod tests {
74 use super::RequestParameters;
75
76 #[test]
77 fn headers_include_requested_bypass_flags() {
78 let parameters = RequestParameters {
79 bypass_business_logic_execution_custom_sync: true,
80 bypass_business_logic_execution_custom_async: true,
81 bypass_custom_plugin_execution: true,
82 suppress_callback_registration_expander_job: true,
83 };
84
85 let headers = parameters.headers();
86
87 assert!(headers.contains(&(
88 "MSCRM.BypassBusinessLogicExecution",
89 "CustomSync,CustomAsync"
90 )));
91 assert!(headers.contains(&("MSCRM.BypassCustomPluginExecution", "true")));
92 assert!(headers.contains(&(
93 "MSCRM.SuppressCallbackRegistrationExpanderJob",
94 "true"
95 )));
96 }
97
98 #[test]
99 fn headers_omit_business_logic_value_when_no_flags_are_set() {
100 let headers = RequestParameters::default().headers();
101
102 assert!(!headers
103 .iter()
104 .any(|(name, _)| *name == "MSCRM.BypassBusinessLogicExecution"));
105 }
106}