Browse Source

Adjusted according to comments

Signed-off-by: BlackDex <black.dex@gmail.com>
pull/4977/head
BlackDex 7 months ago
parent
commit
46f89f3205
No known key found for this signature in database GPG Key ID: 58C80A2AA6C765E1
  1. 12
      Cargo.lock
  2. 13
      Cargo.toml
  3. 6
      src/api/core/accounts.rs
  4. 14
      src/api/icons.rs
  5. 2
      src/config.rs
  6. 2
      src/db/models/emergency_access.rs
  7. 7
      src/error.rs

12
Cargo.lock

@ -2543,9 +2543,9 @@ dependencies = [
[[package]]
name = "pkg-config"
version = "0.3.30"
version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec"
checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2"
[[package]]
name = "polling"
@ -3573,18 +3573,18 @@ dependencies = [
[[package]]
name = "thiserror"
version = "1.0.63"
version = "1.0.64"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724"
checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.63"
version = "1.0.64"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261"
checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3"
dependencies = [
"proc-macro2",
"quote",

13
Cargo.toml

@ -198,6 +198,7 @@ lto = "thin"
codegen-units = 16
# Linting config
# https://doc.rust-lang.org/rustc/lints/groups.html
[lints.rust]
# Forbid
unsafe_code = "forbid"
@ -212,8 +213,8 @@ noop_method_call = "deny"
refining_impl_trait = { level = "deny", priority = -1 }
rust_2018_idioms = { level = "deny", priority = -1 }
rust_2021_compatibility = { level = "deny", priority = -1 }
rust_2024_compatibility = { level = "deny", priority = -1 }
single_use_lifetimes = { level = "deny", priority = -1 }
# rust_2024_compatibility = { level = "deny", priority = -1 } # Enable once we are at MSRV 1.81.0
single_use_lifetimes = "deny"
trivial_casts = "deny"
trivial_numeric_casts = "deny"
unused = { level = "deny", priority = -1 }
@ -221,15 +222,22 @@ unused_import_braces = "deny"
unused_lifetimes = "deny"
unused_qualifications = "deny"
variant_size_differences = "deny"
# The lints below are part of the rust_2024_compatibility group
static-mut-refs = "deny"
unsafe-op-in-unsafe-fn = "deny"
# https://rust-lang.github.io/rust-clippy/stable/index.html
[lints.clippy]
# Warn
dbg_macro = "warn"
todo = "warn"
# Deny
case_sensitive_file_extension_comparisons = "deny"
cast_lossless = "deny"
clone_on_ref_ptr = "deny"
equatable_if_let = "deny"
filter_map_next = "deny"
float_cmp_const = "deny"
inefficient_to_string = "deny"
iter_on_empty_collections = "deny"
@ -254,4 +262,3 @@ unused_async = "deny"
unused_self = "deny"
verbose_file_reads = "deny"
zero_sized_map_values = "deny"
filter_map_next = "deny"

6
src/api/core/accounts.rs

@ -223,7 +223,7 @@ pub async fn _register(data: Json<RegisterData>, mut conn: DbConn) -> JsonResult
}
if verified_by_invite && is_email_2fa_required(data.organization_user_id, &mut conn).await {
drop(email::activate_email_2fa(&user, &mut conn).await);
email::activate_email_2fa(&user, &mut conn).await.ok();
}
}
@ -232,7 +232,7 @@ pub async fn _register(data: Json<RegisterData>, mut conn: DbConn) -> JsonResult
// accept any open emergency access invitations
if !CONFIG.mail_enabled() && CONFIG.emergency_access_allowed() {
for mut emergency_invite in EmergencyAccess::find_all_invited_by_grantee_email(&user.email, &mut conn).await {
drop(emergency_invite.accept_invite(&user.uuid, &user.email, &mut conn).await);
emergency_invite.accept_invite(&user.uuid, &user.email, &mut conn).await.ok();
}
}
@ -1038,7 +1038,7 @@ async fn put_device_token(uuid: &str, data: Json<PushToken>, headers: Headers, m
return Ok(());
} else {
// Try to unregister already registered device
drop(unregister_push_device(device.push_uuid).await);
unregister_push_device(device.push_uuid).await.ok();
}
// clear the push_uuid
device.push_uuid = None;

14
src/api/icons.rs

@ -1,4 +1,5 @@
use std::{
collections::HashMap,
net::IpAddr,
sync::Arc,
time::{Duration, SystemTime},
@ -446,6 +447,9 @@ async fn get_page_with_referer(url: &str, referer: &str) -> Result<Response, Err
/// priority2 = get_icon_priority("https://example.com/path/to/a/favicon.ico", "");
/// ```
fn get_icon_priority(href: &str, sizes: &str) -> u8 {
static PRIORITY_MAP: Lazy<HashMap<&'static str, u8>> =
Lazy::new(|| [(".png", 10), (".jpg", 20), (".jpeg", 20)].into_iter().collect());
// Check if there is a dimension set
let (width, height) = parse_sizes(sizes);
@ -470,13 +474,9 @@ fn get_icon_priority(href: &str, sizes: &str) -> u8 {
200
}
} else {
// Change priority by file extension
if href.ends_with(".png") {
10
} else if href.ends_with(".jpg") || href.ends_with(".jpeg") {
20
} else {
30
match href.rsplit_once('.') {
Some((_, extension)) => PRIORITY_MAP.get(&*extension.to_ascii_lowercase()).copied().unwrap_or(30),
None => 30,
}
}
}

2
src/config.rs

@ -26,7 +26,6 @@ pub static CONFIG: Lazy<Config> = Lazy::new(|| {
pub type Pass = String;
#[allow(edition_2024_expr_fragment_specifier)]
macro_rules! make_config {
($(
$(#[doc = $groupdoc:literal])?
@ -1297,7 +1296,6 @@ where
hb.register_helper("case", Box::new(case_helper));
hb.register_helper("to_json", Box::new(to_json));
#[allow(edition_2024_expr_fragment_specifier)]
macro_rules! reg {
($name:expr) => {{
let template = include_str!(concat!("static/templates/", $name, ".hbs"));

2
src/db/models/emergency_access.rs

@ -89,7 +89,7 @@ impl EmergencyAccess {
Some(user) => user,
None => {
// remove outstanding invitations which should not exist
drop(Self::delete_all_by_grantee_email(email, conn).await);
Self::delete_all_by_grantee_email(email, conn).await.ok();
return None;
}
}

7
src/error.rs

@ -5,7 +5,6 @@ use crate::db::models::EventType;
use crate::http_client::CustomHttpClientError;
use std::error::Error as StdError;
#[allow(edition_2024_expr_fragment_specifier)]
macro_rules! make_error {
( $( $name:ident ( $ty:ty ): $src_fn:expr, $usr_msg_fun:expr ),+ $(,)? ) => {
const BAD_REQUEST: u16 = 400;
@ -228,7 +227,6 @@ impl Responder<'_, 'static> for Error {
// Error return macros
//
#[macro_export]
#[allow(edition_2024_expr_fragment_specifier)]
macro_rules! err {
($msg:expr) => {{
error!("{}", $msg);
@ -249,7 +247,6 @@ macro_rules! err {
}
#[macro_export]
#[allow(edition_2024_expr_fragment_specifier)]
macro_rules! err_silent {
($msg:expr) => {{
return Err($crate::error::Error::new($msg, $msg));
@ -260,7 +257,6 @@ macro_rules! err_silent {
}
#[macro_export]
#[allow(edition_2024_expr_fragment_specifier)]
macro_rules! err_code {
($msg:expr, $err_code:expr) => {{
error!("{}", $msg);
@ -273,7 +269,6 @@ macro_rules! err_code {
}
#[macro_export]
#[allow(edition_2024_expr_fragment_specifier)]
macro_rules! err_discard {
($msg:expr, $data:expr) => {{
std::io::copy(&mut $data.open(), &mut std::io::sink()).ok();
@ -286,7 +281,6 @@ macro_rules! err_discard {
}
#[macro_export]
#[allow(edition_2024_expr_fragment_specifier)]
macro_rules! err_json {
($expr:expr, $log_value:expr) => {{
return Err(($log_value, $expr).into());
@ -297,7 +291,6 @@ macro_rules! err_json {
}
#[macro_export]
#[allow(edition_2024_expr_fragment_specifier)]
macro_rules! err_handler {
($expr:expr) => {{
error!(target: "auth", "Unauthorized Error: {}", $expr);

Loading…
Cancel
Save