Skip to main content

rpc/forms/
config_set.rs

1//! The `config-set` form submit: one config value of the user.
2
3use forms::{CONFIG_SET, FormValues};
4use server::command::config::SetConfig;
5use uuid::Uuid;
6
7use super::Failure;
8use super::transaction_rows::single_line;
9
10const CTX: &str = "config-set";
11
12/// `config-set` submit: stores the value under the key.
13pub async fn set_config(user_id: Uuid, values: &FormValues) -> Result<(), Failure> {
14    let mut errors = values.check(&CONFIG_SET);
15    let key = values.text("key").unwrap_or_default().trim();
16    errors.extend(single_line("key", key).err());
17    if !errors.is_empty() {
18        return Err(errors.into());
19    }
20    SetConfig::new()
21        .user_id(user_id)
22        .name(key.to_string())
23        .value(values.text("value").unwrap_or_default().to_string())
24        .run()
25        .await
26        .map(drop)
27        .map_err(|err| Failure::from_command(CTX, err))
28}