Add require_2fa_by, extra_domains to UpdateOrg. Add-legacy_user_id to…#75
Conversation
mrmauer
left a comment
There was a problem hiding this comment.
Thanks for putting this together! Left some comments
There was a problem hiding this comment.
I believe we don't actually need Deserialize on UpdateOrgRequest
src/models/update_org_request.rs
Outdated
| // #[serde(rename = "require_2fa_by", skip_serializing_if = "Option::is_none")] | ||
| // pub require_2fa_by: Option<chrono::DateTime<chrono::Utc>>, | ||
| #[serde(rename = "require_2fa_by", skip_serializing_if = "Option::is_none")] | ||
| pub require_2fa_by: Option<chrono::DateTime<chrono::Utc>>, |
There was a problem hiding this comment.
Looks like we'll need a custom serializer for this. Something like
pub fn serialize_optional_datetime_to_string<S>(x: &Option<chrono::DateTime<chrono::UTC>>, s: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
match x {
Some(datetime) => s.serialize_str(&datetime.format("%Y-%m-%dT%H:%M:%s").to_string()),
None => s.serialize_none(),
}
}
Or something along those lines. From the docs, it seems this approach with chrono will require us to add a chrono feature to the Cargo.toml. Alternatively, we can use another DateTime type. But a raw String will put the onus of correct formatting on the caller. Either way, we should smoke test it to make sure it plays nice with the parser on the BE.
There was a problem hiding this comment.
(Forgot to say) to then use the custom serializer
#[serde(rename = "require_2fa_by", serialize_with = "serialize_optional_datetime_to_string")]
pub require_2fa_by: Option<chrono::DateTime<chrono::Utc>>,
| legacy_org_id: None, | ||
| // require_2fa_by: None, | ||
| require_2fa_by: None, | ||
| extra_domains: None, |
There was a problem hiding this comment.
Actually, a correction on this one...
we should instead define extra_domains as
#[serde(rename = "extra_domains", skip_serializing_if = "Option::is_none")]
pub extra_domains: Option<Vec<String>>,
to distinguish between the cases where there's no change vs setting to an empty array. Then this line stays
extra_domains: None,
… UpdateUser