Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/workspace roles #6783

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/rust-lib/flowy-ai-pub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ flowy-error = { workspace = true }
client-api = { workspace = true }
bytes.workspace = true
futures.workspace = true
serde_json.workspace = true
serde_json.workspace = true
2 changes: 2 additions & 0 deletions frontend/rust-lib/flowy-ai/src/local_ai/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver};
use tracing::{error, trace};

#[cfg(any(target_os = "windows", target_os = "macos", target_os = "linux"))]
#[allow(dead_code)]
pub struct WatchContext {
#[allow(dead_code)]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need to keep #[allow(dead_code)] for the watcher?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we dont need this anymore, I'll remove it

watcher: notify::RecommendedWatcher,
pub path: PathBuf,
}

#[cfg(any(target_os = "windows", target_os = "macos", target_os = "linux"))]
#[allow(dead_code)]
pub fn watch_offline_app() -> FlowyResult<(WatchContext, UnboundedReceiver<WatchDiskEvent>)> {
use notify::{Event, Watcher};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,7 @@ fn to_user_workspace(af_workspace: AFWorkspace) -> UserWorkspace {
workspace_database_id: af_workspace.database_storage_id.to_string(),
icon: af_workspace.icon,
member_count: af_workspace.member_count.unwrap_or(0),
role: af_workspace.role.map(|r| r.into()),
}
}

Expand Down
5 changes: 3 additions & 2 deletions frontend/rust-lib/flowy-server/src/local_server/impls/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl UserCloudService for LocalServerUserAuthServiceImpl {
let params = params.unbox_or_error::<SignUpParams>()?;
let uid = ID_GEN.lock().await.next_id();
let workspace_id = uuid::Uuid::new_v4().to_string();
let user_workspace = UserWorkspace::new(&workspace_id, uid);
let user_workspace = UserWorkspace::new_local(&workspace_id, uid);
let user_name = if params.name.is_empty() {
DEFAULT_USER_NAME()
} else {
Expand Down Expand Up @@ -214,6 +214,7 @@ fn make_user_workspace() -> UserWorkspace {
created_at: Default::default(),
workspace_database_id: uuid::Uuid::new_v4().to_string(),
icon: "".to_string(),
member_count: 0,
member_count: 1,
role: None,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE user_workspace_table DROP COLUMN role;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE user_workspace_table ADD COLUMN role INT;
1 change: 1 addition & 0 deletions frontend/rust-lib/flowy-sqlite/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ diesel::table! {
database_storage_id -> Text,
icon -> Text,
member_count -> BigInt,
role -> Nullable<Integer>,
}
}

Expand Down
16 changes: 15 additions & 1 deletion frontend/rust-lib/flowy-user-pub/src/entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::str::FromStr;

use chrono::{DateTime, Utc};
pub use client_api::entity::billing_dto::RecurringInterval;
use client_api::entity::AFRole;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use serde_repr::*;
Expand Down Expand Up @@ -145,17 +146,20 @@ pub struct UserWorkspace {
pub icon: String,
#[serde(default)]
pub member_count: i64,
#[serde(default)]
pub role: Option<Role>,
}

impl UserWorkspace {
pub fn new(workspace_id: &str, _uid: i64) -> Self {
pub fn new_local(workspace_id: &str, _uid: i64) -> Self {
Self {
id: workspace_id.to_string(),
name: "".to_string(),
created_at: Utc::now(),
workspace_database_id: Uuid::new_v4().to_string(),
icon: "".to_string(),
member_count: 1,
role: None,
}
}
}
Expand Down Expand Up @@ -420,6 +424,16 @@ impl From<Role> for i32 {
}
}

impl From<AFRole> for Role {
fn from(value: AFRole) -> Self {
match value {
AFRole::Owner => Role::Owner,
AFRole::Member => Role::Member,
AFRole::Guest => Role::Guest,
}
}
}

pub struct WorkspaceMember {
pub email: String,
pub role: Role,
Expand Down
3 changes: 2 additions & 1 deletion frontend/rust-lib/flowy-user-pub/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ impl<'de> Visitor<'de> for SessionVisitor {
// For historical reasons, the database_storage_id is constructed by the user_id.
workspace_database_id: STANDARD.encode(format!("{}:user:database", user_id)),
icon: "".to_owned(),
member_count: 0,
member_count: 1,
role: None,
})
}
}
Expand Down
5 changes: 5 additions & 0 deletions frontend/rust-lib/flowy-user/src/entities/user_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::entities::{AIModelPB, AuthenticatorPB};
use crate::errors::ErrorCode;

use super::parser::UserStabilityAIKey;
use super::AFRolePB;

#[derive(Default, ProtoBuf)]
pub struct UserTokenPB {
Expand Down Expand Up @@ -237,6 +238,9 @@ pub struct UserWorkspacePB {

#[pb(index = 5)]
pub member_count: i64,

#[pb(index = 6, one_of)]
pub role: Option<AFRolePB>,
}

impl From<UserWorkspace> for UserWorkspacePB {
Expand All @@ -247,6 +251,7 @@ impl From<UserWorkspace> for UserWorkspacePB {
created_at_timestamp: value.created_at.timestamp(),
icon: value.icon,
member_count: value.member_count,
role: value.role.map(AFRolePB::from),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/rust-lib/flowy-user/src/entities/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ pub struct UpdateWorkspaceMemberPB {
}

// Workspace Role
#[derive(ProtoBuf_Enum, Clone, Default)]
#[derive(Debug, ProtoBuf_Enum, Clone, Default)]
pub enum AFRolePB {
Owner = 0,
Member = 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct UserWorkspaceTable {
pub database_storage_id: String,
pub icon: String,
pub member_count: i64,
pub role: Option<i32>,
}

pub fn get_user_workspace_op(workspace_id: &str, mut conn: DBConnection) -> Option<UserWorkspace> {
Expand Down Expand Up @@ -94,6 +95,7 @@ impl TryFrom<(i64, &UserWorkspace)> for UserWorkspaceTable {
database_storage_id: value.1.workspace_database_id.clone(),
icon: value.1.icon.clone(),
member_count: value.1.member_count,
role: value.1.role.clone().map(|v| v as i32),
})
}
}
Expand All @@ -110,6 +112,7 @@ impl From<UserWorkspaceTable> for UserWorkspace {
workspace_database_id: value.database_storage_id,
icon: value.icon,
member_count: value.member_count,
role: value.role.map(|v| v.into()),
}
}
}
Loading