Open platform to collect and prioritize feedback
Add feature flag on post creation with tags
Mercier Mateo3b44094be9ce
diff --git a/app/actions/post.go b/app/actions/post.goindex b2865050b..18255a655 100644--- a/app/actions/post.go+++ b/app/actions/post.go@@ -3,12 +3,14 @@ package actionsimport ("context""time"+ "fmt""github.com/getfider/fider/app/models/dto""github.com/getfider/fider/app/models/entity""github.com/getfider/fider/app/models/enum""github.com/getfider/fider/app/models/query""github.com/getfider/fider/app/pkg/bus"+ "github.com/getfider/fider/app/pkg/env""github.com/getfider/fider/app/pkg/i18n""github.com/gosimple/slug"@@ -29,14 +31,17 @@ type CreateNewPost struct {// OnPreExecute prefetches Tags for later usefunc (input *CreateNewPost) OnPreExecute(ctx context.Context) error {- input.Tags = make([]*entity.Tag, len(input.TagSlugs))- for i, slug := range input.TagSlugs {- getTag := &query.GetTagBySlug{Slug: slug}- if err := bus.Dispatch(ctx, getTag); err != nil {- return err+ fmt.Println(env.Config.PostCreationWithTagsEnabled)+ if env.Config.PostCreationWithTagsEnabled {+ input.Tags = make([]*entity.Tag, len(input.TagSlugs))+ for i, slug := range input.TagSlugs {+ getTag := &query.GetTagBySlug{Slug: slug}+ if err := bus.Dispatch(ctx, getTag); err != nil {+ return err+ }++ input.Tags[i] = getTag.Result}-- input.Tags[i] = getTag.Result}return nil@@ -46,7 +51,7 @@ func (input *CreateNewPost) OnPreExecute(ctx context.Context) error {func (action *CreateNewPost) IsAuthorized(ctx context.Context, user *entity.User) bool {if user == nil {return false- } else if !user.IsCollaborator() {+ } else if env.Config.PostCreationWithTagsEnabled && !user.IsCollaborator() {for _, tag := range action.Tags {if !tag.IsPublic {return falsediff --git a/app/handlers/apiv1/post.go b/app/handlers/apiv1/post.goindex 2c57cbeb8..19f2631cd 100644--- a/app/handlers/apiv1/post.go+++ b/app/handlers/apiv1/post.go@@ -8,6 +8,7 @@ import ("github.com/getfider/fider/app/models/enum""github.com/getfider/fider/app/models/query""github.com/getfider/fider/app/pkg/bus"+ "github.com/getfider/fider/app/pkg/env""github.com/getfider/fider/app/pkg/web""github.com/getfider/fider/app/tasks")@@ -60,10 +61,12 @@ func CreatePost() web.HandlerFunc {return c.Failure(err)}- for _, tag := range action.Tags {- assignTag := &cmd.AssignTag{Tag: tag, Post: newPost.Result}- if err := bus.Dispatch(c, assignTag); err != nil {- return c.Failure(err)+ if env.Config.PostCreationWithTagsEnabled {+ for _, tag := range action.Tags {+ assignTag := &cmd.AssignTag{Tag: tag, Post: newPost.Result}+ if err := bus.Dispatch(c, assignTag); err != nil {+ return c.Failure(err)+ }}}diff --git a/app/pkg/env/env.go b/app/pkg/env/env.goindex 027036338..cb1327846 100644--- a/app/pkg/env/env.go+++ b/app/pkg/env/env.go@@ -42,12 +42,13 @@ type config struct {WriteTimeout time.Duration `env:"HTTP_WRITE_TIMEOUT,default=10s,strict"`IdleTimeout time.Duration `env:"HTTP_IDLE_TIMEOUT,default=120s,strict"`}- Port string `env:"PORT,default=3000"`- HostMode string `env:"HOST_MODE,default=single"`- HostDomain string `env:"HOST_DOMAIN"`- BaseURL string `env:"BASE_URL"`- Locale string `env:"LOCALE,default=en"`- JWTSecret string `env:"JWT_SECRET,required"`+ Port string `env:"PORT,default=3000"`+ HostMode string `env:"HOST_MODE,default=single"`+ HostDomain string `env:"HOST_DOMAIN"`+ BaseURL string `env:"BASE_URL"`+ Locale string `env:"LOCALE,default=en"`+ JWTSecret string `env:"JWT_SECRET,required"`+ PostCreationWithTagsEnabled bool `env:"POST_CREATION_WITH_TAGS_ENABLED,default=false"`Paddle struct {IsSandbox bool `env:"PADDLE_SANDBOX,default=false"`VendorID string `env:"PADDLE_VENDOR_ID"`