mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: workspace settings page (#5225)
* feat: my account settings page * test: amend tests * chore: remove unused code * test: remove widget tests * fix: text color on select buttons * test: clean and remove unused test helpers * feat: settings workspace page * chore: fixes after merge * fix: recent views bugfix * fix: make sure text buttons have color * test: add test for delete workspace in settings * test: remove pumpAndSettle for create workspace * test: longer pump duration * test: attempt with large pump duration * test: attempt workaround * chore: clean code * fix: missing language key * test: add one more check * test: pump * test: more pump * test: attempt pumpAndSettle * chore: code review * fix: persist single workspace on patch * fix: listen to workspace changes * chore: remove redundant builder * test: remove unstable test * fix: changes after merge * chore: changes after merge * feat: support changing cursor and selection color * chore: move members up in menu * feat: clean code and beautify dialogs * fix: fix test and make show selected font --------- Co-authored-by: Lucas.Xu <lucas.xu@appflowy.io>
This commit is contained in:
@ -13,6 +13,7 @@ pub(crate) enum UserNotification {
|
||||
DidUpdateUserProfile = 2,
|
||||
DidUpdateUserWorkspaces = 3,
|
||||
DidUpdateCloudConfig = 4,
|
||||
DidUpdateUserWorkspace = 5,
|
||||
}
|
||||
|
||||
impl std::convert::From<UserNotification> for i32 {
|
||||
|
@ -39,11 +39,13 @@ use crate::services::collab_interact::{CollabInteract, DefaultCollabInteract};
|
||||
|
||||
use crate::services::sqlite_sql::user_sql::{select_user_profile, UserTable, UserTableChangeset};
|
||||
use crate::user_manager::manager_user_encryption::validate_encryption_sign;
|
||||
use crate::user_manager::manager_user_workspace::save_user_workspaces;
|
||||
use crate::user_manager::manager_user_workspace::save_all_user_workspaces;
|
||||
use crate::user_manager::user_login_state::UserAuthProcess;
|
||||
use crate::{errors::FlowyError, notification::*};
|
||||
use flowy_user_pub::session::Session;
|
||||
|
||||
use super::manager_user_workspace::save_user_workspace;
|
||||
|
||||
pub struct UserManager {
|
||||
pub(crate) cloud_services: Arc<dyn UserCloudServiceProvider>,
|
||||
pub(crate) store_preferences: Arc<StorePreferences>,
|
||||
@ -708,7 +710,7 @@ impl UserManager {
|
||||
self.set_anon_user(session.clone());
|
||||
}
|
||||
|
||||
save_user_workspaces(uid, self.db_connection(uid)?, response.user_workspaces())?;
|
||||
save_all_user_workspaces(uid, self.db_connection(uid)?, response.user_workspaces())?;
|
||||
info!(
|
||||
"Save new user profile to disk, authenticator: {:?}",
|
||||
authenticator
|
||||
@ -779,13 +781,13 @@ impl UserManager {
|
||||
}
|
||||
|
||||
// Save the old user workspace setting.
|
||||
save_user_workspaces(
|
||||
save_user_workspace(
|
||||
old_user.session.user_id,
|
||||
self
|
||||
.authenticate_user
|
||||
.database
|
||||
.get_connection(old_user.session.user_id)?,
|
||||
&[old_user.session.user_workspace.clone()],
|
||||
&old_user.session.user_workspace.clone(),
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ use flowy_user_pub::entities::{
|
||||
};
|
||||
use lib_dispatch::prelude::af_spawn;
|
||||
|
||||
use crate::entities::{RepeatedUserWorkspacePB, ResetWorkspacePB};
|
||||
use crate::entities::{RepeatedUserWorkspacePB, ResetWorkspacePB, UserWorkspacePB};
|
||||
use crate::migrations::AnonUser;
|
||||
use crate::notification::{send_notification, UserNotification};
|
||||
use crate::services::data_import::{
|
||||
@ -239,7 +239,14 @@ impl UserManager {
|
||||
user_workspace.icon = new_workspace_icon.to_string();
|
||||
}
|
||||
|
||||
save_user_workspaces(uid, conn, &[user_workspace])
|
||||
let _ = save_user_workspace(uid, conn, &user_workspace);
|
||||
|
||||
let payload: UserWorkspacePB = user_workspace.clone().into();
|
||||
send_notification(&uid.to_string(), UserNotification::DidUpdateUserWorkspace)
|
||||
.payload(payload)
|
||||
.send();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[instrument(level = "info", skip(self), err)]
|
||||
@ -371,7 +378,7 @@ impl UserManager {
|
||||
af_spawn(async move {
|
||||
if let Ok(new_user_workspaces) = service.get_all_workspace(uid).await {
|
||||
if let Ok(conn) = pool.get() {
|
||||
let _ = save_user_workspaces(uid, conn, &new_user_workspaces);
|
||||
let _ = save_all_user_workspaces(uid, conn, &new_user_workspaces);
|
||||
let repeated_workspace_pbs = RepeatedUserWorkspacePB::from(new_user_workspaces);
|
||||
send_notification(&uid.to_string(), UserNotification::DidUpdateUserWorkspaces)
|
||||
.payload(repeated_workspace_pbs)
|
||||
@ -403,7 +410,48 @@ impl UserManager {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn save_user_workspaces(
|
||||
/// This method is used to save one user workspace to the SQLite database
|
||||
///
|
||||
/// If the workspace is already persisted in the database, it will be overridden.
|
||||
///
|
||||
/// Consider using [save_all_user_workspaces] if you need to override all workspaces of the user.
|
||||
///
|
||||
pub fn save_user_workspace(
|
||||
uid: i64,
|
||||
mut conn: DBConnection,
|
||||
user_workspace: &UserWorkspace,
|
||||
) -> FlowyResult<()> {
|
||||
conn.immediate_transaction(|conn| {
|
||||
let user_workspace = UserWorkspaceTable::try_from((uid, user_workspace))?;
|
||||
let affected_rows = diesel::update(
|
||||
user_workspace_table::dsl::user_workspace_table
|
||||
.filter(user_workspace_table::id.eq(&user_workspace.id)),
|
||||
)
|
||||
.set((
|
||||
user_workspace_table::name.eq(&user_workspace.name),
|
||||
user_workspace_table::created_at.eq(&user_workspace.created_at),
|
||||
user_workspace_table::database_storage_id.eq(&user_workspace.database_storage_id),
|
||||
user_workspace_table::icon.eq(&user_workspace.icon),
|
||||
))
|
||||
.execute(conn)?;
|
||||
|
||||
if affected_rows == 0 {
|
||||
diesel::insert_into(user_workspace_table::table)
|
||||
.values(user_workspace)
|
||||
.execute(conn)?;
|
||||
}
|
||||
|
||||
Ok::<(), FlowyError>(())
|
||||
})
|
||||
}
|
||||
|
||||
/// This method is used to save the user workspaces (plural) to the SQLite database
|
||||
///
|
||||
/// The workspaces provided in [user_workspaces] will override the existing workspaces in the database.
|
||||
///
|
||||
/// Consider using [save_user_workspace] if you only need to save a single workspace.
|
||||
///
|
||||
pub fn save_all_user_workspaces(
|
||||
uid: i64,
|
||||
mut conn: DBConnection,
|
||||
user_workspaces: &[UserWorkspace],
|
||||
|
Reference in New Issue
Block a user