Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

Generated back-end mostly code.

Matt Robertsb40ef195ed41
diff --git a/app/actions/tenant.go b/app/actions/tenant.go
index fcbd1df1a..13a3e9333 100644
--- a/app/actions/tenant.go
+++ b/app/actions/tenant.go
@@ -193,8 +193,9 @@ func (action *UpdateTenantAdvancedSettings) Validate(ctx context.Context, user *
// UpdateTenantPrivacySettings is the input model used to update tenant privacy settings
type UpdateTenantPrivacySettings struct {
- IsPrivate bool `json:"isPrivate"`
- IsFeedEnabled bool `json:"isFeedEnabled"`
+ IsPrivate bool `json:"isPrivate"`
+ IsFeedEnabled bool `json:"isFeedEnabled"`
+ IsModerationEnabled bool `json:"isModerationEnabled"`
}
// IsAuthorized returns true if current user is authorized to perform this action
diff --git a/app/cmd/routes.go b/app/cmd/routes.go
index 4fdd01da5..388861843 100644
--- a/app/cmd/routes.go
+++ b/app/cmd/routes.go
@@ -161,6 +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/authentication", handlers.ManageAuthentication())
ui.Get("/_api/admin/oauth/:provider", handlers.GetOAuthConfig())
@@ -185,6 +186,13 @@ func routes(r *web.Engine) *web.Engine {
ui.Post("/_api/admin/roles/:role/users", handlers.ChangeUserRole())
ui.Put("/_api/admin/users/:userID/block", handlers.BlockUser())
ui.Delete("/_api/admin/users/:userID/block", handlers.UnblockUser())
+ ui.Get("/_api/admin/moderation/items", handlers.GetModerationItems())
+ ui.Post("/_api/admin/moderation/posts/:id/approve", handlers.ApprovePost())
+ ui.Post("/_api/admin/moderation/posts/:id/decline", handlers.DeclinePost())
+ ui.Post("/_api/admin/moderation/comments/:id/approve", handlers.ApproveComment())
+ ui.Post("/_api/admin/moderation/comments/:id/decline", handlers.DeclineComment())
+ ui.Post("/_api/admin/moderation/bulk/approve", handlers.BulkApproveItems())
+ ui.Post("/_api/admin/moderation/bulk/decline", handlers.BulkDeclineItems())
if env.IsBillingEnabled() {
ui.Get("/admin/billing", handlers.ManageBilling())
diff --git a/app/handlers/admin.go b/app/handlers/admin.go
index 376bebf47..19824e254 100644
--- a/app/handlers/admin.go
+++ b/app/handlers/admin.go
@@ -103,8 +103,9 @@ func UpdatePrivacySettings() web.HandlerFunc {
}
updateSettings := &cmd.UpdateTenantPrivacySettings{
- IsPrivate: action.IsPrivate,
- IsFeedEnabled: action.IsFeedEnabled,
+ IsPrivate: action.IsPrivate,
+ IsFeedEnabled: action.IsFeedEnabled,
+ IsModerationEnabled: action.IsModerationEnabled,
}
if err := bus.Dispatch(c, updateSettings); err != nil {
return c.Failure(err)
diff --git a/app/handlers/moderation.go b/app/handlers/moderation.go
new file mode 100644
index 000000000..2683646f7
--- /dev/null
+++ b/app/handlers/moderation.go
@@ -0,0 +1,173 @@
+package handlers
+
+import (
+ "net/http"
+ "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/web"
+)
+
+// ModerationPage is the moderation administration page
+func ModerationPage() web.HandlerFunc {
+ return func(c *web.Context) error {
+ return c.Page(http.StatusOK, web.Props{
+ Page: "Administration/pages/Moderation.page",
+ Title: "Moderation · Site Settings",
+ })
+ }
+}
+
+// GetModerationItems returns all unmoderated posts and comments
+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,
+ })
+ }
+}
+
+// ApprovePost approves a post
+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{})
+ }
+}
+
+// DeclinePost declines (deletes) a post
+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{})
+ }
+}
+
+// ApproveComment approves a comment
+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{})
+ }
+}
+
+// DeclineComment declines (deletes) a comment
+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{})
+ }
+}
+
+// BulkApproveItems approves multiple posts and comments
+func BulkApproveItems() web.HandlerFunc {
+ return func(c *web.Context) error {
+ var request struct {
+ PostIDs []string `json:"postIds"`
+ CommentIDs []string `json:"commentIds"`
+ }
+
+ if err := c.Bind(&request); err != nil {
+ return c.BadRequest(web.Map{"error": "Invalid request format"})
+ }
+
+ postIDs := make([]int, 0, len(request.PostIDs))
+ for _, idStr := range request.PostIDs {
+ if id, err := strconv.Atoi(idStr); err == nil {
+ postIDs = append(postIDs, id)
+ }
+ }
+
+ commentIDs := make([]int, 0, len(request.CommentIDs))
+ for _, idStr := range request.CommentIDs {
+ if id, err := strconv.Atoi(idStr); err == nil {
+ commentIDs = append(commentIDs, id)
+ }
+ }
+
+ if err := bus.Dispatch(c, &cmd.BulkApproveItems{
+ PostIDs: postIDs,
+ CommentIDs: commentIDs,
+ }); err != nil {
+ return c.Failure(err)
+ }
+
+ return c.Ok(web.Map{})
+ }
+}
+
+// BulkDeclineItems declines (deletes) multiple posts and comments
+func BulkDeclineItems() web.HandlerFunc {
+ return func(c *web.Context) error {
+ var request struct {
+ PostIDs []string `json:"postIds"`
+ CommentIDs []string `json:"commentIds"`
+ }
+
+ if err := c.Bind(&request); err != nil {
+ return c.BadRequest(web.Map{"error": "Invalid request format"})
+ }
+
+ postIDs := make([]int, 0, len(request.PostIDs))
+ for _, idStr := range request.PostIDs {
+ if id, err := strconv.Atoi(idStr); err == nil {
+ postIDs = append(postIDs, id)
+ }
+ }
+
+ commentIDs := make([]int, 0, len(request.CommentIDs))
+ for _, idStr := range request.CommentIDs {
+ if id, err := strconv.Atoi(idStr); err == nil {
+ commentIDs = append(commentIDs, id)
+ }
+ }
+
+ if err := bus.Dispatch(c, &cmd.BulkDeclineItems{
+ PostIDs: postIDs,
+ CommentIDs: commentIDs,
+ }); err != nil {
+ return c.Failure(err)
+ }
+
+ return c.Ok(web.Map{})
+ }
+}
\ No newline at end of file
diff --git a/app/models/cmd/moderation.go b/app/models/cmd/moderation.go
new file mode 100644
index 000000000..24ee12137
--- /dev/null
+++ b/app/models/cmd/moderation.go
@@ -0,0 +1,27 @@
+package cmd
+
+type ApprovePost struct {
+ PostID int
+}
+
+type DeclinePost struct {
+ PostID int
+}
+
+type ApproveComment struct {
+ CommentID int
+}
+
+type DeclineComment struct {
+ CommentID int
+}
+
+type BulkApproveItems struct {
+ PostIDs []int
+ CommentIDs []int
+}
+
+type BulkDeclineItems struct {
+ PostIDs []int
+ CommentIDs []int
+}
\ No newline at end of file
diff --git a/app/models/cmd/tenant.go b/app/models/cmd/tenant.go
index 482514280..375d19a02 100644
--- a/app/models/cmd/tenant.go
+++ b/app/models/cmd/tenant.go
@@ -17,8 +17,9 @@ type CreateTenant struct {
}
type UpdateTenantPrivacySettings struct {
- IsPrivate bool
- IsFeedEnabled bool
+ IsPrivate bool
+ IsFeedEnabled bool
+ IsModerationEnabled bool
}
type UpdateTenantEmailAuthAllowedSettings struct {
diff --git a/app/models/entity/comment.go b/app/models/entity/comment.go
index b07135415..c1343cc5a 100644
--- a/app/models/entity/comment.go
+++ b/app/models/entity/comment.go
@@ -20,4 +20,5 @@ type Comment struct {
EditedAt *time.Time `json:"editedAt,omitempty"`
EditedBy *User `json:"editedBy,omitempty"`
ReactionCounts []ReactionCounts `json:"reactionCounts,omitempty"`
+ IsApproved bool `json:"isApproved"`
}
diff --git a/app/models/entity/post.go b/app/models/entity/post.go
index 98273b017..3e2a93348 100644
--- a/app/models/entity/post.go
+++ b/app/models/entity/post.go
@@ -22,6 +22,7 @@ type Post struct {
Status enum.PostStatus `json:"status"`
Response *PostResponse `json:"response,omitempty"`
Tags []string `json:"tags"`
+ IsApproved bool `json:"isApproved"`
}
// CanBeVoted returns true if this post can have its vote changed
diff --git a/app/models/entity/tenant.go b/app/models/entity/tenant.go
index 98c92e2a6..788013c0d 100644
--- a/app/models/entity/tenant.go
+++ b/app/models/entity/tenant.go
@@ -19,6 +19,7 @@ type Tenant struct {
IsEmailAuthAllowed bool `json:"isEmailAuthAllowed"`
IsFeedEnabled bool `json:"isFeedEnabled"`
PreventIndexing bool `json:"preventIndexing"`
+ IsModerationEnabled bool `json:"isModerationEnabled"`
}
func (t *Tenant) IsDisabled() bool {
diff --git a/app/models/query/moderation.go b/app/models/query/moderation.go
new file mode 100644
index 000000000..2359679b3
--- /dev/null
+++ b/app/models/query/moderation.go
@@ -0,0 +1,20 @@
+package query
+
+import (
+ "github.com/getfider/fider/app/models/entity"
+)
+
+type ModerationItem struct {
+ Type string `json:"type"` // "post" or "comment"
+ ID int `json:"id"`
+ PostID int `json:"postId,omitempty"`
+ Title string `json:"title,omitempty"`
+ Content string `json:"content"`
+ User *entity.User `json:"user"`
+ CreatedAt string `json:"createdAt"`
+ PostTitle string `json:"postTitle,omitempty"`
+}
+
+type GetModerationItems struct {
+ Result []*ModerationItem
+}
\ No newline at end of file
diff --git a/app/services/sqlstore/postgres/comment.go b/app/services/sqlstore/postgres/comment.go
index eaaa17d73..a3e6c6b27 100644
--- a/app/services/sqlstore/postgres/comment.go
+++ b/app/services/sqlstore/postgres/comment.go
@@ -21,6 +21,7 @@ type dbComment struct {
EditedAt dbx.NullTime `db:"edited_at"`
EditedBy *dbUser `db:"edited_by"`
ReactionCounts dbx.NullString `db:"reaction_counts"`
+ IsApproved bool `db:"is_approved"`
}
func (c *dbComment) toModel(ctx context.Context) *entity.Comment {
@@ -30,6 +31,7 @@ func (c *dbComment) toModel(ctx context.Context) *entity.Comment {
CreatedAt: c.CreatedAt,
User: c.User.toModel(ctx),
Attachments: c.Attachments,
+ IsApproved: c.IsApproved,
}
if c.EditedAt.Valid {
comment.EditedBy = c.EditedBy.toModel(ctx)
@@ -44,12 +46,13 @@ func (c *dbComment) toModel(ctx context.Context) *entity.Comment {
func addNewComment(ctx context.Context, c *cmd.AddNewComment) error {
return using(ctx, func(trx *dbx.Trx, tenant *entity.Tenant, user *entity.User) error {
+ isApproved := !tenant.IsModerationEnabled
var id int
if err := trx.Get(&id, `
- INSERT INTO comments (tenant_id, post_id, content, user_id, created_at)
- VALUES ($1, $2, $3, $4, $5)
+ INSERT INTO comments (tenant_id, post_id, content, user_id, created_at, is_approved)
+ VALUES ($1, $2, $3, $4, $5, $6)
RETURNING id
- `, tenant.ID, c.Post.ID, c.Content, user.ID, time.Now()); err != nil {
+ `, tenant.ID, c.Post.ID, c.Content, user.ID, time.Now(), isApproved); err != nil {
return errors.Wrap(err, "failed add new comment")
}
@@ -129,6 +132,7 @@ func getCommentByID(ctx context.Context, q *query.GetCommentByID) error {
c.content,
c.created_at,
c.edited_at,
+ c.is_approved,
u.id AS user_id,
u.name AS user_name,
u.email AS user_email,
@@ -212,6 +216,7 @@ func getCommentsByPost(ctx context.Context, q *query.GetCommentsByPost) error {
c.content,
c.created_at,
c.edited_at,
+ c.is_approved,
u.id AS user_id,
u.name AS user_name,
u.email AS user_email,
diff --git a/app/services/sqlstore/postgres/moderation.go b/app/services/sqlstore/postgres/moderation.go
new file mode 100644
index 000000000..ce991bca8
--- /dev/null
+++ b/app/services/sqlstore/postgres/moderation.go
@@ -0,0 +1,223 @@
+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/query"
+ "github.com/getfider/fider/app/pkg/dbx"
+ "github.com/getfider/fider/app/pkg/errors"
+)
+
+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
+ })
+}
+
+func declinePost(ctx context.Context, c *cmd.DeclinePost) error {
+ return using(ctx, func(trx *dbx.Trx, tenant *entity.Tenant, user *entity.User) error {
+ _, err := trx.Execute(`
+ DELETE FROM posts
+ WHERE id = $1 AND tenant_id = $2`, c.PostID, tenant.ID)
+ if err != nil {
+ return errors.Wrap(err, "failed to decline post")
+ }
+ return nil
+ })
+}
+
+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
+ })
+}
+
+func declineComment(ctx context.Context, c *cmd.DeclineComment) error {
+ return using(ctx, func(trx *dbx.Trx, tenant *entity.Tenant, user *entity.User) error {
+ _, err := trx.Execute(`
+ DELETE FROM comments
+ WHERE id = $1 AND tenant_id = $2`, c.CommentID, tenant.ID)
+ if err != nil {
+ return errors.Wrap(err, "failed to decline comment")
+ }
+ return nil
+ })
+}
+
+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
+ })
+}
+
+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 {
+ postIDsStr := ""
+ for i, id := range c.PostIDs {
+ if i > 0 {
+ postIDsStr += ","
+ }
+ postIDsStr += fmt.Sprintf("%d", id)
+ }
+ _, err := trx.Execute(fmt.Sprintf(`
+ DELETE FROM posts
+ WHERE id IN (%s) AND tenant_id = $1`, postIDsStr), tenant.ID)
+ if err != nil {
+ return errors.Wrap(err, "failed to bulk decline 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(`
+ DELETE FROM comments
+ WHERE id IN (%s) AND tenant_id = $1`, commentIDsStr), tenant.ID)
+ if err != nil {
+ return errors.Wrap(err, "failed to bulk decline comments")
+ }
+ }
+
+ return nil
+ })
+}
+
+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
+ posts := []struct {
+ ID int `db:"id"`
+ Title string `db:"title"`
+ Description string `db:"description"`
+ CreatedAt time.Time `db:"created_at"`
+ UserID int `db:"user_id"`
+ UserName string `db:"user_name"`
+ UserEmail string `db:"user_email"`
+ }{}
+
+ err := trx.Select(&posts, `
+ SELECT p.id, p.title, p.description, p.created_at,
+ u.id as user_id, u.name as user_name, u.email as user_email
+ 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
+ ORDER BY p.created_at DESC`, tenant.ID)
+ if err != nil {
+ return errors.Wrap(err, "failed to get unmoderated posts")
+ }
+
+ for _, post := range posts {
+ q.Result = append(q.Result, &query.ModerationItem{
+ Type: "post",
+ ID: post.ID,
+ Title: post.Title,
+ Content: post.Description,
+ CreatedAt: post.CreatedAt.Format("January 2, 2006 at 3:04 PM"),
+ User: &entity.User{
+ ID: post.UserID,
+ Name: post.UserName,
+ Email: post.UserEmail,
+ },
+ })
+ }
+
+ // Get unmoderated comments
+ comments := []struct {
+ ID int `db:"id"`
+ PostID int `db:"post_id"`
+ Content string `db:"content"`
+ CreatedAt time.Time `db:"created_at"`
+ UserID int `db:"user_id"`
+ UserName string `db:"user_name"`
+ UserEmail string `db:"user_email"`
+ PostTitle string `db:"post_title"`
+ }{}
+
+ err = trx.Select(&comments, `
+ SELECT c.id, c.post_id, c.content, c.created_at,
+ u.id as user_id, u.name as user_name, u.email as user_email,
+ 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
+ ORDER BY c.created_at DESC`, tenant.ID)
+ if err != nil {
+ return errors.Wrap(err, "failed to get unmoderated comments")
+ }
+
+ for _, comment := range comments {
+ q.Result = append(q.Result, &query.ModerationItem{
+ Type: "comment",
+ ID: comment.ID,
+ PostID: comment.PostID,
+ Content: comment.Content,
+ CreatedAt: comment.CreatedAt.Format("January 2, 2006 at 3:04 PM"),
+ PostTitle: comment.PostTitle,
+ User: &entity.User{
+ ID: comment.UserID,
+ Name: comment.UserName,
+ Email: comment.UserEmail,
+ },
+ })
+ }
+
+ return nil
+ })
+}
\ No newline at end of file
diff --git a/app/services/sqlstore/postgres/post.go b/app/services/sqlstore/postgres/post.go
index 9b12dc05d..4bb251dbe 100644
--- a/app/services/sqlstore/postgres/post.go
+++ b/app/services/sqlstore/postgres/post.go
@@ -44,6 +44,7 @@ type dbPost struct {
OriginalSlug sql.NullString `db:"original_slug"`
OriginalStatus sql.NullInt64 `db:"original_status"`
Tags []string `db:"tags"`
+ IsApproved bool `db:"is_approved"`
}
func (i *dbPost) toModel(ctx context.Context) *entity.Post {
@@ -60,6 +61,7 @@ func (i *dbPost) toModel(ctx context.Context) *entity.Post {
Status: enum.PostStatus(i.Status),
User: i.User.toModel(ctx),
Tags: i.Tags,
+ IsApproved: i.IsApproved,
}
if i.Response.Valid {
@@ -289,11 +291,12 @@ func countPostPerStatus(ctx context.Context, q *query.CountPostPerStatus) error
func addNewPost(ctx context.Context, c *cmd.AddNewPost) error {
return using(ctx, func(trx *dbx.Trx, tenant *entity.Tenant, user *entity.User) error {
+ isApproved := !tenant.IsModerationEnabled
var id int
err := trx.Get(&id,
- `INSERT INTO posts (title, slug, number, description, tenant_id, user_id, created_at, status)
- VALUES ($1, $2, (SELECT COALESCE(MAX(number), 0) + 1 FROM posts p WHERE p.tenant_id = $4), $3, $4, $5, $6, 0)
- RETURNING id`, c.Title, slug.Make(c.Title), c.Description, tenant.ID, user.ID, time.Now())
+ `INSERT INTO posts (title, slug, number, description, tenant_id, user_id, created_at, status, is_approved)
+ VALUES ($1, $2, (SELECT COALESCE(MAX(number), 0) + 1 FROM posts p WHERE p.tenant_id = $4), $3, $4, $5, $6, 0, $7)
+ RETURNING id`, c.Title, slug.Make(c.Title), c.Description, tenant.ID, user.ID, time.Now(), isApproved)
if err != nil {
return errors.Wrap(err, "failed add new post")
}
diff --git a/app/services/sqlstore/postgres/postgres.go b/app/services/sqlstore/postgres/postgres.go
index b8bbf9847..4bbb79e78 100644
--- a/app/services/sqlstore/postgres/postgres.go
+++ b/app/services/sqlstore/postgres/postgres.go
@@ -139,6 +139,14 @@ func (s Service) Init() {
bus.AddHandler(getSystemSettings)
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)
}
type SqlHandler func(trx *dbx.Trx, tenant *entity.Tenant, user *entity.User) error
diff --git a/app/services/sqlstore/postgres/tenant.go b/app/services/sqlstore/postgres/tenant.go
index 63e7c10cd..33a78901c 100644
--- a/app/services/sqlstore/postgres/tenant.go
+++ b/app/services/sqlstore/postgres/tenant.go
@@ -133,6 +133,10 @@ func updateTenantPrivacySettings(ctx context.Context, c *cmd.UpdateTenantPrivacy
if err != nil {
return errors.Wrap(err, "failed update tenant feed setting")
}
+ _, err = trx.Execute("UPDATE tenants SET is_moderation_enabled = $1 WHERE id = $2", c.IsModerationEnabled, tenant.ID)
+ if err != nil {
+ return errors.Wrap(err, "failed update tenant moderation setting")
+ }
return nil
})
}
diff --git a/locale/ar/client.json b/locale/ar/client.json
index 40b96252d..e28eb8cf7 100644
--- a/locale/ar/client.json
+++ b/locale/ar/client.json
@@ -198,4 +198,3 @@
"validation.custom.maxattachments": "يُسمح بحد أقصى {number} من المرفقات.",
"validation.custom.maximagesize": "يجب أن يكون حجم الصورة أصغر من {kilobytes}KB.",
"{count, plural, one {# tag} other {# tags}}": "{count, plural, zero {}one {# وسم} two {# وسوم} few {# وسوم} many {# وسوم} other {# وسوم}}"
-}
\ No newline at end of file
diff --git a/locale/de/client.json b/locale/de/client.json
index 490a58d4a..c82923a42 100644
--- a/locale/de/client.json
+++ b/locale/de/client.json
@@ -198,4 +198,3 @@
"validation.custom.maxattachments": "Es sind maximal {number} Anhänge zulässig.",
"validation.custom.maximagesize": "Die Bildgröße muss kleiner als {kilobytes}KB sein.",
"{count, plural, one {# tag} other {# tags}}": "{count, plural, one {# Tag} other {# Tags}}"
-}
\ No newline at end of file
diff --git a/locale/el/client.json b/locale/el/client.json
index 285154b93..75e603614 100644
--- a/locale/el/client.json
+++ b/locale/el/client.json
@@ -198,4 +198,3 @@
"validation.custom.maxattachments": "Επιτρέπονται έως {number} συνημμένα.",
"validation.custom.maximagesize": "Το μέγεθος της εικόνας πρέπει να είναι μικρότερο από {kilobytes}KB.",
"{count, plural, one {# tag} other {# tags}}": "{count, plural, one {# ετικέτα} other {# ετικέτες}}"
-}
\ No newline at end of file
diff --git a/locale/es-ES/client.json b/locale/es-ES/client.json
index 03ad16bfa..14988203b 100644
--- a/locale/es-ES/client.json
+++ b/locale/es-ES/client.json
@@ -198,4 +198,3 @@
"validation.custom.maxattachments": "Se permite un máximo de {number} archivos adjuntos.",
"validation.custom.maximagesize": "El tamaño de la imagen debe ser menor que {kilobytes}KB.",
"{count, plural, one {# tag} other {# tags}}": "{count, plural, one {# etiqueta} other {# etiquetas}}"
-}
\ No newline at end of file
diff --git a/locale/fr/client.json b/locale/fr/client.json
index a523c0309..944f7e176 100644
--- a/locale/fr/client.json
+++ b/locale/fr/client.json
@@ -198,4 +198,3 @@
"validation.custom.maxattachments": "Un maximum de {number} pièces jointes est autorisé.",
"validation.custom.maximagesize": "La taille de l'image doit être inférieure à {kilobytes}KB.",
"{count, plural, one {# tag} other {# tags}}": "{count, plural, one {# tag} other {# tags}}"
-}
\ No newline at end of file
diff --git a/locale/it/client.json b/locale/it/client.json
index 7ae0a96c6..16bae16a6 100644
--- a/locale/it/client.json
+++ b/locale/it/client.json
@@ -198,4 +198,3 @@
"validation.custom.maxattachments": "Sono consentiti al massimo {number} allegati.",
"validation.custom.maximagesize": "La dimensione dell'immagine deve essere inferiore a {kilobytes}KB.",
"{count, plural, one {# tag} other {# tags}}": "{count, plural, one {# tag} other {# tags}}"
-}
\ No newline at end of file
diff --git a/locale/ja/client.json b/locale/ja/client.json
index f1bc26cdb..a439c64e7 100644
--- a/locale/ja/client.json
+++ b/locale/ja/client.json
@@ -198,4 +198,3 @@
"validation.custom.maxattachments": "最大 {number} 個の添付ファイルが許可されます。",
"validation.custom.maximagesize": "画像サイズは{kilobytes}KB未満である必要があります。",
"{count, plural, one {# tag} other {# tags}}": "{count, plural, one {# tag} other {# tags}}"
-}
\ No newline at end of file
diff --git a/locale/nl/client.json b/locale/nl/client.json
index b2bca7d40..86a36ac79 100644
--- a/locale/nl/client.json
+++ b/locale/nl/client.json
@@ -198,4 +198,3 @@
"validation.custom.maxattachments": "Er zijn maximaal {number} bijlagen toegestaan.",
"validation.custom.maximagesize": "De afbeeldingsgrootte moet kleiner zijn dan {kilobytes}KB.",
"{count, plural, one {# tag} other {# tags}}": "{count, plural, one {# tag} other {# tags}}"
-}
\ No newline at end of file
diff --git a/locale/pl/client.json b/locale/pl/client.json
index 9d4a8ac22..0aa1bf81f 100644
--- a/locale/pl/client.json
+++ b/locale/pl/client.json
@@ -198,4 +198,3 @@
"validation.custom.maxattachments": "Maksymalna liczba załączników to {number}.",
"validation.custom.maximagesize": "Rozmiar obrazu musi być mniejszy niż {kilobytes}KB.",
"{count, plural, one {# tag} other {# tags}}": "{count, plural, one {# tag} few {# tagów} many {# tagów} other {# tagi}}"
-}
\ No newline at end of file
diff --git a/locale/pt-BR/client.json b/locale/pt-BR/client.json
index deedbc39c..07f2d348b 100644
--- a/locale/pt-BR/client.json
+++ b/locale/pt-BR/client.json
@@ -198,4 +198,3 @@
"validation.custom.maxattachments": "São permitidos no máximo {number} anexos.",
"validation.custom.maximagesize": "O tamanho da imagem deve ser menor que {kilobytes}KB.",
"{count, plural, one {# tag} other {# tags}}": "{count, plural, one {# tag} other {# tags}}"
-}
\ No newline at end of file
diff --git a/locale/ru/client.json b/locale/ru/client.json
index 95705f6f1..9d23ae9f5 100644
--- a/locale/ru/client.json
+++ b/locale/ru/client.json
@@ -198,4 +198,3 @@
"validation.custom.maxattachments": "Разрешено максимум {number} вложений.",
"validation.custom.maximagesize": "Размер изображения должен быть меньше {kilobytes}КБ.",
"{count, plural, one {# tag} other {# tags}}": "{count, plural, one {# tag} other {# tags}}"
-}
\ No newline at end of file
diff --git a/locale/sk/client.json b/locale/sk/client.json
index 7b51921ec..9cc563320 100644
--- a/locale/sk/client.json
+++ b/locale/sk/client.json
@@ -198,4 +198,3 @@
"validation.custom.maxattachments": "Maximálny počet príloh je {number}.",
"validation.custom.maximagesize": "Veľkosť obrázka musí byť menšia ako {kilobytes}KB.",
"{count, plural, one {# tag} other {# tags}}": "{count, plural, one {# tag} other {# tags}}"
-}
\ No newline at end of file
diff --git a/locale/sv-SE/client.json b/locale/sv-SE/client.json
index ebdd5a2a9..b2ca6f9f6 100644
--- a/locale/sv-SE/client.json
+++ b/locale/sv-SE/client.json
@@ -198,4 +198,3 @@
"validation.custom.maxattachments": "Maximalt {number} bilagor är tillåtna.",
"validation.custom.maximagesize": "Bildstorleken måste vara mindre än {kilobytes}KB.",
"{count, plural, one {# tag} other {# tags}}": "{count, plural, =1 {# etikett} other {# etiketter}}"
-}
\ No newline at end of file
diff --git a/locale/tr/client.json b/locale/tr/client.json
index a7f8d39e8..dc1128176 100644
--- a/locale/tr/client.json
+++ b/locale/tr/client.json
@@ -198,4 +198,3 @@
"validation.custom.maxattachments": "En fazla {number} ek dosyaya izin verilir.",
"validation.custom.maximagesize": "Resim boyutu {kilobytes}KB'den küçük olmalıdır.",
"{count, plural, one {# tag} other {# tags}}": "{count, plural, one {# etiket} other {# etiket}}"
-}
\ No newline at end of file
diff --git a/locale/zh-CN/client.json b/locale/zh-CN/client.json
index 3e14f306a..4e74ab08b 100644
--- a/locale/zh-CN/client.json
+++ b/locale/zh-CN/client.json
@@ -198,4 +198,3 @@
"validation.custom.maxattachments": "最多允许 {number} 个附件。",
"validation.custom.maximagesize": "图像大小必须小于{kilobytes}KB。",
"{count, plural, one {# tag} other {# tags}}": "{count, plural, one {# tag} other {# tags}}"
-}
\ No newline at end of file
diff --git a/migrations/202507010830_add_moderation_enabled.sql b/migrations/202507010830_add_moderation_enabled.sql
new file mode 100644
index 000000000..3e1306969
--- /dev/null
+++ b/migrations/202507010830_add_moderation_enabled.sql
@@ -0,0 +1,5 @@
+ALTER TABLE tenants ADD is_moderation_enabled BOOLEAN NULL;
+
+UPDATE tenants SET is_moderation_enabled = false;
+
+ALTER TABLE tenants ALTER COLUMN is_moderation_enabled SET NOT NULL;
\ No newline at end of file
diff --git a/migrations/202507010831_add_is_approved.sql b/migrations/202507010831_add_is_approved.sql
new file mode 100644
index 000000000..32763491b
--- /dev/null
+++ b/migrations/202507010831_add_is_approved.sql
@@ -0,0 +1,9 @@
+-- Add is_approved column to posts table
+ALTER TABLE posts ADD is_approved BOOLEAN NULL;
+UPDATE posts SET is_approved = true;
+ALTER TABLE posts ALTER COLUMN is_approved SET NOT NULL;
+
+-- Add is_approved column to comments table
+ALTER TABLE comments ADD is_approved BOOLEAN NULL;
+UPDATE comments SET is_approved = true;
+ALTER TABLE comments ALTER COLUMN is_approved SET NOT NULL;
\ No newline at end of file
diff --git a/public/models/identity.ts b/public/models/identity.ts
index 4e724f9e2..788403f4a 100644
--- a/public/models/identity.ts
+++ b/public/models/identity.ts
@@ -12,6 +12,7 @@ export interface Tenant {
allowedSchemes: string
isEmailAuthAllowed: boolean
isFeedEnabled: boolean
+ isModerationEnabled: boolean
}
export enum TenantStatus {
diff --git a/public/pages/Administration/pages/PrivacySettings.page.tsx b/public/pages/Administration/pages/PrivacySettings.page.tsx
index d10715f4f..0e21fcae8 100644
--- a/public/pages/Administration/pages/PrivacySettings.page.tsx
+++ b/public/pages/Administration/pages/PrivacySettings.page.tsx
@@ -6,6 +6,7 @@ import { AdminBasePage } from "@fider/pages/Administration/components/AdminBaseP
export interface PrivacySettingsPageState {
isPrivate: boolean
isFeedEnabled: boolean
+ isModerationEnabled: boolean
}
export default class PrivacySettingsPage extends AdminBasePage<any, PrivacySettingsPageState> {
@@ -20,14 +21,16 @@ export default class PrivacySettingsPage extends AdminBasePage<any, PrivacySetti
this.state = {
isPrivate: Fider.session.tenant.isPrivate,
isFeedEnabled: Fider.session.tenant.isFeedEnabled,
+ isModerationEnabled: Fider.session.tenant.isModerationEnabled,
}
}
- private updatePrivacySettings = async (isPrivate: boolean, isFeedEnabled: boolean) => {
+ private updatePrivacySettings = async (isPrivate: boolean, isFeedEnabled: boolean, isModerationEnabled?: boolean) => {
this.setState(
{
isPrivate,
isFeedEnabled: isPrivate ? false : isFeedEnabled, // Disable feed if site is private
+ isModerationEnabled: isModerationEnabled !== undefined ? isModerationEnabled : this.state.isModerationEnabled,
},
async () => {
const response = await actions.updateTenantPrivacy(this.state)
@@ -46,6 +49,10 @@ export default class PrivacySettingsPage extends AdminBasePage<any, PrivacySetti
this.updatePrivacySettings(this.state.isPrivate, enabled)
}
+ private moderationToggle = async (enabled: boolean) => {
+ this.updatePrivacySettings(this.state.isPrivate, this.state.isFeedEnabled, enabled)
+ }
+
public content() {
return (
<Form>
@@ -63,6 +70,13 @@ export default class PrivacySettingsPage extends AdminBasePage<any, PrivacySetti
format. Links to feeds and autodiscovery metadata are shown on the site.
</p>
</Field>
+ <Field label="Content Moderation">
+ <Toggle disabled={!Fider.session.user.isAdministrator} active={this.state.isModerationEnabled} onToggle={this.moderationToggle} />
+ <p className="text-muted mt-1">
+ When enabled, new posts and comments will require approval from an administrator before being visible to other users. <br />
+ Content creators can see their own unmoderated content, but it will be hidden from other users until approved.
+ </p>
+ </Field>
</Form>
)
}