Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

Starting to plumb in commercial toggle

Matt Robertsa44bfee8a370
diff --git a/app/const.go b/app/const.go
index 114118ef9..a0b230ca9 100644
--- a/app/const.go
+++ b/app/const.go
@@ -5,6 +5,9 @@ import "errors"
// ErrNotFound represents an object not found error
var ErrNotFound = errors.New("Object not found")
+// ErrCommercialLicenseRequired is used when a commercial feature is accessed without a license
+var ErrCommercialLicenseRequired = errors.New("Content moderation requires a commercial license")
+
// InvitePlaceholder represents the placeholder used by members to invite other users
var InvitePlaceholder = "%invite%"
diff --git a/app/pkg/env/env.go b/app/pkg/env/env.go
index 8c95ecd5f..784b183a0 100644
--- a/app/pkg/env/env.go
+++ b/app/pkg/env/env.go
@@ -144,6 +144,9 @@ type config struct {
}
GoogleAnalytics string `env:"GOOGLE_ANALYTICS"`
SearchNoiseWords string `env:"SEARCH_NOISE_WORDS,default=add|support|for|implement|create|make|allow|enable|provide|some|also|include|very|make|and|for|to|a|able|function|feature|app"`
+ Commercial struct {
+ Enabled bool `env:"COMMERCIAL_ENABLED,default=true"`
+ }
}
// Config is a strongly typed reference to all configuration parsed from Environment Variables
@@ -244,6 +247,11 @@ func IsBillingEnabled() bool {
return Config.Paddle.VendorID != "" && Config.Paddle.VendorAuthCode != ""
}
+// IsCommercialEnabled returns true if commercial features are enabled
+func IsCommercialEnabled() bool {
+ return Config.Commercial.Enabled
+}
+
// IsProduction returns true on Fider production environment
func IsProduction() bool {
return Config.Environment == "production" || (!IsTest() && !IsDevelopment())
diff --git a/app/pkg/web/context.go b/app/pkg/web/context.go
index a4fc17c08..95064535c 100644
--- a/app/pkg/web/context.go
+++ b/app/pkg/web/context.go
@@ -273,6 +273,10 @@ func (c *Context) Failure(err error) error {
return c.NotFound()
}
+ if cause == app.ErrCommercialLicenseRequired {
+ return c.Forbidden()
+ }
+
if renderErr := c.Page(http.StatusInternalServerError, Props{
Page: "Error/Error500.page",
Title: "Shoot! Well, this is unexpected…",
diff --git a/app/pkg/web/renderer.go b/app/pkg/web/renderer.go
index 53e0b6e28..f21191b10 100644
--- a/app/pkg/web/renderer.go
+++ b/app/pkg/web/renderer.go
@@ -204,19 +204,20 @@ func (r *Renderer) Render(w io.Writer, statusCode int, props Props, ctx *Context
public["tenant"] = tenant
public["props"] = props.Data
public["settings"] = &Map{
- "mode": env.Config.HostMode,
- "locale": locale,
- "localeDirection": localeDirection,
- "environment": env.Config.Environment,
- "googleAnalytics": env.Config.GoogleAnalytics,
- "domain": env.MultiTenantDomain(),
- "hasLegal": env.HasLegal(),
- "isBillingEnabled": env.IsBillingEnabled(),
- "baseURL": ctx.BaseURL(),
- "assetsURL": AssetsURL(ctx, ""),
- "oauth": oauthProviders.Result,
- "postWithTags": env.Config.PostCreationWithTagsEnabled,
- "allowAllowedSchemes": env.Config.AllowAllowedSchemes,
+ "mode": env.Config.HostMode,
+ "locale": locale,
+ "localeDirection": localeDirection,
+ "environment": env.Config.Environment,
+ "googleAnalytics": env.Config.GoogleAnalytics,
+ "domain": env.MultiTenantDomain(),
+ "hasLegal": env.HasLegal(),
+ "isBillingEnabled": env.IsBillingEnabled(),
+ "isCommercialEnabled": env.IsCommercialEnabled(),
+ "baseURL": ctx.BaseURL(),
+ "assetsURL": AssetsURL(ctx, ""),
+ "oauth": oauthProviders.Result,
+ "postWithTags": env.Config.PostCreationWithTagsEnabled,
+ "allowAllowedSchemes": env.Config.AllowAllowedSchemes,
}
if ctx.IsAuthenticated() {
diff --git a/commercial/components/ModerationIndicator.tsx b/commercial/components/ModerationIndicator.tsx
index a568944dc..eaba5a9f4 100644
--- a/commercial/components/ModerationIndicator.tsx
+++ b/commercial/components/ModerationIndicator.tsx
@@ -11,8 +11,7 @@ export const ModerationIndicator = () => {
const [loading, setLoading] = useState(true)
// Check if commercial license is available
- // TODO: This will be replaced with proper license validation in Phase 4
- const hasCommercialLicense = true // Placeholder for development
+ const hasCommercialLicense = fider.settings.isCommercialEnabled
useEffect(() => {
const fetchCount = async () => {
@@ -38,8 +37,6 @@ export const ModerationIndicator = () => {
}, [fider.session.user, fider.session.tenant.isModerationEnabled])
// Don't show the indicator if commercial license is not available
- console.log("hasCommercialLicense:", hasCommercialLicense)
- console.log("isModerationEnabled:", fider.session.tenant.isModerationEnabled)
if (!hasCommercialLicense) {
return null
}
diff --git a/commercial/init.go b/commercial/init.go
index cdd68afdb..44ae65344 100644
--- a/commercial/init.go
+++ b/commercial/init.go
@@ -3,6 +3,7 @@ package commercial
import (
"github.com/getfider/fider/app/handlers"
"github.com/getfider/fider/app/handlers/apiv1"
+ "github.com/getfider/fider/app/pkg/env"
"github.com/getfider/fider/app/services"
commercialHandlers "github.com/getfider/fider/commercial/handlers"
commercialApiv1 "github.com/getfider/fider/commercial/handlers/apiv1"
@@ -12,23 +13,26 @@ func init() {
// Register commercial license service
services.License = &commercialLicenseService{}
- // Register commercial HTTP handlers
- handlers.RegisterModerationHandlers(
- commercialHandlers.ModerationPage,
- commercialHandlers.GetModerationItems,
- commercialHandlers.GetModerationCount,
- )
+ // Only register commercial handlers if commercial features are enabled
+ if env.IsCommercialEnabled() {
+ // Register commercial HTTP handlers
+ handlers.RegisterModerationHandlers(
+ commercialHandlers.ModerationPage,
+ commercialHandlers.GetModerationItems,
+ commercialHandlers.GetModerationCount,
+ )
- apiv1.RegisterModerationHandlers(
- commercialApiv1.ApprovePost,
- commercialApiv1.DeclinePost,
- commercialApiv1.ApproveComment,
- commercialApiv1.DeclineComment,
- commercialApiv1.DeclinePostAndBlock,
- commercialApiv1.DeclineCommentAndBlock,
- commercialApiv1.ApprovePostAndVerify,
- commercialApiv1.ApproveCommentAndVerify,
- )
+ apiv1.RegisterModerationHandlers(
+ commercialApiv1.ApprovePost,
+ commercialApiv1.DeclinePost,
+ commercialApiv1.ApproveComment,
+ commercialApiv1.DeclineComment,
+ commercialApiv1.DeclinePostAndBlock,
+ commercialApiv1.DeclineCommentAndBlock,
+ commercialApiv1.ApprovePostAndVerify,
+ commercialApiv1.ApproveCommentAndVerify,
+ )
+ }
}
// Commercial license service implementation
@@ -36,7 +40,11 @@ type commercialLicenseService struct{}
func (s *commercialLicenseService) IsCommercialFeatureEnabled(feature string) bool {
// TODO: Implement actual license validation
- // For now, return true to enable commercial features during development
+ // For now, use environment variable to control feature availability
+ // Set COMMERCIAL_ENABLED=false to test without commercial features
+ if !env.IsCommercialEnabled() {
+ return false
+ }
return feature == services.FeatureContentModeration
}
@@ -46,4 +54,4 @@ func (s *commercialLicenseService) GetLicenseInfo() *services.LicenseInfo {
Features: []string{services.FeatureContentModeration},
LicenseHolder: "Commercial License Holder",
}
-}
\ No newline at end of file
+}
diff --git a/public/models/settings.ts b/public/models/settings.ts
index 98c129440..a2ff962a7 100644
--- a/public/models/settings.ts
+++ b/public/models/settings.ts
@@ -17,6 +17,7 @@ export interface SystemSettings {
domain: string
hasLegal: boolean
isBillingEnabled: boolean
+ isCommercialEnabled: boolean
baseURL: string
assetsURL: string
oauth: OAuthProviderOption[]