feat: scope articles by brand
This commit is contained in:
@@ -167,6 +167,11 @@ func (s *PromptRuleGenerationService) runtimeConfig() generationRuntimeConfig {
|
||||
|
||||
func (s *PromptRuleGenerationService) GenerateFromRule(ctx context.Context, req GenerateFromRuleRequest) (*GenerateFromRuleResponse, error) {
|
||||
actor := auth.MustActor(ctx)
|
||||
brandID, err := requireCurrentBrandID(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.BrandID = &brandID
|
||||
extra := clonePromptRuleExtraParams(req.ExtraParams)
|
||||
if strings.TrimSpace(extractString(extra, "generation_mode")) == "" {
|
||||
extra["generation_mode"] = "instant"
|
||||
@@ -258,6 +263,9 @@ func (s *PromptRuleGenerationService) enqueuePromptRuleGeneration(ctx context.Co
|
||||
if err := s.llm.Validate(); err != nil {
|
||||
return nil, response.ErrServiceUnavailable(50311, "llm_unavailable", err.Error())
|
||||
}
|
||||
if input.BrandID == nil || *input.BrandID <= 0 {
|
||||
return nil, response.ErrBadRequest(40033, "brand_context_required", "current brand is required")
|
||||
}
|
||||
|
||||
rule, err := s.loadPromptRule(ctx, input.TenantID, input.PromptRuleID)
|
||||
if err != nil {
|
||||
@@ -408,10 +416,10 @@ func (s *PromptRuleGenerationService) enqueuePromptRuleGeneration(ctx context.Co
|
||||
|
||||
var articleID int64
|
||||
err = tx.QueryRow(ctx, `
|
||||
INSERT INTO articles (tenant_id, source_type, prompt_rule_id, generate_status, publish_status, wizard_state_json)
|
||||
VALUES ($1, 'custom_generation', $2, 'generating', 'unpublished', $3)
|
||||
INSERT INTO articles (tenant_id, brand_id, source_type, prompt_rule_id, generate_status, publish_status, wizard_state_json)
|
||||
VALUES ($1, $2, 'custom_generation', $3, 'generating', 'unpublished', $4)
|
||||
RETURNING id
|
||||
`, input.TenantID, input.PromptRuleID, wizardStateJSON).Scan(&articleID)
|
||||
`, input.TenantID, *input.BrandID, input.PromptRuleID, wizardStateJSON).Scan(&articleID)
|
||||
if err != nil {
|
||||
return nil, response.ErrInternal(50012, "create_failed", "failed to create prompt rule article")
|
||||
}
|
||||
@@ -666,7 +674,13 @@ func (s *PromptRuleGenerationService) enqueueScheduleAutoPublish(ctx context.Con
|
||||
publishTitle = "定时生成文章"
|
||||
}
|
||||
|
||||
if _, err := s.publishJobs.Create(ctx, auth.Actor{
|
||||
brandID := int64(extractInt(job.InputParams, "brand_id"))
|
||||
publishCtx := ctx
|
||||
if brandID > 0 {
|
||||
publishCtx = auth.WithCurrentBrandID(ctx, brandID)
|
||||
}
|
||||
|
||||
if _, err := s.publishJobs.Create(publishCtx, auth.Actor{
|
||||
TenantID: job.TenantID,
|
||||
UserID: job.OperatorID,
|
||||
PrimaryWorkspaceID: workspaceID,
|
||||
|
||||
Reference in New Issue
Block a user