From 0540f515ec98f128461a32e4756c72dee9770c99 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Thu, 28 Aug 2025 08:15:50 +0200 Subject: [PATCH] Fix cargo clippy issues --- .../accommodations_list_controller.rs | 10 +++---- .../src/controllers/couples_controller.rs | 15 ++++------ .../src/controllers/members_controller.rs | 30 ++++++++----------- .../src/controllers/photos_controller.rs | 10 +++---- .../src/services/members_service.rs | 5 ++-- geneit_backend/src/services/openid_service.rs | 2 +- 6 files changed, 29 insertions(+), 43 deletions(-) diff --git a/geneit_backend/src/controllers/accommodations_list_controller.rs b/geneit_backend/src/controllers/accommodations_list_controller.rs index 0fd69ba..f659d5f 100644 --- a/geneit_backend/src/controllers/accommodations_list_controller.rs +++ b/geneit_backend/src/controllers/accommodations_list_controller.rs @@ -34,18 +34,16 @@ impl AccommodationRequest { } accommodation.name = self.name; - if let Some(d) = &self.description { - if !c.accommodation_description_len.validate(d) { + if let Some(d) = &self.description + && !c.accommodation_description_len.validate(d) { return Err(AccommodationListControllerErr::InvalidDescriptionLength.into()); } - } accommodation.description.clone_from(&self.description); - if let Some(c) = &self.color { - if !lazy_regex::regex!("[a-fA-F0-9]{6}").is_match(c) { + if let Some(c) = &self.color + && !lazy_regex::regex!("[a-fA-F0-9]{6}").is_match(c) { return Err(AccommodationListControllerErr::MalformedColor.into()); } - } accommodation.color.clone_from(&self.color); accommodation.need_validation = self.need_validation; diff --git a/geneit_backend/src/controllers/couples_controller.rs b/geneit_backend/src/controllers/couples_controller.rs index 061b221..350c86d 100644 --- a/geneit_backend/src/controllers/couples_controller.rs +++ b/geneit_backend/src/controllers/couples_controller.rs @@ -48,23 +48,20 @@ impl CoupleRequest { } } - if let Some(husband) = self.husband { - if !members_service::exists(couple.family_id(), husband).await? { + if let Some(husband) = self.husband + && !members_service::exists(couple.family_id(), husband).await? { return Err(CoupleControllerErr::HusbandNotExisting.into()); } - } - if let Some(d) = &self.wedding { - if !d.check() { + if let Some(d) = &self.wedding + && !d.check() { return Err(CoupleControllerErr::MalformedDateOfWedding.into()); } - } - if let Some(d) = &self.divorce { - if !d.check() { + if let Some(d) = &self.divorce + && !d.check() { return Err(CoupleControllerErr::MalformedDateOfDivorce.into()); } - } couple.set_wife(self.wife); couple.set_husband(self.husband); diff --git a/geneit_backend/src/controllers/members_controller.rs b/geneit_backend/src/controllers/members_controller.rs index 03d0f72..2bf8937 100644 --- a/geneit_backend/src/controllers/members_controller.rs +++ b/geneit_backend/src/controllers/members_controller.rs @@ -95,11 +95,10 @@ fn check_opt_str_val( c: SizeConstraint, err: MemberControllerErr, ) -> anyhow::Result<()> { - if let Some(v) = val { - if !c.validate(v) { + if let Some(v) = val + && !c.validate(v) { return Err(err.into()); } - } Ok(()) } @@ -151,11 +150,10 @@ impl MemberRequest { MemberControllerErr::MalformedEmailAddress, )?; - if let Some(mail) = &self.email { - if !mailchecker::is_valid(mail) { + if let Some(mail) = &self.email + && !mailchecker::is_valid(mail) { return Err(MemberControllerErr::InvalidEmailAddress.into()); } - } check_opt_str_val( &self.phone, @@ -187,23 +185,20 @@ impl MemberRequest { MemberControllerErr::MalformedCountry, )?; - if let Some(c) = &self.country { - if !countries_utils::is_code_valid(c) { + if let Some(c) = &self.country + && !countries_utils::is_code_valid(c) { return Err(MemberControllerErr::InvalidCountryCode.into()); } - } - if let Some(d) = &self.birth { - if !d.check() { + if let Some(d) = &self.birth + && !d.check() { return Err(MemberControllerErr::MalformedDateOfBirth.into()); } - } - if let Some(d) = &self.death { - if !d.check() { + if let Some(d) = &self.death + && !d.check() { return Err(MemberControllerErr::MalformedDateOfDeath.into()); } - } check_opt_str_val( &self.note, @@ -221,11 +216,10 @@ impl MemberRequest { } } - if let Some(father) = self.father { - if !members_service::exists(member.family_id(), father).await? { + if let Some(father) = self.father + && !members_service::exists(member.family_id(), father).await? { return Err(MemberControllerErr::FatherNotExisting.into()); } - } member.first_name = self.first_name; member.last_name = self.last_name; diff --git a/geneit_backend/src/controllers/photos_controller.rs b/geneit_backend/src/controllers/photos_controller.rs index b817886..99f92b6 100644 --- a/geneit_backend/src/controllers/photos_controller.rs +++ b/geneit_backend/src/controllers/photos_controller.rs @@ -36,16 +36,15 @@ async fn get_photo(id: &PhotoIdPath, full_size: bool, req: HttpRequest) -> HttpR }; // Check if an upload is un-necessary - if let Some(c) = req.headers().get(header::IF_NONE_MATCH) { - if c.to_str().unwrap_or("") == hash { + if let Some(c) = req.headers().get(header::IF_NONE_MATCH) + && c.to_str().unwrap_or("") == hash { return Ok(HttpResponse::NotModified().finish()); } - } if let Some(c) = req.headers().get(header::IF_MODIFIED_SINCE) { let date_str = c.to_str().unwrap_or(""); - if let Ok(date) = httpdate::parse_http_date(date_str) { - if date + if let Ok(date) = httpdate::parse_http_date(date_str) + && date .add(Duration::from_secs(1)) .duration_since(UNIX_EPOCH) .unwrap() @@ -54,7 +53,6 @@ async fn get_photo(id: &PhotoIdPath, full_size: bool, req: HttpRequest) -> HttpR { return Ok(HttpResponse::NotModified().finish()); } - } } let bytes = s3_connection::get_file(&match full_size { diff --git a/geneit_backend/src/services/members_service.rs b/geneit_backend/src/services/members_service.rs index aa026df..b2f0790 100644 --- a/geneit_backend/src/services/members_service.rs +++ b/geneit_backend/src/services/members_service.rs @@ -149,11 +149,10 @@ pub mod loop_detection { impl LoopStack<'_> { pub fn contains(&self, id: MemberID) -> bool { - if let Some(ls) = &self.prev { - if ls.contains(id) { + if let Some(ls) = &self.prev + && ls.contains(id) { return true; } - } self.curr == id } diff --git a/geneit_backend/src/services/openid_service.rs b/geneit_backend/src/services/openid_service.rs index db37c9d..d7b6d2f 100644 --- a/geneit_backend/src/services/openid_service.rs +++ b/geneit_backend/src/services/openid_service.rs @@ -64,7 +64,7 @@ fn redis_key(state: &str) -> String { format!("oidc-state-{state}") } -async fn load_provider_info(prov_id: &str) -> anyhow::Result { +async fn load_provider_info(prov_id: &str) -> anyhow::Result> { let prov = AppConfig::get() .openid_providers() .into_iter()