Skip to content

Commit

Permalink
chore: save workspace member info to disk (#5536)
Browse files Browse the repository at this point in the history
* chore: save workspace member info to disk

* chore: fix clippy
  • Loading branch information
appflowy authored Jun 14, 2024
1 parent 785597f commit 27899ee
Show file tree
Hide file tree
Showing 18 changed files with 207 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/database/application/row/row_service.dart';
import 'package:appflowy/plugins/database/grid/presentation/layout/sizes.dart';
import 'package:appflowy/workspace/presentation/widgets/dialogs.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/protobuf.dart';
import 'package:appflowy_popover/appflowy_popover.dart';
import 'package:easy_localization/easy_localization.dart';
Expand Down Expand Up @@ -52,7 +53,17 @@ class RowActionMenu extends StatelessWidget {
child: FlowyButton(
text: FlowyText.medium(action.text, overflow: TextOverflow.ellipsis),
onTap: () {
action.performAction(context, viewId, rowId);
if (action == RowAction.delete) {
NavigatorOkCancelDialog(
message: LocaleKeys.grid_row_deleteRowPrompt.tr(),
onOkPressed: () {
action.performAction(context, viewId, rowId);
},
).show(context);
} else {
action.performAction(context, viewId, rowId);
}

PopoverContainer.of(context).close();
},
leftIcon: icon,
Expand Down
3 changes: 2 additions & 1 deletion frontend/resources/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,7 @@
"action": "Action",
"add": "Click add to below",
"drag": "Drag to move",
"deleteRowPrompt": "Are you sure you want to delete this row? This action cannot be undone",
"dragAndClick": "Drag to move, click to open menu",
"insertRecordAbove": "Insert record above",
"insertRecordBelow": "Insert record below",
Expand Down Expand Up @@ -1915,4 +1916,4 @@
"title": "Spaces",
"defaultSpaceName": "General"
}
}
}
22 changes: 18 additions & 4 deletions frontend/rust-lib/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/rust-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ collab-database = { version = "0.2" }
collab-plugins = { version = "0.2" }
collab-user = { version = "0.2" }
yrs = "0.18.8"
validator = { version = "0.16.1", features = ["derive"] }

# Please using the following command to update the revision id
# Current directory: frontend
Expand Down
2 changes: 1 addition & 1 deletion frontend/rust-lib/flowy-chat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ uuid.workspace = true
strum_macros = "0.21"
protobuf.workspace = true
bytes.workspace = true
validator = { version = "0.16.0", features = ["derive"] }
validator = { workspace = true, features = ["derive"] }
lib-infra = { workspace = true, features = ["isolate_flutter"] }
flowy-chat-pub.workspace = true
dashmap = "5.5"
Expand Down
2 changes: 1 addition & 1 deletion frontend/rust-lib/flowy-database2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ chrono-tz = "0.8.2"
csv = "1.1.6"
strum = "0.25"
strum_macros = "0.25"
validator = { version = "0.16.0", features = ["derive"] }
validator = { workspace = true, features = ["derive"] }

[dev-dependencies]
event-integration-test = { path = "../event-integration-test", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion frontend/rust-lib/flowy-error/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ protobuf.workspace = true
bytes.workspace = true
anyhow.workspace = true
thiserror = "1.0"
validator = "0.16.0"
validator.workspace = true
tokio = { workspace = true, features = ["sync", "rt"] }

fancy-regex = { version = "0.11.0" }
Expand Down
4 changes: 2 additions & 2 deletions frontend/rust-lib/flowy-folder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ strum_macros = "0.21"
protobuf.workspace = true
uuid.workspace = true
tokio-stream = { workspace = true, features = ["sync"] }
serde = { workspace = true, features = ["derive"]}
serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true
validator = "0.16.0"
validator.workspace = true
async-trait.workspace = true

[build-dependencies]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- This file should undo anything in `up.sql`
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- Your SQL goes here
CREATE TABLE workspace_members_table (
email TEXT KEY NOT NULL,
role INTEGER NOT NULL,
name TEXT NOT NULL,
avatar_url TEXT,
uid BIGINT NOT NULL,
workspace_id TEXT NOT NULL,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (email, workspace_id)
);
13 changes: 13 additions & 0 deletions frontend/rust-lib/flowy-sqlite/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,24 @@ diesel::table! {
}
}

