Skip to main content

bitwarden_organization_invite_link/
organization_invite_link.rs

1use bitwarden_api_api::models::OrganizationInviteLinkResponseModel;
2use bitwarden_core::{MissingFieldError, OrganizationId, require};
3use bitwarden_organization_crypto::invite::Invite;
4use chrono::{DateTime, Utc};
5use serde::{Deserialize, Serialize};
6#[cfg(feature = "wasm")]
7use tsify::Tsify;
8use uuid::Uuid;
9
10use crate::InviteLinkError;
11
12/// An organization invite link as persisted by the server.
13#[derive(Serialize, Deserialize, Debug, Clone)]
14#[cfg_attr(feature = "wasm", derive(Tsify), tsify(into_wasm_abi, from_wasm_abi))]
15#[serde(rename_all = "camelCase")]
16pub struct OrganizationInviteLink {
17    /// Unique identifier of the invite link.
18    pub id: Uuid,
19    /// The invite code invitees present when accepting or confirming the invite.
20    pub code: Uuid,
21    /// The organization this invite link belongs to.
22    pub organization_id: OrganizationId,
23    /// Email domains permitted to redeem this invite link.
24    pub allowed_domains: Vec<String>,
25    /// The sealed cryptographic invite carried in the invite link.
26    pub invite: Invite,
27    /// Whether invitees can self-confirm using this invite link.
28    pub supports_confirmation: bool,
29    /// When the invite link was created.
30    pub creation_date: DateTime<Utc>,
31}
32
33impl TryFrom<OrganizationInviteLinkResponseModel> for OrganizationInviteLink {
34    type Error = InviteLinkError;
35
36    fn try_from(response: OrganizationInviteLinkResponseModel) -> Result<Self, Self::Error> {
37        Ok(Self {
38            id: require!(response.id),
39            code: require!(response.code),
40            organization_id: OrganizationId::new(require!(response.organization_id)),
41            allowed_domains: response.allowed_domains.unwrap_or_default(),
42            invite: require!(response.invite).parse()?,
43            supports_confirmation: response.supports_confirmation.unwrap_or(false),
44            creation_date: require!(response.creation_date)
45                .parse()
46                .map_err(|_| MissingFieldError("creation_date"))?,
47        })
48    }
49}