From 4ee5a2e119a4ce0fa7a8037d589bf5a79b363000 Mon Sep 17 00:00:00 2001 From: Lennart Kloock Date: Mon, 16 Oct 2023 21:31:11 +0200 Subject: [PATCH] fix(api): rebased --- platform/api/src/api/v1/gql/guards/mod.rs | 2 +- platform/api/src/api/v1/gql/models/user.rs | 16 +--------------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/platform/api/src/api/v1/gql/guards/mod.rs b/platform/api/src/api/v1/gql/guards/mod.rs index b359d7c74..bc8782a2e 100644 --- a/platform/api/src/api/v1/gql/guards/mod.rs +++ b/platform/api/src/api/v1/gql/guards/mod.rs @@ -18,7 +18,7 @@ pub async fn auth_guard( ) -> Result { let request_context = ctx.get_req_context(); - let auth = request_context.auth().await; + let auth = request_context.auth().await?; if let Some(auth) = auth { if Ulid::from(auth.session.user_id) == user_id diff --git a/platform/api/src/api/v1/gql/models/user.rs b/platform/api/src/api/v1/gql/models/user.rs index 5903c56a3..76d10d696 100644 --- a/platform/api/src/api/v1/gql/models/user.rs +++ b/platform/api/src/api/v1/gql/models/user.rs @@ -57,21 +57,7 @@ impl User { } async fn totp_enabled(&self, ctx: &Context<'_>) -> Result { - let request_context = ctx.get_req_context(); - let auth = request_context.auth().await?; - - if let Some(auth) = auth { - if Ulid::from(auth.session.user_id) == *self.id - || auth.user_permissions.has_permission(RolePermission::Admin) - { - return Ok(self.totp_enabled_); - } - } - - Err(GqlError::Unauthorized { - field: "totpEnabled", - } - .into()) + auth_guard(ctx, "totpEnabled", self.totp_enabled_, self.id.into()).await } }