add notes #973
| @@ -1,5 +1,6 @@ | ||||
| use std::ops::DerefMut; | ||||
|  | ||||
| use super::user::User; | ||||
| use chrono::NaiveDateTime; | ||||
| use serde::{Deserialize, Serialize}; | ||||
| use sqlx::{FromRow, Sqlite, SqlitePool, Transaction}; | ||||
| @@ -51,4 +52,21 @@ impl Activity { | ||||
|         Self::create_with_tx(&mut tx, text, relevant_for, keep_until).await; | ||||
|         tx.commit().await.unwrap(); | ||||
|     } | ||||
|  | ||||
|     pub async fn for_user(db: &SqlitePool, user: &User) -> Vec<Activity> { | ||||
|         let user_str = format!("user-{};", user.id); | ||||
|         sqlx::query_as!( | ||||
|             Self, | ||||
|             " | ||||
| SELECT id, created_at, text, relevant_for, keep_until FROM activity | ||||
| WHERE  | ||||
|   relevant_for like CONCAT('%', ?, '%') | ||||
| ORDER BY created_at DESC; | ||||
|             ", | ||||
|             user_str | ||||
|         ) | ||||
|         .fetch_all(db) | ||||
|         .await | ||||
|         .unwrap() | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -11,11 +11,18 @@ impl User { | ||||
|         &self, | ||||
|         db: &SqlitePool, | ||||
|         updated_by: &ManageUserUser, | ||||
|         user: &User, | ||||
|         note: &str, | ||||
|     ) -> Result<(), String> { | ||||
|         let note = note.trim(); | ||||
|  | ||||
|         Activity::create(db, note, "relevant_for", None).await; | ||||
|         Activity::create( | ||||
|             db, | ||||
|             &format!("({updated_by}) {note}"), | ||||
|             &format!("user-{};", user.id), | ||||
|             None, | ||||
|         ) | ||||
|         .await; | ||||
|  | ||||
|         Ok(()) | ||||
|     } | ||||
|   | ||||
| @@ -1,5 +1,6 @@ | ||||
| use crate::{ | ||||
|     model::{ | ||||
|         activity::Activity, | ||||
|         family::Family, | ||||
|         log::Log, | ||||
|         logbook::Logbook, | ||||
| @@ -128,6 +129,7 @@ async fn view( | ||||
|  | ||||
|     let member = Member::from(db, user.clone()).await; | ||||
|     let fee = user.fee(db).await; | ||||
|     let activities = Activity::for_user(db, &user).await; | ||||
|  | ||||
|     let user = UserWithRolesAndMembershipPdf::from_user(db, user).await; | ||||
|  | ||||
| @@ -147,6 +149,7 @@ async fn view( | ||||
|     context.insert("supposed_to_pay", &member.supposed_to_pay()); | ||||
|     context.insert("fee", &fee); | ||||
|     context.insert("member", &member); | ||||
|     context.insert("activities", &activities); | ||||
|     context.insert("roles", &roles); | ||||
|     context.insert("families", &families); | ||||
|     context.insert( | ||||
| @@ -332,7 +335,7 @@ pub struct AddNoteForm { | ||||
|     note: String, | ||||
| } | ||||
|  | ||||
| #[post("/user/<id>/add-note", data = "<data>")] | ||||
| #[post("/user/<id>/new-note", data = "<data>")] | ||||
| async fn add_note( | ||||
|     db: &State<SqlitePool>, | ||||
|     data: Form<AddNoteForm>, | ||||
| @@ -346,7 +349,7 @@ async fn add_note( | ||||
|         ); | ||||
|     }; | ||||
|  | ||||
|     match user.add_note(db, &admin, &data.note).await { | ||||
|     match user.add_note(db, &admin, &user, &data.note).await { | ||||
|         Ok(_) => Flash::success( | ||||
|             Redirect::to(format!("/admin/user/{}", user.id)), | ||||
|             "Notiz hinzugefügt", | ||||
|   | ||||
| @@ -32,11 +32,10 @@ | ||||
|                             {{ macros::inputgroup(label='Spitzname', name='nickname', type="text", value=user.nickname, readonly=not allowed_to_edit) }} | ||||
|                         </form> | ||||
|                         {% if allowed_to_edit %} | ||||
|                         <form action="/admin/user/{{ user.id }}/new-note" method="post"> | ||||
|                             {{ macros::inputgroup(label='Neue Notiz', name='note', type="text") }} | ||||
|                         </form> | ||||
|                             <form action="/admin/user/{{ user.id }}/new-note" method="post"> | ||||
|                                 {{ macros::inputgroup(label='Neue Notiz', name='note', type="text") }} | ||||
|                             </form> | ||||
|                         {% endif %} | ||||
|                         <span>Notizen: to be replaced with activity :-)</span> | ||||
|                         {% if user.pw and allowed_to_edit %} | ||||
|                             <div> | ||||
|                                 <a class="block my-1 font-normal text-[#f43f5e] dark:text-primary-200 hover:text-primary-900 dark:hover:text-primary-300 underline" | ||||
| @@ -390,8 +389,11 @@ | ||||
|                 <div class="mx-3 divide-y divide-gray-200 dark:divide-primary-600"> | ||||
|                     <div class="py-3"> | ||||
|                         <ul class="list-disc ms-4"> | ||||
|                             <li>Passwort zurückgesetzt am/um X</li> | ||||
|                             <li>Am X beigetreten.</li> | ||||
|                             {% for activity in activities %} | ||||
|                                 <li>{{ activity.created_at | date(format="%d. %m. %Y") }}: {{ activity.text }}</li> | ||||
|                             {% else %} | ||||
|                                 <li>Noch keine Aktivität... Stay tuned 😆</li> | ||||
|                             {% endfor %} | ||||
|                         </ul> | ||||
|                     </div> | ||||
|                 </div> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user