From 6e33d345f0ab9f3f0161ef9a631537ad0cd1b08e Mon Sep 17 00:00:00 2001 From: boxbeam Date: Wed, 10 Apr 2024 13:02:12 -0400 Subject: [PATCH] Apply suggestion, add back authentication middleware --- ee/tabby-webserver/src/handler.rs | 6 +++++- ee/tabby-webserver/src/hub/mod.rs | 4 ++-- ee/tabby-webserver/src/integrations/github.rs | 11 +++++++++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/ee/tabby-webserver/src/handler.rs b/ee/tabby-webserver/src/handler.rs index 8ac832f6edb2..1339a522bea2 100644 --- a/ee/tabby-webserver/src/handler.rs +++ b/ee/tabby-webserver/src/handler.rs @@ -86,7 +86,11 @@ impl WebserverHandle { ) .nest( "/integrations/github", - integrations::github::routes(ctx.setting(), ctx.github_repository_provider()), + integrations::github::routes( + ctx.auth(), + ctx.setting(), + ctx.github_repository_provider(), + ), ) .route( "/avatar/:id", diff --git a/ee/tabby-webserver/src/hub/mod.rs b/ee/tabby-webserver/src/hub/mod.rs index f44ca16eb69b..767cdefb34b4 100644 --- a/ee/tabby-webserver/src/hub/mod.rs +++ b/ee/tabby-webserver/src/hub/mod.rs @@ -166,7 +166,7 @@ impl Hub for Arc { let provider_service = self.ctx.github_repository_provider(); let repository_providers = provider_service - .list_github_repository_providers(None, None, Some(1024), None) + .list_github_repository_providers(None, None, None, None) .await .unwrap_or_else(|e| { warn!("Failed to fetch GitHub repository providers: {e}"); @@ -186,7 +186,7 @@ impl Hub for Arc { vec![provider.id.clone()], None, None, - Some(1024), + None, None, ) .await diff --git a/ee/tabby-webserver/src/integrations/github.rs b/ee/tabby-webserver/src/integrations/github.rs index af70237253c8..2b2b84e77a68 100644 --- a/ee/tabby-webserver/src/integrations/github.rs +++ b/ee/tabby-webserver/src/integrations/github.rs @@ -3,6 +3,7 @@ use std::sync::Arc; use anyhow::Result; use axum::{ extract::{Path, Query, State}, + middleware::from_fn_with_state, response::Redirect, routing, Router, }; @@ -12,8 +13,12 @@ use serde::Deserialize; use tracing::error; use url::Url; -use crate::schema::{ - github_repository_provider::GithubRepositoryProviderService, setting::SettingService, +use crate::{ + handler::require_login_middleware, + schema::{ + auth::AuthenticationService, github_repository_provider::GithubRepositoryProviderService, + setting::SettingService, + }, }; #[derive(Debug, Deserialize)] @@ -47,6 +52,7 @@ struct IntegrationState { } pub fn routes( + auth: Arc, settings: Arc, github_repository_provider: Arc, ) -> Router { @@ -57,6 +63,7 @@ pub fn routes( Router::new() .route("/connect/:id", routing::get(connect)) .route("/callback", routing::get(callback)) + .layer(from_fn_with_state(auth, require_login_middleware)) .with_state(state) }