Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/models/update_metadata_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ pub struct UpdateMetadataRequest {
pub properties: Option<HashMap<String, Value>>,
#[serde(rename = "update_password_required", skip_serializing_if = "Option::is_none")]
pub update_password_required: Option<bool>,
#[serde(rename = "legacy_user_id", skip_serializing_if = "Option::is_none")]
pub legacy_user_id: Option<String>,
}

impl UpdateMetadataRequest {
Expand All @@ -43,6 +45,7 @@ impl UpdateMetadataRequest {
metadata: None,
properties: None,
update_password_required: None,
legacy_user_id: None,
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/models/update_org_request.rs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we don't actually need Deserialize on UpdateOrgRequest

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

use serde_json::Value;

#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]

Check failure on line 15 in src/models/update_org_request.rs

View workflow job for this annotation

GitHub Actions / Rust project

mismatched types

Check failure on line 15 in src/models/update_org_request.rs

View workflow job for this annotation

GitHub Actions / Rust project

the trait bound `DateTime<Utc>: Serialize` is not satisfied

Check failure on line 15 in src/models/update_org_request.rs

View workflow job for this annotation

GitHub Actions / Rust project

the trait bound `DateTime<Utc>: Deserialize<'_>` is not satisfied
pub struct UpdateOrgRequest {
#[serde(rename = "name", skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
Expand All @@ -30,9 +30,10 @@
pub restrict_to_domain: Option<bool>,
#[serde(rename = "legacy_org_id", skip_serializing_if = "Option::is_none")]
pub legacy_org_id: Option<String>,
// TODO: This should be added once supported in the FE.
// #[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>>,

Check failure on line 34 in src/models/update_org_request.rs

View workflow job for this annotation

GitHub Actions / Rust project

the trait bound `DateTime<Utc>: Deserialize<'_>` is not satisfied

Check failure on line 34 in src/models/update_org_request.rs

View workflow job for this annotation

GitHub Actions / Rust project

the trait bound `DateTime<Utc>: Deserialize<'_>` is not satisfied
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(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>>,

#[serde(rename = "extra_domains", skip_serializing_if = "Option::is_none")]
pub extra_domains: Vec<String>,
}

impl UpdateOrgRequest {
Expand All @@ -46,7 +47,8 @@
autojoin_by_domain: None,
restrict_to_domain: None,
legacy_org_id: None,
// require_2fa_by: None,
require_2fa_by: None,
extra_domains: None,

Check failure on line 51 in src/models/update_org_request.rs

View workflow job for this annotation

GitHub Actions / Rust project

mismatched types
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,

}
}
}
Loading