Lines
93.75 %
Functions
66.67 %
Branches
100 %
//! The `config-set` form submit: one config value of the user.
use forms::{CONFIG_SET, FormValues};
use server::command::config::SetConfig;
use uuid::Uuid;
use super::Failure;
use super::transaction_rows::single_line;
const CTX: &str = "config-set";
/// `config-set` submit: stores the value under the key.
pub async fn set_config(user_id: Uuid, values: &FormValues) -> Result<(), Failure> {
let mut errors = values.check(&CONFIG_SET);
let key = values.text("key").unwrap_or_default().trim();
errors.extend(single_line("key", key).err());
if !errors.is_empty() {
return Err(errors.into());
}
SetConfig::new()
.user_id(user_id)
.name(key.to_string())
.value(values.text("value").unwrap_or_default().to_string())
.run()
.await
.map(drop)
.map_err(|err| Failure::from_command(CTX, err))