refactor(backend-api)!: Rename GetCurrentUser, add GetCurrentUserWithNamespaces

Make the GetCurrentUser query only return a plain user without
namespaces.

Rename the current function/query to GetCurrentUserWithNamespaces,
get_current_user_with_namespaces.

This makes more sense , since the namespace query adds quite a lot of
extra work.
This commit is contained in:
Christoph Herzog
2024-06-08 23:54:23 +02:00
parent c20ebcbcf4
commit 0bf8682daf
2 changed files with 32 additions and 14 deletions

View File

@@ -164,7 +164,15 @@ pub async fn tag_package_release(
.map(|r| r.tag_package_release)
}
/// Get the currently logged in used, together with all accessible namespaces.
/// Get the currently logged in user.
pub async fn current_user(client: &WasmerClient) -> Result<Option<types::User>, anyhow::Error> {
client
.run_graphql(types::GetCurrentUser::build(()))
.await
.map(|x| x.viewer)
}
/// Get the currently logged in user, together with all accessible namespaces.
///
/// You can optionally filter the namespaces by the user role.
pub async fn current_user_with_namespaces(
@@ -172,9 +180,9 @@ pub async fn current_user_with_namespaces(
namespace_role: Option<types::GrapheneRole>,
) -> Result<types::UserWithNamespaces, anyhow::Error> {
client
.run_graphql(types::GetCurrentUser::build(types::GetCurrentUserVars {
namespace_role,
}))
.run_graphql(types::GetCurrentUserWithNamespaces::build(
types::GetCurrentUserWithNamespacesVars { namespace_role },
))
.await?
.viewer
.context("not logged in")
@@ -544,9 +552,11 @@ pub async fn user_accessible_apps(
// Get all aps in user-accessible namespaces.
let namespace_res = client
.run_graphql(types::GetCurrentUser::build(types::GetCurrentUserVars {
namespace_role: None,
}))
.run_graphql(types::GetCurrentUserWithNamespaces::build(
types::GetCurrentUserWithNamespacesVars {
namespace_role: None,
},
))
.await?;
let active_user = namespace_res.viewer.context("not logged in")?;
let namespace_names = active_user
@@ -655,9 +665,11 @@ pub async fn user_namespaces(
client: &WasmerClient,
) -> Result<Vec<types::Namespace>, anyhow::Error> {
let user = client
.run_graphql(types::GetCurrentUser::build(types::GetCurrentUserVars {
namespace_role: None,
}))
.run_graphql(types::GetCurrentUserWithNamespaces::build(
types::GetCurrentUserWithNamespacesVars {
namespace_role: None,
},
))
.await?
.viewer
.context("not logged in")?;