Merge pull request 'bit nicer logs' (#275) from staging into main
Reviewed-on: #275
This commit is contained in:
commit
a1126e0509
@ -168,19 +168,24 @@ async fn fees_paid(
|
||||
user_ids: Vec<i32>,
|
||||
referer: Referer,
|
||||
) -> Flash<Redirect> {
|
||||
Log::create(
|
||||
db,
|
||||
format!("{admin:?} set fees paid for user_ids: {user_ids:?}"),
|
||||
)
|
||||
.await;
|
||||
let mut res = String::new();
|
||||
for user_id in user_ids {
|
||||
let user = User::find_by_id(db, user_id).await.unwrap();
|
||||
res.push_str(&format!("{} + ", user.name));
|
||||
if user.has_role(db, "paid").await {
|
||||
Log::create(
|
||||
db,
|
||||
format!("{} set fees NOT paid for '{}'", admin.user.name, user.name),
|
||||
)
|
||||
.await;
|
||||
user.remove_role(db, &Role::find_by_name(db, "paid").await.unwrap())
|
||||
.await;
|
||||
} else {
|
||||
Log::create(
|
||||
db,
|
||||
format!("{} set fees paid for '{}'", admin.user.name, user.name),
|
||||
)
|
||||
.await;
|
||||
user.add_role(db, &Role::find_by_name(db, "paid").await.unwrap())
|
||||
.await;
|
||||
}
|
||||
@ -212,7 +217,7 @@ async fn resetpw(db: &State<SqlitePool>, _admin: AdminUser, user: i32) -> Flash<
|
||||
#[get("/user/<user>/delete")]
|
||||
async fn delete(db: &State<SqlitePool>, admin: AdminUser, user: i32) -> Flash<Redirect> {
|
||||
let user = User::find_by_id(db, user).await;
|
||||
Log::create(db, format!("{admin:?} deleted user: {user:?}")).await;
|
||||
Log::create(db, format!("{} deleted user: {user:?}", admin.user.name)).await;
|
||||
match user {
|
||||
Some(user) => {
|
||||
user.delete(db).await;
|
||||
@ -251,7 +256,7 @@ async fn update(
|
||||
let user = User::find_by_id(db, data.id).await;
|
||||
Log::create(
|
||||
db,
|
||||
format!("{admin:?} updated user from {user:?} to {data:?}"),
|
||||
format!("{} updated user from {user:?} to {data:?}", admin.user.name),
|
||||
)
|
||||
.await;
|
||||
let Some(user) = user else {
|
||||
@ -277,8 +282,12 @@ async fn create(
|
||||
data: Form<UserAddForm<'_>>,
|
||||
admin: AdminUser,
|
||||
) -> Flash<Redirect> {
|
||||
Log::create(db, format!("{admin:?} created new user: {data:?}")).await;
|
||||
if User::create(db, data.name).await {
|
||||
Log::create(
|
||||
db,
|
||||
format!("{} created new user: {data:?}", admin.user.name),
|
||||
)
|
||||
.await;
|
||||
Flash::success(Redirect::to("/admin/user"), "Successfully created user")
|
||||
} else {
|
||||
Flash::error(
|
||||
|
Loading…
Reference in New Issue
Block a user