start replacing activitybuilder
All checks were successful
CI/CD Pipeline / test (push) Successful in 18m49s
CI/CD Pipeline / deploy-staging (push) Has been skipped
CI/CD Pipeline / deploy-main (push) Has been skipped

This commit is contained in:
2025-05-12 23:08:45 +02:00
parent e4a8caf632
commit 3ab1dbd1f1
3 changed files with 56 additions and 37 deletions

View File

@ -2,7 +2,10 @@
use super::{AllowedToEditPaymentStatusUser, ManageUserUser, User};
use crate::model::{
activity::ActivityBuilder, family::Family, mail::valid_mails, notification::Notification,
activity::{self, ActivityBuilder},
family::Family,
mail::valid_mails,
notification::Notification,
role::Role,
};
use chrono::NaiveDate;
@ -19,10 +22,13 @@ impl User {
) -> Result<(), String> {
let note = note.trim();
ActivityBuilder::new(&format!("({updated_by}) {note}"))
.relevant_for_user(user)
.save(db)
.await;
ActivityBuilder::from(activity::Reason::UserDataChange(
updated_by,
self,
format!("Neue Notizen: {note}"),
))
.save(db)
.await;
Ok(())
}
@ -47,18 +53,11 @@ impl User {
.unwrap(); //Okay, because we can only create a User of a valid id
let msg = match &self.mail {
Some(old_mail) => {
format!(
"{updated_by} hat die Mail-Adresse von {self} von {old_mail} auf {new_mail} geändert."
)
}
None => {
format!("{updated_by} eine neue Mail-Adresse für {self} hinzugefügt: {new_mail}")
}
Some(old_mail) => format!("Mail-Adresse von {old_mail} auf {new_mail} geändert."),
None => format!("Neue Mail-Adresse für: {new_mail}"),
};
ActivityBuilder::new(&msg)
.relevant_for_user(self)
ActivityBuilder::from(activity::Reason::UserDataChange(updated_by, self, msg))
.save(db)
.await;
@ -89,19 +88,16 @@ impl User {
query.execute(db).await.unwrap(); //Okay, because we can only create a User of a valid id
let msg = match &self.phone {
Some(old_phone) if new_phone.is_empty() => format!(
"{updated_by} hat die Telefonnummer von {self} entfernt (alte Nummer: {old_phone})"
),
Some(old_phone) => format!(
"{updated_by} hat die Telefonnummer von {self} von {old_phone} auf {new_phone} geändert."
),
None => format!(
"{updated_by} hat eine neue Telefonnummer für {self} hinzugefügt: {new_phone}"
),
Some(old_phone) if new_phone.is_empty() => {
format!("Telefonnummer wurde entfernt (alte Nummer: {old_phone})")
}
Some(old_phone) => {
format!("Telefonnummer wurde von {old_phone} auf {new_phone} geändert.")
}
None => format!("Neue Telefonnummer hinzugefügt: {new_phone}"),
};
ActivityBuilder::new(&msg)
.relevant_for_user(self)
ActivityBuilder::from(activity::Reason::UserDataChange(updated_by, self, msg))
.save(db)
.await;
}