mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-08-15 20:31:38 +00:00

* refactor: weak passed-in params in handler * refactor: rename struct * chore: update tables * chore: update schema * chore: add permission * chore: update tables * chore: support transaction mode * chore: workspace database id * chore: add user workspace * feat: return list of workspaces * chore: add user to workspace * feat: separate database row table * refactor: update schema * chore: partition table * chore: use transaction * refactor: dir * refactor: collab db ref * fix: collab db lock * chore: rename files * chore: add tables descriptions * chore: update readme * docs: update documentation * chore: rename crate * chore: update ref * chore: update tests * chore: update tests * refactor: crate deps * chore: update crate ref * chore: remove unused deps * chore: remove unused deps * chore: update collab crate refs * chore: replace client with transaction in pooler * refactor: return error type * refactor: use anyhow error in deps * feat: supabase postgrest user signin (wip) * fix: Cargo.toml source git deps, changed Error to anyhow::Error * fix: uuid serialization * chore: fix conflict * chore: extend the response * feat: add implementation place holders * feat: impl get_user_workspaces * feat: impl get_user_profile * test: create workspace * fix: postgrest: field names and alias * chore: implement folder restful api * chore: implement collab storate with restful api * feat: added placeholders for impl: update_user_profile, check_user * feat: impl: update_user_profile * feat: impl: check_user * fix: use UidResponse, add more debug info for serde serialization error * fix: get_user_profile: use Optional<UserProfileResponse> * chore: imple init sync * chore: support soft delete * feat: postgresql: add migration test * feat: postgresql migration test: added UID display and colored output * feat: postgresql migration test: workspace role * feat: postgresql migration test: create shared common utils * feat: postgresql migration test: fixed shebang * chore: add flush_collab_update pg function * chore: implement datbaase and document restful api * chore: migrate to use restful api * chore: update table schema * chore: fix tests * chore: remove unused code * chore: format code * chore: remove unused env * fix: tauri build * fix: tauri build --------- Co-authored-by: Fu Zi Xiang <speed2exe@live.com.sg>
153 lines
3.0 KiB
Rust
153 lines
3.0 KiB
Rust
use std::collections::HashMap;
|
|
use std::convert::TryInto;
|
|
|
|
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
|
use flowy_user_deps::entities::*;
|
|
|
|
use crate::entities::parser::*;
|
|
use crate::errors::ErrorCode;
|
|
|
|
#[derive(ProtoBuf, Default)]
|
|
pub struct SignInPayloadPB {
|
|
#[pb(index = 1)]
|
|
pub email: String,
|
|
|
|
#[pb(index = 2)]
|
|
pub password: String,
|
|
|
|
#[pb(index = 3)]
|
|
pub name: String,
|
|
|
|
#[pb(index = 4)]
|
|
pub auth_type: AuthTypePB,
|
|
|
|
// Only used in local sign in.
|
|
#[pb(index = 5, one_of)]
|
|
pub uid: Option<i64>,
|
|
}
|
|
|
|
impl TryInto<SignInParams> for SignInPayloadPB {
|
|
type Error = ErrorCode;
|
|
|
|
fn try_into(self) -> Result<SignInParams, Self::Error> {
|
|
let email = UserEmail::parse(self.email)?;
|
|
let password = UserPassword::parse(self.password)?;
|
|
|
|
Ok(SignInParams {
|
|
email: email.0,
|
|
password: password.0,
|
|
name: self.name,
|
|
auth_type: self.auth_type.into(),
|
|
uid: self.uid,
|
|
})
|
|
}
|
|
}
|
|
|
|
#[derive(ProtoBuf, Default)]
|
|
pub struct SignUpPayloadPB {
|
|
#[pb(index = 1)]
|
|
pub email: String,
|
|
|
|
#[pb(index = 2)]
|
|
pub name: String,
|
|
|
|
#[pb(index = 3)]
|
|
pub password: String,
|
|
|
|
#[pb(index = 4)]
|
|
pub auth_type: AuthTypePB,
|
|
}
|
|
impl TryInto<SignUpParams> for SignUpPayloadPB {
|
|
type Error = ErrorCode;
|
|
|
|
fn try_into(self) -> Result<SignUpParams, Self::Error> {
|
|
let email = UserEmail::parse(self.email)?;
|
|
let password = UserPassword::parse(self.password)?;
|
|
let name = UserName::parse(self.name)?;
|
|
|
|
Ok(SignUpParams {
|
|
email: email.0,
|
|
name: name.0,
|
|
password: password.0,
|
|
auth_type: self.auth_type.into(),
|
|
})
|
|
}
|
|
}
|
|
|
|
#[derive(ProtoBuf, Default)]
|
|
pub struct ThirdPartyAuthPB {
|
|
/// Use this field to store the third party auth information.
|
|
/// Different auth type has different fields.
|
|
/// Supabase:
|
|
/// - map: { "uuid": "xxx" }
|
|
///
|
|
#[pb(index = 1)]
|
|
pub map: HashMap<String, String>,
|
|
|
|
#[pb(index = 2)]
|
|
pub auth_type: AuthTypePB,
|
|
}
|
|
|
|
#[derive(ProtoBuf_Enum, Eq, PartialEq, Debug, Clone)]
|
|
pub enum AuthTypePB {
|
|
Local = 0,
|
|
SelfHosted = 1,
|
|
Supabase = 2,
|
|
}
|
|
|
|
impl Default for AuthTypePB {
|
|
fn default() -> Self {
|
|
Self::Local
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, ProtoBuf, Default)]
|
|
pub struct UserCredentialsPB {
|
|
#[pb(index = 1, one_of)]
|
|
pub uid: Option<i64>,
|
|
|
|
#[pb(index = 2, one_of)]
|
|
pub uuid: Option<String>,
|
|
|
|
#[pb(index = 3, one_of)]
|
|
pub token: Option<String>,
|
|
}
|
|
|
|
impl UserCredentialsPB {
|
|
pub fn from_uid(uid: i64) -> Self {
|
|
Self {
|
|
uid: Some(uid),
|
|
uuid: None,
|
|
token: None,
|
|
}
|
|
}
|
|
|
|
pub fn from_token(token: &str) -> Self {
|
|
Self {
|
|
uid: None,
|
|
uuid: None,
|
|
token: Some(token.to_owned()),
|
|
}
|
|
}
|
|
|
|
pub fn from_uuid(uuid: &str) -> Self {
|
|
Self {
|
|
uid: None,
|
|
uuid: Some(uuid.to_owned()),
|
|
token: None,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<UserCredentialsPB> for UserCredentials {
|
|
fn from(value: UserCredentialsPB) -> Self {
|
|
Self::new(value.token, value.uid, value.uuid)
|
|
}
|
|
}
|
|
|
|
#[derive(Default, ProtoBuf)]
|
|
pub struct UserStatePB {
|
|
#[pb(index = 1)]
|
|
pub auth_type: AuthTypePB,
|
|
}
|