diff --git a/ee/tabby-db/src/users.rs b/ee/tabby-db/src/users.rs index c7add2dfa056..347415e04735 100644 --- a/ee/tabby-db/src/users.rs +++ b/ee/tabby-db/src/users.rs @@ -125,20 +125,10 @@ impl DbConn { pub async fn list_users_with_filter( &self, - emails: Option>, limit: Option, skip_id: Option, backwards: bool, ) -> Result> { - let email_condition = emails.map(|emails| { - let emails = emails - .into_iter() - .map(|e| format!("'{}'", e)) - .collect::>() - .join(", "); - format!("email in ({emails})") - }); - let users = query_paged_as!( UserDAO, "users", @@ -155,8 +145,7 @@ impl DbConn { ], limit, skip_id, - backwards, - email_condition + backwards ) .fetch_all(&self.pool) .await?; @@ -410,7 +399,7 @@ mod tests { assert_eq!( empty, to_ids( - conn.list_users_with_filter(None, None, None, false) + conn.list_users_with_filter(None, None, false) .await .unwrap() ) @@ -418,7 +407,7 @@ mod tests { assert_eq!( empty, to_ids( - conn.list_users_with_filter(None, Some(2), None, false) + conn.list_users_with_filter(Some(2), None, false) .await .unwrap() ) @@ -426,7 +415,7 @@ mod tests { assert_eq!( empty, to_ids( - conn.list_users_with_filter(None, None, Some(1), false) + conn.list_users_with_filter(None, Some(1), false) .await .unwrap() ) @@ -434,7 +423,7 @@ mod tests { assert_eq!( empty, to_ids( - conn.list_users_with_filter(None, Some(2), Some(1), false) + conn.list_users_with_filter(Some(2), Some(1), false) .await .unwrap() ) @@ -442,16 +431,12 @@ mod tests { // backwards assert_eq!( empty, - to_ids( - conn.list_users_with_filter(None, None, None, true) - .await - .unwrap() - ) + to_ids(conn.list_users_with_filter(None, None, true).await.unwrap()) ); assert_eq!( empty, to_ids( - conn.list_users_with_filter(None, Some(2), None, true) + conn.list_users_with_filter(Some(2), None, true) .await .unwrap() ) @@ -459,7 +444,7 @@ mod tests { assert_eq!( empty, to_ids( - conn.list_users_with_filter(None, None, Some(1), true) + conn.list_users_with_filter(None, Some(1), true) .await .unwrap() ) @@ -467,7 +452,7 @@ mod tests { assert_eq!( empty, to_ids( - conn.list_users_with_filter(None, Some(1), Some(1), true) + conn.list_users_with_filter(Some(1), Some(1), true) .await .unwrap() ) @@ -488,7 +473,7 @@ mod tests { assert_eq!( vec![id1], to_ids( - conn.list_users_with_filter(None, None, None, false) + conn.list_users_with_filter(None, None, false) .await .unwrap() ) @@ -496,7 +481,7 @@ mod tests { assert_eq!( vec![id1], to_ids( - conn.list_users_with_filter(None, Some(2), None, false) + conn.list_users_with_filter(Some(2), None, false) .await .unwrap() ) @@ -504,7 +489,7 @@ mod tests { assert_eq!( empty, to_ids( - conn.list_users_with_filter(None, None, Some(1), false) + conn.list_users_with_filter(None, Some(1), false) .await .unwrap() ) @@ -512,7 +497,7 @@ mod tests { assert_eq!( empty, to_ids( - conn.list_users_with_filter(None, Some(2), Some(1), false) + conn.list_users_with_filter(Some(2), Some(1), false) .await .unwrap() ) @@ -520,16 +505,12 @@ mod tests { // backwards assert_eq!( vec![id1], - to_ids( - conn.list_users_with_filter(None, None, None, true) - .await - .unwrap() - ) + to_ids(conn.list_users_with_filter(None, None, true).await.unwrap()) ); assert_eq!( vec![id1], to_ids( - conn.list_users_with_filter(None, Some(2), None, true) + conn.list_users_with_filter(Some(2), None, true) .await .unwrap() ) @@ -537,7 +518,7 @@ mod tests { assert_eq!( empty, to_ids( - conn.list_users_with_filter(None, None, Some(1), true) + conn.list_users_with_filter(None, Some(1), true) .await .unwrap() ) @@ -545,55 +526,12 @@ mod tests { assert_eq!( empty, to_ids( - conn.list_users_with_filter(None, Some(1), Some(1), true) + conn.list_users_with_filter(Some(1), Some(1), true) .await .unwrap() ) ); - // by email - assert_eq!( - vec![id1], - to_ids( - conn.list_users_with_filter( - Some(vec!["use1@example.com".into()]), - None, - None, - true - ) - .await - .unwrap() - ) - ); - - assert_eq!( - vec![id1], - to_ids( - conn.list_users_with_filter( - Some(vec!["use1@example.com".into()]), - Some(1), - None, - true - ) - .await - .unwrap() - ) - ); - - assert_eq!( - empty, - to_ids( - conn.list_users_with_filter( - Some(vec!["notexisted@example.com".into()]), - None, - None, - true - ) - .await - .unwrap() - ) - ); - let id2 = conn .create_user( "use2@example.com".into(), @@ -636,7 +574,7 @@ mod tests { assert_eq!( vec![id1, id2, id3, id4, id5], to_ids( - conn.list_users_with_filter(None, None, None, false) + conn.list_users_with_filter(None, None, false) .await .unwrap() ) @@ -644,7 +582,7 @@ mod tests { assert_eq!( vec![id1, id2], to_ids( - conn.list_users_with_filter(None, Some(2), None, false) + conn.list_users_with_filter(Some(2), None, false) .await .unwrap() ) @@ -652,7 +590,7 @@ mod tests { assert_eq!( vec![id3, id4, id5], to_ids( - conn.list_users_with_filter(None, None, Some(2), false) + conn.list_users_with_filter(None, Some(2), false) .await .unwrap() ) @@ -660,7 +598,7 @@ mod tests { assert_eq!( vec![id3, id4], to_ids( - conn.list_users_with_filter(None, Some(2), Some(2), false) + conn.list_users_with_filter(Some(2), Some(2), false) .await .unwrap() ) @@ -668,16 +606,12 @@ mod tests { // backwards assert_eq!( vec![id1, id2, id3, id4, id5], - to_ids( - conn.list_users_with_filter(None, None, None, true) - .await - .unwrap() - ) + to_ids(conn.list_users_with_filter(None, None, true).await.unwrap()) ); assert_eq!( vec![id4, id5], to_ids( - conn.list_users_with_filter(None, Some(2), None, true) + conn.list_users_with_filter(Some(2), None, true) .await .unwrap() ) @@ -685,7 +619,7 @@ mod tests { assert_eq!( vec![id1, id2, id3], to_ids( - conn.list_users_with_filter(None, None, Some(4), true) + conn.list_users_with_filter(None, Some(4), true) .await .unwrap() ) @@ -693,26 +627,11 @@ mod tests { assert_eq!( vec![id2, id3], to_ids( - conn.list_users_with_filter(None, Some(2), Some(4), true) + conn.list_users_with_filter(Some(2), Some(4), true) .await .unwrap() ) ); - - // by email - assert_eq!( - vec![id2, id3], - to_ids( - conn.list_users_with_filter( - Some(vec!["use2@example.com".into(), "use3@example.com".into()]), - None, - None, - false - ) - .await - .unwrap() - ) - ); } #[tokio::test] diff --git a/ee/tabby-schema/graphql/schema.graphql b/ee/tabby-schema/graphql/schema.graphql index 2edf2abdff18..97c59b64c9d0 100644 --- a/ee/tabby-schema/graphql/schema.graphql +++ b/ee/tabby-schema/graphql/schema.graphql @@ -678,7 +678,7 @@ type Query { registrationToken: String! me: UserSecured! "List users, accessible for all login users." - users(emails: [String!], after: String, before: String, first: Int, last: Int): UserConnection! + users(after: String, before: String, first: Int, last: Int): UserConnection! invitations(after: String, before: String, first: Int, last: Int): InvitationConnection! jobRuns(ids: [ID!], jobs: [String!], after: String, before: String, first: Int, last: Int): JobRunConnection! jobRunStats(jobs: [String!]): JobStats! diff --git a/ee/tabby-schema/src/schema/auth.rs b/ee/tabby-schema/src/schema/auth.rs index 8956ce628e9a..c05ed1b6d27b 100644 --- a/ee/tabby-schema/src/schema/auth.rs +++ b/ee/tabby-schema/src/schema/auth.rs @@ -386,7 +386,6 @@ pub trait AuthenticationService: Send + Sync { async fn list_users( &self, - emails: Option>, after: Option, before: Option, first: Option, diff --git a/ee/tabby-schema/src/schema/mod.rs b/ee/tabby-schema/src/schema/mod.rs index 3d6a1826b82c..504b9ef0a02a 100644 --- a/ee/tabby-schema/src/schema/mod.rs +++ b/ee/tabby-schema/src/schema/mod.rs @@ -265,7 +265,6 @@ impl Query { /// List users, accessible for all login users. async fn users( ctx: &Context, - emails: Option>, after: Option, before: Option, first: Option, @@ -280,7 +279,7 @@ impl Query { |after, before, first, last| async move { ctx.locator .auth() - .list_users(emails, after, before, first, last) + .list_users(after, before, first, last) .await .map(|users| users.into_iter().map(UserValue::UserSecured).collect()) }, diff --git a/ee/tabby-webserver/src/service/auth.rs b/ee/tabby-webserver/src/service/auth.rs index 5740aafcf362..8df4f01f4f15 100644 --- a/ee/tabby-webserver/src/service/auth.rs +++ b/ee/tabby-webserver/src/service/auth.rs @@ -450,7 +450,6 @@ impl AuthenticationService for AuthenticationServiceImpl { async fn list_users( &self, - emails: Option>, after: Option, before: Option, first: Option, @@ -460,7 +459,7 @@ impl AuthenticationService for AuthenticationServiceImpl { Ok(self .db - .list_users_with_filter(emails, skip_id, limit, backwards) + .list_users_with_filter(skip_id, limit, backwards) .await? .into_iter() .map(|x| UserSecured::new(self.db.clone(), x)) @@ -982,7 +981,6 @@ mod tests { async fn list_users( db: &AuthenticationServiceImpl, - emails: Option>, after: Option, before: Option, first: Option, @@ -994,10 +992,7 @@ mod tests { first, last, |after, before, first, last| async move { - Ok(db - .list_users(emails, after, before, first, last) - .await - .unwrap()) + Ok(db.list_users(after, before, first, last).await.unwrap()) }, ) .await @@ -1293,14 +1288,13 @@ mod tests { .await .unwrap(); - let all_users = list_users(&service, None, None, None, None, None).await; + let all_users = list_users(&service, None, None, None, None).await; assert!(!all_users.page_info.has_next_page); assert!(!all_users.page_info.has_previous_page); let users = list_users( &service, - None, Some(all_users.edges[0].cursor.clone()), None, None, @@ -1311,7 +1305,7 @@ mod tests { assert!(!users.page_info.has_next_page); assert!(users.page_info.has_previous_page); - let users = list_users(&service, None, None, None, Some(2), None).await; + let users = list_users(&service, None, None, Some(2), None).await; assert!(users.page_info.has_next_page); assert!(!users.page_info.has_previous_page); @@ -1319,7 +1313,6 @@ mod tests { let users = list_users( &service, None, - None, Some(all_users.edges[1].cursor.clone()), None, Some(1), @@ -1331,7 +1324,6 @@ mod tests { let users = list_users( &service, - None, Some(all_users.edges[2].cursor.clone()), None, None, @@ -1341,13 +1333,12 @@ mod tests { assert!(!users.page_info.has_next_page); assert!(users.page_info.has_previous_page); - let users = list_users(&service, None, None, None, Some(3), None).await; + let users = list_users(&service, None, None, Some(3), None).await; assert!(!users.page_info.has_next_page); assert!(!users.page_info.has_previous_page); let users = list_users( &service, - None, Some(all_users.edges[0].cursor.clone()), None, Some(2), @@ -1358,65 +1349,6 @@ mod tests { assert!(users.page_info.has_previous_page); } - #[tokio::test] - async fn test_users_by_emails() { - let service = test_authentication_service().await; - let name1 = "User1"; - let name2 = "User2"; - let name3 = "User3"; - service - .db - .create_user( - "a@example.com".into(), - Some("pass".into()), - false, - Some(name1.into()), - ) - .await - .unwrap(); - service - .db - .create_user( - "b@example.com".into(), - Some("pass".into()), - false, - Some(name2.into()), - ) - .await - .unwrap(); - service - .db - .create_user( - "c@example.com".into(), - Some("pass".into()), - false, - Some(name3.into()), - ) - .await - .unwrap(); - - let cases = vec![ - (vec![name1, name2, name3], None), - ( - vec![name2, name3], - Some(vec!["b@example.com".into(), "c@example.com".into()]), - ), - (vec![name2], Some(vec!["b@example.com".into()])), - ]; - - for (expected, emails) in cases { - let users = list_users(&service, emails, None, None, None, None).await; - assert_eq!(users.edges.len(), expected.len()); - let mut names = users - .edges - .into_iter() - .map(|x| x.node.name.clone()) - .collect::>(); - names.sort(); - assert_eq!(names, expected); - } - } - #[tokio::test] #[serial] async fn test_allow_self_signup() {