diff --git a/backend/renders/renders.go b/backend/renders/renders.go index 7c609cc..76217f7 100644 --- a/backend/renders/renders.go +++ b/backend/renders/renders.go @@ -273,23 +273,35 @@ func AdminUserUpdate(db *gorm.DB) http.HandlerFunc { func AdminConversationPage(db *gorm.DB) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { idStr := mux.Vars(r)["id"] - data := map[string]interface{}{ "UserID": idStr, } - if _, exists := data["User"]; !exists { - if val := r.Context().Value("ssoid"); val != nil { - ssoid := val.(string) - var user models.User - if err := db.Where("sso_id = ?", ssoid).First(&user).Error; err == nil { - data["User"] = user - } + + var currentUser models.User + if val := r.Context().Value("ssoid"); val != nil { + ssoid := val.(string) + if err := db.Where("sso_id = ?", ssoid).First(¤tUser).Error; err == nil { + data["User"] = currentUser } } + + // Si ADMIN → récupérer tous les utilisateurs qui ont des conversations + if currentUser.Role == models.ROLE_ADMIN { + var clients []models.User + db.Raw(` + SELECT DISTINCT users.* + FROM users + JOIN conversations ON users.id = conversations.user_id + ORDER BY users.email + `).Scan(&clients) + data["Clients"] = clients + } + renderTemplate(w, "adminconversations", data) } } + func AdminConversationRows(db *gorm.DB) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { // 1. Récupérer SSOID depuis le contexte @@ -426,7 +438,6 @@ func Dashboard(db *gorm.DB) http.HandlerFunc { } - func renderTemplate(w http.ResponseWriter, templ string, data map[string]interface{}) { t, err := template.ParseFiles( "./frontend/templates/head.pages.tmpl", diff --git a/frontend/templates/admin_users.pages.tmpl b/frontend/templates/admin_users.pages.tmpl index a9f4a38..fbf40d5 100644 --- a/frontend/templates/admin_users.pages.tmpl +++ b/frontend/templates/admin_users.pages.tmpl @@ -45,16 +45,13 @@ > ✏️ Modifier - - - + {{ end }} diff --git a/frontend/templates/adminconversations.pages.tmpl b/frontend/templates/adminconversations.pages.tmpl index ff76d4b..a444da1 100644 --- a/frontend/templates/adminconversations.pages.tmpl +++ b/frontend/templates/adminconversations.pages.tmpl @@ -6,6 +6,26 @@
+ {{ if eq .User.Role "ADMIN" }} +
+ +
+
+ +
+
+
+{{ end }} +

💬 Historique des messages — Utilisateur #{{ .UserID }}