Open platform to collect and prioritize feedback
More moderation stuff - decline and block
Matt Roberts2099114e2088
diff --git a/app/cmd/routes.go b/app/cmd/routes.goindex f6f40b106..16879520d 100644--- a/app/cmd/routes.go+++ b/app/cmd/routes.go@@ -262,12 +262,12 @@ 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", handlers.ApprovePost())- adminApi.Post("/api/v1/admin/moderation/posts/:id/decline", handlers.DeclinePost())- adminApi.Post("/api/v1/admin/moderation/comments/:id/approve", handlers.ApproveComment())- adminApi.Post("/api/v1/admin/moderation/comments/:id/decline", handlers.DeclineComment())- adminApi.Post("/api/v1/admin/moderation/bulk/approve", handlers.BulkApproveItems())- adminApi.Post("/api/v1/admin/moderation/bulk/decline", handlers.BulkDeclineItems())+ 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/posts/:id/decline-and-block", apiv1.DeclinePostAndBlock())+ 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.Use(middlewares.BlockLockedTenants())adminApi.Delete("/api/v1/posts/:number", apiv1.DeletePost())diff --git a/app/handlers/apiv1/moderation.go b/app/handlers/apiv1/moderation.gonew file mode 100644index 000000000..ae92f2661--- /dev/null+++ b/app/handlers/apiv1/moderation.go@@ -0,0 +1,135 @@+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/web"+)++// 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{})+ }+}++// DeclinePostAndBlock declines (deletes) a post and blocks the user+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{})+ }+}++// DeclineCommentAndBlock declines (deletes) a comment and blocks the user+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{})+ }+}diff --git a/app/handlers/apiv1/moderation_test.go b/app/handlers/apiv1/moderation_test.gonew file mode 100644index 000000000..8e5c0555c--- /dev/null+++ b/app/handlers/apiv1/moderation_test.go@@ -0,0 +1,408 @@+package apiv1_test++import (+ "context"+ "net/http"+ "testing"++ "github.com/getfider/fider/app"+ "github.com/getfider/fider/app/handlers/apiv1"+ "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/assert"+ "github.com/getfider/fider/app/pkg/bus"+ "github.com/getfider/fider/app/pkg/mock"+)++func TestApprovePost_Success(t *testing.T) {+ RegisterT(t)++ var approvePost *cmd.ApprovePost+ bus.AddHandler(func(ctx context.Context, c *cmd.ApprovePost) error {+ approvePost = c+ return nil+ })++ code, _ := mock.NewServer().+ OnTenant(mock.DemoTenant).+ AsUser(mock.JonSnow).+ AddParam("id", "5").+ ExecutePost(apiv1.ApprovePost(), `{}`)++ Expect(code).Equals(http.StatusOK)+ Expect(approvePost.PostID).Equals(5)+}++func TestApprovePost_InvalidID(t *testing.T) {+ RegisterT(t)++ code, response := mock.NewServer().+ OnTenant(mock.DemoTenant).+ AsUser(mock.JonSnow).+ AddParam("id", "invalid").+ ExecuteAsJSON(apiv1.ApprovePost())++ Expect(code).Equals(http.StatusBadRequest)+ Expect(response.String("error")).Equals("Invalid post ID")+}++func TestApprovePost_CommandFailure(t *testing.T) {+ RegisterT(t)++ bus.AddHandler(func(ctx context.Context, c *cmd.ApprovePost) error {+ return app.ErrNotFound+ })++ code, _ := mock.NewServer().+ OnTenant(mock.DemoTenant).+ AsUser(mock.JonSnow).+ AddParam("id", "5").+ ExecutePost(apiv1.ApprovePost(), `{}`)++ Expect(code).Equals(http.StatusNotFound)+}++func TestDeclinePost_Success(t *testing.T) {+ RegisterT(t)++ var declinePost *cmd.DeclinePost+ bus.AddHandler(func(ctx context.Context, c *cmd.DeclinePost) error {+ declinePost = c+ return nil+ })++ code, _ := mock.NewServer().+ OnTenant(mock.DemoTenant).+ AsUser(mock.JonSnow).+ AddParam("id", "10").+ ExecutePost(apiv1.DeclinePost(), `{}`)++ Expect(code).Equals(http.StatusOK)+ Expect(declinePost.PostID).Equals(10)+}++func TestDeclinePost_InvalidID(t *testing.T) {+ RegisterT(t)++ code, response := mock.NewServer().+ OnTenant(mock.DemoTenant).+ AsUser(mock.JonSnow).+ AddParam("id", "abc").+ ExecuteAsJSON(apiv1.DeclinePost())++ Expect(code).Equals(http.StatusBadRequest)+ Expect(response.String("error")).Equals("Invalid post ID")+}++func TestDeclinePost_CommandFailure(t *testing.T) {+ RegisterT(t)++ bus.AddHandler(func(ctx context.Context, c *cmd.DeclinePost) error {+ return app.ErrNotFound+ })++ code, _ := mock.NewServer().+ OnTenant(mock.DemoTenant).+ AsUser(mock.JonSnow).+ AddParam("id", "10").+ ExecutePost(apiv1.DeclinePost(), `{}`)++ Expect(code).Equals(http.StatusNotFound)+}++func TestApproveComment_Success(t *testing.T) {+ RegisterT(t)++ var approveComment *cmd.ApproveComment+ bus.AddHandler(func(ctx context.Context, c *cmd.ApproveComment) error {+ approveComment = c+ return nil+ })++ code, _ := mock.NewServer().+ OnTenant(mock.DemoTenant).+ AsUser(mock.JonSnow).+ AddParam("id", "15").+ ExecutePost(apiv1.ApproveComment(), `{}`)++ Expect(code).Equals(http.StatusOK)+ Expect(approveComment.CommentID).Equals(15)+}++func TestApproveComment_InvalidID(t *testing.T) {+ RegisterT(t)++ code, response := mock.NewServer().+ OnTenant(mock.DemoTenant).+ AsUser(mock.JonSnow).+ AddParam("id", "not-a-number").+ ExecuteAsJSON(apiv1.ApproveComment())++ Expect(code).Equals(http.StatusBadRequest)+ Expect(response.String("error")).Equals("Invalid comment ID")+}++func TestApproveComment_CommandFailure(t *testing.T) {+ RegisterT(t)++ bus.AddHandler(func(ctx context.Context, c *cmd.ApproveComment) error {+ return app.ErrNotFound+ })++ code, _ := mock.NewServer().+ OnTenant(mock.DemoTenant).+ AsUser(mock.JonSnow).+ AddParam("id", "15").+ ExecutePost(apiv1.ApproveComment(), `{}`)++ Expect(code).Equals(http.StatusNotFound)+}++func TestDeclineComment_Success(t *testing.T) {+ RegisterT(t)++ var declineComment *cmd.DeclineComment+ bus.AddHandler(func(ctx context.Context, c *cmd.DeclineComment) error {+ declineComment = c+ return nil+ })++ code, _ := mock.NewServer().+ OnTenant(mock.DemoTenant).+ AsUser(mock.JonSnow).+ AddParam("id", "20").+ ExecutePost(apiv1.DeclineComment(), `{}`)++ Expect(code).Equals(http.StatusOK)+ Expect(declineComment.CommentID).Equals(20)+}++func TestDeclineComment_InvalidID(t *testing.T) {+ RegisterT(t)++ code, response := mock.NewServer().+ OnTenant(mock.DemoTenant).+ AsUser(mock.JonSnow).+ AddParam("id", "").+ ExecuteAsJSON(apiv1.DeclineComment())++ Expect(code).Equals(http.StatusBadRequest)+ Expect(response.String("error")).Equals("Invalid comment ID")+}++func TestDeclineComment_CommandFailure(t *testing.T) {+ RegisterT(t)++ bus.AddHandler(func(ctx context.Context, c *cmd.DeclineComment) error {+ return app.ErrNotFound+ })++ code, _ := mock.NewServer().+ OnTenant(mock.DemoTenant).+ AsUser(mock.JonSnow).+ AddParam("id", "20").+ ExecutePost(apiv1.DeclineComment(), `{}`)++ Expect(code).Equals(http.StatusNotFound)+}++func TestDeclinePostAndBlock_Success(t *testing.T) {+ RegisterT(t)++ post := &entity.Post{+ ID: 1,+ Number: 5,+ Title: "Test Post",+ User: mock.AryaStark,+ }++ bus.AddHandler(func(ctx context.Context, q *query.GetPostByNumber) error {+ if q.Number == 5 {+ q.Result = post+ return nil+ }+ return app.ErrNotFound+ })++ var blockUser *cmd.BlockUser+ bus.AddHandler(func(ctx context.Context, c *cmd.BlockUser) error {+ blockUser = c+ return nil+ })++ var declinePost *cmd.DeclinePost+ bus.AddHandler(func(ctx context.Context, c *cmd.DeclinePost) error {+ declinePost = c+ return nil+ })++ code, _ := mock.NewServer().+ OnTenant(mock.DemoTenant).+ AsUser(mock.JonSnow).+ AddParam("id", "5").+ ExecutePost(apiv1.DeclinePostAndBlock(), `{}`)++ Expect(code).Equals(http.StatusOK)+ Expect(blockUser.UserID).Equals(mock.AryaStark.ID)+ Expect(declinePost.PostID).Equals(5)+}++func TestDeclinePostAndBlock_InvalidID(t *testing.T) {+ RegisterT(t)++ code, response := mock.NewServer().+ OnTenant(mock.DemoTenant).+ AsUser(mock.JonSnow).+ AddParam("id", "invalid").+ ExecuteAsJSON(apiv1.DeclinePostAndBlock())++ Expect(code).Equals(http.StatusBadRequest)+ Expect(response.String("error")).Equals("Invalid post ID")+}++func TestDeclinePostAndBlock_PostNotFound(t *testing.T) {+ RegisterT(t)++ bus.AddHandler(func(ctx context.Context, q *query.GetPostByNumber) error {+ return app.ErrNotFound+ })++ code, _ := mock.NewServer().+ OnTenant(mock.DemoTenant).+ AsUser(mock.JonSnow).+ AddParam("id", "999").+ ExecutePost(apiv1.DeclinePostAndBlock(), `{}`)++ Expect(code).Equals(http.StatusNotFound)+}++func TestDeclinePostAndBlock_BlockUserFailure(t *testing.T) {+ RegisterT(t)++ post := &entity.Post{+ ID: 1,+ Number: 5,+ Title: "Test Post",+ User: mock.AryaStark,+ }++ bus.AddHandler(func(ctx context.Context, q *query.GetPostByNumber) error {+ if q.Number == 5 {+ q.Result = post+ return nil+ }+ return app.ErrNotFound+ })++ bus.AddHandler(func(ctx context.Context, c *cmd.BlockUser) error {+ return app.ErrNotFound+ })++ code, _ := mock.NewServer().+ OnTenant(mock.DemoTenant).+ AsUser(mock.JonSnow).+ AddParam("id", "5").+ ExecutePost(apiv1.DeclinePostAndBlock(), `{}`)++ Expect(code).Equals(http.StatusNotFound)+}++func TestDeclineCommentAndBlock_Success(t *testing.T) {+ RegisterT(t)++ comment := &entity.Comment{+ ID: 25,+ Content: "Test Comment",+ User: mock.AryaStark,+ }++ bus.AddHandler(func(ctx context.Context, q *query.GetCommentByID) error {+ if q.CommentID == 25 {+ q.Result = comment+ return nil+ }+ return app.ErrNotFound+ })++ var blockUser *cmd.BlockUser+ bus.AddHandler(func(ctx context.Context, c *cmd.BlockUser) error {+ blockUser = c+ return nil+ })++ var declineComment *cmd.DeclineComment+ bus.AddHandler(func(ctx context.Context, c *cmd.DeclineComment) error {+ declineComment = c+ return nil+ })++ code, _ := mock.NewServer().+ OnTenant(mock.DemoTenant).+ AsUser(mock.JonSnow).+ AddParam("id", "25").+ ExecutePost(apiv1.DeclineCommentAndBlock(), `{}`)++ Expect(code).Equals(http.StatusOK)+ Expect(blockUser.UserID).Equals(mock.AryaStark.ID)+ Expect(declineComment.CommentID).Equals(25)+}++func TestDeclineCommentAndBlock_InvalidID(t *testing.T) {+ RegisterT(t)++ code, response := mock.NewServer().+ OnTenant(mock.DemoTenant).+ AsUser(mock.JonSnow).+ AddParam("id", "xyz").+ ExecuteAsJSON(apiv1.DeclineCommentAndBlock())++ Expect(code).Equals(http.StatusBadRequest)+ Expect(response.String("error")).Equals("Invalid comment ID")+}++func TestDeclineCommentAndBlock_CommentNotFound(t *testing.T) {+ RegisterT(t)++ bus.AddHandler(func(ctx context.Context, q *query.GetCommentByID) error {+ return app.ErrNotFound+ })++ code, _ := mock.NewServer().+ OnTenant(mock.DemoTenant).+ AsUser(mock.JonSnow).+ AddParam("id", "999").+ ExecutePost(apiv1.DeclineCommentAndBlock(), `{}`)++ Expect(code).Equals(http.StatusNotFound)+}++func TestDeclineCommentAndBlock_BlockUserFailure(t *testing.T) {+ RegisterT(t)++ comment := &entity.Comment{+ ID: 25,+ Content: "Test Comment",+ User: mock.AryaStark,+ }++ bus.AddHandler(func(ctx context.Context, q *query.GetCommentByID) error {+ if q.CommentID == 25 {+ q.Result = comment+ return nil+ }+ return app.ErrNotFound+ })++ bus.AddHandler(func(ctx context.Context, c *cmd.BlockUser) error {+ return app.ErrNotFound+ })++ code, _ := mock.NewServer().+ OnTenant(mock.DemoTenant).+ AsUser(mock.JonSnow).+ AddParam("id", "25").+ ExecutePost(apiv1.DeclineCommentAndBlock(), `{}`)++ Expect(code).Equals(http.StatusNotFound)+}diff --git a/app/handlers/moderation.go b/app/handlers/moderation.goindex b8d4b2912..563a536aa 100644--- a/app/handlers/moderation.go+++ b/app/handlers/moderation.go@@ -2,9 +2,7 @@ package handlersimport ("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"@@ -47,205 +45,3 @@ func GetModerationCount() web.HandlerFunc {})}}--// 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{})- }-}--// DeclinePostAndBlock declines (deletes) a post and blocks the user-func DeclinePostAndBlock() 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.DeclinePostAndBlock{PostID: postID}); err != nil {- return c.Failure(err)- }-- return c.Ok(web.Map{})- }-}--// DeclineCommentAndBlock declines (deletes) a comment and blocks the user-func DeclineCommentAndBlock() 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.DeclineCommentAndBlock{CommentID: commentID}); err != nil {- return c.Failure(err)- }-- return c.Ok(web.Map{})- }-}--// ApprovePostAndVerify approves a post and verifies the user-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"})- }-- if err := bus.Dispatch(c, &cmd.ApprovePostAndVerify{PostID: postID}); err != nil {- return c.Failure(err)- }-- return c.Ok(web.Map{})- }-}--// ApproveCommentAndVerify approves a comment and verifies the user-func ApproveCommentAndVerify() 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.ApproveCommentAndVerify{CommentID: commentID}); err != nil {- return c.Failure(err)- }-- return c.Ok(web.Map{})- }-}diff --git a/app/models/cmd/moderation.go b/app/models/cmd/moderation.goindex 1f012b075..ea365d36e 100644--- a/app/models/cmd/moderation.go+++ b/app/models/cmd/moderation.go@@ -26,22 +26,6 @@ type BulkDeclineItems struct {CommentIDs []int}-type DeclinePostAndBlock struct {- PostID int-}--type DeclineCommentAndBlock struct {- CommentID int-}--type ApprovePostAndVerify struct {- PostID int-}--type ApproveCommentAndVerify struct {- CommentID int-}-type VerifyUser struct {UserID int-}\ No newline at end of file+}diff --git a/app/services/sqlstore/postgres/moderation.go b/app/services/sqlstore/postgres/moderation.goindex 8afcf77fb..e4493f3d7 100644--- a/app/services/sqlstore/postgres/moderation.go+++ b/app/services/sqlstore/postgres/moderation.go@@ -267,222 +267,6 @@ func getModerationCount(ctx context.Context, q *query.GetModerationCount) error})}-func declinePostAndBlock(ctx context.Context, c *cmd.DeclinePostAndBlock) error {- return using(ctx, func(trx *dbx.Trx, tenant *entity.Tenant, user *entity.User) error {- // Get the post and user info first- var postUserID int- err := trx.Get(&postUserID, `- SELECT user_id FROM posts- WHERE id = $1 AND tenant_id = $2`, c.PostID, tenant.ID)- if err != nil {- return errors.Wrap(err, "failed to get post user")- }-- // Block the user- _, err = trx.Execute(`- UPDATE users SET status = $1- WHERE id = $2 AND tenant_id = $3`, enum.UserBlocked, postUserID, tenant.ID)- if err != nil {- return errors.Wrap(err, "failed to block user")- }-- // Get all unmoderated posts by this user- var postIDs []int- err = trx.Select(&postIDs, `- SELECT id FROM posts- WHERE user_id = $1 AND tenant_id = $2 AND is_approved = false`, postUserID, tenant.ID)- if err != nil {- return errors.Wrap(err, "failed to get user posts")- }-- // Soft-delete all unmoderated posts by this user using existing commands- for _, postID := range 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 user post")- }-- // Use SetPostResponse to properly delete the post- setResponse := &cmd.SetPostResponse{- Post: getPost.Result,- Text: "Post removed due to user block during moderation",- Status: enum.PostDeleted,- }-- if err := bus.Dispatch(ctx, setResponse); err != nil {- return errors.Wrap(err, "failed to delete user post")- }- }-- // Get all unmoderated comments by this user and use proper delete command- var commentIDs []int- err = trx.Select(&commentIDs, `- SELECT id FROM comments- WHERE user_id = $1 AND tenant_id = $2 AND is_approved = false`, postUserID, tenant.ID)- if err != nil {- return errors.Wrap(err, "failed to get user comments")- }-- // Soft-delete all unmoderated comments using existing delete command- for _, commentID := range commentIDs {- deleteComment := &cmd.DeleteComment{CommentID: commentID}- if err := bus.Dispatch(ctx, deleteComment); err != nil {- return errors.Wrap(err, "failed to delete user comment")- }- }-- return nil- })-}--func declineCommentAndBlock(ctx context.Context, c *cmd.DeclineCommentAndBlock) error {- return using(ctx, func(trx *dbx.Trx, tenant *entity.Tenant, user *entity.User) error {- // Get the comment and user info first- var commentUserID int- err := trx.Get(&commentUserID, `- SELECT user_id FROM comments- WHERE id = $1 AND tenant_id = $2`, c.CommentID, tenant.ID)- if err != nil {- return errors.Wrap(err, "failed to get comment user")- }-- // Block the user- _, err = trx.Execute(`- UPDATE users SET status = $1- WHERE id = $2 AND tenant_id = $3`, enum.UserBlocked, commentUserID, tenant.ID)- if err != nil {- return errors.Wrap(err, "failed to block user")- }-- // Get all unmoderated posts by this user- var postIDs []int- err = trx.Select(&postIDs, `- SELECT id FROM posts- WHERE user_id = $1 AND tenant_id = $2 AND is_approved = false`, commentUserID, tenant.ID)- if err != nil {- return errors.Wrap(err, "failed to get user posts")- }-- // Soft-delete all unmoderated posts by this user using existing commands- for _, postID := range 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 user post")- }-- // Use SetPostResponse to properly delete the post- setResponse := &cmd.SetPostResponse{- Post: getPost.Result,- Text: "Post removed due to user block during moderation",- Status: enum.PostDeleted,- }-- if err := bus.Dispatch(ctx, setResponse); err != nil {- return errors.Wrap(err, "failed to delete user post")- }- }-- // Get all unmoderated comments by this user- var commentIDs []int- err = trx.Select(&commentIDs, `- SELECT id FROM comments- WHERE user_id = $1 AND tenant_id = $2 AND is_approved = false`, commentUserID, tenant.ID)- if err != nil {- return errors.Wrap(err, "failed to get user comments")- }-- // Soft-delete all unmoderated comments using existing delete command- for _, commentID := range commentIDs {- deleteComment := &cmd.DeleteComment{CommentID: commentID}- if err := bus.Dispatch(ctx, deleteComment); err != nil {- return errors.Wrap(err, "failed to delete user comment")- }- }-- return nil- })-}--func approvePostAndVerify(ctx context.Context, c *cmd.ApprovePostAndVerify) error {- return using(ctx, func(trx *dbx.Trx, tenant *entity.Tenant, user *entity.User) error {- // Get the post and user info first- var postUserID int- err := trx.Get(&postUserID, `- SELECT user_id FROM posts- WHERE id = $1 AND tenant_id = $2`, c.PostID, tenant.ID)- if err != nil {- return errors.Wrap(err, "failed to get post user")- }-- // 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, postUserID, tenant.ID)- if err != nil {- return errors.Wrap(err, "failed to verify user")- }-- // Approve all unmoderated posts by this user- _, err = trx.Execute(`- UPDATE posts SET is_approved = true- WHERE user_id = $1 AND tenant_id = $2 AND is_approved = false`, postUserID, tenant.ID)- if err != nil {- return errors.Wrap(err, "failed to approve user posts")- }-- // Approve all unmoderated comments by this user- _, err = trx.Execute(`- UPDATE comments SET is_approved = true- WHERE user_id = $1 AND tenant_id = $2 AND is_approved = false`, postUserID, tenant.ID)- if err != nil {- return errors.Wrap(err, "failed to approve user comments")- }-- return nil- })-}--func approveCommentAndVerify(ctx context.Context, c *cmd.ApproveCommentAndVerify) error {- return using(ctx, func(trx *dbx.Trx, tenant *entity.Tenant, user *entity.User) error {- // Get the comment and user info first- var commentUserID int- err := trx.Get(&commentUserID, `- SELECT user_id FROM comments- WHERE id = $1 AND tenant_id = $2`, c.CommentID, tenant.ID)- if err != nil {- return errors.Wrap(err, "failed to get comment user")- }-- // 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, commentUserID, tenant.ID)- if err != nil {- return errors.Wrap(err, "failed to verify user")- }-- // Approve all unmoderated posts by this user- _, err = trx.Execute(`- UPDATE posts SET is_approved = true- WHERE user_id = $1 AND tenant_id = $2 AND is_approved = false`, commentUserID, tenant.ID)- if err != nil {- return errors.Wrap(err, "failed to approve user posts")- }-- // Approve all unmoderated comments by this user- _, err = trx.Execute(`- UPDATE comments SET is_approved = true- WHERE user_id = $1 AND tenant_id = $2 AND is_approved = false`, commentUserID, tenant.ID)- if err != nil {- return errors.Wrap(err, "failed to approve user comments")- }-- 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)diff --git a/app/services/sqlstore/postgres/postgres.go b/app/services/sqlstore/postgres/postgres.goindex 9dd4c0e3f..382a10120 100644--- a/app/services/sqlstore/postgres/postgres.go+++ b/app/services/sqlstore/postgres/postgres.go@@ -148,10 +148,6 @@ func (s Service) Init() {bus.AddHandler(bulkDeclineItems)bus.AddHandler(getModerationItems)bus.AddHandler(getModerationCount)- bus.AddHandler(declinePostAndBlock)- bus.AddHandler(declineCommentAndBlock)- bus.AddHandler(approvePostAndVerify)- bus.AddHandler(approveCommentAndVerify)bus.AddHandler(verifyUser)}diff --git a/public/pages/Administration/pages/ContentModeration.page.tsx b/public/pages/Administration/pages/ContentModeration.page.tsxindex 8bdf4ad22..f48e2481d 100644--- a/public/pages/Administration/pages/ContentModeration.page.tsx+++ b/public/pages/Administration/pages/ContentModeration.page.tsx@@ -107,7 +107,7 @@ const ContentModerationPage = () => {}const handleApprovePostAndVerify = async (postId: number) => {- const result = await http.post(`/api/v1/admin/moderation/posts/${postId}/approve-and-verify`)+ const result = await actions.approvePostAndVerify(postId)if (result.ok) {notify.success(<Trans id="moderation.post.approved.verified">Post approved and user verified</Trans>)setState((prev) => ({@@ -120,7 +120,7 @@ const ContentModerationPage = () => {}const handleDeclinePostAndBlock = async (postId: number) => {- const result = await http.post(`/api/v1/admin/moderation/posts/${postId}/decline-and-block`)+ const result = await actions.declinePostAndBlock(postId)if (result.ok) {notify.success(<Trans id="moderation.post.declined.blocked">Post declined and user blocked</Trans>)setState((prev) => ({@@ -133,7 +133,7 @@ const ContentModerationPage = () => {}const handleApproveCommentAndVerify = async (commentId: number) => {- const result = await http.post(`/api/v1/admin/moderation/comments/${commentId}/approve-and-verify`)+ const result = await actions.approveCommentAndVerify(commentId)if (result.ok) {notify.success(<Trans id="moderation.comment.approved.verified">Comment approved and user verified</Trans>)setState((prev) => ({@@ -146,7 +146,7 @@ const ContentModerationPage = () => {}const handleDeclineCommentAndBlock = async (commentId: number) => {- const result = await http.post(`/api/v1/admin/moderation/comments/${commentId}/decline-and-block`)+ const result = await actions.declineCommentAndBlock(commentId)if (result.ok) {notify.success(<Trans id="moderation.comment.declined.blocked">Comment declined and user blocked</Trans>)setState((prev) => ({diff --git a/public/services/actions/post.ts b/public/services/actions/post.tsindex 5bb5c023e..c9d73fff2 100644--- a/public/services/actions/post.ts+++ b/public/services/actions/post.ts@@ -135,10 +135,18 @@ export const declineComment = async (commentID: number): Promise<Result> => {return http.post(`/api/v1/admin/moderation/comments/${commentID}/decline`).then(http.event("comment", "decline"))}-export const bulkApproveItems = async (postIDs: number[], commentIDs: number[]): Promise<Result> => {- return http.post(`/api/v1/admin/moderation/bulk/approve`, { postIDs, commentIDs }).then(http.event("moderation", "bulk-approve"))+export const approvePostAndVerify = async (postID: number): Promise<Result> => {+ return http.post(`/api/v1/admin/moderation/posts/${postID}/approve-and-verify`).then(http.event("post", "approve-and-verify"))}-export const bulkDeclineItems = async (postIDs: number[], commentIDs: number[]): Promise<Result> => {- return http.post(`/api/v1/admin/moderation/bulk/decline`, { postIDs, commentIDs }).then(http.event("moderation", "bulk-decline"))+export const declinePostAndBlock = async (postID: number): Promise<Result> => {+ return http.post(`/api/v1/admin/moderation/posts/${postID}/decline-and-block`).then(http.event("post", "decline-and-block"))+}++export const approveCommentAndVerify = async (commentID: number): Promise<Result> => {+ return http.post(`/api/v1/admin/moderation/comments/${commentID}/approve-and-verify`).then(http.event("comment", "approve-and-verify"))+}++export const declineCommentAndBlock = async (commentID: number): Promise<Result> => {+ return http.post(`/api/v1/admin/moderation/comments/${commentID}/decline-and-block`).then(http.event("comment", "decline-and-block"))}