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
+27 -22
View File
@@ -26,6 +26,7 @@ func RegisterRoutes(app *bootstrap.App) {
protected.Use(auth.Middleware(app.JWT, app.Sessions))
protected.Use(middleware.TenantScope())
protected.Use(middleware.WorkspaceScope(app.DB))
protected.Use(middleware.BrandScope(app.DB))
protected.GET("/auth/me", authHandler.Me)
protected.POST("/auth/logout", authHandler.Logout)
@@ -76,8 +77,8 @@ func RegisterRoutes(app *bootstrap.App) {
tenantProtected.POST("/tasks/:id/reconcile", desktopTaskHandler.Reconcile)
tenantProtected.POST("/tasks/:id/cancel", desktopTaskHandler.TenantCancel)
tenantProtected.GET("/publish-tasks", desktopTaskHandler.TenantListPublish)
tenantProtected.POST("/publish-tasks/:id/retry", desktopTaskHandler.TenantRetryPublish)
tenantProtected.POST("/publish-jobs", publishJobHandler.Create)
tenantProtected.POST("/publish-tasks/:id/retry", middleware.RequireCurrentBrand(), desktopTaskHandler.TenantRetryPublish)
tenantProtected.POST("/publish-jobs", middleware.RequireCurrentBrand(), publishJobHandler.Create)
complianceHandler := NewComplianceHandler(app)
compliance := tenantProtected.Group("/compliance")
@@ -90,8 +91,8 @@ func RegisterRoutes(app *bootstrap.App) {
workspace := tenantProtected.Group("/workspace")
wsHandler := NewWorkspaceHandler(app)
workspace.GET("/overview", wsHandler.Overview)
workspace.GET("/recent-articles", wsHandler.RecentArticles)
workspace.GET("/overview", middleware.RequireCurrentBrand(), wsHandler.Overview)
workspace.GET("/recent-articles", middleware.RequireCurrentBrand(), wsHandler.RecentArticles)
workspace.GET("/quota-summary", wsHandler.QuotaSummary)
workspace.GET("/ai-point-usage", wsHandler.AIPointUsageLogs)
workspace.GET("/template-cards", wsHandler.TemplateCards)
@@ -101,14 +102,14 @@ func RegisterRoutes(app *bootstrap.App) {
tplHandler := NewTemplateHandler(app)
templates.GET("", tplHandler.List)
templates.GET("/:id", tplHandler.Detail)
templates.POST("/:id/drafts", tplHandler.SaveDraft)
templates.POST("/:id/drafts", middleware.RequireCurrentBrand(), tplHandler.SaveDraft)
templates.POST("/:id/analyze-tasks", tplHandler.CreateAnalyzeTask)
templates.GET("/:id/analyze_task_result", tplHandler.GetAnalyzeTaskResult)
templates.POST("/:id/title-tasks", tplHandler.CreateTitleTask)
templates.GET("/:id/gen_title_task_result", tplHandler.GetTitleTaskResult)
templates.POST("/:id/outline-tasks", tplHandler.CreateOutlineTask)
templates.GET("/:id/gen_outline_task_result", tplHandler.GetOutlineTaskResult)
templates.POST("/:id/generate", tplHandler.Generate)
templates.POST("/:id/generate", middleware.RequireCurrentBrand(), tplHandler.Generate)
kolManage := tenantProtected.Group("/kol/manage")
kolManageHandler := NewKolManageHandler(app, publicAssets)
@@ -152,28 +153,31 @@ func RegisterRoutes(app *bootstrap.App) {
kolSubscriptions.GET("/subscriptions", kolMarketplaceHandler.ListSubscriptions)
kolSubscriptions.GET("/subscription-prompts", kolMarketplaceHandler.ListSubscriptionPrompts)
kolSubscriptions.GET("/subscription-prompts/:id/schema", kolMarketplaceHandler.SubscriptionPromptSchema)
kolSubscriptions.POST("/subscription-prompts/:id/generate", kolMarketplaceHandler.Generate)
kolSubscriptions.POST("/subscription-prompts/:id/generate", middleware.RequireCurrentBrand(), kolMarketplaceHandler.Generate)
articles := tenantProtected.Group("/articles")
artHandler := NewArticleHandler(app)
articles.Use(middleware.RequireCurrentBrand())
articles.GET("", artHandler.List)
articles.POST("", artHandler.Create)
articles.POST("/generate-from-rule", artHandler.GenerateFromRule)
articles.POST("/imitations/generate", artHandler.GenerateImitation)
articles.POST("/:id/regenerate", artHandler.Regenerate)
articles.POST("/:id/images", artHandler.UploadImage)
articles.POST("/:id/selection-optimize/stream", artHandler.OptimizeSelectionStream)
articles.GET("/:id", artHandler.Detail)
articles.PUT("/:id", artHandler.Update)
articles.GET("/:id/stream", artHandler.Stream)
articles.GET("/:id/versions", artHandler.Versions)
articles.POST("/:id/compliance/check", complianceHandler.CheckArticle)
articles.GET("/:id/compliance/latest", complianceHandler.LatestCheck)
articles.POST("/:id/compliance/manual-reviews", complianceHandler.SubmitManualReview)
articles.GET("/:id/compliance/manual-reviews/latest", complianceHandler.LatestManualReview)
articles.POST("/:id/compliance/manual-reviews/:review_id/cancel", complianceHandler.CancelManualReview)
articles.GET("/:id/publish-records", mediaHandler.ListPublishRecords)
articles.DELETE("/:id", artHandler.Delete)
articleRecords := articles.Group("/:id")
articleRecords.Use(middleware.ArticleBrandScope(app.DB))
articleRecords.POST("/regenerate", artHandler.Regenerate)
articleRecords.POST("/images", artHandler.UploadImage)
articleRecords.POST("/selection-optimize/stream", artHandler.OptimizeSelectionStream)
articleRecords.GET("", artHandler.Detail)
articleRecords.PUT("", artHandler.Update)
articleRecords.GET("/stream", artHandler.Stream)
articleRecords.GET("/versions", artHandler.Versions)
articleRecords.POST("/compliance/check", complianceHandler.CheckArticle)
articleRecords.GET("/compliance/latest", complianceHandler.LatestCheck)
articleRecords.POST("/compliance/manual-reviews", complianceHandler.SubmitManualReview)
articleRecords.GET("/compliance/manual-reviews/latest", complianceHandler.LatestManualReview)
articleRecords.POST("/compliance/manual-reviews/:review_id/cancel", complianceHandler.CancelManualReview)
articleRecords.GET("/publish-records", mediaHandler.ListPublishRecords)
articleRecords.DELETE("", artHandler.Delete)
brands := tenantProtected.Group("/brands")
brandHandler := NewBrandHandler(app)
@@ -242,6 +246,7 @@ func RegisterRoutes(app *bootstrap.App) {
// Schedule Tasks
schedules := tenantProtected.Group("/schedules")
schHandler := NewScheduleTaskHandler(app)
schedules.Use(middleware.RequireCurrentBrand())
schedules.GET("", schHandler.List)
schedules.POST("", schHandler.Create)
schedules.GET("/:id", schHandler.Detail)
@@ -251,7 +256,7 @@ func RegisterRoutes(app *bootstrap.App) {
instantTasks := tenantProtected.Group("/instant-tasks")
instHandler := NewInstantTaskHandler(app)
instantTasks.GET("", instHandler.List)
instantTasks.GET("", middleware.RequireCurrentBrand(), instHandler.List)
images := tenantProtected.Group("/images")
imgHandler := NewImageHandler(app)