mz_frontegg_mock/models/
user.rs
1use crate::models::token::ApiToken;
11use chrono::Utc;
12use serde::{Deserialize, Serialize};
13use uuid::Uuid;
14
15#[derive(Deserialize, Clone, Serialize)]
16pub struct UserConfig {
17 pub id: Uuid,
18 pub email: String,
19 pub password: String,
20 pub tenant_id: Uuid,
21 pub initial_api_tokens: Vec<ApiToken>,
22 pub roles: Vec<String>,
23 pub auth_provider: Option<String>,
24 pub verified: Option<bool>,
25 pub metadata: Option<String>,
26}
27
28impl UserConfig {
29 pub fn generate(tenant_id: Uuid, email: impl Into<String>, roles: Vec<String>) -> Self {
30 Self {
31 id: Uuid::new_v4(),
32 email: email.into(),
33 password: Uuid::new_v4().to_string(),
34 tenant_id,
35 initial_api_tokens: vec![ApiToken {
36 client_id: Uuid::new_v4(),
37 secret: Uuid::new_v4(),
38 description: Some("Initial API Token".to_string()),
39 created_at: Utc::now(),
40 }],
41 roles,
42 auth_provider: None,
43 verified: None,
44 metadata: None,
45 }
46 }
47
48 pub fn client_id(&self) -> &Uuid {
49 &self.initial_api_tokens[0].client_id
50 }
51
52 pub fn secret(&self) -> &Uuid {
53 &self.initial_api_tokens[0].secret
54 }
55
56 pub fn frontegg_password(&self) -> String {
57 format!("mzp_{}{}", self.client_id(), self.secret())
58 }
59}
60
61#[derive(Deserialize, Clone, Serialize)]
62pub struct UserCreate {
63 pub email: String,
64 #[serde(rename = "roleIds")]
65 pub role_ids: Option<Vec<String>>,
66}
67
68#[derive(Clone, Serialize, Deserialize)]
69pub struct UserRole {
70 pub id: String,
71 pub name: String,
72 pub key: String,
73}
74
75#[derive(Serialize, Deserialize)]
76pub struct UserResponse {
77 pub id: Uuid,
78 pub email: String,
79 pub verified: bool,
80 pub metadata: String,
81 pub provider: String,
82 pub roles: Vec<UserRole>,
83}
84
85#[derive(Serialize, Deserialize)]
86pub struct UserRolesResponse {
87 pub items: Vec<UserRole>,
88 pub _metadata: UserRolesMetadata,
89}
90
91#[derive(Serialize, Deserialize)]
92pub struct UserRolesMetadata {
93 pub total_items: usize,
94 pub total_pages: usize,
95}
96
97#[derive(Deserialize)]
98pub struct UpdateUserRolesRequest {
99 pub email: String,
100 #[serde(rename = "roleIds")]
101 pub role_ids: Vec<String>,
102}
103
104#[derive(Deserialize)]
105pub struct UsersV3Query {
106 #[serde(rename = "_email")]
107 pub email: Option<String>,
108 #[serde(rename = "_limit")]
109 pub limit: Option<usize>,
110 #[serde(rename = "_offset")]
111 pub offset: Option<usize>,
112 pub ids: Option<String>,
113 #[serde(rename = "_sortBy")]
114 pub sort_by: Option<String>,
115 #[serde(rename = "_order")]
116 pub order: Option<String>,
117 #[serde(rename = "_tenantId")]
118 pub tenant_id: Option<Uuid>,
119 #[serde(rename = "_includeSubTenants")]
120 pub include_sub_tenants: Option<bool>,
121}
122
123#[derive(Serialize)]
124pub struct UsersV3Response {
125 pub items: Vec<UserResponse>,
126 pub _metadata: UsersV3Metadata,
127}
128
129#[derive(Serialize)]
130pub struct UsersV3Metadata {
131 pub total_items: usize,
132}
133
134#[derive(Deserialize)]
135pub struct AddRolesToGroupParams {
136 #[serde(rename = "roleIds")]
137 pub role_ids: Vec<String>,
138}
139
140#[derive(Deserialize)]
141pub struct RemoveRolesFromGroupParams {
142 #[serde(rename = "roleIds")]
143 pub role_ids: Vec<String>,
144}
145
146#[derive(Deserialize)]
147pub struct GetUserPasswordRequest {
148 pub email: String,
149}
150
151#[derive(Serialize)]
152pub struct GetUserPasswordResponse {
153 pub email: String,
154 pub password: String,
155}