diff --git a/backend/renders/renders.go b/backend/renders/renders.go
index 0b91560..cfdaad6 100644
--- a/backend/renders/renders.go
+++ b/backend/renders/renders.go
@@ -206,15 +206,55 @@ func AdminConversationPage(db *gorm.DB) http.HandlerFunc {
func AdminConversationRows(db *gorm.DB) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
+ // 1. Récupérer SSOID depuis le contexte
+ val := r.Context().Value("ssoid")
+ ssoid, ok := val.(string)
+ if !ok || ssoid == "" {
+ http.Error(w, "Non authentifié", http.StatusUnauthorized)
+ return
+ }
+
+ // 2. Trouver l'utilisateur
+ var currentUser models.User
+ if err := db.Where("sso_id = ?", ssoid).First(¤tUser).Error; err != nil {
+ http.Error(w, "Utilisateur introuvable", http.StatusUnauthorized)
+ return
+ }
+
+ // 3. Récupération des filtres
idStr := mux.Vars(r)["id"]
id, _ := strconv.Atoi(idStr)
typeFilter := r.URL.Query().Get("type")
+ dateFilter := r.URL.Query().Get("filter")
+
+ var fromDate time.Time
+ now := time.Now()
+ switch dateFilter {
+ case "today":
+ fromDate = time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
+ case "week":
+ fromDate = now.AddDate(0, 0, -7)
+ default:
+ fromDate = time.Time{}
+ }
var convs []models.Conversation
- query := db.Where("user_id = ?", id)
+ query := db.Model(&models.Conversation{})
+
+ // 4. ADMIN → tout ou par utilisateur ciblé
+ if currentUser.Role != models.ROLE_ADMIN {
+ query = query.Where("user_id = ?", currentUser.ID)
+ } else if id > 0 {
+ query = query.Where("user_id = ?", id)
+ }
+
+ if !fromDate.IsZero() {
+ query = query.Where("created_at >= ?", fromDate)
+ }
if typeFilter != "" {
query = query.Where("type = ?", typeFilter)
}
+
query.Order("created_at desc").Find(&convs)
data := map[string]interface{}{
@@ -225,6 +265,8 @@ func AdminConversationRows(db *gorm.DB) http.HandlerFunc {
}
}
+
+
func AdminConversationThread(db *gorm.DB) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
idStr := mux.Vars(r)["id"]
diff --git a/frontend/templates/adminconversations.pages.tmpl b/frontend/templates/adminconversations.pages.tmpl
index c9a8621..f892ef2 100644
--- a/frontend/templates/adminconversations.pages.tmpl
+++ b/frontend/templates/adminconversations.pages.tmpl
@@ -1,41 +1,69 @@
{{ define "adminconversations.pages.tmpl" }}
{{ template "head" . }}
+
{{ template "sidebar" . }}
+
-
Historique des messages de l'utilisateur #{{ .UserID }}
+
@@ -54,4 +82,5 @@ function filterTable(colIndex, filterValue) {
}
}
+
{{ end }}