Open platform to collect and prioritize feedback
Making changes to support more moderation options.
Matt Roberts4b9b02939679
diff --git a/MODERATION.md b/MODERATION.mdindex 925433bfa..507368fce 100644--- a/MODERATION.md+++ b/MODERATION.md@@ -43,3 +43,15 @@ Here is a screenshot showing the inspiration we found for the moderation pageYou can see the bulk actions on this screenshot, we're interested in having bulk actions to approve or decline too to make it easier, plus a "select all" to highlight them all. The UI for the bulk actions should be like the "Sort by" options on the post listing in public/pages/Home/components/PostsSort.tsx++## Moderation Changes 1++We've decided to make some changes to the moderation admin:++1. Rather than have it part of the admin menu, remove the entry from the side menu in admin. Instead, we want an icon in the top Header (public/components/Header.tsx) that when clicked, takes you to the moderation admin page, without the side menu. Ideally the icon will have a little counter in the top-right of how many items are awaiting moderation.++2. We've decided to make the moderation less onourous to the admins by making some more changes:++ 2.1) As well as decline, you have another option - "decline and block". This option will decline the post or comment, and block the user who made it from posting again. We already have the ability to block users in Fider (see BlockUser in app/handlers/user.go), so we can hook into that. So if you had 1 user who had 5 posts and some comments, and you declined and blocked them, we would also decline all other posts and comments they made, and block them from posting again.++ 2.2) As well as "approve", you have another option - "approve and verify". This option will approve the post (or comment) and ALL other posts and comments from this user. It will also make the user "verified" for posting, meaning that any future posts or comments from that user can bypass moderation. To facilitate this, we're going to need a new column on the user, which will work similar to how blocking a user works, except that it will do the opposite. You can't be both blocked and verified, so if you "approve and verify" we'll need to unset any blocked status for that user.diff --git a/app/cmd/routes.go b/app/cmd/routes.goindex da5455657..f6f40b106 100644--- a/app/cmd/routes.go+++ b/app/cmd/routes.go@@ -187,6 +187,7 @@ func routes(r *web.Engine) *web.Engine {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.Get("/_api/admin/moderation/count", handlers.GetModerationCount())if env.IsBillingEnabled() {ui.Get("/admin/billing", handlers.ManageBilling())diff --git a/app/handlers/moderation.go b/app/handlers/moderation.goindex 2683646f7..c3390ccfb 100644--- a/app/handlers/moderation.go+++ b/app/handlers/moderation.go@@ -34,6 +34,20 @@ func GetModerationItems() web.HandlerFunc {}}+// GetModerationCount returns the count of items awaiting moderation+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,+ })+ }+}+// ApprovePost approves a postfunc ApprovePost() web.HandlerFunc {return func(c *web.Context) error {@@ -168,6 +182,70 @@ func BulkDeclineItems() web.HandlerFunc {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{})}}\ No newline at end of filediff --git a/app/models/cmd/moderation.go b/app/models/cmd/moderation.goindex 24ee12137..1f012b075 100644--- a/app/models/cmd/moderation.go+++ b/app/models/cmd/moderation.go@@ -24,4 +24,24 @@ type BulkApproveItems struct {type BulkDeclineItems struct {PostIDs []intCommentIDs []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 filediff --git a/app/models/entity/user.go b/app/models/entity/user.goindex 8e270e293..c22a512db 100644--- a/app/models/entity/user.go+++ b/app/models/entity/user.go@@ -18,6 +18,7 @@ type User struct {AvatarType enum.AvatarType `json:"-"`AvatarURL string `json:"avatarURL,omitempty"`Status enum.UserStatus `json:"status"`+ IsVerified bool `json:"isVerified"`}// HasProvider returns true if current user has registered with given providerdiff --git a/app/models/query/moderation.go b/app/models/query/moderation.goindex a4ca8c8a9..f69cd47ed 100644--- a/app/models/query/moderation.go+++ b/app/models/query/moderation.go@@ -19,4 +19,8 @@ type ModerationItem struct {type GetModerationItems struct {Result []*ModerationItem+}++type GetModerationCount struct {+ Result int}\ No newline at end of filediff --git a/app/services/sqlstore/postgres/moderation.go b/app/services/sqlstore/postgres/moderation.goindex ddb042ad1..0a80c1052 100644--- a/app/services/sqlstore/postgres/moderation.go+++ b/app/services/sqlstore/postgres/moderation.go@@ -7,7 +7,9 @@ import ("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")@@ -26,13 +28,20 @@ func approvePost(ctx context.Context, c *cmd.ApprovePost) error {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")+ // Use existing query to get the post+ getPost := &query.GetPostByID{PostID: c.PostID}+ if err := bus.Dispatch(ctx, getPost); err != nil {+ return err}- return nil++ // 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)})}@@ -50,13 +59,9 @@ func approveComment(ctx context.Context, c *cmd.ApproveComment) error {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+ // Use existing delete command+ deleteComment := &cmd.DeleteComment{CommentID: c.CommentID}+ return bus.Dispatch(ctx, deleteComment)})}@@ -101,34 +106,34 @@ func bulkApproveItems(ctx context.Context, c *cmd.BulkApproveItems) error {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 += ","+ // 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")}- 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 += ","+ // 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")}- 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")}}@@ -230,6 +235,255 @@ func getModerationItems(ctx context.Context, q *query.GetModerationItems) error})}+ 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) ++ (SELECT COUNT(*) FROM comments WHERE tenant_id = $1 AND is_approved = false)+ `, tenant.ID)++ if err != nil {+ return errors.Wrap(err, "failed to get moderation count")+ }++ q.Result = count+ return nil+ })+}++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)+ _, 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})}\ No newline at end of filediff --git a/app/services/sqlstore/postgres/postgres.go b/app/services/sqlstore/postgres/postgres.goindex 4bbb79e78..9dd4c0e3f 100644--- a/app/services/sqlstore/postgres/postgres.go+++ b/app/services/sqlstore/postgres/postgres.go@@ -147,6 +147,12 @@ func (s Service) Init() {bus.AddHandler(bulkApproveItems)bus.AddHandler(bulkDeclineItems)bus.AddHandler(getModerationItems)+ bus.AddHandler(getModerationCount)+ bus.AddHandler(declinePostAndBlock)+ bus.AddHandler(declineCommentAndBlock)+ bus.AddHandler(approvePostAndVerify)+ bus.AddHandler(approveCommentAndVerify)+ bus.AddHandler(verifyUser)}type SqlHandler func(trx *dbx.Trx, tenant *entity.Tenant, user *entity.User) errordiff --git a/app/services/sqlstore/postgres/user.go b/app/services/sqlstore/postgres/user.goindex b3930d9da..4e75e1cee 100644--- a/app/services/sqlstore/postgres/user.go+++ b/app/services/sqlstore/postgres/user.go@@ -26,6 +26,7 @@ type dbUser struct {Status sql.NullInt64 `db:"status"`AvatarType sql.NullInt64 `db:"avatar_type"`AvatarBlobKey sql.NullString `db:"avatar_bkey"`+ IsVerified sql.NullBool `db:"is_verified"`Providers []*dbUserProvider}@@ -56,6 +57,7 @@ func (u *dbUser) toModel(ctx context.Context) *entity.User {AvatarType: avatarType,AvatarBlobKey: u.AvatarBlobKey.String,AvatarURL: avatarURL,+ IsVerified: u.IsVerified.Bool,}for i, p := range u.Providers {@@ -413,7 +415,7 @@ func getAllUsersNames(ctx context.Context, q *query.GetAllUsersNames) error {func queryUser(ctx context.Context, trx *dbx.Trx, filter string, args ...any) (*entity.User, error) {user := dbUser{}- sql := fmt.Sprintf("SELECT id, name, email, tenant_id, role, status, avatar_type, avatar_bkey FROM users WHERE status != %d AND ", enum.UserDeleted)+ sql := fmt.Sprintf("SELECT id, name, email, tenant_id, role, status, avatar_type, avatar_bkey, is_verified FROM users WHERE status != %d AND ", enum.UserDeleted)err := trx.Get(&user, sql+filter, args...)if err != nil {return nil, errdiff --git a/migrations/202507020900_add_user_verification.sql b/migrations/202507020900_add_user_verification.sqlnew file mode 100644index 000000000..9815af8d6--- /dev/null+++ b/migrations/202507020900_add_user_verification.sql@@ -0,0 +1,6 @@+-- Add user verification column to users table+-- This allows users to be verified for automatic approval of their content+ALTER TABLE users ADD COLUMN is_verified boolean NOT NULL DEFAULT false;++-- Add index for performance+CREATE INDEX idx_users_verification ON users(tenant_id, is_verified) WHERE is_verified = true;\ No newline at end of filediff --git a/public/components/Header.tsx b/public/components/Header.tsxindex 4629bf58c..8ddeaffba 100644--- a/public/components/Header.tsx+++ b/public/components/Header.tsx@@ -1,5 +1,5 @@import React, { useState } from "react"-import { SignInModal, RSSModal, TenantLogo, NotificationIndicator, UserMenu, ThemeSwitcher, Icon } from "@fider/components"+import { SignInModal, RSSModal, TenantLogo, NotificationIndicator, ModerationIndicator, UserMenu, ThemeSwitcher, Icon } from "@fider/components"import { useFider } from "@fider/hooks"import { HStack } from "./layout"import { Trans } from "@lingui/react/macro"@@ -44,6 +44,7 @@ export const Header = () => {</button>)}<ThemeSwitcher />+ <ModerationIndicator /><NotificationIndicator /><UserMenu /></HStack>diff --git a/public/components/ModerationIndicator.tsx b/public/components/ModerationIndicator.tsxnew file mode 100644index 000000000..3f7760dd5--- /dev/null+++ b/public/components/ModerationIndicator.tsx@@ -0,0 +1,62 @@+import React, { useState, useEffect } from "react"+import { Icon } from "@fider/components"+import { useFider } from "@fider/hooks"+import IconShield from "@fider/assets/images/heroicons-shieldcheck.svg"++export const ModerationIndicator = () => {+ const fider = useFider()+ const [count, setCount] = useState(0)+ const [loading, setLoading] = useState(true)++ useEffect(() => {+ const fetchCount = async () => {+ try {+ const response = await fetch("/_api/admin/moderation/count")+ if (response.ok) {+ const data = await response.json()+ setCount(data.count || 0)+ }+ } catch (error) {+ console.error("Failed to fetch moderation count:", error)+ } finally {+ setLoading(false)+ }+ }++ // Only fetch if user is admin/collaborator and moderation is enabled+ if ((fider.session.user.isAdministrator || fider.session.user.isCollaborator) &&+ fider.session.tenant.isModerationEnabled) {+ fetchCount()+ } else {+ setLoading(false)+ }+ }, [fider.session.user, fider.session.tenant.isModerationEnabled])++ // Don't show the indicator if user is not admin/collaborator or moderation is disabled+ if (!fider.session.user.isAdministrator && !fider.session.user.isCollaborator) {+ return null+ }++ if (!fider.session.tenant.isModerationEnabled) {+ return null+ }++ if (loading) {+ return null+ }++ return (+ <a+ href="/admin/moderation"+ className="relative c-themeswitcher"+ title={`${count} item(s) awaiting moderation`}+ >+ <Icon sprite={IconShield} className="h-6 text-gray-500 hover:text-gray-700" />+ {count > 0 && (+ <span className="absolute -top-1 -right-1 bg-red-500 text-white text-xs rounded-full h-4 w-4 flex items-center justify-center">+ {count > 99 ? "99+" : count}+ </span>+ )}+ </a>+ )+}\ No newline at end of filediff --git a/public/components/index.tsx b/public/components/index.tsxindex 55a123ae7..fcb849400 100644--- a/public/components/index.tsx+++ b/public/components/index.tsx@@ -8,6 +8,7 @@ export * from "./SignInModal"export * from "./RSSModal"export * from "./VoteCounter"export * from "./NotificationIndicator"+export * from "./ModerationIndicator"export * from "./UserMenu"export * from "./Reactions"export * from "./ReadOnlyNotice"diff --git a/public/pages/Administration/components/SideMenu.tsx b/public/pages/Administration/components/SideMenu.tsxindex 66427cc06..b88e7b321 100644--- a/public/pages/Administration/components/SideMenu.tsx+++ b/public/pages/Administration/components/SideMenu.tsx@@ -44,7 +44,6 @@ export const SideMenu = (props: SiteMenuProps) => {<SideMenuItem name="privacy" title="Privacy" href="/admin/privacy" isActive={activeItem === "privacy"} /><SideMenuItem name="members" title="Members" href="/admin/members" isActive={activeItem === "members"} /><SideMenuItem name="tags" title="Tags" href="/admin/tags" isActive={activeItem === "tags"} />- <SideMenuItem name="moderation" title="Moderation" href="/admin/moderation" isActive={activeItem === "moderation"} /><SideMenuItem name="invitations" title="Invitations" href="/admin/invitations" isActive={activeItem === "invitations"} /><SideMenuItem name="authentication" title="Authentication" href="/admin/authentication" isActive={activeItem === "authentication"} /><SideMenuItem name="advanced" title="Advanced" href="/admin/advanced" isActive={activeItem === "advanced"} />