Merge pull request 'not so much clutter when addding notes' (#1018) from nicer-notes into main
Reviewed-on: #1018
This commit was merged in pull request #1018.
	This commit is contained in:
		@@ -17,11 +17,14 @@ pub struct Activity {
 | 
			
		||||
    pub keep_until: Option<NaiveDateTime>,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// TODO: add `reason` as additional db field, to be able to query and show this to the users
 | 
			
		||||
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),
 | 
			
		||||
    // New Note for User
 | 
			
		||||
    NewUserNote(&'a ManageUserUser, &'a User, String),
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl From<Reason<'_>> for ActivityBuilder {
 | 
			
		||||
@@ -36,6 +39,9 @@ impl From<Reason<'_>> for ActivityBuilder {
 | 
			
		||||
                "{changed_by} hat die Daten von {changed_user} aktualisiert: {explanation}"
 | 
			
		||||
            ))
 | 
			
		||||
            .relevant_for_user(changed_user),
 | 
			
		||||
            Reason::NewUserNote(changed_by, user, explanation) => {
 | 
			
		||||
                Self::new(&format!("({changed_by}) {explanation}")).relevant_for_user(user)
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -17,7 +17,6 @@ impl User {
 | 
			
		||||
        &self,
 | 
			
		||||
        db: &SqlitePool,
 | 
			
		||||
        updated_by: &ManageUserUser,
 | 
			
		||||
        user: &User,
 | 
			
		||||
        note: &str,
 | 
			
		||||
    ) -> Result<(), String> {
 | 
			
		||||
        let note = note.trim();
 | 
			
		||||
@@ -25,7 +24,7 @@ impl User {
 | 
			
		||||
        ActivityBuilder::from(activity::Reason::UserDataChange(
 | 
			
		||||
            updated_by,
 | 
			
		||||
            self,
 | 
			
		||||
            format!("Neue Notizen: {note}"),
 | 
			
		||||
            note.to_string(),
 | 
			
		||||
        ))
 | 
			
		||||
        .save(db)
 | 
			
		||||
        .await;
 | 
			
		||||
 
 | 
			
		||||
@@ -7,11 +7,11 @@ use crate::{
 | 
			
		||||
        mail::valid_mails,
 | 
			
		||||
        role::Role,
 | 
			
		||||
        user::{
 | 
			
		||||
            AdminUser, AllowedToEditPaymentStatusUser, ManageUserUser, User, UserWithDetails,
 | 
			
		||||
            UserWithMembershipPdf, UserWithRolesAndMembershipPdf, VorstandUser,
 | 
			
		||||
            clubmember::ClubMemberUser, foerdernd::FoerderndUser, member::Member,
 | 
			
		||||
            regular::RegularUser, scheckbuch::ScheckbuchUser, schnupperant::SchnupperantUser,
 | 
			
		||||
            schnupperinterest::SchnupperInterestUser, unterstuetzend::UnterstuetzendUser,
 | 
			
		||||
            AdminUser, AllowedToEditPaymentStatusUser, ManageUserUser, User, UserWithDetails,
 | 
			
		||||
            UserWithMembershipPdf, UserWithRolesAndMembershipPdf, VorstandUser,
 | 
			
		||||
        },
 | 
			
		||||
    },
 | 
			
		||||
    tera::Config,
 | 
			
		||||
@@ -19,7 +19,6 @@ use crate::{
 | 
			
		||||
use chrono::NaiveDate;
 | 
			
		||||
use futures::future::join_all;
 | 
			
		||||
use rocket::{
 | 
			
		||||
    FromForm, Request, Route, State,
 | 
			
		||||
    form::Form,
 | 
			
		||||
    fs::TempFile,
 | 
			
		||||
    get,
 | 
			
		||||
@@ -27,9 +26,9 @@ use rocket::{
 | 
			
		||||
    post,
 | 
			
		||||
    request::{FlashMessage, FromRequest, Outcome},
 | 
			
		||||
    response::{Flash, Redirect},
 | 
			
		||||
    routes,
 | 
			
		||||
    routes, FromForm, Request, Route, State,
 | 
			
		||||
};
 | 
			
		||||
use rocket_dyn_templates::{Template, tera::Context};
 | 
			
		||||
use rocket_dyn_templates::{tera::Context, Template};
 | 
			
		||||
use sqlx::SqlitePool;
 | 
			
		||||
 | 
			
		||||
// Custom request guard to extract the Referer header
 | 
			
		||||
@@ -350,7 +349,7 @@ async fn add_note(
 | 
			
		||||
        );
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    match user.add_note(db, &admin, &user, &data.note).await {
 | 
			
		||||
    match user.add_note(db, &admin, &data.note).await {
 | 
			
		||||
        Ok(_) => Flash::success(
 | 
			
		||||
            Redirect::to(format!("/admin/user/{}", user.id)),
 | 
			
		||||
            "Notiz hinzugefügt",
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user