From fa5362401ab1583970e19d7dc5049adfa4eae072 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 23 Feb 2026 03:03:05 -0500 Subject: [PATCH] feat: audit log buyer group filter --- internal/handler/audit.go | 17 +++++++++++++++-- internal/handler/deals.go | 8 ++++++++ templates/audit.templ | 25 ++++++++++++++++++++++--- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/internal/handler/audit.go b/internal/handler/audit.go index f492368..68f1140 100644 --- a/internal/handler/audit.go +++ b/internal/handler/audit.go @@ -9,9 +9,10 @@ import ( func (h *Handler) handleAuditLog(w http.ResponseWriter, r *http.Request) { profile := getProfile(r.Context()) dealID := r.URL.Query().Get("deal_id") + buyerGroup := r.URL.Query().Get("buyer_group") deals := h.getDeals(profile) - activities := h.getActivitiesFiltered(profile.OrganizationID, dealID, 50) + activities := h.getActivitiesFilteredBuyer(profile.OrganizationID, dealID, buyerGroup, 50) // Populate deal names dealNames := make(map[string]string) @@ -24,5 +25,17 @@ func (h *Handler) handleAuditLog(w http.ResponseWriter, r *http.Request) { } } - templates.AuditLogPage(profile, activities, deals, dealID).Render(r.Context(), w) + // Get distinct buyer groups for filter + var buyerGroups []string + rows, _ := h.db.Query(`SELECT DISTINCT COALESCE(buyer_group, '') FROM deal_activity WHERE organization_id = ? AND COALESCE(buyer_group, '') != '' ORDER BY buyer_group`, profile.OrganizationID) + if rows != nil { + for rows.Next() { + var bg string + rows.Scan(&bg) + buyerGroups = append(buyerGroups, bg) + } + rows.Close() + } + + templates.AuditLogPage(profile, activities, deals, dealID, buyerGroups, buyerGroup).Render(r.Context(), w) } diff --git a/internal/handler/deals.go b/internal/handler/deals.go index da05cd9..e763cef 100644 --- a/internal/handler/deals.go +++ b/internal/handler/deals.go @@ -499,6 +499,10 @@ func (h *Handler) getActivities(orgID string, limit int) []*model.DealActivity { } func (h *Handler) getActivitiesFiltered(orgID string, dealID string, limit int) []*model.DealActivity { + return h.getActivitiesFilteredBuyer(orgID, dealID, "", limit) +} + +func (h *Handler) getActivitiesFilteredBuyer(orgID string, dealID string, buyerGroup string, limit int) []*model.DealActivity { query := ` SELECT a.id, a.deal_id, a.user_id, a.activity_type, a.resource_type, a.resource_name, a.created_at, COALESCE(p.full_name, 'Unknown') FROM deal_activity a LEFT JOIN profiles p ON a.user_id = p.id @@ -508,6 +512,10 @@ func (h *Handler) getActivitiesFiltered(orgID string, dealID string, limit int) query += " AND a.deal_id = ?" args = append(args, dealID) } + if buyerGroup != "" { + query += " AND a.buyer_group = ?" + args = append(args, buyerGroup) + } query += " ORDER BY a.created_at DESC LIMIT ?" args = append(args, limit) diff --git a/templates/audit.templ b/templates/audit.templ index e0bb5f5..7115b34 100644 --- a/templates/audit.templ +++ b/templates/audit.templ @@ -3,7 +3,7 @@ package templates import "dealroom/internal/model" import "fmt" -templ AuditLogPage(profile *model.Profile, activities []*model.DealActivity, deals []*model.Deal, selectedDealID string) { +templ AuditLogPage(profile *model.Profile, activities []*model.DealActivity, deals []*model.Deal, selectedDealID string, buyerGroups []string, selectedBuyerGroup string) { @Layout(profile, "audit") {
@@ -11,14 +11,33 @@ templ AuditLogPage(profile *model.Profile, activities []*model.DealActivity, dea

Audit Log

Complete activity timeline across all deal rooms.

-
- for _, deal := range deals { } + if len(buyerGroups) > 0 { + + }
+