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

pull/391/head
Daniel García 6 years ago
parent ef63342e20
commit 8b4a6f2a64
No known key found for this signature in database
GPG Key ID: FC8A7D14C3CD543A

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

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

@ -462,7 +462,7 @@ pub fn validate_u2f_login(user_uuid: &str, response: &str, conn: &DbConn) -> Emp
}
Err(e) => {
info!("E {:#}", e);
break;
// break;
}
}
}
@ -494,7 +494,7 @@ use yubico::Yubico;
fn parse_yubikeys(data: &EnableYubikeyData) -> Vec<String> {
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 {

@ -9,7 +9,7 @@ lazy_static! {
println!("Error loading config:\n\t{:?}\n", e);
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 {
@ -71,7 +71,7 @@ macro_rules! make_config {
/// Returns a new builder with all the elements from self,
/// 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();
$($(
if &self.$name != &other.$name {

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

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

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

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

Loading…
Cancel
Save