feat: scope articles by brand

This commit is contained in:
2026-05-20 15:37:25 +08:00
parent 5fb9d0b0dd
commit dd082e2ed1
72 changed files with 3213 additions and 432 deletions
@@ -78,7 +78,11 @@ func (s *ArticleSelectionOptimizeService) ValidateRequest(
}
actor := auth.MustActor(ctx)
return s.ensureArticleEditable(ctx, articleID, actor.TenantID)
brandID, err := requireCurrentBrandID(ctx)
if err != nil {
return err
}
return s.ensureArticleEditable(ctx, articleID, actor.TenantID, brandID)
}
func (s *ArticleSelectionOptimizeService) OptimizeSelection(
@@ -154,15 +158,17 @@ func (s *ArticleSelectionOptimizeService) ensureArticleEditable(
ctx context.Context,
articleID int64,
tenantID int64,
brandID int64,
) error {
var generateStatus string
err := s.pool.QueryRow(
ctx,
`SELECT generate_status
FROM articles
WHERE id = $1 AND tenant_id = $2 AND deleted_at IS NULL`,
WHERE id = $1 AND tenant_id = $2 AND brand_id = $3 AND deleted_at IS NULL`,
articleID,
tenantID,
brandID,
).Scan(&generateStatus)
if err != nil {
if err == pgx.ErrNoRows {