Skip to main content

bitwarden_policies/
models.rs

1//! Data models for the policy domain.
2//!
3//! These are the inputs to the policy filtering API and are exposed across the
4//! FFI boundary.
5
6use bitwarden_organizations::{OrganizationUserStatusType, OrganizationUserType};
7use chrono::{DateTime, Utc};
8use serde::{Deserialize, Serialize};
9#[cfg(feature = "wasm")]
10use tsify::Tsify;
11use uuid::Uuid;
12
13use crate::policy_type::PolicyType;
14
15/// An organization policy.
16#[derive(Serialize, Deserialize, Debug, Clone)]
17#[serde(rename_all = "camelCase")]
18#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
19#[cfg_attr(feature = "wasm", derive(Tsify), tsify(into_wasm_abi, from_wasm_abi))]
20pub struct PolicyView {
21    /// The policy's unique ID.
22    pub id: Uuid,
23    /// The organization this policy belongs to.
24    pub organization_id: Uuid,
25    /// The type of policy.
26    pub r#type: PolicyType,
27    /// The policy's additional configuration data as a JSON string, if any.
28    pub data: Option<String>,
29    /// Whether the policy is enabled.
30    pub enabled: bool,
31    /// When the policy was last modified.
32    pub revision_date: Option<DateTime<Utc>>,
33}
34
35/// A minimal set of data for a user in an organization. This provides
36/// the context needed to evaluate the policies that are applied to the
37/// user by the organization.
38#[derive(Serialize, Deserialize, Debug, Clone)]
39#[serde(rename_all = "camelCase")]
40#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
41#[cfg_attr(feature = "wasm", derive(Tsify), tsify(into_wasm_abi, from_wasm_abi))]
42pub struct OrganizationUserPolicyContext {
43    /// The organization's unique ID.
44    pub id: Uuid,
45    /// The user's membership status in the organization.
46    pub status: OrganizationUserStatusType,
47    /// The user's role within the organization.
48    pub role: OrganizationUserType,
49    /// Whether the organization is enabled.
50    pub enabled: bool,
51    /// Whether the organization's plan supports policies.
52    pub use_policies: bool,
53    /// Whether the user is acting on behalf of a provider
54    /// that manages the organization.
55    pub is_provider_user: bool,
56}