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
@@ -38,6 +38,10 @@ type articleRegenerationRecord struct {
func (s *ArticleService) Regenerate(ctx context.Context, articleID int64) (*RegenerateArticleResponse, error) {
actor := auth.MustActor(ctx)
brandID, err := requireCurrentBrandID(ctx)
if err != nil {
return nil, err
}
if s == nil || s.llm == nil || s.rabbitMQ == nil {
return nil, response.ErrServiceUnavailable(50310, "generation_queue_unavailable", "generation queue is not configured")
}
@@ -57,7 +61,7 @@ func (s *ArticleService) Regenerate(ctx context.Context, articleID int64) (*Rege
}
defer rollbackGenerationTx(tx)
record, err := loadArticleForRegeneration(ctx, tx, actor.TenantID, articleID)
record, err := loadArticleForRegeneration(ctx, tx, actor.TenantID, brandID, articleID)
if err != nil {
return nil, err
}
@@ -184,15 +188,15 @@ func (s *ArticleService) Regenerate(ctx context.Context, articleID int64) (*Rege
return &RegenerateArticleResponse{ArticleID: articleID, TaskID: taskID}, nil
}
func loadArticleForRegeneration(ctx context.Context, tx pgx.Tx, tenantID, articleID int64) (*articleRegenerationRecord, error) {
func loadArticleForRegeneration(ctx context.Context, tx pgx.Tx, tenantID, brandID, articleID int64) (*articleRegenerationRecord, error) {
record := &articleRegenerationRecord{}
var templateID, kolPromptID, promptRuleID sql.NullInt64
err := tx.QueryRow(ctx, `
SELECT id, source_type, template_id, kol_prompt_id, prompt_rule_id, generate_status, wizard_state_json
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
FOR UPDATE
`, articleID, tenantID).Scan(
`, articleID, tenantID, brandID).Scan(
&record.ArticleID,
&record.SourceType,
&templateID,