Lots of clippy appeasement

This commit is contained in:
Lennart
2025-10-27 20:12:21 +01:00
parent 0d071d3b92
commit 86cf490fa9
84 changed files with 413 additions and 435 deletions

View File

@@ -8,7 +8,7 @@ use futures_core::future::BoxFuture;
use headers::{ContentType, ETag, HeaderMapExt};
use http::{Method, StatusCode};
use rust_embed::RustEmbed;
use std::{convert::Infallible, marker::PhantomData, str::FromStr};
use std::{borrow::Cow, convert::Infallible, marker::PhantomData, str::FromStr};
use tower::Service;
#[derive(Clone, RustEmbed, Default)]
@@ -16,6 +16,7 @@ use tower::Service;
#[allow(dead_code)] // Since this is not used with the frontend-dev feature
pub struct Assets;
#[allow(dead_code)]
#[derive(Clone, Default)]
pub struct EmbedService<E>
where
@@ -41,6 +42,7 @@ where
}
#[inline]
#[allow(clippy::similar_names)]
fn call(&mut self, mut req: Request) -> Self::Future {
Box::pin(async move {
if req.method() != Method::GET && req.method() != Method::HEAD {
@@ -60,7 +62,7 @@ where
let mime = mime_guess::from_path(path).first_or_octet_stream();
let body = if req.method() == Method::HEAD {
Default::default()
Cow::default()
} else {
data
};

View File

@@ -48,7 +48,7 @@ pub fn frontend_router<AP: AuthenticationProvider, CS: CalendarStore, AS: Addres
) -> Router {
let user_router = Router::new()
.route("/", get(route_get_home))
.route("/{user}", get(route_user_named::<CS, AS, AP>))
.route("/{user}", get(route_user_named::<AP>))
// App token management
.route("/{user}/app_token", post(route_post_app_token::<AP>))
.route(

View File

@@ -27,20 +27,22 @@ pub async fn post_nextcloud_login(
let token = uuid::Uuid::new_v4().to_string();
let app_name = user_agent.to_string();
let mut flows = state.flows.write().await;
// Flows must not last longer than 10 minutes
// We also enforce that condition here to prevent a memory leak where unpolled flows would
// never be cleaned up
flows.retain(|_, flow| Utc::now() - flow.created_at < Duration::minutes(10));
flows.insert(
flow_id.clone(),
NextcloudFlow {
app_name: app_name.clone(),
created_at: Utc::now(),
token: token.clone(),
response: None,
},
);
{
let mut flows = state.flows.write().await;
// Flows must not last longer than 10 minutes
// We also enforce that condition here to prevent a memory leak where unpolled flows would
// never be cleaned up
flows.retain(|_, flow| Utc::now() - flow.created_at < Duration::minutes(10));
flows.insert(
flow_id.clone(),
NextcloudFlow {
app_name: app_name.clone(),
created_at: Utc::now(),
token: token.clone(),
response: None,
},
);
}
Json(NextcloudLoginResponse {
login: format!("https://{host}/index.php/login/v2/flow/{flow_id}"),
poll: NextcloudLoginPoll {
@@ -56,6 +58,7 @@ pub struct NextcloudPollForm {
token: String,
}
#[allow(clippy::significant_drop_tightening)]
pub async fn post_nextcloud_poll<AP: AuthenticationProvider>(
Extension(state): Extension<Arc<NextcloudFlows>>,
Path(flow_id): Path<String>,

View File

@@ -1,8 +1,7 @@
use std::sync::Arc;
use async_trait::async_trait;
use rustical_oidc::UserStore;
use rustical_store::auth::{AuthenticationProvider, Principal};
use rustical_store::auth::{AuthenticationProvider, Principal, PrincipalType};
use std::sync::Arc;
pub struct OidcUserStore<AP: AuthenticationProvider>(pub Arc<AP>);
@@ -26,7 +25,7 @@ impl<AP: AuthenticationProvider> UserStore for OidcUserStore<AP> {
Principal {
id: id.to_owned(),
displayname: None,
principal_type: Default::default(),
principal_type: PrincipalType::default(),
password: None,
memberships: vec![],
},

View File

@@ -42,8 +42,8 @@ pub async fn route_addressbook_restore<AS: AddressbookStore>(
return Ok(StatusCode::UNAUTHORIZED.into_response());
}
store.restore_addressbook(&owner, &addressbook_id).await?;
Ok(match referer {
Some(referer) => Redirect::to(&referer.to_string()).into_response(),
None => (StatusCode::CREATED, "Restored").into_response(),
})
Ok(referer.map_or_else(
|| (StatusCode::CREATED, "Restored").into_response(),
|referer| Redirect::to(&referer.to_string()).into_response(),
))
}

View File

@@ -42,8 +42,8 @@ pub async fn route_calendar_restore<CS: CalendarStore>(
return Ok(StatusCode::UNAUTHORIZED.into_response());
}
store.restore_calendar(&owner, &cal_id).await?;
Ok(match referer {
Some(referer) => Redirect::to(&referer.to_string()).into_response(),
None => (StatusCode::CREATED, "Restored").into_response(),
})
Ok(referer.map_or_else(
|| (StatusCode::CREATED, "Restored").into_response(),
|referer| Redirect::to(&referer.to_string()).into_response(),
))
}

View File

@@ -10,10 +10,7 @@ use axum::{
use axum_extra::{TypedHeader, extract::Host};
use headers::UserAgent;
use http::StatusCode;
use rustical_store::{
AddressbookStore, CalendarStore,
auth::{AppToken, AuthenticationProvider, Principal},
};
use rustical_store::auth::{AppToken, AuthenticationProvider, Principal};
use crate::pages::user::{Section, UserPage};
@@ -32,14 +29,8 @@ pub struct ProfileSection {
pub davx5_hostname: Option<String>,
}
pub async fn route_user_named<
CS: CalendarStore,
AS: AddressbookStore,
AP: AuthenticationProvider,
>(
pub async fn route_user_named<AP: AuthenticationProvider>(
Path(user_id): Path<String>,
Extension(cal_store): Extension<Arc<CS>>,
Extension(addr_store): Extension<Arc<AS>>,
Extension(auth_provider): Extension<Arc<AP>>,
TypedHeader(user_agent): TypedHeader<UserAgent>,
Host(host): Host,
@@ -49,26 +40,6 @@ pub async fn route_user_named<
return StatusCode::UNAUTHORIZED.into_response();
}
let mut calendars = vec![];
for group in user.memberships() {
calendars.extend(cal_store.get_calendars(group).await.unwrap());
}
let mut deleted_calendars = vec![];
for group in user.memberships() {
deleted_calendars.extend(cal_store.get_deleted_calendars(group).await.unwrap());
}
let mut addressbooks = vec![];
for group in user.memberships() {
addressbooks.extend(addr_store.get_addressbooks(group).await.unwrap());
}
let mut deleted_addressbooks = vec![];
for group in user.memberships() {
deleted_addressbooks.extend(addr_store.get_deleted_addressbooks(group).await.unwrap());
}
let is_apple = user_agent.as_str().contains("Apple") || user_agent.as_str().contains("Mac OS");
let davx5_hostname = user_agent.as_str().contains("Android").then_some(host);