fc-server: fix clippy warnings about manual clamp patterns
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I5cc30a1f6f7444a7acd836430ad44a576a6a6964
This commit is contained in:
parent
6c322c061b
commit
d620ec5454
3 changed files with 88 additions and 88 deletions
|
|
@ -73,7 +73,8 @@ pub async fn require_api_key(
|
||||||
{
|
{
|
||||||
// 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")
|
||||||
&& 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)
|
||||||
|
|
@ -95,7 +96,8 @@ pub async fn require_api_key(
|
||||||
|
|
||||||
// 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")
|
||||||
&& 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)
|
||||||
|
|
@ -133,7 +135,8 @@ impl FromRequestParts<AppState> for RequireAdmin {
|
||||||
) -> 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>()
|
||||||
&& 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,
|
||||||
|
|
@ -173,7 +176,8 @@ impl RequireRoles {
|
||||||
) -> 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>()
|
||||||
&& (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(),
|
||||||
|
|
@ -217,7 +221,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")
|
||||||
&& 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)
|
||||||
|
|
@ -236,7 +241,8 @@ pub async fn extract_session(
|
||||||
|
|
||||||
// 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")
|
||||||
&& 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)
|
||||||
|
|
|
||||||
|
|
@ -435,7 +435,7 @@ async fn projects_page(
|
||||||
Query(params): Query<PageParams>,
|
Query(params): Query<PageParams>,
|
||||||
extensions: Extensions,
|
extensions: Extensions,
|
||||||
) -> Html<String> {
|
) -> Html<String> {
|
||||||
let limit = params.limit.unwrap_or(50).min(200).max(1);
|
let limit = params.limit.unwrap_or(50).clamp(1, 200);
|
||||||
let offset = params.offset.unwrap_or(0).max(0);
|
let offset = params.offset.unwrap_or(0).max(0);
|
||||||
let items = fc_common::repo::projects::list(&state.pool, limit, offset)
|
let items = fc_common::repo::projects::list(&state.pool, limit, offset)
|
||||||
.await
|
.await
|
||||||
|
|
@ -602,7 +602,7 @@ async fn evaluations_page(
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
Query(params): Query<PageParams>,
|
Query(params): Query<PageParams>,
|
||||||
) -> Html<String> {
|
) -> Html<String> {
|
||||||
let limit = params.limit.unwrap_or(50).min(200).max(1);
|
let limit = params.limit.unwrap_or(50).clamp(1, 200);
|
||||||
let offset = params.offset.unwrap_or(0).max(0);
|
let offset = params.offset.unwrap_or(0).max(0);
|
||||||
let items = fc_common::repo::evaluations::list_filtered(
|
let items = fc_common::repo::evaluations::list_filtered(
|
||||||
&state.pool,
|
&state.pool,
|
||||||
|
|
@ -760,7 +760,7 @@ async fn builds_page(
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
Query(params): Query<BuildFilterParams>,
|
Query(params): Query<BuildFilterParams>,
|
||||||
) -> Html<String> {
|
) -> Html<String> {
|
||||||
let limit = params.limit.unwrap_or(50).min(200).max(1);
|
let limit = params.limit.unwrap_or(50).clamp(1, 200);
|
||||||
let offset = params.offset.unwrap_or(0).max(0);
|
let offset = params.offset.unwrap_or(0).max(0);
|
||||||
let items = fc_common::repo::builds::list_filtered(
|
let items = fc_common::repo::builds::list_filtered(
|
||||||
&state.pool,
|
&state.pool,
|
||||||
|
|
|
||||||
|
|
@ -8,13 +8,7 @@ use axum::{
|
||||||
routing::get,
|
routing::get,
|
||||||
};
|
};
|
||||||
use fc_common::{
|
use fc_common::{
|
||||||
models::{
|
models::{CreateStarredJob, CreateUser, PaginationParams, UpdateUser, User},
|
||||||
CreateStarredJob,
|
|
||||||
CreateUser,
|
|
||||||
PaginationParams,
|
|
||||||
UpdateUser,
|
|
||||||
User,
|
|
||||||
},
|
|
||||||
repo::{self},
|
repo::{self},
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue