2021-11-07 13:45:18 +00:00
|
|
|
use std::convert::TryInto;
|
2023-05-17 01:49:39 +00:00
|
|
|
|
2023-08-17 15:46:39 +00:00
|
|
|
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
2023-07-29 01:46:24 +00:00
|
|
|
use flowy_user_deps::entities::*;
|
2023-05-17 01:49:39 +00:00
|
|
|
|
|
|
|
use crate::entities::parser::{UserEmail, UserIcon, UserName, UserOpenaiKey, UserPassword};
|
2023-07-29 01:46:24 +00:00
|
|
|
use crate::entities::AuthTypePB;
|
2023-05-17 01:49:39 +00:00
|
|
|
use crate::errors::ErrorCode;
|
2023-08-14 04:57:59 +00:00
|
|
|
use crate::services::entities::HistoricalUser;
|
2021-07-11 07:33:19 +00:00
|
|
|
|
2021-08-31 09:25:08 +00:00
|
|
|
#[derive(Default, ProtoBuf)]
|
2022-07-19 06:40:56 +00:00
|
|
|
pub struct UserTokenPB {
|
2023-02-13 01:29:49 +00:00
|
|
|
#[pb(index = 1)]
|
|
|
|
pub token: String,
|
2021-08-31 09:25:08 +00:00
|
|
|
}
|
|
|
|
|
2022-11-11 09:24:10 +00:00
|
|
|
#[derive(ProtoBuf, Default, Clone)]
|
|
|
|
pub struct UserSettingPB {
|
2023-02-13 01:29:49 +00:00
|
|
|
#[pb(index = 1)]
|
|
|
|
pub(crate) user_folder: String,
|
2022-11-11 09:24:10 +00:00
|
|
|
}
|
|
|
|
|
2023-07-14 05:37:13 +00:00
|
|
|
#[derive(ProtoBuf, Default, Eq, PartialEq, Debug, Clone)]
|
2022-07-19 06:40:56 +00:00
|
|
|
pub struct UserProfilePB {
|
2023-02-13 01:29:49 +00:00
|
|
|
#[pb(index = 1)]
|
2023-04-04 00:41:16 +00:00
|
|
|
pub id: i64,
|
2021-07-11 07:33:19 +00:00
|
|
|
|
2023-02-13 01:29:49 +00:00
|
|
|
#[pb(index = 2)]
|
|
|
|
pub email: String,
|
2021-07-11 07:33:19 +00:00
|
|
|
|
2023-02-13 01:29:49 +00:00
|
|
|
#[pb(index = 3)]
|
|
|
|
pub name: String,
|
2021-09-08 10:25:32 +00:00
|
|
|
|
2023-02-13 01:29:49 +00:00
|
|
|
#[pb(index = 4)]
|
|
|
|
pub token: String,
|
2022-08-06 14:31:55 +00:00
|
|
|
|
2023-02-13 01:29:49 +00:00
|
|
|
#[pb(index = 5)]
|
|
|
|
pub icon_url: String,
|
2023-02-14 02:04:36 +00:00
|
|
|
|
|
|
|
#[pb(index = 6)]
|
|
|
|
pub openai_key: String,
|
2023-07-14 05:37:13 +00:00
|
|
|
|
|
|
|
#[pb(index = 7)]
|
|
|
|
pub auth_type: AuthTypePB,
|
2023-08-17 15:46:39 +00:00
|
|
|
|
|
|
|
#[pb(index = 8)]
|
|
|
|
pub encryption_sign: String,
|
|
|
|
|
|
|
|
#[pb(index = 9)]
|
|
|
|
pub encryption_type: EncryptionTypePB,
|
2023-08-21 16:19:15 +00:00
|
|
|
|
|
|
|
#[pb(index = 10)]
|
|
|
|
pub workspace_id: String,
|
2023-08-17 15:46:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(ProtoBuf_Enum, Eq, PartialEq, Debug, Clone)]
|
|
|
|
pub enum EncryptionTypePB {
|
|
|
|
NoEncryption = 0,
|
|
|
|
Symmetric = 1,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for EncryptionTypePB {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self::NoEncryption
|
|
|
|
}
|
2021-07-11 07:33:19 +00:00
|
|
|
}
|
|
|
|
|
2023-01-31 11:30:48 +00:00
|
|
|
impl std::convert::From<UserProfile> for UserProfilePB {
|
2023-02-13 01:29:49 +00:00
|
|
|
fn from(user_profile: UserProfile) -> Self {
|
2023-08-17 15:46:39 +00:00
|
|
|
let (encryption_sign, encryption_ty) = match user_profile.encryption_type {
|
|
|
|
EncryptionType::NoEncryption => ("".to_string(), EncryptionTypePB::NoEncryption),
|
|
|
|
EncryptionType::SelfEncryption(sign) => (sign, EncryptionTypePB::Symmetric),
|
|
|
|
};
|
2023-02-13 01:29:49 +00:00
|
|
|
Self {
|
2023-08-17 15:46:39 +00:00
|
|
|
id: user_profile.uid,
|
2023-02-13 01:29:49 +00:00
|
|
|
email: user_profile.email,
|
|
|
|
name: user_profile.name,
|
|
|
|
token: user_profile.token,
|
|
|
|
icon_url: user_profile.icon_url,
|
2023-02-14 02:04:36 +00:00
|
|
|
openai_key: user_profile.openai_key,
|
2023-07-14 05:37:13 +00:00
|
|
|
auth_type: user_profile.auth_type.into(),
|
2023-08-17 15:46:39 +00:00
|
|
|
encryption_sign,
|
|
|
|
encryption_type: encryption_ty,
|
2023-08-21 16:19:15 +00:00
|
|
|
workspace_id: user_profile.workspace_id,
|
2023-01-31 11:30:48 +00:00
|
|
|
}
|
2023-02-13 01:29:49 +00:00
|
|
|
}
|
2023-01-31 11:30:48 +00:00
|
|
|
}
|
|
|
|
|
2021-08-31 09:25:08 +00:00
|
|
|
#[derive(ProtoBuf, Default)]
|
2022-07-19 06:40:56 +00:00
|
|
|
pub struct UpdateUserProfilePayloadPB {
|
2023-02-13 01:29:49 +00:00
|
|
|
#[pb(index = 1)]
|
2023-04-04 00:41:16 +00:00
|
|
|
pub id: i64,
|
2021-08-31 09:25:08 +00:00
|
|
|
|
2023-02-13 01:29:49 +00:00
|
|
|
#[pb(index = 2, one_of)]
|
|
|
|
pub name: Option<String>,
|
2021-08-31 09:25:08 +00:00
|
|
|
|
2023-02-13 01:29:49 +00:00
|
|
|
#[pb(index = 3, one_of)]
|
|
|
|
pub email: Option<String>,
|
2021-08-31 09:25:08 +00:00
|
|
|
|
2023-02-13 01:29:49 +00:00
|
|
|
#[pb(index = 4, one_of)]
|
|
|
|
pub password: Option<String>,
|
2022-08-06 14:31:55 +00:00
|
|
|
|
2023-02-13 01:29:49 +00:00
|
|
|
#[pb(index = 5, one_of)]
|
|
|
|
pub icon_url: Option<String>,
|
2023-02-14 02:04:36 +00:00
|
|
|
|
|
|
|
#[pb(index = 6, one_of)]
|
|
|
|
pub openai_key: Option<String>,
|
2021-08-31 09:25:08 +00:00
|
|
|
}
|
|
|
|
|
2022-07-19 06:40:56 +00:00
|
|
|
impl UpdateUserProfilePayloadPB {
|
2023-04-04 00:41:16 +00:00
|
|
|
pub fn new(id: i64) -> Self {
|
2023-02-13 01:29:49 +00:00
|
|
|
Self {
|
2023-04-04 00:41:16 +00:00
|
|
|
id,
|
2023-02-13 01:29:49 +00:00
|
|
|
..Default::default()
|
2022-08-06 14:31:55 +00:00
|
|
|
}
|
2023-02-13 01:29:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn name(mut self, name: &str) -> Self {
|
|
|
|
self.name = Some(name.to_owned());
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn email(mut self, email: &str) -> Self {
|
|
|
|
self.email = Some(email.to_owned());
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn password(mut self, password: &str) -> Self {
|
|
|
|
self.password = Some(password.to_owned());
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn icon_url(mut self, icon_url: &str) -> Self {
|
|
|
|
self.icon_url = Some(icon_url.to_owned());
|
|
|
|
self
|
|
|
|
}
|
2023-02-14 02:04:36 +00:00
|
|
|
|
|
|
|
pub fn openai_key(mut self, openai_key: &str) -> Self {
|
|
|
|
self.openai_key = Some(openai_key.to_owned());
|
|
|
|
self
|
|
|
|
}
|
2021-09-01 08:08:32 +00:00
|
|
|
}
|
|
|
|
|
2022-07-19 06:40:56 +00:00
|
|
|
impl TryInto<UpdateUserProfileParams> for UpdateUserProfilePayloadPB {
|
2023-02-13 01:29:49 +00:00
|
|
|
type Error = ErrorCode;
|
|
|
|
|
|
|
|
fn try_into(self) -> Result<UpdateUserProfileParams, Self::Error> {
|
|
|
|
let name = match self.name {
|
|
|
|
None => None,
|
|
|
|
Some(name) => Some(UserName::parse(name)?.0),
|
|
|
|
};
|
|
|
|
|
|
|
|
let email = match self.email {
|
|
|
|
None => None,
|
|
|
|
Some(email) => Some(UserEmail::parse(email)?.0),
|
|
|
|
};
|
|
|
|
|
|
|
|
let password = match self.password {
|
|
|
|
None => None,
|
|
|
|
Some(password) => Some(UserPassword::parse(password)?.0),
|
|
|
|
};
|
|
|
|
|
|
|
|
let icon_url = match self.icon_url {
|
|
|
|
None => None,
|
|
|
|
Some(icon_url) => Some(UserIcon::parse(icon_url)?.0),
|
|
|
|
};
|
|
|
|
|
2023-02-14 02:04:36 +00:00
|
|
|
let openai_key = match self.openai_key {
|
|
|
|
None => None,
|
|
|
|
Some(openai_key) => Some(UserOpenaiKey::parse(openai_key)?.0),
|
|
|
|
};
|
|
|
|
|
2023-02-13 01:29:49 +00:00
|
|
|
Ok(UpdateUserProfileParams {
|
2023-08-17 15:46:39 +00:00
|
|
|
uid: self.id,
|
2023-02-13 01:29:49 +00:00
|
|
|
name,
|
|
|
|
email,
|
|
|
|
password,
|
|
|
|
icon_url,
|
2023-02-14 02:04:36 +00:00
|
|
|
openai_key,
|
2023-08-17 15:46:39 +00:00
|
|
|
encryption_sign: None,
|
2023-02-13 01:29:49 +00:00
|
|
|
})
|
|
|
|
}
|
2021-07-11 07:33:19 +00:00
|
|
|
}
|
2023-07-29 01:46:24 +00:00
|
|
|
|
|
|
|
#[derive(ProtoBuf, Default, Debug, Clone)]
|
|
|
|
pub struct RepeatedUserWorkspacePB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub items: Vec<UserWorkspacePB>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<Vec<UserWorkspace>> for RepeatedUserWorkspacePB {
|
|
|
|
fn from(workspaces: Vec<UserWorkspace>) -> Self {
|
|
|
|
Self {
|
|
|
|
items: workspaces.into_iter().map(UserWorkspacePB::from).collect(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(ProtoBuf, Default, Debug, Clone)]
|
|
|
|
pub struct UserWorkspacePB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub id: String,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub name: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<UserWorkspace> for UserWorkspacePB {
|
|
|
|
fn from(value: UserWorkspace) -> Self {
|
|
|
|
Self {
|
|
|
|
id: value.id,
|
|
|
|
name: value.name,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(ProtoBuf, Default)]
|
|
|
|
pub struct AddWorkspaceUserPB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub email: String,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub workspace_id: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(ProtoBuf, Default)]
|
|
|
|
pub struct RemoveWorkspaceUserPB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub email: String,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub workspace_id: String,
|
|
|
|
}
|
2023-08-07 14:24:04 +00:00
|
|
|
|
|
|
|
#[derive(ProtoBuf, Default, Clone)]
|
|
|
|
pub struct RepeatedHistoricalUserPB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub items: Vec<HistoricalUserPB>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(ProtoBuf, Default, Clone)]
|
|
|
|
pub struct HistoricalUserPB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub user_id: i64,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub user_name: String,
|
|
|
|
|
|
|
|
#[pb(index = 3)]
|
|
|
|
pub last_time: i64,
|
|
|
|
|
|
|
|
#[pb(index = 4)]
|
|
|
|
pub auth_type: AuthTypePB,
|
2023-08-12 09:36:31 +00:00
|
|
|
|
|
|
|
#[pb(index = 5)]
|
|
|
|
pub device_id: String,
|
2023-08-07 14:24:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl From<Vec<HistoricalUser>> for RepeatedHistoricalUserPB {
|
|
|
|
fn from(historical_users: Vec<HistoricalUser>) -> Self {
|
|
|
|
Self {
|
|
|
|
items: historical_users
|
|
|
|
.into_iter()
|
|
|
|
.map(HistoricalUserPB::from)
|
|
|
|
.collect(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<HistoricalUser> for HistoricalUserPB {
|
|
|
|
fn from(historical_user: HistoricalUser) -> Self {
|
|
|
|
Self {
|
|
|
|
user_id: historical_user.user_id,
|
|
|
|
user_name: historical_user.user_name,
|
|
|
|
last_time: historical_user.sign_in_timestamp,
|
|
|
|
auth_type: historical_user.auth_type.into(),
|
2023-08-12 09:36:31 +00:00
|
|
|
device_id: historical_user.device_id,
|
2023-08-07 14:24:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-08-21 16:19:15 +00:00
|
|
|
|
|
|
|
#[derive(ProtoBuf, Default, Clone)]
|
|
|
|
pub struct ResetWorkspacePB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub uid: i64,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub workspace_id: String,
|
|
|
|
}
|