diesel::table! {
workspace_members_table (email, workspace_id) {
email -> Text,
role -> Integer,
name -> Text,
avatar_url -> Nullable<Text>,
uid -> BigInt,
workspace_id -> Text,
updated_at -> Timestamp,
}
}

diesel::allow_tables_to_appear_in_same_query!(
chat_message_table,
chat_table,
collab_snapshot,
user_data_migration_records,
user_table,
user_workspace_table,
workspace_members_table,
);
30 changes: 26 additions & 4 deletions frontend/rust-lib/flowy-user-pub/src/entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,11 +384,33 @@ pub enum UserTokenState {
}

// Workspace Role
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Serialize_repr, Deserialize_repr)]
#[repr(u8)]
pub enum Role {
Owner,
Member,
Guest,
Owner = 0,
Member = 1,
Guest = 2,
}

impl From<i32> for Role {
fn from(value: i32) -> Self {
match value {
0 => Role::Owner,
1 => Role::Member,
2 => Role::Guest,
_ => Role::Guest,
}
}
}

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

pub struct WorkspaceMember {
Expand Down
4 changes: 2 additions & 2 deletions frontend/rust-lib/flowy-user/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ edition = "2018"
flowy-derive.workspace = true
flowy-sqlite = { workspace = true }
flowy-encrypt = { workspace = true }
flowy-error = { workspace = true, features = ["impl_from_dispatch_error", "impl_from_sqlite", "impl_from_collab_folder", "impl_from_collab_persistence"] }
flowy-error = { workspace = true, features = ["impl_from_dispatch_error", "impl_from_sqlite", "impl_from_collab_folder", "impl_from_collab_persistence", "impl_from_collab_document"] }
flowy-folder-pub = { workspace = true }
lib-infra = { workspace = true }
flowy-notification = { workspace = true }
Expand Down Expand Up @@ -39,14 +39,14 @@ parking_lot.workspace = true
strum = "0.25"
strum_macros = "0.25.2"
tokio = { workspace = true, features = ["rt"] }
validator = "0.16.0"
unicode-segmentation = "1.10"
fancy-regex = "0.11.0"
uuid.workspace = true
chrono = { workspace = true, default-features = false, features = ["clock"] }
base64 = "^0.21"
tokio-stream = "0.1.14"
semver = "1.0.22"
validator = { workspace = true, features = ["derive"] }

[dev-dependencies]
nanoid = "0.4.0"
Expand Down
52 changes: 52 additions & 0 deletions frontend/rust-lib/flowy-user/src/services/sqlite_sql/member_sql.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use diesel::{insert_into, RunQueryDsl};
use flowy_error::FlowyResult;

use flowy_sqlite::schema::workspace_members_table;

use flowy_sqlite::schema::workspace_members_table::dsl;
use flowy_sqlite::{query_dsl::*, DBConnection, ExpressionMethods};

#[derive(Queryable, Insertable, AsChangeset, Debug)]
#[diesel(table_name = workspace_members_table)]
#[diesel(primary_key(email, workspace_id))]
pub struct WorkspaceMemberTable {
pub email: String,
pub role: i32,
pub name: String,
pub avatar_url: Option<String>,
pub uid: i64,
pub workspace_id: String,
pub updated_at: chrono::NaiveDateTime,
}

pub fn upsert_workspace_member<T: Into<WorkspaceMemberTable>>(
mut conn: DBConnection,
member: T,
) -> FlowyResult<()> {
let member = member.into();

insert_into(workspace_members_table::table)
.values(&member)
.on_conflict((
workspace_members_table::email,
workspace_members_table::workspace_id,
))
.do_update()
.set(&member)
.execute(&mut conn)?;

Ok(())
}

pub fn select_workspace_member(
mut conn: DBConnection,
workspace_id: &str,
uid: i64,
) -> FlowyResult<WorkspaceMemberTable> {
let member = dsl::workspace_members_table
.filter(workspace_members_table::workspace_id.eq(workspace_id))
.filter(workspace_members_table::uid.eq(uid))
.first::<WorkspaceMemberTable>(&mut conn)?;

Ok(member)
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub(crate) mod member_sql;
pub(crate) mod user_sql;
pub(crate) mod workspace_sql;
Loading

0 comments on commit 27899ee

Please sign in to comment.