1
0
Fork 0

Fixed some clippy lints and changed update_uuid_revision to only use one db query

Dieser Commit ist enthalten in:
Daniel García 2019-02-08 18:45:07 +01:00
Ursprung ef63342e20
Commit 8b4a6f2a64
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: FC8A7D14C3CD543A
8 geänderte Dateien mit 32 neuen und 27 gelöschten Zeilen

Datei anzeigen

@ -117,8 +117,8 @@ fn post_eq_domains(data: JsonUpcase<EquivDomainData>, headers: Headers, conn: Db
let mut user = headers.user; let mut user = headers.user;
use serde_json::to_string; use serde_json::to_string;
user.excluded_globals = to_string(&excluded_globals).unwrap_or("[]".to_string()); user.excluded_globals = to_string(&excluded_globals).unwrap_or_else(|_| "[]".to_string());
user.equivalent_domains = to_string(&equivalent_domains).unwrap_or("[]".to_string()); user.equivalent_domains = to_string(&equivalent_domains).unwrap_or_else(|_| "[]".to_string());
user.save(&conn)?; user.save(&conn)?;

Datei anzeigen

@ -452,7 +452,7 @@ where
D: Deserializer<'de>, D: Deserializer<'de>,
{ {
// Deserialize null to empty Vec // Deserialize null to empty Vec
Deserialize::deserialize(deserializer).or(Ok(vec![])) Deserialize::deserialize(deserializer).or_else(|_| Ok(vec![]))
} }
#[derive(Deserialize)] #[derive(Deserialize)]
@ -486,9 +486,10 @@ fn send_invite(org_id: String, data: JsonUpcase<InviteData>, headers: AdminHeade
} }
for email in data.Emails.iter() { for email in data.Emails.iter() {
let mut user_org_status = match CONFIG.mail_enabled() { let mut user_org_status = if CONFIG.mail_enabled() {
true => UserOrgStatus::Invited as i32, UserOrgStatus::Invited as i32
false => UserOrgStatus::Accepted as i32, // Automatically mark user as accepted if no email invites } else {
UserOrgStatus::Accepted as i32 // Automatically mark user as accepted if no email invites
}; };
let user = match User::find_by_mail(&email, &conn) { let user = match User::find_by_mail(&email, &conn) {
None => { None => {

Datei anzeigen

@ -462,7 +462,7 @@ pub fn validate_u2f_login(user_uuid: &str, response: &str, conn: &DbConn) -> Emp
} }
Err(e) => { Err(e) => {
info!("E {:#}", e); info!("E {:#}", e);
break; // break;
} }
} }
} }
@ -494,7 +494,7 @@ use yubico::Yubico;
fn parse_yubikeys(data: &EnableYubikeyData) -> Vec<String> { fn parse_yubikeys(data: &EnableYubikeyData) -> Vec<String> {
let data_keys = [&data.Key1, &data.Key2, &data.Key3, &data.Key4, &data.Key5]; let data_keys = [&data.Key1, &data.Key2, &data.Key3, &data.Key4, &data.Key5];
data_keys.into_iter().filter_map(|e| e.as_ref().cloned()).collect() data_keys.iter().filter_map(|e| e.as_ref().cloned()).collect()
} }
fn jsonify_yubikeys(yubikeys: Vec<String>) -> serde_json::Value { fn jsonify_yubikeys(yubikeys: Vec<String>) -> serde_json::Value {

Datei anzeigen

@ -9,7 +9,7 @@ lazy_static! {
println!("Error loading config:\n\t{:?}\n", e); println!("Error loading config:\n\t{:?}\n", e);
exit(12) exit(12)
}); });
pub static ref CONFIG_FILE: String = get_env("CONFIG_FILE").unwrap_or("data/config.json".into()); pub static ref CONFIG_FILE: String = get_env("CONFIG_FILE").unwrap_or_else(|| "data/config.json".into());
} }
macro_rules! make_config { macro_rules! make_config {
@ -71,7 +71,7 @@ macro_rules! make_config {
/// Returns a new builder with all the elements from self, /// Returns a new builder with all the elements from self,
/// except those that are equal in both sides /// except those that are equal in both sides
fn remove(&self, other: &Self) -> Self { fn _remove(&self, other: &Self) -> Self {
let mut builder = ConfigBuilder::default(); let mut builder = ConfigBuilder::default();
$($( $($(
if &self.$name != &other.$name { if &self.$name != &other.$name {

Datei anzeigen

@ -15,7 +15,7 @@ pub struct TwoFactor {
} }
#[allow(dead_code)] #[allow(dead_code)]
#[derive(FromPrimitive, ToPrimitive)] #[derive(FromPrimitive)]
pub enum TwoFactorType { pub enum TwoFactorType {
Authenticator = 0, Authenticator = 0,
Email = 1, Email = 1,

Datei anzeigen

@ -172,23 +172,27 @@ impl User {
.map_res("Error deleting user") .map_res("Error deleting user")
} }
pub fn update_uuid_revision(uuid: &str, conn: &DbConn) -> Vec<String> { pub fn update_uuid_revision(uuid: &str, conn: &DbConn) {
if let Some(mut user) = User::find_by_uuid(&uuid, conn) { if let Err(e) = Self::_update_revision(uuid, &Utc::now().naive_utc(), conn) {
if user.update_revision(conn).is_err() { warn!("Failed to update revision for {}: {:#?}", uuid, e);
warn!("Failed to update revision for {}", user.email); }
};
};
vec![uuid.to_string()]
} }
pub fn update_revision(&mut self, conn: &DbConn) -> EmptyResult { pub fn update_revision(&mut self, conn: &DbConn) -> EmptyResult {
self.updated_at = Utc::now().naive_utc(); self.updated_at = Utc::now().naive_utc();
crate::util::retry( || {
diesel::update(users::table.filter(users::uuid.eq(&self.uuid))) Self::_update_revision(&self.uuid, &self.updated_at, conn)
.set(users::updated_at.eq(&self.updated_at)) }
fn _update_revision(uuid: &str, date: &NaiveDateTime, conn: &DbConn) -> EmptyResult {
crate::util::retry(
|| {
diesel::update(users::table.filter(users::uuid.eq(uuid)))
.set(users::updated_at.eq(date))
.execute(&**conn) .execute(&**conn)
}, 10) },
10,
)
.map_res("Error updating user revision") .map_res("Error updating user revision")
} }

Datei anzeigen

@ -6,7 +6,7 @@ use std::error::Error as StdError;
macro_rules! make_error { macro_rules! make_error {
( $( $name:ident ( $ty:ty ): $src_fn:expr, $usr_msg_fun:expr ),+ $(,)? ) => { ( $( $name:ident ( $ty:ty ): $src_fn:expr, $usr_msg_fun:expr ),+ $(,)? ) => {
#[derive(Display)] #[derive(Display)]
enum ErrorKind { $($name( $ty )),+ } pub enum ErrorKind { $($name( $ty )),+ }
pub struct Error { message: String, error: ErrorKind } pub struct Error { message: String, error: ErrorKind }
$(impl From<$ty> for Error { $(impl From<$ty> for Error {

Datei anzeigen

@ -86,8 +86,8 @@ pub fn send_invite(
"email/send_org_invite", "email/send_org_invite",
json!({ json!({
"url": CONFIG.domain(), "url": CONFIG.domain(),
"org_id": org_id.unwrap_or("_".to_string()), "org_id": org_id.unwrap_or_else(|| "_".to_string()),
"org_user_id": org_user_id.unwrap_or("_".to_string()), "org_user_id": org_user_id.unwrap_or_else(|| "_".to_string()),
"email": address, "email": address,
"org_name": org_name, "org_name": org_name,
"token": invite_token, "token": invite_token,