delete large user-update-function 🎉 Fixes #958
This commit is contained in:
@ -1,5 +1,3 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::{
|
||||
model::{
|
||||
family::Family,
|
||||
@ -301,49 +299,6 @@ async fn delete(db: &State<SqlitePool>, admin: ManageUserUser, user: i32) -> Fla
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(FromForm, Debug)]
|
||||
pub struct UserEditForm<'a> {
|
||||
pub(crate) id: i32,
|
||||
pub(crate) dob: Option<String>,
|
||||
pub(crate) weight: Option<String>,
|
||||
pub(crate) sex: Option<String>,
|
||||
pub(crate) roles: HashMap<String, String>,
|
||||
pub(crate) member_since_date: Option<String>,
|
||||
pub(crate) birthdate: Option<String>,
|
||||
pub(crate) mail: Option<String>,
|
||||
pub(crate) nickname: Option<String>,
|
||||
pub(crate) notes: Option<String>,
|
||||
pub(crate) phone: Option<String>,
|
||||
pub(crate) address: Option<String>,
|
||||
pub(crate) family_id: Option<i64>,
|
||||
pub(crate) membership_pdf: Option<TempFile<'a>>,
|
||||
}
|
||||
|
||||
#[post("/user", data = "<data>", format = "multipart/form-data")]
|
||||
async fn update(
|
||||
db: &State<SqlitePool>,
|
||||
data: Form<UserEditForm<'_>>,
|
||||
admin: ManageUserUser,
|
||||
) -> Flash<Redirect> {
|
||||
let user = User::find_by_id(db, data.id).await;
|
||||
Log::create(
|
||||
db,
|
||||
format!("{} updated user from {user:?} to {data:?}", admin.user.name),
|
||||
)
|
||||
.await;
|
||||
let Some(user) = user else {
|
||||
return Flash::error(
|
||||
Redirect::to("/admin/user"),
|
||||
format!("User with ID {} does not exist!", data.id),
|
||||
);
|
||||
};
|
||||
|
||||
match user.update(db, data.into_inner()).await {
|
||||
Ok(_) => Flash::success(Redirect::to("/admin/user"), "Successfully updated user"),
|
||||
Err(e) => Flash::error(Redirect::to("/admin/user"), e),
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(FromForm, Debug)]
|
||||
pub struct MailUpdateForm {
|
||||
mail: String,
|
||||
@ -712,11 +667,11 @@ async fn create(
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(FromForm, Debug)]
|
||||
struct UserAddScheckbuchForm<'r> {
|
||||
name: &'r str,
|
||||
mail: &'r str,
|
||||
}
|
||||
//#[derive(FromForm, Debug)]
|
||||
//struct UserAddScheckbuchForm<'r> {
|
||||
// name: &'r str,
|
||||
// mail: &'r str,
|
||||
//}
|
||||
|
||||
//#[post("/user/new/scheckbuch", data = "<data>")]
|
||||
//async fn create_scheckbuch(
|
||||
@ -778,7 +733,7 @@ pub struct SchnupperantToRegularForm<'a> {
|
||||
#[post("/user/<id>/schnupperant-to-regular", data = "<data>")]
|
||||
async fn schnupperant_to_regular(
|
||||
db: &State<SqlitePool>,
|
||||
data: Form<ScheckToRegularForm<'_>>,
|
||||
data: Form<SchnupperantToRegularForm<'_>>,
|
||||
admin: ManageUserUser,
|
||||
config: &State<Config>,
|
||||
id: i32,
|
||||
@ -1174,7 +1129,6 @@ pub fn routes() -> Vec<Route> {
|
||||
index_admin,
|
||||
view,
|
||||
resetpw,
|
||||
update,
|
||||
create,
|
||||
//create_scheckbuch,
|
||||
delete,
|
||||
|
Reference in New Issue
Block a user