dddd
This commit is contained in:
parent
1740282725
commit
6a6ccf96cb
@ -273,23 +273,35 @@ func AdminUserUpdate(db *gorm.DB) http.HandlerFunc {
|
|||||||
func AdminConversationPage(db *gorm.DB) http.HandlerFunc {
|
func AdminConversationPage(db *gorm.DB) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
idStr := mux.Vars(r)["id"]
|
idStr := mux.Vars(r)["id"]
|
||||||
|
|
||||||
|
|
||||||
data := map[string]interface{}{
|
data := map[string]interface{}{
|
||||||
"UserID": idStr,
|
"UserID": idStr,
|
||||||
}
|
}
|
||||||
if _, exists := data["User"]; !exists {
|
|
||||||
if val := r.Context().Value("ssoid"); val != nil {
|
var currentUser models.User
|
||||||
ssoid := val.(string)
|
if val := r.Context().Value("ssoid"); val != nil {
|
||||||
var user models.User
|
ssoid := val.(string)
|
||||||
if err := db.Where("sso_id = ?", ssoid).First(&user).Error; err == nil {
|
if err := db.Where("sso_id = ?", ssoid).First(¤tUser).Error; err == nil {
|
||||||
data["User"] = user
|
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)
|
renderTemplate(w, "adminconversations", data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func AdminConversationRows(db *gorm.DB) http.HandlerFunc {
|
func AdminConversationRows(db *gorm.DB) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
// 1. Récupérer SSOID depuis le contexte
|
// 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{}) {
|
func renderTemplate(w http.ResponseWriter, templ string, data map[string]interface{}) {
|
||||||
t, err := template.ParseFiles(
|
t, err := template.ParseFiles(
|
||||||
"./frontend/templates/head.pages.tmpl",
|
"./frontend/templates/head.pages.tmpl",
|
||||||
|
|||||||
@ -45,16 +45,13 @@
|
|||||||
>
|
>
|
||||||
✏️ Modifier
|
✏️ Modifier
|
||||||
</a>
|
</a>
|
||||||
<button class="button is-small is-danger"
|
<button class="button is-small is-danger"
|
||||||
hx-delete="/api/user/delete/{{ .ID }}"
|
hx-delete="/api/user/delete/{{ .ID }}"
|
||||||
hx-confirm="Confirmer suppression ?"
|
hx-confirm="Confirmer suppression ?"
|
||||||
hx-target="#userList"
|
hx-target="#userList"
|
||||||
hx-swap="outerHTML"
|
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
|
||||||
🗑️ Supprimer
|
</button>
|
||||||
</button>
|
|
||||||
|
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|||||||
@ -6,6 +6,26 @@
|
|||||||
|
|
||||||
<div class="column is-10">
|
<div class="column is-10">
|
||||||
<section class="section">
|
<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>
|
<h1 class="title is-4">💬 Historique des messages — Utilisateur #{{ .UserID }}</h1>
|
||||||
|
|
||||||
<!-- Filtres -->
|
<!-- Filtres -->
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user