Autoformat
This commit is contained in:
parent
8f83d92a42
commit
80c37ce1bb
1 changed files with 53 additions and 53 deletions
106
src/config.rs
106
src/config.rs
|
@ -106,15 +106,15 @@ pub fn read<T>(db: &T) -> Result<Config>
|
||||||
.select((users::columns::name, users::columns::admin))
|
.select((users::columns::name, users::columns::admin))
|
||||||
.get_results(connection.deref())?;
|
.get_results(connection.deref())?;
|
||||||
config.users = Some(found_users
|
config.users = Some(found_users
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(n, a)| {
|
.map(|(n, a)| {
|
||||||
ConfigUser {
|
ConfigUser {
|
||||||
name: n,
|
name: n,
|
||||||
password: "".to_owned(),
|
password: "".to_owned(),
|
||||||
admin: a != 0,
|
admin: a != 0,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect::<_>());
|
.collect::<_>());
|
||||||
|
|
||||||
let ydns = ddns_config
|
let ydns = ddns_config
|
||||||
.select((host, username, password))
|
.select((host, username, password))
|
||||||
|
@ -170,9 +170,9 @@ pub fn amend<T>(db: &T, new_config: &Config) -> Result<()>
|
||||||
let delete_usernames: Vec<String> = old_usernames
|
let delete_usernames: Vec<String> = old_usernames
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter(|old_name| match config_users.iter().find(|u| &u.name == old_name) {
|
.filter(|old_name| match config_users.iter().find(|u| &u.name == old_name) {
|
||||||
None => true,
|
None => true,
|
||||||
Some(new_user) => !new_user.password.is_empty(),
|
Some(new_user) => !new_user.password.is_empty(),
|
||||||
})
|
})
|
||||||
.collect::<_>();
|
.collect::<_>();
|
||||||
diesel::delete(users::table.filter(users::name.eq_any(&delete_usernames)))
|
diesel::delete(users::table.filter(users::name.eq_any(&delete_usernames)))
|
||||||
.execute(connection.deref())?;
|
.execute(connection.deref())?;
|
||||||
|
@ -213,8 +213,8 @@ pub fn amend<T>(db: &T, new_config: &Config) -> Result<()>
|
||||||
use self::ddns_config::dsl::*;
|
use self::ddns_config::dsl::*;
|
||||||
diesel::update(ddns_config)
|
diesel::update(ddns_config)
|
||||||
.set((host.eq(ydns.host.clone()),
|
.set((host.eq(ydns.host.clone()),
|
||||||
username.eq(ydns.username.clone()),
|
username.eq(ydns.username.clone()),
|
||||||
password.eq(ydns.password.clone())))
|
password.eq(ydns.password.clone())))
|
||||||
.execute(connection.deref())?;
|
.execute(connection.deref())?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,14 +256,14 @@ fn test_amend() {
|
||||||
reindex_every_n_seconds: Some(123),
|
reindex_every_n_seconds: Some(123),
|
||||||
prefix_url: None,
|
prefix_url: None,
|
||||||
mount_dirs: Some(vec![MountPoint {
|
mount_dirs: Some(vec![MountPoint {
|
||||||
source: "C:\\Music".into(),
|
source: "C:\\Music".into(),
|
||||||
name: "root".into(),
|
name: "root".into(),
|
||||||
}]),
|
}]),
|
||||||
users: Some(vec![ConfigUser {
|
users: Some(vec![ConfigUser {
|
||||||
name: "Teddy🐻".into(),
|
name: "Teddy🐻".into(),
|
||||||
password: "Tasty🍖".into(),
|
password: "Tasty🍖".into(),
|
||||||
admin: false,
|
admin: false,
|
||||||
}]),
|
}]),
|
||||||
ydns: None,
|
ydns: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -272,19 +272,19 @@ fn test_amend() {
|
||||||
reindex_every_n_seconds: None,
|
reindex_every_n_seconds: None,
|
||||||
prefix_url: Some("polaris".into()),
|
prefix_url: Some("polaris".into()),
|
||||||
mount_dirs: Some(vec![MountPoint {
|
mount_dirs: Some(vec![MountPoint {
|
||||||
source: "/home/music".into(),
|
source: "/home/music".into(),
|
||||||
name: "🎵📁".into(),
|
name: "🎵📁".into(),
|
||||||
}]),
|
}]),
|
||||||
users: Some(vec![ConfigUser {
|
users: Some(vec![ConfigUser {
|
||||||
name: "Kermit🐸".into(),
|
name: "Kermit🐸".into(),
|
||||||
password: "🐞🐞".into(),
|
password: "🐞🐞".into(),
|
||||||
admin: false,
|
admin: false,
|
||||||
}]),
|
}]),
|
||||||
ydns: Some(DDNSConfig {
|
ydns: Some(DDNSConfig {
|
||||||
host: "🐸🐸🐸.ydns.eu".into(),
|
host: "🐸🐸🐸.ydns.eu".into(),
|
||||||
username: "kfr🐸g".into(),
|
username: "kfr🐸g".into(),
|
||||||
password: "tasty🐞".into(),
|
password: "tasty🐞".into(),
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut expected_config = new_config.clone();
|
let mut expected_config = new_config.clone();
|
||||||
|
@ -313,10 +313,10 @@ fn test_amend_preserve_password_hashes() {
|
||||||
prefix_url: None,
|
prefix_url: None,
|
||||||
mount_dirs: None,
|
mount_dirs: None,
|
||||||
users: Some(vec![ConfigUser {
|
users: Some(vec![ConfigUser {
|
||||||
name: "Teddy🐻".into(),
|
name: "Teddy🐻".into(),
|
||||||
password: "Tasty🍖".into(),
|
password: "Tasty🍖".into(),
|
||||||
admin: false,
|
admin: false,
|
||||||
}]),
|
}]),
|
||||||
ydns: None,
|
ydns: None,
|
||||||
};
|
};
|
||||||
amend(&db, &initial_config).unwrap();
|
amend(&db, &initial_config).unwrap();
|
||||||
|
@ -336,15 +336,15 @@ fn test_amend_preserve_password_hashes() {
|
||||||
prefix_url: None,
|
prefix_url: None,
|
||||||
mount_dirs: None,
|
mount_dirs: None,
|
||||||
users: Some(vec![ConfigUser {
|
users: Some(vec![ConfigUser {
|
||||||
name: "Kermit🐸".into(),
|
name: "Kermit🐸".into(),
|
||||||
password: "tasty🐞".into(),
|
password: "tasty🐞".into(),
|
||||||
admin: false,
|
admin: false,
|
||||||
},
|
},
|
||||||
ConfigUser {
|
ConfigUser {
|
||||||
name: "Teddy🐻".into(),
|
name: "Teddy🐻".into(),
|
||||||
password: "".into(),
|
password: "".into(),
|
||||||
admin: false,
|
admin: false,
|
||||||
}]),
|
}]),
|
||||||
ydns: None,
|
ydns: None,
|
||||||
};
|
};
|
||||||
amend(&db, &new_config).unwrap();
|
amend(&db, &new_config).unwrap();
|
||||||
|
@ -374,10 +374,10 @@ fn test_toggle_admin() {
|
||||||
prefix_url: None,
|
prefix_url: None,
|
||||||
mount_dirs: None,
|
mount_dirs: None,
|
||||||
users: Some(vec![ConfigUser {
|
users: Some(vec![ConfigUser {
|
||||||
name: "Teddy🐻".into(),
|
name: "Teddy🐻".into(),
|
||||||
password: "Tasty🍖".into(),
|
password: "Tasty🍖".into(),
|
||||||
admin: true,
|
admin: true,
|
||||||
}]),
|
}]),
|
||||||
ydns: None,
|
ydns: None,
|
||||||
};
|
};
|
||||||
amend(&db, &initial_config).unwrap();
|
amend(&db, &initial_config).unwrap();
|
||||||
|
@ -397,10 +397,10 @@ fn test_toggle_admin() {
|
||||||
prefix_url: None,
|
prefix_url: None,
|
||||||
mount_dirs: None,
|
mount_dirs: None,
|
||||||
users: Some(vec![ConfigUser {
|
users: Some(vec![ConfigUser {
|
||||||
name: "Teddy🐻".into(),
|
name: "Teddy🐻".into(),
|
||||||
password: "".into(),
|
password: "".into(),
|
||||||
admin: false,
|
admin: false,
|
||||||
}]),
|
}]),
|
||||||
ydns: None,
|
ydns: None,
|
||||||
};
|
};
|
||||||
amend(&db, &new_config).unwrap();
|
amend(&db, &new_config).unwrap();
|
||||||
|
|
Loading…
Add table
Reference in a new issue