Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

Working route resolution with a registry

Matt Robertsa4fcdb5eee34
diff --git a/app/cmd/routes.go b/app/cmd/routes.go
index 72911fffb..db7af0794 100644
--- a/app/cmd/routes.go
+++ b/app/cmd/routes.go
@@ -161,7 +161,7 @@ func routes(r *web.Engine) *web.Engine {
ui.Get("/admin/invitations", handlers.Page("Invitations · Site Settings", "", "Administration/pages/Invitations.page"))
ui.Get("/admin/members", handlers.ManageMembers())
ui.Get("/admin/tags", handlers.ManageTags())
- ui.Get("/admin/moderation", handlers.ModerationPage())
+ ui.Get("/admin/moderation", handlers.GetModerationPageHandler())
ui.Get("/admin/authentication", handlers.ManageAuthentication())
ui.Get("/_api/admin/oauth/:provider", handlers.GetOAuthConfig())
@@ -188,8 +188,8 @@ func routes(r *web.Engine) *web.Engine {
ui.Delete("/_api/admin/users/:userID/block", handlers.UnblockUser())
ui.Put("/_api/admin/users/:userID/verify", handlers.VerifyUser())
ui.Delete("/_api/admin/users/:userID/verify", handlers.UnverifyUser())
- ui.Get("/_api/admin/moderation/items", handlers.GetModerationItems())
- ui.Get("/_api/admin/moderation/count", handlers.GetModerationCount())
+ ui.Get("/_api/admin/moderation/items", handlers.GetModerationItemsHandler())
+ ui.Get("/_api/admin/moderation/count", handlers.GetModerationCountHandler())
if env.IsBillingEnabled() {
ui.Get("/admin/billing", handlers.ManageBilling())
@@ -264,14 +264,14 @@ func routes(r *web.Engine) *web.Engine {
adminApi.Put("/api/v1/tags/:slug", apiv1.CreateEditTag())
adminApi.Delete("/api/v1/tags/:slug", apiv1.DeleteTag())
- adminApi.Post("/api/v1/admin/moderation/posts/:id/approve-and-verify", apiv1.ApprovePostAndVerify())
- adminApi.Post("/api/v1/admin/moderation/posts/:id/decline-and-block", apiv1.DeclinePostAndBlock())
- adminApi.Post("/api/v1/admin/moderation/posts/:id/approve", apiv1.ApprovePost())
- adminApi.Post("/api/v1/admin/moderation/posts/:id/decline", apiv1.DeclinePost())
- adminApi.Post("/api/v1/admin/moderation/comments/:id/approve-and-verify", apiv1.ApproveCommentAndVerify())
- adminApi.Post("/api/v1/admin/moderation/comments/:id/decline-and-block", apiv1.DeclineCommentAndBlock())
- adminApi.Post("/api/v1/admin/moderation/comments/:id/approve", apiv1.ApproveComment())
- adminApi.Post("/api/v1/admin/moderation/comments/:id/decline", apiv1.DeclineComment())
+ adminApi.Post("/api/v1/admin/moderation/posts/:id/approve-and-verify", apiv1.GetApprovePostAndVerifyHandler())
+ adminApi.Post("/api/v1/admin/moderation/posts/:id/decline-and-block", apiv1.GetDeclinePostAndBlockHandler())
+ adminApi.Post("/api/v1/admin/moderation/posts/:id/approve", apiv1.GetApprovePostHandler())
+ adminApi.Post("/api/v1/admin/moderation/posts/:id/decline", apiv1.GetDeclinePostHandler())
+ adminApi.Post("/api/v1/admin/moderation/comments/:id/approve-and-verify", apiv1.GetApproveCommentAndVerifyHandler())
+ adminApi.Post("/api/v1/admin/moderation/comments/:id/decline-and-block", apiv1.GetDeclineCommentAndBlockHandler())
+ adminApi.Post("/api/v1/admin/moderation/comments/:id/approve", apiv1.GetApproveCommentHandler())
+ adminApi.Post("/api/v1/admin/moderation/comments/:id/decline", apiv1.GetDeclineCommentHandler())
adminApi.Use(middlewares.BlockLockedTenants())
adminApi.Delete("/api/v1/posts/:number", apiv1.DeletePost())
diff --git a/app/handlers/apiv1/moderation.go b/app/handlers/apiv1/moderation.go
index b6734172a..7bf70ff60 100644
--- a/app/handlers/apiv1/moderation.go
+++ b/app/handlers/apiv1/moderation.go
@@ -1,193 +1,61 @@
package apiv1
import (
- "strconv"
-
- "github.com/getfider/fider/app/models/cmd"
- "github.com/getfider/fider/app/models/query"
- "github.com/getfider/fider/app/pkg/bus"
- "github.com/getfider/fider/app/pkg/log"
"github.com/getfider/fider/app/pkg/web"
)
-// ApprovePost approves a post
+// ApprovePost approves a post (stub - requires commercial license)
func ApprovePost() web.HandlerFunc {
return func(c *web.Context) error {
- postID, err := strconv.Atoi(c.Param("id"))
- if err != nil {
- return c.BadRequest(web.Map{"error": "Invalid post ID"})
- }
-
- if err := bus.Dispatch(c, &cmd.ApprovePost{PostID: postID}); err != nil {
- return c.Failure(err)
- }
-
- return c.Ok(web.Map{})
+ return c.BadRequest(web.Map{"error": "Content moderation requires commercial license"})
}
}
-// DeclinePost declines (deletes) a post
+// DeclinePost declines (deletes) a post (stub - requires commercial license)
func DeclinePost() web.HandlerFunc {
return func(c *web.Context) error {
- postID, err := strconv.Atoi(c.Param("id"))
- if err != nil {
- return c.BadRequest(web.Map{"error": "Invalid post ID"})
- }
-
- if err := bus.Dispatch(c, &cmd.DeclinePost{PostID: postID}); err != nil {
- return c.Failure(err)
- }
-
- return c.Ok(web.Map{})
+ return c.BadRequest(web.Map{"error": "Content moderation requires commercial license"})
}
}
-// ApproveComment approves a comment
+// ApproveComment approves a comment (stub - requires commercial license)
func ApproveComment() web.HandlerFunc {
return func(c *web.Context) error {
- commentID, err := strconv.Atoi(c.Param("id"))
- if err != nil {
- return c.BadRequest(web.Map{"error": "Invalid comment ID"})
- }
-
- if err := bus.Dispatch(c, &cmd.ApproveComment{CommentID: commentID}); err != nil {
- return c.Failure(err)
- }
-
- return c.Ok(web.Map{})
+ return c.BadRequest(web.Map{"error": "Content moderation requires commercial license"})
}
}
-// DeclineComment declines (deletes) a comment
+// DeclineComment declines (deletes) a comment (stub - requires commercial license)
func DeclineComment() web.HandlerFunc {
return func(c *web.Context) error {
- commentID, err := strconv.Atoi(c.Param("id"))
- if err != nil {
- return c.BadRequest(web.Map{"error": "Invalid comment ID"})
- }
-
- if err := bus.Dispatch(c, &cmd.DeclineComment{CommentID: commentID}); err != nil {
- return c.Failure(err)
- }
-
- return c.Ok(web.Map{})
+ return c.BadRequest(web.Map{"error": "Content moderation requires commercial license"})
}
}
-// DeclinePostAndBlock declines (deletes) a post and blocks the user
+// DeclinePostAndBlock declines (deletes) a post and blocks the user (stub - requires commercial license)
func DeclinePostAndBlock() web.HandlerFunc {
return func(c *web.Context) error {
-
- // Get the post that is being declined
- postID, err := strconv.Atoi(c.Param("id"))
- if err != nil {
- return c.BadRequest(web.Map{"error": "Invalid post ID"})
- }
-
- getPost := &query.GetPostByID{PostID: postID}
- if err := bus.Dispatch(c, getPost); err != nil {
- return c.Failure(err)
- }
-
- // Call the existing BlockUser command inside the DeclinePostAndBlock handler
- err = bus.Dispatch(c, &cmd.BlockUser{UserID: getPost.Result.User.ID})
- if err != nil {
- return c.Failure(err)
- }
-
- // Finally call the existing DeclinePost command
- err = bus.Dispatch(c, &cmd.DeclinePost{PostID: postID})
- if err != nil {
- return c.Failure(err)
- }
-
- return c.Ok(web.Map{})
+ return c.BadRequest(web.Map{"error": "Content moderation requires commercial license"})
}
}
-// DeclineCommentAndBlock declines (deletes) a comment and blocks the user
+// DeclineCommentAndBlock declines (deletes) a comment and blocks the user (stub - requires commercial license)
func DeclineCommentAndBlock() web.HandlerFunc {
return func(c *web.Context) error {
- // Get the comment that is being declined
- commentID, err := strconv.Atoi(c.Param("id"))
- if err != nil {
- return c.BadRequest(web.Map{"error": "Invalid comment ID"})
- }
-
- getComment := &query.GetCommentByID{CommentID: commentID}
- if err := bus.Dispatch(c, getComment); err != nil {
- return c.Failure(err)
- }
-
- // Call the existing BlockUser command inside the DeclinePostAndBlock handler
- err = bus.Dispatch(c, &cmd.BlockUser{UserID: getComment.Result.User.ID})
- if err != nil {
- return c.Failure(err)
- }
-
- // Finally call the existing DeclinePost command
- err = bus.Dispatch(c, &cmd.DeclineComment{CommentID: commentID})
- if err != nil {
- return c.Failure(err)
- }
-
- return c.Ok(web.Map{})
+ return c.BadRequest(web.Map{"error": "Content moderation requires commercial license"})
}
}
-// ApprovePostAndVerify approves a post and verifies the user
+// ApprovePostAndVerify approves a post and verifies the user (stub - requires commercial license)
func ApprovePostAndVerify() web.HandlerFunc {
return func(c *web.Context) error {
- postID, err := strconv.Atoi(c.Param("id"))
- if err != nil {
- return c.BadRequest(web.Map{"error": "Invalid post ID"})
- }
-
- // Get the post that is being approved
- getPost := &query.GetPostByID{PostID: postID}
- if err := bus.Dispatch(c, getPost); err != nil {
- return c.Failure(err)
- }
-
- // First approve the post
- if err := bus.Dispatch(c, &cmd.ApprovePost{PostID: postID}); err != nil {
- return c.Failure(err)
- }
-
- // Then verify the user
- if err := bus.Dispatch(c, &cmd.VerifyUser{UserID: getPost.Result.User.ID}); err != nil {
- return c.Failure(err)
- }
-
- return c.Ok(web.Map{})
+ return c.BadRequest(web.Map{"error": "Content moderation requires commercial license"})
}
}
-// ApproveCommentAndVerify approves a comment and verifies the user
+// ApproveCommentAndVerify approves a comment and verifies the user (stub - requires commercial license)
func ApproveCommentAndVerify() web.HandlerFunc {
return func(c *web.Context) error {
- log.Info(c, "Approving comment and verifying user")
- commentID, err := strconv.Atoi(c.Param("id"))
- if err != nil {
- return c.BadRequest(web.Map{"error": "Invalid comment ID"})
- }
-
- // Get the comment that is being approved
- getComment := &query.GetCommentByID{CommentID: commentID}
- if err := bus.Dispatch(c, getComment); err != nil {
- return c.Failure(err)
- }
-
- // First approve the comment
- if err := bus.Dispatch(c, &cmd.ApproveComment{CommentID: commentID}); err != nil {
- return c.Failure(err)
- }
-
- // Then verify the user
- if err := bus.Dispatch(c, &cmd.VerifyUser{UserID: getComment.Result.User.ID}); err != nil {
- return c.Failure(err)
- }
-
- return c.Ok(web.Map{})
+ return c.BadRequest(web.Map{"error": "Content moderation requires commercial license"})
}
}
diff --git a/app/handlers/apiv1/registry.go b/app/handlers/apiv1/registry.go
new file mode 100644
index 000000000..43e1baf3c
--- /dev/null
+++ b/app/handlers/apiv1/registry.go
@@ -0,0 +1,82 @@
+package apiv1
+
+import (
+ "github.com/getfider/fider/app/pkg/web"
+)
+
+// Handler registry for commercial API v1 overrides
+type HandlerRegistry struct {
+ ApprovePost func() web.HandlerFunc
+ DeclinePost func() web.HandlerFunc
+ ApproveComment func() web.HandlerFunc
+ DeclineComment func() web.HandlerFunc
+ DeclinePostAndBlock func() web.HandlerFunc
+ DeclineCommentAndBlock func() web.HandlerFunc
+ ApprovePostAndVerify func() web.HandlerFunc
+ ApproveCommentAndVerify func() web.HandlerFunc
+}
+
+var registry = &HandlerRegistry{
+ ApprovePost: ApprovePost,
+ DeclinePost: DeclinePost,
+ ApproveComment: ApproveComment,
+ DeclineComment: DeclineComment,
+ DeclinePostAndBlock: DeclinePostAndBlock,
+ DeclineCommentAndBlock: DeclineCommentAndBlock,
+ ApprovePostAndVerify: ApprovePostAndVerify,
+ ApproveCommentAndVerify: ApproveCommentAndVerify,
+}
+
+// RegisterModerationHandlers allows commercial package to override moderation handlers
+func RegisterModerationHandlers(
+ approvePost func() web.HandlerFunc,
+ declinePost func() web.HandlerFunc,
+ approveComment func() web.HandlerFunc,
+ declineComment func() web.HandlerFunc,
+ declinePostAndBlock func() web.HandlerFunc,
+ declineCommentAndBlock func() web.HandlerFunc,
+ approvePostAndVerify func() web.HandlerFunc,
+ approveCommentAndVerify func() web.HandlerFunc,
+) {
+ registry.ApprovePost = approvePost
+ registry.DeclinePost = declinePost
+ registry.ApproveComment = approveComment
+ registry.DeclineComment = declineComment
+ registry.DeclinePostAndBlock = declinePostAndBlock
+ registry.DeclineCommentAndBlock = declineCommentAndBlock
+ registry.ApprovePostAndVerify = approvePostAndVerify
+ registry.ApproveCommentAndVerify = approveCommentAndVerify
+}
+
+// Handler getters that return the registered handlers
+func GetApprovePostHandler() web.HandlerFunc {
+ return registry.ApprovePost()
+}
+
+func GetDeclinePostHandler() web.HandlerFunc {
+ return registry.DeclinePost()
+}
+
+func GetApproveCommentHandler() web.HandlerFunc {
+ return registry.ApproveComment()
+}
+
+func GetDeclineCommentHandler() web.HandlerFunc {
+ return registry.DeclineComment()
+}
+
+func GetDeclinePostAndBlockHandler() web.HandlerFunc {
+ return registry.DeclinePostAndBlock()
+}
+
+func GetDeclineCommentAndBlockHandler() web.HandlerFunc {
+ return registry.DeclineCommentAndBlock()
+}
+
+func GetApprovePostAndVerifyHandler() web.HandlerFunc {
+ return registry.ApprovePostAndVerify()
+}
+
+func GetApproveCommentAndVerifyHandler() web.HandlerFunc {
+ return registry.ApproveCommentAndVerify()
+}
\ No newline at end of file
diff --git a/app/handlers/moderation.go b/app/handlers/moderation.go
index 563a536aa..841a8384f 100644
--- a/app/handlers/moderation.go
+++ b/app/handlers/moderation.go
@@ -3,12 +3,10 @@ package handlers
import (
"net/http"
- "github.com/getfider/fider/app/models/query"
- "github.com/getfider/fider/app/pkg/bus"
"github.com/getfider/fider/app/pkg/web"
)
-// ModerationPage is the moderation administration page
+// ModerationPage is the moderation administration page (stub - requires commercial license)
func ModerationPage() web.HandlerFunc {
return func(c *web.Context) error {
return c.Page(http.StatusOK, web.Props{
@@ -18,30 +16,20 @@ func ModerationPage() web.HandlerFunc {
}
}
-// GetModerationItems returns all unmoderated posts and comments
+// GetModerationItems returns all unmoderated posts and comments (stub - requires commercial license)
func GetModerationItems() web.HandlerFunc {
return func(c *web.Context) error {
- q := &query.GetModerationItems{}
- if err := bus.Dispatch(c, q); err != nil {
- return c.Failure(err)
- }
-
return c.Ok(web.Map{
- "items": q.Result,
+ "items": []interface{}{},
})
}
}
-// GetModerationCount returns the count of items awaiting moderation
+// GetModerationCount returns the count of items awaiting moderation (stub - requires commercial license)
func GetModerationCount() web.HandlerFunc {
return func(c *web.Context) error {
- q := &query.GetModerationCount{}
- if err := bus.Dispatch(c, q); err != nil {
- return c.Failure(err)
- }
-
return c.Ok(web.Map{
- "count": q.Result,
+ "count": 0,
})
}
}
diff --git a/app/handlers/registry.go b/app/handlers/registry.go
new file mode 100644
index 000000000..138708967
--- /dev/null
+++ b/app/handlers/registry.go
@@ -0,0 +1,42 @@
+package handlers
+
+import (
+ "github.com/getfider/fider/app/pkg/web"
+)
+
+// Handler registry for commercial overrides
+type HandlerRegistry struct {
+ ModerationPage func() web.HandlerFunc
+ GetModerationItems func() web.HandlerFunc
+ GetModerationCount func() web.HandlerFunc
+}
+
+var registry = &HandlerRegistry{
+ ModerationPage: ModerationPage,
+ GetModerationItems: GetModerationItems,
+ GetModerationCount: GetModerationCount,
+}
+
+// RegisterModerationHandlers allows commercial package to override moderation handlers
+func RegisterModerationHandlers(
+ moderationPage func() web.HandlerFunc,
+ getModerationItems func() web.HandlerFunc,
+ getModerationCount func() web.HandlerFunc,
+) {
+ registry.ModerationPage = moderationPage
+ registry.GetModerationItems = getModerationItems
+ registry.GetModerationCount = getModerationCount
+}
+
+// Handler getters that return the registered handlers
+func GetModerationPageHandler() web.HandlerFunc {
+ return registry.ModerationPage()
+}
+
+func GetModerationItemsHandler() web.HandlerFunc {
+ return registry.GetModerationItems()
+}
+
+func GetModerationCountHandler() web.HandlerFunc {
+ return registry.GetModerationCount()
+}
\ No newline at end of file
diff --git a/app/models/entity/user.go b/app/models/entity/user.go
index da6540dc9..017afc1da 100644
--- a/app/models/entity/user.go
+++ b/app/models/entity/user.go
@@ -43,7 +43,7 @@ func (u *User) IsAdministrator() bool {
// RequiresModeration returns true if user requires moderation
func (u *User) RequiresModeration() bool {
- return u.Role == enum.RoleVisitor && u.IsVerified == false
+ return u.Role == enum.RoleVisitor && !u.IsVerified
}
// UserProvider represents the relationship between an User and an Authentication provide
diff --git a/app/services/sqlstore/postgres/moderation.go b/app/services/sqlstore/postgres/moderation.go
index 6d761b2e5..7c35daa77 100644
--- a/app/services/sqlstore/postgres/moderation.go
+++ b/app/services/sqlstore/postgres/moderation.go
@@ -2,282 +2,48 @@ package postgres
import (
"context"
- "fmt"
- "time"
"github.com/getfider/fider/app/models/cmd"
- "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/dbx"
"github.com/getfider/fider/app/pkg/errors"
)
+// Stub functions - commercial license required for content moderation
+
func approvePost(ctx context.Context, c *cmd.ApprovePost) error {
- return using(ctx, func(trx *dbx.Trx, tenant *entity.Tenant, user *entity.User) error {
- _, err := trx.Execute(`
- UPDATE posts SET is_approved = true
- WHERE id = $1 AND tenant_id = $2`, c.PostID, tenant.ID)
- if err != nil {
- return errors.Wrap(err, "failed to approve post")
- }
- return nil
- })
+ return errors.New("Content moderation requires commercial license")
}
func declinePost(ctx context.Context, c *cmd.DeclinePost) error {
- return using(ctx, func(trx *dbx.Trx, tenant *entity.Tenant, user *entity.User) error {
- // Use existing query to get the post
- getPost := &query.GetPostByID{PostID: c.PostID}
- if err := bus.Dispatch(ctx, getPost); err != nil {
- return err
- }
-
- // Use SetPostResponse to properly delete the post
- setResponse := &cmd.SetPostResponse{
- Post: getPost.Result,
- Text: "Post declined during moderation",
- Status: enum.PostDeleted,
- }
-
- return bus.Dispatch(ctx, setResponse)
- })
+ return errors.New("Content moderation requires commercial license")
}
func approveComment(ctx context.Context, c *cmd.ApproveComment) error {
- return using(ctx, func(trx *dbx.Trx, tenant *entity.Tenant, user *entity.User) error {
- _, err := trx.Execute(`
- UPDATE comments SET is_approved = true
- WHERE id = $1 AND tenant_id = $2`, c.CommentID, tenant.ID)
- if err != nil {
- return errors.Wrap(err, "failed to approve comment")
- }
- return nil
- })
+ return errors.New("Content moderation requires commercial license")
}
func declineComment(ctx context.Context, c *cmd.DeclineComment) error {
- return using(ctx, func(trx *dbx.Trx, tenant *entity.Tenant, user *entity.User) error {
- // Use existing delete command
- deleteComment := &cmd.DeleteComment{CommentID: c.CommentID}
- return bus.Dispatch(ctx, deleteComment)
- })
+ return errors.New("Content moderation requires commercial license")
}
func bulkApproveItems(ctx context.Context, c *cmd.BulkApproveItems) error {
- return using(ctx, func(trx *dbx.Trx, tenant *entity.Tenant, user *entity.User) error {
- if len(c.PostIDs) > 0 {
- postIDsStr := ""
- for i, id := range c.PostIDs {
- if i > 0 {
- postIDsStr += ","
- }
- postIDsStr += fmt.Sprintf("%d", id)
- }
- _, err := trx.Execute(fmt.Sprintf(`
- UPDATE posts SET is_approved = true
- WHERE id IN (%s) AND tenant_id = $1`, postIDsStr), tenant.ID)
- if err != nil {
- return errors.Wrap(err, "failed to bulk approve posts")
- }
- }
-
- if len(c.CommentIDs) > 0 {
- commentIDsStr := ""
- for i, id := range c.CommentIDs {
- if i > 0 {
- commentIDsStr += ","
- }
- commentIDsStr += fmt.Sprintf("%d", id)
- }
- _, err := trx.Execute(fmt.Sprintf(`
- UPDATE comments SET is_approved = true
- WHERE id IN (%s) AND tenant_id = $1`, commentIDsStr), tenant.ID)
- if err != nil {
- return errors.Wrap(err, "failed to bulk approve comments")
- }
- }
-
- return nil
- })
+ return errors.New("Content moderation requires commercial license")
}
func bulkDeclineItems(ctx context.Context, c *cmd.BulkDeclineItems) error {
- return using(ctx, func(trx *dbx.Trx, tenant *entity.Tenant, user *entity.User) error {
- if len(c.PostIDs) > 0 {
- // Use existing commands to properly delete each post
- for _, postID := range c.PostIDs {
- // Use existing query to get the post
- getPost := &query.GetPostByID{PostID: postID}
- if err := bus.Dispatch(ctx, getPost); err != nil {
- return errors.Wrap(err, "failed to get post for bulk decline")
- }
-
- // Use SetPostResponse to properly delete the post
- setResponse := &cmd.SetPostResponse{
- Post: getPost.Result,
- Text: "Post declined during bulk moderation",
- Status: enum.PostDeleted,
- }
-
- if err := bus.Dispatch(ctx, setResponse); err != nil {
- return errors.Wrap(err, "failed to bulk decline post")
- }
- }
- }
-
- if len(c.CommentIDs) > 0 {
- // Use existing delete command for each comment
- for _, commentID := range c.CommentIDs {
- deleteComment := &cmd.DeleteComment{CommentID: commentID}
- if err := bus.Dispatch(ctx, deleteComment); err != nil {
- return errors.Wrap(err, "failed to bulk decline comment")
- }
- }
- }
-
- return nil
- })
-}
-
-type dbModerationPost struct {
- ID int `db:"id"`
- Number int `db:"number"`
- Title string `db:"title"`
- Slug string `db:"slug"`
- Description string `db:"description"`
- CreatedAt time.Time `db:"created_at"`
- User *dbUser `db:"user"`
-}
-
-type dbModerationComment struct {
- ID int `db:"id"`
- PostID int `db:"post_id"`
- PostNumber int `db:"post_number"`
- PostSlug string `db:"post_slug"`
- Content string `db:"content"`
- CreatedAt time.Time `db:"created_at"`
- User *dbUser `db:"user"`
- PostTitle string `db:"post_title"`
+ return errors.New("Content moderation requires commercial license")
}
func getModerationItems(ctx context.Context, q *query.GetModerationItems) error {
- return using(ctx, func(trx *dbx.Trx, tenant *entity.Tenant, user *entity.User) error {
- q.Result = make([]*query.ModerationItem, 0)
-
- // Get unmoderated posts
- var posts []*dbModerationPost
-
- err := trx.Select(&posts, `
- SELECT p.id, p.number, p.title, p.slug, p.description, p.created_at,
- u.id AS user_id,
- u.name AS user_name,
- u.email AS user_email,
- u.role AS user_role,
- u.status AS user_status,
- u.avatar_type AS user_avatar_type,
- u.avatar_bkey AS user_avatar_bkey
- FROM posts p
- INNER JOIN users u ON u.id = p.user_id AND u.tenant_id = p.tenant_id
- WHERE p.tenant_id = $1 AND p.is_approved = false and p.status <> $2
- ORDER BY p.created_at DESC`, tenant.ID, enum.PostDeleted)
- if err != nil {
- return errors.Wrap(err, "failed to get unmoderated posts")
- }
-
- for _, post := range posts {
- userWithEmail := &entity.UserWithEmail{
- User: post.User.toModel(ctx),
- }
-
- q.Result = append(q.Result, &query.ModerationItem{
- Type: "post",
- ID: post.ID,
- PostNumber: post.Number,
- PostSlug: post.Slug,
- Title: post.Title,
- Content: post.Description,
- CreatedAt: post.CreatedAt,
- User: userWithEmail,
- })
- }
-
- // Get unmoderated comments
- var comments []*dbModerationComment
-
- err = trx.Select(&comments, `
- SELECT c.id, c.post_id, p.number as post_number, p.slug as post_slug, c.content, c.created_at,
- u.id AS user_id,
- u.name AS user_name,
- u.email AS user_email,
- u.role AS user_role,
- u.status AS user_status,
- u.avatar_type AS user_avatar_type,
- u.avatar_bkey AS user_avatar_bkey,
- p.title as post_title
- FROM comments c
- INNER JOIN users u ON u.id = c.user_id AND u.tenant_id = c.tenant_id
- INNER JOIN posts p ON p.id = c.post_id AND p.tenant_id = c.tenant_id
- WHERE c.tenant_id = $1 AND c.is_approved = false and p.status <> $2
- AND c.deleted_at IS NULL
- ORDER BY c.created_at DESC`, tenant.ID, enum.PostDeleted)
- if err != nil {
- return errors.Wrap(err, "failed to get unmoderated comments")
- }
-
- for _, comment := range comments {
-
- userWithEmail := &entity.UserWithEmail{
- User: comment.User.toModel(ctx),
- }
-
- q.Result = append(q.Result, &query.ModerationItem{
- Type: "comment",
- ID: comment.ID,
- PostID: comment.PostID,
- PostNumber: comment.PostNumber,
- PostSlug: comment.PostSlug,
- Content: comment.Content,
- CreatedAt: comment.CreatedAt,
- PostTitle: comment.PostTitle,
- User: userWithEmail,
- })
- }
-
- return nil
- })
+ q.Result = make([]*query.ModerationItem, 0)
+ return nil
}
func getModerationCount(ctx context.Context, q *query.GetModerationCount) error {
- return using(ctx, func(trx *dbx.Trx, tenant *entity.Tenant, user *entity.User) error {
- var count int
-
- err := trx.Get(&count, `
- SELECT
- (SELECT COUNT(*) FROM posts WHERE tenant_id = $1 AND is_approved = false and status <> $2) +
- (SELECT COUNT(*) FROM comments c JOIN posts p on c.post_id = p.id WHERE p.tenant_id = $1 AND c.is_approved = false AND p.status <> $2 AND c.deleted_at IS NULL)
- `, tenant.ID, enum.PostDeleted)
-
- if err != nil {
- return errors.Wrap(err, "failed to get moderation count")
- }
-
- q.Result = count
- return nil
- })
+ q.Result = 0
+ return nil
}
func verifyUser(ctx context.Context, c *cmd.VerifyUser) error {
- return using(ctx, func(trx *dbx.Trx, tenant *entity.Tenant, user *entity.User) error {
- // Verify and unblock the user (can't be both blocked and verified)
- _, err := trx.Execute(`
- UPDATE users SET is_verified = true, status = $1
- WHERE id = $2 AND tenant_id = $3`, enum.UserActive, c.UserID, tenant.ID)
- if err != nil {
- return errors.Wrap(err, "failed to verify user")
- }
-
- return nil
- })
-}
+ return errors.New("Content moderation requires commercial license")
+}
\ No newline at end of file
diff --git a/app/services/sqlstore/postgres/postgres.go b/app/services/sqlstore/postgres/postgres.go
index 50bae5c84..b80354fb4 100644
--- a/app/services/sqlstore/postgres/postgres.go
+++ b/app/services/sqlstore/postgres/postgres.go
@@ -4,6 +4,7 @@ import (
"context"
"github.com/getfider/fider/app"
+ "github.com/getfider/fider/app/services"
"github.com/getfider/fider/app/models/entity"
"github.com/getfider/fider/app/pkg/bus"
@@ -142,15 +143,19 @@ func (s Service) Init() {
bus.AddHandler(AddMentionNotification)
bus.AddHandler(getMentionsNotifications)
- bus.AddHandler(approvePost)
- bus.AddHandler(declinePost)
- bus.AddHandler(approveComment)
- bus.AddHandler(declineComment)
- bus.AddHandler(bulkApproveItems)
- bus.AddHandler(bulkDeclineItems)
- bus.AddHandler(getModerationItems)
- bus.AddHandler(getModerationCount)
- bus.AddHandler(verifyUser)
+ // Only register moderation handlers if commercial service is not available
+ // Check if commercial features are enabled via license service
+ if !services.IsCommercialFeatureEnabled(services.FeatureContentModeration) {
+ bus.AddHandler(approvePost)
+ bus.AddHandler(declinePost)
+ bus.AddHandler(approveComment)
+ bus.AddHandler(declineComment)
+ bus.AddHandler(bulkApproveItems)
+ bus.AddHandler(bulkDeclineItems)
+ bus.AddHandler(getModerationItems)
+ bus.AddHandler(getModerationCount)
+ bus.AddHandler(verifyUser)
+ }
}
type SqlHandler func(trx *dbx.Trx, tenant *entity.Tenant, user *entity.User) error
diff --git a/commercial/handlers/moderation.go b/commercial/handlers/moderation.go
index a45ee7946..4aaa05b6c 100644
--- a/commercial/handlers/moderation.go
+++ b/commercial/handlers/moderation.go
@@ -1,7 +1,6 @@
package handlers
import (
- "context"
"net/http"
"github.com/getfider/fider/app/models/query"
@@ -36,9 +35,8 @@ func GetModerationItems() web.HandlerFunc {
// GetModerationCount returns the count of items awaiting moderation
func GetModerationCount() web.HandlerFunc {
- log.Info(context.Background(), "GetModerationCount outside Handler")
return func(c *web.Context) error {
- log.Info(c, "GetModerationCount inside Handler")
+ log.Info(c, "Getting the moderation count commercial")
q := &query.GetModerationCount{}
if err := bus.Dispatch(c, q); err != nil {
return c.Failure(err)
diff --git a/commercial/init.go b/commercial/init.go
index f8c88e8cf..cdd68afdb 100644
--- a/commercial/init.go
+++ b/commercial/init.go
@@ -12,7 +12,7 @@ func init() {
// Register commercial license service
services.License = &commercialLicenseService{}
- // Register commercial handlers
+ // Register commercial HTTP handlers
handlers.RegisterModerationHandlers(
commercialHandlers.ModerationPage,
commercialHandlers.GetModerationItems,
diff --git a/commercial/routes.go b/commercial/routes.go
deleted file mode 100644
index d4723bd4b..000000000
--- a/commercial/routes.go
+++ /dev/null
@@ -1,81 +0,0 @@
-package commercial
-
-import (
- commercialHandlers "github.com/getfider/fider/commercial/handlers"
- commercialApiv1 "github.com/getfider/fider/commercial/handlers/apiv1"
- "github.com/getfider/fider/app/pkg/web"
-)
-
-// Override system for commercial routes
-
-var (
- // Commercial handler overrides
- CommercialModerationPage = commercialHandlers.ModerationPage
- CommercialGetModerationItems = commercialHandlers.GetModerationItems
- CommercialGetModerationCount = commercialHandlers.GetModerationCount
-
- // Commercial API v1 handler overrides
- CommercialApprovePost = commercialApiv1.ApprovePost
- CommercialDeclinePost = commercialApiv1.DeclinePost
- CommercialApproveComment = commercialApiv1.ApproveComment
- CommercialDeclineComment = commercialApiv1.DeclineComment
- CommercialDeclinePostAndBlock = commercialApiv1.DeclinePostAndBlock
- CommercialDeclineCommentAndBlock = commercialApiv1.DeclineCommentAndBlock
- CommercialApprovePostAndVerify = commercialApiv1.ApprovePostAndVerify
- CommercialApproveCommentAndVerify = commercialApiv1.ApproveCommentAndVerify
-)
-
-// GetModerationHandler returns the appropriate moderation handler based on license
-func GetModerationHandler(fallback func() web.HandlerFunc) func() web.HandlerFunc {
- return CommercialModerationPage
-}
-
-// GetModerationItemsHandler returns the appropriate moderation items handler based on license
-func GetModerationItemsHandler(fallback func() web.HandlerFunc) func() web.HandlerFunc {
- return CommercialGetModerationItems
-}
-
-// GetModerationCountHandler returns the appropriate moderation count handler based on license
-func GetModerationCountHandler(fallback func() web.HandlerFunc) func() web.HandlerFunc {
- return CommercialGetModerationCount
-}
-
-// GetApprovePostHandler returns the appropriate approve post handler based on license
-func GetApprovePostHandler(fallback func() web.HandlerFunc) func() web.HandlerFunc {
- return CommercialApprovePost
-}
-
-// GetDeclinePostHandler returns the appropriate decline post handler based on license
-func GetDeclinePostHandler(fallback func() web.HandlerFunc) func() web.HandlerFunc {
- return CommercialDeclinePost
-}
-
-// GetApproveCommentHandler returns the appropriate approve comment handler based on license
-func GetApproveCommentHandler(fallback func() web.HandlerFunc) func() web.HandlerFunc {
- return CommercialApproveComment
-}
-
-// GetDeclineCommentHandler returns the appropriate decline comment handler based on license
-func GetDeclineCommentHandler(fallback func() web.HandlerFunc) func() web.HandlerFunc {
- return CommercialDeclineComment
-}
-
-// GetDeclinePostAndBlockHandler returns the appropriate decline post and block handler based on license
-func GetDeclinePostAndBlockHandler(fallback func() web.HandlerFunc) func() web.HandlerFunc {
- return CommercialDeclinePostAndBlock
-}
-
-// GetDeclineCommentAndBlockHandler returns the appropriate decline comment and block handler based on license
-func GetDeclineCommentAndBlockHandler(fallback func() web.HandlerFunc) func() web.HandlerFunc {
- return CommercialDeclineCommentAndBlock
-}
-
-// GetApprovePostAndVerifyHandler returns the appropriate approve post and verify handler based on license
-func GetApprovePostAndVerifyHandler(fallback func() web.HandlerFunc) func() web.HandlerFunc {
- return CommercialApprovePostAndVerify
-}
-
-// GetApproveCommentAndVerifyHandler returns the appropriate approve comment and verify handler based on license
-func GetApproveCommentAndVerifyHandler(fallback func() web.HandlerFunc) func() web.HandlerFunc {
- return CommercialApproveCommentAndVerify
-}
\ No newline at end of file
diff --git a/commercial/services/sqlstore/postgres/moderation.go b/commercial/services/sqlstore/postgres/moderation.go
index 13c6cff61..907ccbe0f 100644
--- a/commercial/services/sqlstore/postgres/moderation.go
+++ b/commercial/services/sqlstore/postgres/moderation.go
@@ -13,7 +13,6 @@ import (
"github.com/getfider/fider/app/pkg/bus"
"github.com/getfider/fider/app/pkg/dbx"
"github.com/getfider/fider/app/pkg/errors"
- "github.com/getfider/fider/app/pkg/log"
)
func ApprovePost(ctx context.Context, c *cmd.ApprovePost) error {
@@ -274,12 +273,9 @@ func GetModerationItems(ctx context.Context, q *query.GetModerationItems) error
}
func GetModerationCount(ctx context.Context, q *query.GetModerationCount) error {
- log.Info(ctx, "COMMERCIAL: GetModerationCount function called!")
return using(ctx, func(trx *dbx.Trx, tenant *entity.Tenant, user *entity.User) error {
var count int
- log.Info(ctx, "COMMERCIAL: Getting the moderation count properly")
-
err := trx.Get(&count, `
SELECT
(SELECT COUNT(*) FROM posts WHERE tenant_id = $1 AND is_approved = false and status <> $2) +