From 2afb6c95aed8fb10755805209678dfe1a043129d Mon Sep 17 00:00:00 2001 From: zleyyij <75810274+zleyyij@users.noreply.github.com> Date: Fri, 9 Aug 2024 18:53:31 -0600 Subject: [PATCH] feat: added reclone button to ui --- backend/src/handlers_prelude/mod.rs | 9 ++ backend/src/handlers_prelude/reclone.rs | 12 ++ backend/src/main.rs | 10 +- .../dashboard/AdminDashboard.svelte | 7 +- .../lib/components/dashboard/ServerTab.svelte | 108 ++++++++++++++++++ 5 files changed, 140 insertions(+), 6 deletions(-) create mode 100644 backend/src/handlers_prelude/reclone.rs create mode 100644 frontend/src/lib/components/dashboard/ServerTab.svelte diff --git a/backend/src/handlers_prelude/mod.rs b/backend/src/handlers_prelude/mod.rs index 14737366..0a1c32e2 100644 --- a/backend/src/handlers_prelude/mod.rs +++ b/backend/src/handlers_prelude/mod.rs @@ -18,6 +18,8 @@ mod logout; pub use logout::*; mod github_hook; pub use github_hook::*; +mod reclone; +pub use reclone::*; use color_eyre::{ eyre::{Context, ContextCompat}, @@ -80,6 +82,13 @@ async fn find_user(state: &AppState, headers: HeaderMap) -> color_eyre::Result, headers: HeaderMap, diff --git a/backend/src/handlers_prelude/reclone.rs b/backend/src/handlers_prelude/reclone.rs new file mode 100644 index 00000000..8d60e642 --- /dev/null +++ b/backend/src/handlers_prelude/reclone.rs @@ -0,0 +1,12 @@ +use axum::{extract::State, http::HeaderMap}; +use reqwest::StatusCode; + +use crate::{perms::Permission, AppState}; + +use super::{eyre_to_axum_err, require_perms}; + +pub async fn post_reclone_handler(State(state): State, headers: HeaderMap) -> Result<(), (StatusCode, String)> { + require_perms(State(&state), headers, &[Permission::ManageUsers]).await?; + state.git.reclone().map_err(eyre_to_axum_err)?; + Ok(()) +} diff --git a/backend/src/main.rs b/backend/src/main.rs index 9a71d5a9..70a0221f 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -193,6 +193,7 @@ async fn start_server(state: AppState, cli_args: Args) -> Result<()> { let app = Router::new() .route("/api/hello", get(|| async { "Hello world" })) .route("/api/logout", get(get_logout_handler)) + .route("/api/reclone", post(post_reclone_handler)) .route("/api/hooks/github", post(github_hook_handler)) .route("/api/doc", get(get_doc_handler)) .route("/api/doc", put(put_doc_handler)) @@ -267,11 +268,12 @@ async fn start_server(state: AppState, cli_args: Args) -> Result<()> { // closures to attach a value to the initially empty field in the info_span // created above. }) - .on_response(|response: &Response, latency: Duration, span: &Span| { + .on_response(|_response: &Response, _latency: Duration, _span: &Span| { // I don't know if this is strictly needed, should be tested - let _span = span.clone().entered(); - let latency_ms = format!("{}ms", latency.as_millis()); - info!(latency=%latency_ms, status=%response.status()); + // Commented out because it was creating duplicate logs for endpoints + // let _span = span.clone().entered(); + // let latency_ms = format!("{}ms", latency.as_millis()); + // info!(latency=%latency_ms, status=%response.status()); }), ); diff --git a/frontend/src/lib/components/dashboard/AdminDashboard.svelte b/frontend/src/lib/components/dashboard/AdminDashboard.svelte index 7218d4ef..3a3d90d8 100644 --- a/frontend/src/lib/components/dashboard/AdminDashboard.svelte +++ b/frontend/src/lib/components/dashboard/AdminDashboard.svelte @@ -1,12 +1,14 @@ + +
+ +
+

Actions

+
+
+ +
+ +
+ +
+

Metrics

+
+
+ TODO +
+ +