diff --git a/internal/db/migrate.go b/internal/db/migrate.go index 385ac74..1314f0f 100644 --- a/internal/db/migrate.go +++ b/internal/db/migrate.go @@ -233,6 +233,9 @@ var additiveMigrationStmts = []string{ `ALTER TABLE folders ADD COLUMN sort_order INTEGER DEFAULT 0`, // Section 7: file storage path `ALTER TABLE files ADD COLUMN storage_path TEXT DEFAULT ''`, + // Section 9: buyer-specific requests + `ALTER TABLE diligence_requests ADD COLUMN is_buyer_specific INTEGER DEFAULT 0`, + `ALTER TABLE diligence_requests ADD COLUMN visible_to_buyer_group TEXT DEFAULT ''`, } func seed(db *sql.DB) error { diff --git a/internal/handler/deals.go b/internal/handler/deals.go index 6c45027..1c7f6df 100644 --- a/internal/handler/deals.go +++ b/internal/handler/deals.go @@ -363,7 +363,7 @@ func (h *Handler) getFiles(dealID string) []*model.File { } func (h *Handler) getRequests(dealID string, profile *model.Profile) []*model.DiligenceRequest { - query := "SELECT id, deal_id, item_number, section, description, priority, atlas_status, atlas_note, confidence, buyer_comment, seller_comment, buyer_group FROM diligence_requests WHERE deal_id = ?" + query := "SELECT id, deal_id, item_number, section, description, priority, atlas_status, atlas_note, confidence, buyer_comment, seller_comment, buyer_group, linked_file_ids, COALESCE(is_buyer_specific, 0), COALESCE(visible_to_buyer_group, '') FROM diligence_requests WHERE deal_id = ?" args := []interface{}{dealID} if rbac.EffectiveIsBuyer(profile) { @@ -374,7 +374,13 @@ func (h *Handler) getRequests(dealID string, profile *model.Profile) []*model.Di placeholders[i] = "?" args = append(args, g) } - query += " AND buyer_group IN (" + strings.Join(placeholders, ",") + ")" + // Show general requests (not buyer-specific) AND buyer-specific ones for this group + query += " AND (COALESCE(is_buyer_specific, 0) = 0 OR COALESCE(visible_to_buyer_group, '') IN (" + strings.Join(placeholders, ",") + "))" + // Also filter by buyer_group for general requests + query += " AND (buyer_group IN (" + strings.Join(placeholders, ",") + ") OR buyer_group = '')" + for _, g := range groups { + args = append(args, g) + } } } query += " ORDER BY item_number" @@ -388,7 +394,7 @@ func (h *Handler) getRequests(dealID string, profile *model.Profile) []*model.Di var reqs []*model.DiligenceRequest for rows.Next() { r := &model.DiligenceRequest{} - rows.Scan(&r.ID, &r.DealID, &r.ItemNumber, &r.Section, &r.Description, &r.Priority, &r.AtlasStatus, &r.AtlasNote, &r.Confidence, &r.BuyerComment, &r.SellerComment, &r.BuyerGroup) + rows.Scan(&r.ID, &r.DealID, &r.ItemNumber, &r.Section, &r.Description, &r.Priority, &r.AtlasStatus, &r.AtlasNote, &r.Confidence, &r.BuyerComment, &r.SellerComment, &r.BuyerGroup, &r.LinkedFileIDs, &r.IsBuyerSpecific, &r.VisibleToBuyerGroup) reqs = append(reqs, r) } return reqs diff --git a/internal/model/models.go b/internal/model/models.go index 50f8b1f..37f690a 100644 --- a/internal/model/models.go +++ b/internal/model/models.go @@ -98,8 +98,10 @@ type DiligenceRequest struct { BuyerComment string SellerComment string BuyerGroup string - LinkedFileIDs string - CreatedBy string + LinkedFileIDs string + IsBuyerSpecific bool + VisibleToBuyerGroup string + CreatedBy string CreatedAt time.Time UpdatedAt time.Time }