mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-07-28 03:21:54 +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>
193 lines
4.2 KiB
Rust
193 lines
4.2 KiB
Rust
use chrono::{DateTime, Utc};
|
|
use serde::{Deserialize, Serialize};
|
|
use serde_repr::*;
|
|
use uuid::Uuid;
|
|
|
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
|
pub struct SignInResponse {
|
|
pub user_id: i64,
|
|
pub name: String,
|
|
pub latest_workspace: UserWorkspace,
|
|
pub user_workspaces: Vec<UserWorkspace>,
|
|
pub email: Option<String>,
|
|
pub token: Option<String>,
|
|
}
|
|
|
|
#[derive(Default, Serialize, Deserialize, Debug)]
|
|
pub struct SignInParams {
|
|
pub email: String,
|
|
pub password: String,
|
|
pub name: String,
|
|
pub auth_type: AuthType,
|
|
// Currently, the uid only used in local sign in.
|
|
pub uid: Option<i64>,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Default, Debug)]
|
|
pub struct SignUpParams {
|
|
pub email: String,
|
|
pub name: String,
|
|
pub password: String,
|
|
pub auth_type: AuthType,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
pub struct SignUpResponse {
|
|
pub user_id: i64,
|
|
pub name: String,
|
|
pub latest_workspace: UserWorkspace,
|
|
pub user_workspaces: Vec<UserWorkspace>,
|
|
pub is_new: bool,
|
|
pub email: Option<String>,
|
|
pub token: Option<String>,
|
|
}
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub struct UserCredentials {
|
|
/// Currently, the token is only used when the [AuthType] is SelfHosted
|
|
pub token: Option<String>,
|
|
|
|
/// The user id
|
|
pub uid: Option<i64>,
|
|
|
|
/// The user id
|
|
pub uuid: Option<String>,
|
|
}
|
|
|
|
impl UserCredentials {
|
|
pub fn from_uid(uid: i64) -> Self {
|
|
Self {
|
|
token: None,
|
|
uid: Some(uid),
|
|
uuid: None,
|
|
}
|
|
}
|
|
|
|
pub fn from_uuid(uuid: String) -> Self {
|
|
Self {
|
|
token: None,
|
|
uid: None,
|
|
uuid: Some(uuid),
|
|
}
|
|
}
|
|
|
|
pub fn new(token: Option<String>, uid: Option<i64>, uuid: Option<String>) -> Self {
|
|
Self { token, uid, uuid }
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
|
pub struct UserWorkspace {
|
|
pub id: String,
|
|
pub name: String,
|
|
pub created_at: DateTime<Utc>,
|
|
pub database_storage_id: String,
|
|
}
|
|
|
|
impl UserWorkspace {
|
|
pub fn new(workspace_id: &str, _uid: i64) -> Self {
|
|
Self {
|
|
id: workspace_id.to_string(),
|
|
name: "".to_string(),
|
|
created_at: Utc::now(),
|
|
database_storage_id: uuid::Uuid::new_v4().to_string(),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Default, Debug, Clone)]
|
|
pub struct UserProfile {
|
|
pub id: i64,
|
|
pub email: String,
|
|
pub name: String,
|
|
pub token: String,
|
|
pub icon_url: String,
|
|
pub openai_key: String,
|
|
pub workspace_id: String,
|
|
pub auth_type: AuthType,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Default, Clone, Debug)]
|
|
pub struct UpdateUserProfileParams {
|
|
pub id: i64,
|
|
pub auth_type: AuthType,
|
|
pub name: Option<String>,
|
|
pub email: Option<String>,
|
|
pub password: Option<String>,
|
|
pub icon_url: Option<String>,
|
|
pub openai_key: Option<String>,
|
|
}
|
|
|
|
impl UpdateUserProfileParams {
|
|
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
|
|
}
|
|
|
|
pub fn openai_key(mut self, openai_key: &str) -> Self {
|
|
self.openai_key = Some(openai_key.to_owned());
|
|
self
|
|
}
|
|
|
|
pub fn is_empty(&self) -> bool {
|
|
self.name.is_none()
|
|
&& self.email.is_none()
|
|
&& self.password.is_none()
|
|
&& self.icon_url.is_none()
|
|
&& self.openai_key.is_none()
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, Hash, Serialize_repr, Deserialize_repr, Eq, PartialEq)]
|
|
#[repr(u8)]
|
|
pub enum AuthType {
|
|
/// It's a local server, we do fake sign in default.
|
|
Local = 0,
|
|
/// Currently not supported. It will be supported in the future when the
|
|
/// [AppFlowy-Server](https://github.com/AppFlowy-IO/AppFlowy-Server) ready.
|
|
SelfHosted = 1,
|
|
/// It uses Supabase as the backend.
|
|
Supabase = 2,
|
|
}
|
|
impl Default for AuthType {
|
|
fn default() -> Self {
|
|
Self::Local
|
|
}
|
|
}
|
|
|
|
impl AuthType {
|
|
pub fn is_local(&self) -> bool {
|
|
matches!(self, AuthType::Local)
|
|
}
|
|
}
|
|
|
|
impl From<i32> for AuthType {
|
|
fn from(value: i32) -> Self {
|
|
match value {
|
|
0 => AuthType::Local,
|
|
1 => AuthType::SelfHosted,
|
|
2 => AuthType::Supabase,
|
|
_ => AuthType::Local,
|
|
}
|
|
}
|
|
}
|
|
pub struct ThirdPartyParams {
|
|
pub uuid: Uuid,
|
|
pub email: String,
|
|
}
|