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

@@ -1,6 +1,9 @@
use std::ops::DerefMut;
use super::{role::Role, user::User};
use super::{
role::Role,
user::{ManageUserUser, User},
};
use chrono::{DateTime, Duration, Local, NaiveDateTime, TimeZone, Utc};
use serde::{Deserialize, Serialize};
use sqlx::{FromRow, Sqlite, SqlitePool, Transaction};
@@ -14,6 +17,29 @@ pub struct Activity {
pub keep_until: Option<NaiveDateTime>,
}
pub enum Reason<'a> {
// `User` tried to login with `String` as UserAgent
SuccLogin(&'a User, String),
// `User` changed the data of `User`, explanation in `String`
UserDataChange(&'a ManageUserUser, &'a User, String),
}
impl From<Reason<'_>> for ActivityBuilder {
fn from(value: Reason<'_>) -> Self {
match value {
Reason::SuccLogin(user, agent) => {
Self::new(&format!("{user} hat sich eingeloggt (User-Agent: {agent})"))
.relevant_for_user(user)
.keep_until_days(7)
}
Reason::UserDataChange(changed_by, changed_user, explanation) => Self::new(&format!(
"{changed_by} hat die Daten von {changed_user} aktualisiert: {explanation}"
))
.relevant_for_user(changed_user),
}
}
}
pub struct ActivityBuilder {
text: String,
relevant_for: String,
@@ -21,6 +47,7 @@ pub struct ActivityBuilder {
}
impl ActivityBuilder {
/// TODO: maybe make this private, and only allow specific acitivites defined in `Reason`
#[must_use]
pub fn new(text: &str) -> Self {
Self {