Skip to content

Commit

Permalink
Revert "feat(graphQL): support list users by email (#3529)" (#3532)
Browse files Browse the repository at this point in the history
This reverts commit 0a57a66.
  • Loading branch information
wsxiaoys authored Dec 10, 2024
1 parent 4c44c93 commit 8e02a2c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 183 deletions.
131 changes: 25 additions & 106 deletions ee/tabby-db/src/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,10 @@ impl DbConn {

pub async fn list_users_with_filter(
&self,
emails: Option<Vec<String>>,
limit: Option<usize>,
skip_id: Option<i32>,
backwards: bool,
) -> Result<Vec<UserDAO>> {
let email_condition = emails.map(|emails| {
let emails = emails
.into_iter()
.map(|e| format!("'{}'", e))
.collect::<Vec<_>>()
.join(", ");
format!("email in ({emails})")
});

let users = query_paged_as!(
UserDAO,
"users",
Expand All @@ -155,8 +145,7 @@ impl DbConn {
],
limit,
skip_id,
backwards,
email_condition
backwards
)
.fetch_all(&self.pool)
.await?;
Expand Down Expand Up @@ -410,64 +399,60 @@ 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()
)
);
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()
)
);
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()
)
);
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()
)
);
// 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()
)
);
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()
)
);
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()
)
Expand All @@ -488,112 +473,65 @@ 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()
)
);
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()
)
);
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()
)
);
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()
)
);
// 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()
)
);
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()
)
);
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!["[email protected]".into()]),
None,
None,
true
)
.await
.unwrap()
)
);

assert_eq!(
vec![id1],
to_ids(
conn.list_users_with_filter(
Some(vec!["[email protected]".into()]),
Some(1),
None,
true
)
.await
.unwrap()
)
);

assert_eq!(
empty,
to_ids(
conn.list_users_with_filter(
Some(vec!["[email protected]".into()]),
None,
None,
true
)
.await
.unwrap()
)
);

let id2 = conn
.create_user(
"[email protected]".into(),
Expand Down Expand Up @@ -636,83 +574,64 @@ 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()
)
);
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()
)
);
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()
)
);
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()
)
);
// 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()
)
);
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()
)
);
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!["[email protected]".into(), "[email protected]".into()]),
None,
None,
false
)
.await
.unwrap()
)
);
}

#[tokio::test]
Expand Down
2 changes: 1 addition & 1 deletion ee/tabby-schema/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
1 change: 0 additions & 1 deletion ee/tabby-schema/src/schema/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,6 @@ pub trait AuthenticationService: Send + Sync {

async fn list_users(
&self,
emails: Option<Vec<String>>,
after: Option<String>,
before: Option<String>,
first: Option<usize>,
Expand Down
3 changes: 1 addition & 2 deletions ee/tabby-schema/src/schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ impl Query {
/// List users, accessible for all login users.
async fn users(
ctx: &Context,
emails: Option<Vec<String>>,
after: Option<String>,
before: Option<String>,
first: Option<i32>,
Expand All @@ -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())
},
Expand Down
Loading

0 comments on commit 8e02a2c

Please sign in to comment.