Open platform to collect and prioritize feedback
Moderation admin
Matt Roberts16d58bce1fc0
diff --git a/app/models/query/moderation.go b/app/models/query/moderation.goindex 2359679b3..a4ca8c8a9 100644--- a/app/models/query/moderation.go+++ b/app/models/query/moderation.go@@ -5,14 +5,16 @@ import ()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 string `json:"type"` // "post" or "comment"+ ID int `json:"id"`+ PostID int `json:"postId,omitempty"`+ PostNumber int `json:"postNumber,omitempty"`+ PostSlug string `json:"postSlug,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 {diff --git a/app/services/sqlstore/postgres/moderation.go b/app/services/sqlstore/postgres/moderation.goindex ce991bca8..ddb042ad1 100644--- a/app/services/sqlstore/postgres/moderation.go+++ b/app/services/sqlstore/postgres/moderation.go@@ -136,23 +136,40 @@ func bulkDeclineItems(ctx context.Context, c *cmd.BulkDeclineItems) error {})}+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"`+ UserID int `db:"user_id"`+ UserName string `db:"user_name"`+ UserEmail string `db:"user_email"`+}++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"`+ UserID int `db:"user_id"`+ UserName string `db:"user_name"`+ UserEmail string `db:"user_email"`+ PostTitle string `db:"post_title"`+}+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"`- }{}+ var posts []*dbModerationPosterr := trx.Select(&posts, `- SELECT p.id, p.title, p.description, p.created_at,+ 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_emailFROM posts pINNER JOIN users u ON u.id = p.user_id AND u.tenant_id = p.tenant_id@@ -166,6 +183,8 @@ func getModerationItems(ctx context.Context, q *query.GetModerationItems) errorq.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.Format("January 2, 2006 at 3:04 PM"),@@ -178,19 +197,10 @@ func getModerationItems(ctx context.Context, q *query.GetModerationItems) error}// 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"`- }{}+ var comments []*dbModerationCommenterr = trx.Select(&comments, `- SELECT c.id, c.post_id, c.content, c.created_at,+ 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,p.title as post_titleFROM comments c@@ -204,12 +214,14 @@ func getModerationItems(ctx context.Context, q *query.GetModerationItems) errorfor _, 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,+ Type: "comment",+ ID: comment.ID,+ PostID: comment.PostID,+ PostNumber: comment.PostNumber,+ PostSlug: comment.PostSlug,+ 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,diff --git a/public/pages/Administration/components/SideMenu.tsx b/public/pages/Administration/components/SideMenu.tsxindex b88e7b321..66427cc06 100644--- a/public/pages/Administration/components/SideMenu.tsx+++ b/public/pages/Administration/components/SideMenu.tsx@@ -44,6 +44,7 @@ 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"} />diff --git a/public/pages/Administration/pages/Moderation.page.tsx b/public/pages/Administration/pages/Moderation.page.tsxnew file mode 100644index 000000000..629ca7aba--- /dev/null+++ b/public/pages/Administration/pages/Moderation.page.tsx@@ -0,0 +1,388 @@+import React from "react"+import { Button, Loader } from "@fider/components"+import { actions, notify, Fider } from "@fider/services"+import { AdminBasePage } from "@fider/pages/Administration/components/AdminBasePage"+import { HStack, VStack } from "@fider/components/layout"++interface ModerationItem {+ id: number+ type: "post" | "comment"+ title?: string+ content: string+ user: {+ id: number+ name: string+ email: string+ }+ createdAt: string+ postId?: number+ postNumber?: number+ postSlug?: string+ postTitle?: string+}++interface ModerationPageState {+ items: ModerationItem[]+ loading: boolean+ selectedItems: Set<string>+ selectAll: boolean+}++export default class ModerationPage extends AdminBasePage<any, ModerationPageState> {+ public id = "p-admin-moderation"+ public name = "moderation"+ public title = "Moderation"+ public subtitle = "Review and approve content"++ constructor(props: any) {+ super(props)++ this.state = {+ items: [],+ loading: true,+ selectedItems: new Set(),+ selectAll: false,+ }+ }++ public async componentDidMount() {+ await this.loadModerationItems()+ }++ private loadModerationItems = async () => {+ this.setState({ loading: true })+ try {+ const response = await fetch("/_api/admin/moderation/items")+ if (response.ok) {+ const data = await response.json()+ this.setState({ items: data.items || [], loading: false })+ } else {+ notify.error("Failed to load moderation items")+ this.setState({ loading: false })+ }+ } catch (error) {+ notify.error("Failed to load moderation items")+ this.setState({ loading: false })+ }+ }++ private handleSelectItem = (itemKey: string, checked: boolean) => {+ const selectedItems = new Set(this.state.selectedItems)+ if (checked) {+ selectedItems.add(itemKey)+ } else {+ selectedItems.delete(itemKey)+ }++ const selectAll = selectedItems.size === this.state.items.length+ this.setState({ selectedItems, selectAll })+ }++ private handleSelectAll = (checked: boolean) => {+ if (checked) {+ const selectedItems = new Set(this.state.items.map(item => `${item.type}-${item.id}`))+ this.setState({ selectedItems, selectAll: true })+ } else {+ this.setState({ selectedItems: new Set(), selectAll: false })+ }+ }++ private bulkApprove = async () => {+ const { selectedItems } = this.state+ if (selectedItems.size === 0) {+ notify.error("Please select items to approve")+ return+ }++ const postIDs: number[] = []+ const commentIDs: number[] = []++ selectedItems.forEach(itemKey => {+ const [type, id] = itemKey.split('-')+ if (type === 'post') {+ postIDs.push(parseInt(id))+ } else if (type === 'comment') {+ commentIDs.push(parseInt(id))+ }+ })++ try {+ const response = await actions.bulkApproveItems(postIDs, commentIDs)+ if (response.ok) {+ notify.success(`Approved ${selectedItems.size} item(s) successfully`)+ await this.loadModerationItems()+ this.setState({ selectedItems: new Set(), selectAll: false })+ } else {+ notify.error("Failed to approve items")+ }+ } catch (error) {+ notify.error("Failed to approve items")+ }+ }++ private bulkDecline = async () => {+ const { selectedItems } = this.state+ if (selectedItems.size === 0) {+ notify.error("Please select items to decline")+ return+ }++ if (!confirm(`Are you sure you want to decline ${selectedItems.size} item(s)? This action cannot be undone.`)) {+ return+ }++ const postIDs: number[] = []+ const commentIDs: number[] = []++ selectedItems.forEach(itemKey => {+ const [type, id] = itemKey.split('-')+ if (type === 'post') {+ postIDs.push(parseInt(id))+ } else if (type === 'comment') {+ commentIDs.push(parseInt(id))+ }+ })++ try {+ const response = await actions.bulkDeclineItems(postIDs, commentIDs)+ if (response.ok) {+ notify.success(`Declined ${selectedItems.size} item(s) successfully`)+ await this.loadModerationItems()+ this.setState({ selectedItems: new Set(), selectAll: false })+ } else {+ notify.error("Failed to decline items")+ }+ } catch (error) {+ notify.error("Failed to decline items")+ }+ }++ private approveItem = async (item: ModerationItem) => {+ try {+ let response+ if (item.type === 'post') {+ response = await actions.approvePost(item.id)+ } else {+ response = await actions.approveComment(item.id)+ }++ if (response.ok) {+ notify.success(`${item.type === 'post' ? 'Post' : 'Comment'} approved successfully`)+ await this.loadModerationItems()+ } else {+ notify.error(`Failed to approve ${item.type}`)+ }+ } catch (error) {+ notify.error(`Failed to approve ${item.type}`)+ }+ }++ private declineItem = async (item: ModerationItem) => {+ if (!confirm(`Are you sure you want to decline this ${item.type}? This action cannot be undone.`)) {+ return+ }++ try {+ let response+ if (item.type === 'post') {+ response = await actions.declinePost(item.id)+ } else {+ response = await actions.declineComment(item.id)+ }++ if (response.ok) {+ notify.success(`${item.type === 'post' ? 'Post' : 'Comment'} declined successfully`)+ await this.loadModerationItems()+ } else {+ notify.error(`Failed to decline ${item.type}`)+ }+ } catch (error) {+ notify.error(`Failed to decline ${item.type}`)+ }+ }++ private formatDate = (dateString: string) => {+ return new Date(dateString).toLocaleDateString('en-US', {+ year: 'numeric',+ month: 'short',+ day: 'numeric',+ hour: '2-digit',+ minute: '2-digit'+ })+ }++ public content() {+ const { items, loading, selectedItems, selectAll } = this.state++ if (!Fider.session.tenant.isModerationEnabled) {+ return (+ <div className="p-4 bg-blue-50 rounded border-l-4 border-blue-500">+ <p className="text-blue-800">+ Content moderation is currently disabled for this site. You can enable it in the{" "}+ <a href="/admin/privacy" className="text-blue-600 underline">Privacy Settings</a>.+ </p>+ </div>+ )+ }++ if (loading) {+ return <Loader />+ }++ if (items.length === 0) {+ return (+ <div className="text-center py-8">+ <h3 className="text-lg font-medium text-gray-900 mb-2">No pending items</h3>+ <p className="text-gray-600">All content has been moderated.</p>+ </div>+ )+ }++ return (+ <VStack spacing={4}>+ <div className="flex justify-between items-center">+ <h3 className="text-lg font-medium">+ {items.length} item(s) awaiting moderation+ </h3>+ <HStack spacing={2}>+ <Button+ variant="primary"+ size="small"+ onClick={this.bulkApprove}+ disabled={selectedItems.size === 0}+ >+ Approve Selected ({selectedItems.size})+ </Button>+ <Button+ variant="danger"+ size="small"+ onClick={this.bulkDecline}+ disabled={selectedItems.size === 0}+ >+ Decline Selected ({selectedItems.size})+ </Button>+ </HStack>+ </div>++ <div className="bg-white shadow rounded-lg overflow-hidden">+ <table className="min-w-full divide-y divide-gray-200">+ <thead className="bg-gray-50">+ <tr>+ <th className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">+ <input+ type="checkbox"+ checked={selectAll}+ onChange={(e) => this.handleSelectAll(e.target.checked)}+ className="rounded border-gray-300"+ />+ </th>+ <th className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">+ Type+ </th>+ <th className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">+ Content+ </th>+ <th className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">+ Author+ </th>+ <th className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">+ Created+ </th>+ <th className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">+ Actions+ </th>+ </tr>+ </thead>+ <tbody className="bg-white divide-y divide-gray-200">+ {items.map((item) => {+ const itemKey = `${item.type}-${item.id}`+ const isSelected = selectedItems.has(itemKey)++ return (+ <tr key={itemKey} className={isSelected ? "bg-blue-50" : ""}>+ <td className="px-4 py-4 whitespace-nowrap">+ <input+ type="checkbox"+ checked={isSelected}+ onChange={(e) => this.handleSelectItem(itemKey, e.target.checked)}+ className="rounded border-gray-300"+ />+ </td>+ <td className="px-4 py-4 whitespace-nowrap">+ <span className={`inline-flex px-2 py-1 text-xs font-semibold rounded-full ${+ item.type === 'post'+ ? 'bg-green-100 text-green-800'+ : 'bg-blue-100 text-blue-800'+ }`}>+ {item.type === 'post' ? 'Post' : 'Comment'}+ </span>+ </td>+ <td className="px-4 py-4">+ <div className="max-w-xs">+ <div className="font-medium text-gray-900 truncate">+ {item.title || (item.type === 'comment' ? 'Comment' : 'Post')}+ </div>+ <div className="text-sm text-gray-500 truncate">+ {item.content}+ </div>+ {item.type === 'comment' && item.postTitle && (+ <div className="text-xs text-gray-400 truncate">+ on: {item.postTitle}+ </div>+ )}+ </div>+ </td>+ <td className="px-4 py-4 whitespace-nowrap text-sm text-gray-900">+ {item.user.name}+ </td>+ <td className="px-4 py-4 whitespace-nowrap text-sm text-gray-500">+ {this.formatDate(item.createdAt)}+ </td>+ <td className="px-4 py-4 whitespace-nowrap text-sm">+ <HStack spacing={1}>+ <Button+ variant="primary"+ size="small"+ onClick={() => this.approveItem(item)}+ >+ Approve+ </Button>+ <Button+ variant="danger"+ size="small"+ onClick={() => this.declineItem(item)}+ >+ Decline+ </Button>+ {item.type === 'post' && item.postNumber && item.postSlug && (+ <a+ href={`/posts/${item.postNumber}/${item.postSlug}`}+ target="_blank"+ rel="noopener noreferrer"+ className="text-blue-600 hover:text-blue-800 text-xs"+ >+ View+ </a>+ )}+ {item.type === 'comment' && item.postNumber && item.postSlug && (+ <a+ href={`/posts/${item.postNumber}/${item.postSlug}#comment-${item.id}`}+ target="_blank"+ rel="noopener noreferrer"+ className="text-blue-600 hover:text-blue-800 text-xs"+ >+ View+ </a>+ )}+ </HStack>+ </td>+ </tr>+ )+ })}+ </tbody>+ </table>+ </div>+ </VStack>+ )+ }+}\ No newline at end of filediff --git a/public/services/actions/post.ts b/public/services/actions/post.tsindex e9948555c..5bb5c023e 100644--- a/public/services/actions/post.ts+++ b/public/services/actions/post.ts@@ -134,3 +134,11 @@ export const approveComment = async (commentID: number): Promise<Result> => {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 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"))+}