various: remove unused imports and parameters; fix clippy lints

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Ia7a4438e1aa73de2ea1bc6cdf26998f06a6a6964
This commit is contained in:
raf 2026-02-05 22:43:25 +03:00
commit 4b375bc546
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
6 changed files with 35 additions and 24 deletions

View file

@ -6,7 +6,7 @@ use uuid::Uuid;
use crate::{ use crate::{
error::{CiError, Result}, error::{CiError, Result},
models::{CreateProjectMember, ProjectMember, UpdateProjectMember}, models::{CreateProjectMember, ProjectMember, UpdateProjectMember},
roles::{VALID_PROJECT_ROLES, has_project_permission}, roles::VALID_PROJECT_ROLES,
validation::validate_role, validation::validate_role,
}; };

View file

@ -6,7 +6,7 @@ use uuid::Uuid;
use crate::{ use crate::{
error::{CiError, Result}, error::{CiError, Result},
models::{CreateUser, LoginCredentials, UpdateUser, User}, models::{CreateUser, LoginCredentials, UpdateUser, User},
roles::{ROLE_READ_ONLY, VALID_ROLES, is_valid_role}, roles::{ROLE_READ_ONLY, VALID_ROLES},
validation::{ validation::{
validate_email, validate_email,
validate_full_name, validate_full_name,

View file

@ -11,8 +11,9 @@ name = "fc-migrate"
path = "src/main.rs" path = "src/main.rs"
[dependencies] [dependencies]
fc-common.workspace = true
anyhow.workspace = true anyhow.workspace = true
clap.workspace = true clap.workspace = true
fc-common = { path = "../common" }
tokio.workspace = true tokio.workspace = true
tracing-subscriber.workspace = true tracing-subscriber.workspace = true

View file

@ -72,8 +72,8 @@ pub async fn require_api_key(
.and_then(|v| v.to_str().ok()) .and_then(|v| v.to_str().ok())
{ {
// Try user session first (new fc_user_session cookie) // Try user session first (new fc_user_session cookie)
if let Some(session_id) = parse_cookie(cookie_header, "fc_user_session") { if let Some(session_id) = parse_cookie(cookie_header, "fc_user_session")
if let Some(session) = state.sessions.get(&session_id) { && let Some(session) = state.sessions.get(&session_id) {
// Check session expiry (24 hours) // Check session expiry (24 hours)
if session.created_at.elapsed() if session.created_at.elapsed()
< std::time::Duration::from_secs(24 * 60 * 60) < std::time::Duration::from_secs(24 * 60 * 60)
@ -92,11 +92,10 @@ pub async fn require_api_key(
state.sessions.remove(&session_id); state.sessions.remove(&session_id);
} }
} }
}
// Try legacy API key session (fc_session cookie) // Try legacy API key session (fc_session cookie)
if let Some(session_id) = parse_cookie(cookie_header, "fc_session") { if let Some(session_id) = parse_cookie(cookie_header, "fc_session")
if let Some(session) = state.sessions.get(&session_id) { && let Some(session) = state.sessions.get(&session_id) {
// Check session expiry (24 hours) // Check session expiry (24 hours)
if session.created_at.elapsed() if session.created_at.elapsed()
< std::time::Duration::from_secs(24 * 60 * 60) < std::time::Duration::from_secs(24 * 60 * 60)
@ -112,7 +111,6 @@ pub async fn require_api_key(
} }
} }
} }
}
// No valid auth found // No valid auth found
if is_read { if is_read {
@ -134,8 +132,8 @@ impl FromRequestParts<AppState> for RequireAdmin {
_state: &AppState, _state: &AppState,
) -> Result<Self, Self::Rejection> { ) -> Result<Self, Self::Rejection> {
// Check for user first (new auth) // Check for user first (new auth)
if let Some(user) = parts.extensions.get::<User>() { if let Some(user) = parts.extensions.get::<User>()
if user.role == "admin" { && user.role == "admin" {
// Create a synthetic API key for compatibility // Create a synthetic API key for compatibility
return Ok(RequireAdmin(ApiKey { return Ok(RequireAdmin(ApiKey {
id: user.id, id: user.id,
@ -147,7 +145,6 @@ impl FromRequestParts<AppState> for RequireAdmin {
user_id: Some(user.id), user_id: Some(user.id),
})); }));
} }
}
// Fall back to API key // Fall back to API key
let key = parts let key = parts
@ -175,8 +172,8 @@ impl RequireRoles {
allowed: &[&str], allowed: &[&str],
) -> Result<ApiKey, StatusCode> { ) -> Result<ApiKey, StatusCode> {
// Check for user first // Check for user first
if let Some(user) = extensions.get::<User>() { if let Some(user) = extensions.get::<User>()
if user.role == "admin" || allowed.contains(&user.role.as_str()) { && (user.role == "admin" || allowed.contains(&user.role.as_str())) {
return Ok(ApiKey { return Ok(ApiKey {
id: user.id, id: user.id,
name: user.username.clone(), name: user.username.clone(),
@ -187,7 +184,6 @@ impl RequireRoles {
user_id: Some(user.id), user_id: Some(user.id),
}); });
} }
}
// Fall back to API key // Fall back to API key
let key = extensions let key = extensions
@ -220,8 +216,8 @@ pub async fn extract_session(
if let Some(cookie_header) = cookie_header { if let Some(cookie_header) = cookie_header {
// Try user session first // Try user session first
if let Some(session_id) = parse_cookie(&cookie_header, "fc_user_session") { if let Some(session_id) = parse_cookie(&cookie_header, "fc_user_session")
if let Some(session) = state.sessions.get(&session_id) { && let Some(session) = state.sessions.get(&session_id) {
// Check session expiry // Check session expiry
if session.created_at.elapsed() if session.created_at.elapsed()
< std::time::Duration::from_secs(24 * 60 * 60) < std::time::Duration::from_secs(24 * 60 * 60)
@ -237,11 +233,10 @@ pub async fn extract_session(
state.sessions.remove(&session_id); state.sessions.remove(&session_id);
} }
} }
}
// Try legacy API key session // Try legacy API key session
if let Some(session_id) = parse_cookie(&cookie_header, "fc_session") { if let Some(session_id) = parse_cookie(&cookie_header, "fc_session")
if let Some(session) = state.sessions.get(&session_id) { && let Some(session) = state.sessions.get(&session_id) {
// Check session expiry // Check session expiry
if session.created_at.elapsed() if session.created_at.elapsed()
< std::time::Duration::from_secs(24 * 60 * 60) < std::time::Duration::from_secs(24 * 60 * 60)
@ -255,7 +250,6 @@ pub async fn extract_session(
} }
} }
} }
}
next.run(request).await next.run(request).await
} }

View file

@ -11,12 +11,11 @@ use fc_common::{
models::{ models::{
CreateStarredJob, CreateStarredJob,
CreateUser, CreateUser,
LoginCredentials,
PaginationParams, PaginationParams,
UpdateUser, UpdateUser,
User, User,
}, },
repo::{self, api_keys}, repo::{self},
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use uuid::Uuid; use uuid::Uuid;
@ -175,7 +174,6 @@ async fn delete_user(
// --- Current User Handlers --- // --- Current User Handlers ---
async fn get_current_user( async fn get_current_user(
State(state): State<AppState>,
extensions: axum::http::Extensions, extensions: axum::http::Extensions,
) -> Result<Json<UserResponse>, ApiError> { ) -> Result<Json<UserResponse>, ApiError> {
// Try to get user from extensions first // Try to get user from extensions first

View file

@ -41,6 +41,24 @@ fn build_app(pool: sqlx::PgPool) -> axum::Router {
fc_server::routes::router(state, &server_config) fc_server::routes::router(state, &server_config)
} }
#[tokio::test]
async fn test_router_no_duplicate_routes() {
let pool = match get_pool().await {
Some(p) => p,
None => return,
};
let config = fc_common::config::Config::default();
let server_config = config.server.clone();
let state = fc_server::state::AppState {
pool,
config,
sessions: std::sync::Arc::new(dashmap::DashMap::new()),
};
let _app = fc_server::routes::router(state, &server_config);
}
fn build_app_with_config( fn build_app_with_config(
pool: sqlx::PgPool, pool: sqlx::PgPool,
config: fc_common::config::Config, config: fc_common::config::Config,