dddd
This commit is contained in:
parent
1740282725
commit
6a6ccf96cb
@ -274,22 +274,34 @@ 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 {
|
||||
|
||||
var currentUser models.User
|
||||
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
|
||||
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",
|
||||
|
||||
@ -49,12 +49,9 @@
|
||||
hx-delete="/api/user/delete/{{ .ID }}"
|
||||
hx-confirm="Confirmer suppression ?"
|
||||
hx-target="#userList"
|
||||
hx-swap="outerHTML"
|
||||
hx-on="htmx:afterRequest: if (event.detail.xhr.status === 200) { alert('Utilisateur supprimé avec succès'); setTimeout(() => window.location.reload(), 500); }">
|
||||
🗑️ Supprimer
|
||||
</button>
|
||||
|
||||
|
||||
hx-swap="outerHTML">
|
||||
🗑️ Supprimer
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
|
||||
@ -6,6 +6,26 @@
|
||||
|
||||
<div class="column is-10">
|
||||
<section class="section">
|
||||
{{ if eq .User.Role "ADMIN" }}
|
||||
<div class="field mb-3">
|
||||
<label class="label">👤 Voir les conversations de :</label>
|
||||
<div class="control">
|
||||
<div class="select is-small">
|
||||
<select id="userSelect"
|
||||
name="user"
|
||||
onchange="location.href='/admin/user/' + this.value + '/conversations'">
|
||||
<option value="">Tous les utilisateurs</option>
|
||||
{{ range .Clients }}
|
||||
<option value="{{ .ID }}" {{ if eq $.UserID (printf "%d" .ID) }}selected{{ end }}>
|
||||
{{ .Email }}
|
||||
</option>
|
||||
{{ end }}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{ end }}
|
||||
|
||||
<h1 class="title is-4">💬 Historique des messages — Utilisateur #{{ .UserID }}</h1>
|
||||
|
||||
<!-- Filtres -->
|
||||
|
||||
Loading…
Reference in New Issue
Block a user