Remove deprecated add member (#5611)

* chore: remove deprecated add member directly

* chore: cargo clippy

* chore: cargo clippy

* chore: cargo clippy
This commit is contained in:
Zack 2024-06-24 14:19:36 +08:00 committed by GitHub
parent 7586a0ed48
commit d2ca41c8f5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 65 additions and 127 deletions

View File

@ -94,7 +94,7 @@ validator = { version = "0.16.1", features = ["derive"] }
# Please using the following command to update the revision id
# Current directory: frontend
# Run the script.add_workspace_members:
# Run the script:
# scripts/tool/update_client_api_rev.sh new_rev_id
# ⚠️⚠️⚠️️
client-api = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "6262816043efeede8823d7a7ea252083adf407e9" }

View File

@ -7,7 +7,7 @@ use flowy_folder::event_map::FolderEvent::*;
use flowy_folder::{entities::*, ViewLayout};
use flowy_search::services::manager::{SearchHandler, SearchType};
use flowy_user::entities::{
AcceptWorkspaceInvitationPB, AddWorkspaceMemberPB, QueryWorkspacePB, RemoveWorkspaceMemberPB,
AcceptWorkspaceInvitationPB, QueryWorkspacePB, RemoveWorkspaceMemberPB,
RepeatedWorkspaceInvitationPB, RepeatedWorkspaceMemberPB, WorkspaceMemberInvitationPB,
WorkspaceMemberPB,
};
@ -19,21 +19,6 @@ use crate::event_builder::EventBuilder;
use crate::EventIntegrationTest;
impl EventIntegrationTest {
pub async fn add_workspace_member(&self, workspace_id: &str, email: &str) {
if let Some(err) = EventBuilder::new(self.clone())
.event(UserEvent::AddWorkspaceMember)
.payload(AddWorkspaceMemberPB {
workspace_id: workspace_id.to_string(),
email: email.to_string(),
})
.async_send()
.await
.error()
{
panic!("Add workspace member failed: {:?}", err);
}
}
pub async fn invite_workspace_member(&self, workspace_id: &str, email: &str, role: Role) {
EventBuilder::new(self.clone())
.event(UserEvent::InviteWorkspaceMember)
@ -46,6 +31,26 @@ impl EventIntegrationTest {
.await;
}
// convenient function to add workspace member by inviting and accepting the invitation
pub async fn add_workspace_member(&self, workspace_id: &str, other: &EventIntegrationTest) {
let other_email = other.get_user_profile().await.unwrap().email;
self
.invite_workspace_member(workspace_id, &other_email, Role::Member)
.await;
let invitations = other.list_workspace_invitations().await;
let target_invi = invitations
.items
.into_iter()
.find(|i| i.workspace_id == workspace_id)
.unwrap();
other
.accept_workspace_invitation(&target_invi.invite_id)
.await;
}
pub async fn list_workspace_invitations(&self) -> RepeatedWorkspaceInvitationPB {
EventBuilder::new(self.clone())
.event(UserEvent::ListWorkspaceInvitations)

View File

@ -26,10 +26,8 @@ async fn af_cloud_upload_file_test() {
.unwrap();
while let Ok(result) = rx.recv().await {
if result.file_id == created_upload.file_id {
if result.status == UploadStatus::Finish {
break;
}
if result.file_id == created_upload.file_id && result.status == UploadStatus::Finish {
break;
}
}
@ -54,10 +52,8 @@ async fn af_cloud_upload_big_file_test() {
let mut rx = test.storage_manager.subscribe_upload_result();
while let Ok(result) = rx.recv().await {
if result.file_id == created_upload.file_id {
if result.status == UploadStatus::InProgress {
break;
}
if result.file_id == created_upload.file_id && result.status == UploadStatus::InProgress {
break;
}
}
@ -71,10 +67,8 @@ async fn af_cloud_upload_big_file_test() {
let test = EventIntegrationTest::new_with_config(config).await;
let mut rx = test.storage_manager.subscribe_upload_result();
while let Ok(result) = rx.recv().await {
if result.file_id == created_upload.file_id {
if result.status == UploadStatus::Finish {
break;
}
if result.file_id == created_upload.file_id && result.status == UploadStatus::Finish {
break;
}
}
@ -101,7 +95,7 @@ async fn af_cloud_upload_6_files_test() {
let mut rx = test.storage_manager.subscribe_upload_result();
let mut created_uploads = vec![];
for file_size in vec![1, 2, 5, 8, 12, 20] {
for file_size in [1, 2, 5, 8, 12, 20] {
let file_path = generate_file_with_bytes_len(file_size * 1024 * 1024)
.await
.0;

View File

@ -47,7 +47,7 @@ async fn af_cloud_add_workspace_member_test() {
assert_eq!(members[0].email, user_1.email);
test_1
.add_workspace_member(&user_1.workspace_id, &user_2.email)
.add_workspace_member(&user_1.workspace_id, &test_2)
.await;
let members = test_1.get_workspace_members(&user_1.workspace_id).await;
@ -66,7 +66,7 @@ async fn af_cloud_delete_workspace_member_test() {
let user_2 = test_2.af_cloud_sign_up().await;
test_1
.add_workspace_member(&user_1.workspace_id, &user_2.email)
.add_workspace_member(&user_1.workspace_id, &test_2)
.await;
test_1
@ -88,7 +88,7 @@ async fn af_cloud_leave_workspace_test() {
let user_2 = test_2.af_cloud_sign_up().await;
test_1
.add_workspace_member(&user_1.workspace_id, &user_2.email)
.add_workspace_member(&user_1.workspace_id, &test_2)
.await;
// test_2 should have 2 workspace

View File

@ -182,7 +182,7 @@ async fn af_cloud_different_open_same_workspace_test() {
}
client_1
.add_workspace_member(&owner_profile.workspace_id, &client_profile.email)
.add_workspace_member(&owner_profile.workspace_id, &client)
.await;
clients.push((client, client_profile));
}

View File

@ -6,8 +6,7 @@ use client_api::entity::billing_dto::{
SubscriptionPlan, SubscriptionStatus, WorkspaceSubscriptionPlan, WorkspaceSubscriptionStatus,
};
use client_api::entity::workspace_dto::{
CreateWorkspaceMember, CreateWorkspaceParam, PatchWorkspaceParam, WorkspaceMemberChangeset,
WorkspaceMemberInvitation,
CreateWorkspaceParam, PatchWorkspaceParam, WorkspaceMemberChangeset, WorkspaceMemberInvitation,
};
use client_api::entity::{
AFRole, AFWorkspace, AFWorkspaceInvitation, AuthProvider, CollabParams, CreateCollabParams,
@ -222,28 +221,6 @@ where
})
}
#[allow(deprecated)]
fn add_workspace_member(
&self,
user_email: String,
workspace_id: String,
) -> FutureResult<(), FlowyError> {
let try_get_client = self.server.try_get_client();
FutureResult::new(async move {
// TODO(zack): add_workspace_members will be deprecated after finishing the invite logic. Don't forget to remove the #[allow(deprecated)]
try_get_client?
.add_workspace_members(
workspace_id,
vec![CreateWorkspaceMember {
email: user_email,
role: AFRole::Member,
}],
)
.await?;
Ok(())
})
}
fn invite_workspace_member(
&self,
invitee_email: String,

View File

@ -102,13 +102,13 @@ diesel::table! {
}
diesel::allow_tables_to_appear_in_same_query!(
chat_message_table,
chat_table,
collab_snapshot,
upload_file_part,
upload_file_table,
user_data_migration_records,
user_table,
user_workspace_table,
workspace_members_table,
chat_message_table,
chat_table,
collab_snapshot,
upload_file_part,
upload_file_table,
user_data_migration_records,
user_table,
user_workspace_table,
workspace_members_table,
);

View File

@ -314,12 +314,12 @@ impl StorageService for StorageServiceImpl {
// When resuming an upload, check if the upload_id is empty.
// If the upload_id is empty, the upload has likely not been created yet.
// If the upload_id is not empty, verify which parts have already been uploaded.
select_upload_file(conn, &workspace_id, &parent_dir, &file_id)?.and_then(|record| {
select_upload_file(conn, workspace_id, parent_dir, file_id)?.map(|record| {
if record.upload_id.is_empty() {
Some((record, vec![]))
(record, vec![])
} else {
let parts = select_upload_parts(conn, &record.upload_id).unwrap_or_default();
Some((record, parts))
(record, parts)
}
}),
)
@ -358,7 +358,7 @@ async fn create_upload_record(
let content_type = mime_guess::from_path(&local_file_path)
.first_or_octet_stream()
.to_string();
let file_id = format!("{}.{}", fxhash::hash(&chunked_bytes.data).to_string(), ext);
let file_id = format!("{}.{}", fxhash::hash(&chunked_bytes.data), ext);
let record = UploadFileTable {
workspace_id,
file_id,
@ -430,10 +430,10 @@ async fn start_upload(
upload_file.file_id,
chunked_bytes.iter().count()
);
let mut iter = chunked_bytes.iter().enumerate();
let iter = chunked_bytes.iter().enumerate();
let mut completed_parts = Vec::new();
while let Some((index, chunk_bytes)) = iter.next() {
for (index, chunk_bytes) in iter {
let part_number = index as i32 + 1;
trace!(
"[File] {} uploading part: {}, len:{}KB",
@ -443,8 +443,8 @@ async fn start_upload(
);
// start uploading parts
match upload_part(
&cloud_service,
&user_service,
cloud_service,
user_service,
&upload_file.workspace_id,
&upload_file.parent_dir,
&upload_file.upload_id,
@ -476,8 +476,8 @@ async fn start_upload(
// mark it as completed
complete_upload(
&cloud_service,
&user_service,
cloud_service,
user_service,
temp_storage,
&upload_file,
completed_parts,
@ -540,6 +540,7 @@ async fn resume_upload(
Ok(())
}
#[allow(clippy::too_many_arguments)]
#[instrument(level = "debug", skip_all)]
async fn upload_part(
cloud_service: &Arc<dyn StorageCloudService>,
@ -553,10 +554,10 @@ async fn upload_part(
) -> Result<UploadPartResponse, FlowyError> {
let resp = cloud_service
.upload_part(
&workspace_id,
&parent_dir,
&upload_id,
&file_id,
workspace_id,
parent_dir,
upload_id,
file_id,
part_number,
body,
)

View File

@ -13,7 +13,7 @@ use std::path::PathBuf;
use std::time::Duration;
pub fn test_database() -> (Database, PathBuf) {
let db_path = temp_dir().join(&format!("test-{}.db", generate_random_string(8)));
let db_path = temp_dir().join(format!("test-{}.db", generate_random_string(8)));
(flowy_sqlite::init(&db_path).unwrap(), db_path)
}
@ -102,7 +102,7 @@ async fn test_upload_part_test() {
// get all existing parts
let mut conn = db.get_connection().unwrap();
let parts = select_upload_parts(&mut *conn, &upload_id).unwrap();
let parts = select_upload_parts(&mut conn, &upload_id).unwrap();
assert_eq!(parts.len(), 2);
assert_eq!(parts[0].part_num, 1);
assert_eq!(parts[1].part_num, 2);
@ -112,7 +112,7 @@ async fn test_upload_part_test() {
delete_upload_file(conn, &upload_id).unwrap();
let mut conn = db.get_connection().unwrap();
let parts = select_upload_parts(&mut *conn, &upload_id).unwrap();
let parts = select_upload_parts(&mut conn, &upload_id).unwrap();
assert!(parts.is_empty())
}
@ -165,7 +165,7 @@ pub async fn create_upload_file_record(
let file_id = fxhash::hash(&chunked_bytes.data).to_string();
// Create UploadFileTable record
let upload_file = UploadFileTable {
UploadFileTable {
workspace_id,
file_id,
upload_id,
@ -175,7 +175,5 @@ pub async fn create_upload_file_record(
chunk_size: MIN_CHUNK_SIZE as i32,
num_chunk: chunked_bytes.offsets.len() as i32,
created_at: chrono::Utc::now().timestamp(),
};
upload_file
}
}

View File

@ -178,15 +178,6 @@ pub trait UserCloudService: Send + Sync + 'static {
/// Deletes a workspace owned by the user.
fn delete_workspace(&self, workspace_id: &str) -> FutureResult<(), FlowyError>;
// Deprecated, use invite instead
fn add_workspace_member(
&self,
user_email: String,
workspace_id: String,
) -> FutureResult<(), FlowyError> {
FutureResult::new(async { Ok(()) })
}
fn invite_workspace_member(
&self,
invitee_email: String,

View File

@ -98,6 +98,7 @@ pub struct AcceptWorkspaceInvitationPB {
pub invite_id: String,
}
// Deprecated
#[derive(ProtoBuf, Default, Clone, Validate)]
pub struct AddWorkspaceMemberPB {
#[pb(index = 1)]

View File

@ -623,19 +623,6 @@ pub async fn update_reminder_event_handler(
Ok(())
}
#[tracing::instrument(level = "debug", skip_all, err)]
pub async fn add_workspace_member_handler(
data: AFPluginData<AddWorkspaceMemberPB>,
manager: AFPluginState<Weak<UserManager>>,
) -> Result<(), FlowyError> {
let data = data.try_into_inner()?;
let manager = upgrade_manager(manager)?;
manager
.add_workspace_member(data.email, data.workspace_id)
.await?;
Ok(())
}
#[tracing::instrument(level = "debug", skip_all, err)]
pub async fn delete_workspace_member_handler(
data: AFPluginData<RemoveWorkspaceMemberPB>,

View File

@ -54,9 +54,6 @@ pub fn init(user_manager: Weak<UserManager>) -> AFPlugin {
.event(UserEvent::SetNotificationSettings, set_notification_settings)
.event(UserEvent::GetNotificationSettings, get_notification_settings)
.event(UserEvent::ImportAppFlowyDataFolder, import_appflowy_data_folder_handler)
// Workspace member
.event(UserEvent::AddWorkspaceMember, add_workspace_member_handler) // deprecated, use invite
// instead
.event(UserEvent::GetMemberInfo, get_workspace_member_info)
.event(UserEvent::RemoveWorkspaceMember, delete_workspace_member_handler)
.event(UserEvent::GetWorkspaceMembers, get_workspace_members_handler)
@ -196,6 +193,7 @@ pub enum UserEvent {
#[event(output = "NotificationSettingsPB")]
GetNotificationSettings = 36,
// Deprecated
#[event(input = "AddWorkspaceMemberPB")]
AddWorkspaceMember = 37,

View File

@ -327,20 +327,6 @@ impl UserManager {
Ok(())
}
// deprecated, use invite instead
pub async fn add_workspace_member(
&self,
user_email: String,
workspace_id: String,
) -> FlowyResult<()> {
self
.cloud_services
.get_user_service()?
.add_workspace_member(user_email, workspace_id)
.await?;
Ok(())
}
pub async fn remove_workspace_member(
&self,
user_email: String,