diff --git a/backend/src/config/const_define.rs b/backend/src/config/const_define.rs index a4bceecc15..bfd2aa6eac 100644 --- a/backend/src/config/const_define.rs +++ b/backend/src/config/const_define.rs @@ -4,4 +4,4 @@ pub const HEARTBEAT_INTERVAL: Duration = Duration::from_secs(8); pub const PING_TIMEOUT: Duration = Duration::from_secs(60); pub const MAX_PAYLOAD_SIZE: usize = 262_144; // max payload size is 256k -pub const IGNORE_ROUTES: [&str; 2] = ["/api/register", "/api/auth/"]; +pub const IGNORE_ROUTES: [&str; 2] = ["/api/register", "/api/auth"]; diff --git a/backend/src/middleware/auth_middleware.rs b/backend/src/middleware/auth_middleware.rs index 0036cbadbe..451c44206b 100644 --- a/backend/src/middleware/auth_middleware.rs +++ b/backend/src/middleware/auth_middleware.rs @@ -2,8 +2,6 @@ use crate::user_service::{LoggedUser, AUTHORIZED_USERS}; use actix_service::{Service, Transform}; use actix_web::{ dev::{ServiceRequest, ServiceResponse}, - http::{HeaderName, HeaderValue, Method}, - web::Data, Error, HttpResponse, ResponseError, @@ -11,15 +9,11 @@ use actix_web::{ use crate::config::IGNORE_ROUTES; use actix_web::{body::AnyBody, dev::MessageBody}; -use flowy_net::{config::HEADER_TOKEN, errors::ServerError, response::FlowyResponse}; -use futures::{ - future::{ok, LocalBoxFuture, Ready}, - Future, -}; +use flowy_net::{config::HEADER_TOKEN, errors::ServerError}; +use futures::future::{ok, LocalBoxFuture, Ready}; use std::{ convert::TryInto, error::Error as StdError, - pin::Pin, task::{Context, Poll}, }; @@ -59,7 +53,7 @@ where self.service.poll_ready(cx) } - fn call(&self, mut req: ServiceRequest) -> Self::Future { + fn call(&self, req: ServiceRequest) -> Self::Future { let mut authenticate_pass: bool = false; for ignore_route in IGNORE_ROUTES.iter() { if req.path().starts_with(ignore_route) { diff --git a/backend/src/workspace_service/app/app.rs b/backend/src/workspace_service/app/app.rs index 3131c80ebf..0a62856b0c 100644 --- a/backend/src/workspace_service/app/app.rs +++ b/backend/src/workspace_service/app/app.rs @@ -12,7 +12,7 @@ use crate::{ use anyhow::Context; use chrono::Utc; use flowy_net::errors::invalid_params; -use flowy_user::entities::parser::UserId; + use flowy_workspace::{ entities::{ app::parser::{AppDesc, AppName}, diff --git a/backend/src/workspace_service/workspace/router.rs b/backend/src/workspace_service/workspace/router.rs index ea5f8e336f..68770123e5 100644 --- a/backend/src/workspace_service/workspace/router.rs +++ b/backend/src/workspace_service/workspace/router.rs @@ -10,7 +10,7 @@ use crate::{ use crate::user_service::LoggedUser; use actix_web::{ - web::{Data, Path, Payload}, + web::{Data, Payload}, HttpResponse, }; use flowy_net::errors::ServerError; diff --git a/backend/src/workspace_service/workspace/workspace.rs b/backend/src/workspace_service/workspace/workspace.rs index ca0e8d60b4..727dd90e01 100644 --- a/backend/src/workspace_service/workspace/workspace.rs +++ b/backend/src/workspace_service/workspace/workspace.rs @@ -10,7 +10,6 @@ use flowy_net::{ errors::{invalid_params, ServerError}, response::FlowyResponse, }; -use flowy_user::entities::parser::UserId; use crate::{ user_service::LoggedUser, diff --git a/rust-lib/flowy-net/src/response/response_http.rs b/rust-lib/flowy-net/src/response/response_http.rs index dcd400eb3a..b5853f49bb 100644 --- a/rust-lib/flowy-net/src/response/response_http.rs +++ b/rust-lib/flowy-net/src/response/response_http.rs @@ -18,7 +18,7 @@ impl std::convert::Into for FlowyResponse { fn into(self) -> AnyBody { match serde_json::to_string(&self) { Ok(body) => AnyBody::from(body), - Err(err) => AnyBody::Empty, + Err(_) => AnyBody::Empty, } } } diff --git a/rust-lib/flowy-test/src/helper.rs b/rust-lib/flowy-test/src/helper.rs index 2776178142..12bc47aacf 100644 --- a/rust-lib/flowy-test/src/helper.rs +++ b/rust-lib/flowy-test/src/helper.rs @@ -44,7 +44,6 @@ pub(crate) fn create_default_workspace_if_need(user_id: &str) -> Result<(), User let payload: Bytes = CreateWorkspaceRequest { name: DEFAULT_WORKSPACE_NAME.to_string(), desc: DEFAULT_WORKSPACE_DESC.to_string(), - user_id: user_id.to_string(), } .into_bytes() .unwrap(); @@ -52,21 +51,12 @@ pub(crate) fn create_default_workspace_if_need(user_id: &str) -> Result<(), User let request = ModuleRequest::new(CreateWorkspace).payload(payload); let result = EventDispatch::sync_send(request) .parse::() - .map_err(|e| { - ErrorBuilder::new(ErrorCode::CreateDefaultWorkspaceFailed) - .error(e) - .build() - })?; + .map_err(|e| ErrorBuilder::new(ErrorCode::CreateDefaultWorkspaceFailed).error(e).build())?; - let workspace = result.map_err(|e| { - ErrorBuilder::new(ErrorCode::CreateDefaultWorkspaceFailed) - .error(e) - .build() - })?; + let workspace = result.map_err(|e| ErrorBuilder::new(ErrorCode::CreateDefaultWorkspaceFailed).error(e).build())?; let query: Bytes = QueryWorkspaceRequest { workspace_id: Some(workspace.id.clone()), - user_id: user_id.to_string(), } .into_bytes() .unwrap(); diff --git a/rust-lib/flowy-user/src/services/server/server_api.rs b/rust-lib/flowy-user/src/services/server/server_api.rs index 9760572edb..4fa39d1faa 100644 --- a/rust-lib/flowy-user/src/services/server/server_api.rs +++ b/rust-lib/flowy-user/src/services/server/server_api.rs @@ -6,7 +6,6 @@ use crate::{ use crate::{entities::UpdateUserParams, services::server::UserServerAPI}; use flowy_infra::future::ResultFuture; use flowy_net::{config::*, request::HttpRequestBuilder}; -use std::sync::Arc; pub struct UserServer {} impl UserServer { diff --git a/rust-lib/flowy-workspace/src/handlers/mod.rs b/rust-lib/flowy-workspace/src/handlers/mod.rs index 95ed7acdcb..ecd74014c6 100644 --- a/rust-lib/flowy-workspace/src/handlers/mod.rs +++ b/rust-lib/flowy-workspace/src/handlers/mod.rs @@ -2,6 +2,6 @@ mod app_handler; mod view_handler; mod workspace_handler; -pub use app_handler::*; -pub use view_handler::*; -pub use workspace_handler::*; +pub(crate) use app_handler::*; +pub(crate) use view_handler::*; +pub(crate) use workspace_handler::*; diff --git a/rust-lib/flowy-workspace/src/services/app_controller.rs b/rust-lib/flowy-workspace/src/services/app_controller.rs index 7affeb4b8a..0e7a9324db 100644 --- a/rust-lib/flowy-workspace/src/services/app_controller.rs +++ b/rust-lib/flowy-workspace/src/services/app_controller.rs @@ -7,7 +7,7 @@ use crate::{ sql_tables::app::{AppTable, AppTableChangeset, AppTableSql}, }; use flowy_dispatch::prelude::DispatchFuture; -use flowy_net::request::HttpRequestBuilder; + use std::sync::Arc; pub(crate) struct AppController { diff --git a/rust-lib/flowy-workspace/src/services/mod.rs b/rust-lib/flowy-workspace/src/services/mod.rs index 0f9da5c841..9f2f5750ec 100644 --- a/rust-lib/flowy-workspace/src/services/mod.rs +++ b/rust-lib/flowy-workspace/src/services/mod.rs @@ -1,6 +1,6 @@ -pub use app_controller::*; -pub use view_controller::*; -pub use workspace_controller::*; +pub(crate) use app_controller::*; +pub(crate) use view_controller::*; +pub(crate) use workspace_controller::*; mod app_controller; mod database; diff --git a/rust-lib/flowy-workspace/src/services/server/server_api_mock.rs b/rust-lib/flowy-workspace/src/services/server/server_api_mock.rs index 58a5208bbe..e7c481dcf3 100644 --- a/rust-lib/flowy-workspace/src/services/server/server_api_mock.rs +++ b/rust-lib/flowy-workspace/src/services/server/server_api_mock.rs @@ -59,7 +59,7 @@ impl WorkspaceServerAPI for WorkspaceServerMock { } fn read_view(&self, _token: &str, _params: QueryViewParams) -> ResultFuture, WorkspaceError> { - ResultFuture::new(async { Ok((None)) }) + ResultFuture::new(async { Ok(None) }) } fn delete_view(&self, _token: &str, _params: DeleteViewParams) -> ResultFuture<(), WorkspaceError> { diff --git a/rust-lib/flowy-workspace/src/services/view_controller.rs b/rust-lib/flowy-workspace/src/services/view_controller.rs index a5c9c1a710..c68502bd7f 100644 --- a/rust-lib/flowy-workspace/src/services/view_controller.rs +++ b/rust-lib/flowy-workspace/src/services/view_controller.rs @@ -1,12 +1,12 @@ use crate::{ - entities::view::{CreateViewParams, DeleteViewParams, QueryViewParams, UpdateViewParams, View}, + entities::view::{CreateViewParams, UpdateViewParams, View}, errors::WorkspaceError, module::WorkspaceDatabase, observable::{send_observable, WorkspaceObservable}, services::server::Server, sql_tables::view::{ViewTable, ViewTableChangeset, ViewTableSql}, }; -use flowy_net::request::HttpRequestBuilder; + use std::sync::Arc; pub(crate) struct ViewController { diff --git a/rust-lib/flowy-workspace/src/services/workspace_controller.rs b/rust-lib/flowy-workspace/src/services/workspace_controller.rs index 02728fa9b4..7ea0ed18f0 100644 --- a/rust-lib/flowy-workspace/src/services/workspace_controller.rs +++ b/rust-lib/flowy-workspace/src/services/workspace_controller.rs @@ -8,8 +8,8 @@ use crate::{ }; use flowy_dispatch::prelude::DispatchFuture; use flowy_infra::kv::KVStore; -use flowy_net::request::HttpRequestBuilder; -use std::{future::Future, sync::Arc}; + +use std::sync::Arc; pub(crate) struct WorkspaceController { pub user: Arc, diff --git a/rust-lib/flowy-workspace/tests/event/helper.rs b/rust-lib/flowy-workspace/tests/event/helper.rs index f0943255fa..bd09bea84c 100644 --- a/rust-lib/flowy-workspace/tests/event/helper.rs +++ b/rust-lib/flowy-workspace/tests/event/helper.rs @@ -18,14 +18,9 @@ pub fn create_workspace(name: &str, desc: &str) -> (String, Workspace) { let request = CreateWorkspaceRequest { name: name.to_owned(), desc: desc.to_owned(), - user_id: user_id.clone(), }; - let workspace = builder - .event(CreateWorkspace) - .request(request) - .sync_send() - .parse::(); + let workspace = builder.event(CreateWorkspace).request(request).sync_send().parse::(); (user_id, workspace) } @@ -38,10 +33,7 @@ pub fn read_workspaces(request: QueryWorkspaceRequest) -> Option { .parse::(); debug_assert_eq!(repeated_workspace.len(), 1); - repeated_workspace - .drain(..1) - .collect::>() - .pop() + repeated_workspace.drain(..1).collect::>().pop() } pub fn create_app(name: &str, desc: &str, workspace_id: &str) -> App { @@ -65,25 +57,13 @@ pub fn delete_app(app_id: &str) { app_id: app_id.to_string(), }; - AnnieTestBuilder::new() - .event(DeleteApp) - .request(delete_app_request) - .sync_send(); + AnnieTestBuilder::new().event(DeleteApp).request(delete_app_request).sync_send(); } -pub fn update_app(request: UpdateAppRequest) { - AnnieTestBuilder::new() - .event(UpdateApp) - .request(request) - .sync_send(); -} +pub fn update_app(request: UpdateAppRequest) { AnnieTestBuilder::new().event(UpdateApp).request(request).sync_send(); } pub fn read_app(request: QueryAppRequest) -> App { - let app = AnnieTestBuilder::new() - .event(ReadApp) - .request(request) - .sync_send() - .parse::(); + let app = AnnieTestBuilder::new().event(ReadApp).request(request).sync_send().parse::(); app } @@ -112,17 +92,6 @@ pub fn create_view() -> View { create_view_with_request(request) } -pub fn update_view(request: UpdateViewRequest) { - AnnieTestBuilder::new() - .event(UpdateView) - .request(request) - .sync_send(); -} +pub fn update_view(request: UpdateViewRequest) { AnnieTestBuilder::new().event(UpdateView).request(request).sync_send(); } -pub fn read_view(request: QueryViewRequest) -> View { - AnnieTestBuilder::new() - .event(ReadView) - .request(request) - .sync_send() - .parse::() -} +pub fn read_view(request: QueryViewRequest) -> View { AnnieTestBuilder::new().event(ReadView).request(request).sync_send().parse::() } diff --git a/rust-lib/flowy-workspace/tests/event/workspace_test.rs b/rust-lib/flowy-workspace/tests/event/workspace_test.rs index 2df7aca428..d3df4827d8 100644 --- a/rust-lib/flowy-workspace/tests/event/workspace_test.rs +++ b/rust-lib/flowy-workspace/tests/event/workspace_test.rs @@ -10,11 +10,8 @@ fn workspace_create_success() { let _ = create_workspace("First workspace", ""); #[test] fn workspace_read_all() { - let (user_id, _) = create_workspace( - "Workspace A", - "workspace_create_and_then_get_workspace_success", - ); - let request = QueryWorkspaceRequest::new(&user_id); + let (_, _) = create_workspace("Workspace A", "workspace_create_and_then_get_workspace_success"); + let request = QueryWorkspaceRequest::new(); let workspaces = AnnieTestBuilder::new() .event(ReadWorkspaces) .request(request) @@ -26,21 +23,18 @@ fn workspace_read_all() { #[test] fn workspace_create_and_then_get_workspace() { - let (user_id, workspace) = create_workspace( - "Workspace A", - "workspace_create_and_then_get_workspace_success", - ); - let request = QueryWorkspaceRequest::new(&user_id).workspace_id(&workspace.id); + let (_user_id, workspace) = create_workspace("Workspace A", "workspace_create_and_then_get_workspace_success"); + let request = QueryWorkspaceRequest::new().workspace_id(&workspace.id); let workspace_from_db = read_workspaces(request).unwrap(); assert_eq!(workspace.name, workspace_from_db.name); } #[test] fn workspace_create_with_apps() { - let (user_id, workspace) = create_workspace("Workspace", ""); + let (_user_id, workspace) = create_workspace("Workspace", ""); let app = create_app("App A", "AppFlowy Github Project", &workspace.id); - let request = QueryWorkspaceRequest::new(&user_id).workspace_id(&workspace.id); + let request = QueryWorkspaceRequest::new().workspace_id(&workspace.id); let workspace_from_db = read_workspaces(request).unwrap(); assert_eq!(&app, workspace_from_db.apps.first_or_crash()); } @@ -49,21 +43,10 @@ fn workspace_create_with_apps() { fn workspace_create_with_invalid_name() { for name in invalid_workspace_name_test_case() { let builder = AnnieTestBuilder::new(); - let user_id = builder.user_detail.as_ref().unwrap().id.clone(); - - let request = CreateWorkspaceRequest { - name, - desc: "".to_owned(), - user_id: user_id.clone(), - }; + let request = CreateWorkspaceRequest { name, desc: "".to_owned() }; assert_eq!( - builder - .event(CreateWorkspace) - .request(request) - .sync_send() - .error() - .code, + builder.event(CreateWorkspace).request(request).sync_send().error().code, ErrorCode::WorkspaceNameInvalid ) } @@ -73,21 +56,10 @@ fn workspace_create_with_invalid_name() { fn workspace_update_with_invalid_name() { for name in invalid_workspace_name_test_case() { let builder = AnnieTestBuilder::new(); - let user_id = builder.user_detail.as_ref().unwrap().id.clone(); - - let request = CreateWorkspaceRequest { - name, - desc: "".to_owned(), - user_id: user_id.clone(), - }; + let request = CreateWorkspaceRequest { name, desc: "".to_owned() }; assert_eq!( - builder - .event(CreateWorkspace) - .request(request) - .sync_send() - .error() - .code, + builder.event(CreateWorkspace).request(request).sync_send().error().code, ErrorCode::WorkspaceNameInvalid ) }