Take control over your live stream video by running it yourself. Streaming + chat out of the box.
HTML activitypubbroadcastingchatdecentralizedfederationfediversegolanghacktoberfesthlslivelivestreamowncastrtmpself-hostedstreaming-videovideo
fix(admin): show complete moderator and banned user lists
Gabe Kangas3b20e1779a23
diff --git a/db/query.sql b/db/query.sqlindex 6622129024..b600f4cccd 100644--- a/db/query.sql+++ b/db/query.sql@@ -180,17 +180,17 @@ UPDATE users SET display_color = ? WHERE id = ?;-- A page of users of every type (chat viewers, authenticated/plugin users, and-- API integrations), newest first, filtered to display names containing-- @search and an optional @status: '' or 'all' = every user; otherwise--- 'active' (not banned), 'banned' (disabled), 'moderators', or 'bots' (API--- users). An empty @search matches every user (LIKE '%%').+-- 'active' (not banned) or 'bots' (API users). An empty @search matches every+-- user (LIKE '%%'). The complete banned and moderator sets come from+-- GetDisabledUsers and GetModeratorUsers instead, since those need every match+-- rather than a page.SELECT id, display_name, display_color, created_at, disabled_at, previous_names, namechanged_at, authenticated_at, scopes, type = 'API' AS is_botFROM usersWHERE display_name LIKE '%' || @search || '%'AND (@status = '' OR @status = 'all'OR (@status = 'active' AND disabled_at IS NULL)- OR (@status = 'banned' AND disabled_at IS NOT NULL)OR (@status = 'bots' AND type = 'API')- OR (@status = 'moderators' AND scopes LIKE '%MODERATOR%'))ORDER BY created_at DESCLIMIT @page_limit OFFSET @page_offset;@@ -202,9 +202,7 @@ WHERE display_name LIKE '%' || @search || '%'AND (@status = '' OR @status = 'all'OR (@status = 'active' AND disabled_at IS NULL)- OR (@status = 'banned' AND disabled_at IS NOT NULL)OR (@status = 'bots' AND type = 'API')- OR (@status = 'moderators' AND scopes LIKE '%MODERATOR%'));-- name: DeleteUserAccessTokens :execdiff --git a/db/query.sql.go b/db/query.sql.goindex e0e8b42201..cd5f7f5ff8 100644--- a/db/query.sql.go+++ b/db/query.sql.go@@ -255,9 +255,7 @@ WHERE display_name LIKE '%' || ?1 || '%'AND (?2 = '' OR ?2 = 'all'OR (?2 = 'active' AND disabled_at IS NULL)- OR (?2 = 'banned' AND disabled_at IS NOT NULL)OR (?2 = 'bots' AND type = 'API')- OR (?2 = 'moderators' AND scopes LIKE '%MODERATOR%'))`@@ -1332,9 +1330,7 @@ WHERE display_name LIKE '%' || ?1 || '%'AND (?2 = '' OR ?2 = 'all'OR (?2 = 'active' AND disabled_at IS NULL)- OR (?2 = 'banned' AND disabled_at IS NOT NULL)OR (?2 = 'bots' AND type = 'API')- OR (?2 = 'moderators' AND scopes LIKE '%MODERATOR%'))ORDER BY created_at DESCLIMIT ?4 OFFSET ?3@@ -1363,8 +1359,10 @@ type GetUsersPaginatedRow struct {// A page of users of every type (chat viewers, authenticated/plugin users, and// API integrations), newest first, filtered to display names containing// @search and an optional @status: ” or 'all' = every user; otherwise-// 'active' (not banned), 'banned' (disabled), 'moderators', or 'bots' (API-// users). An empty @search matches every user (LIKE '%%').+// 'active' (not banned) or 'bots' (API users). An empty @search matches every+// user (LIKE '%%'). The complete banned and moderator sets come from+// GetDisabledUsers and GetModeratorUsers instead, since those need every match+// rather than a page.func (q *Queries) GetUsersPaginated(ctx context.Context, arg GetUsersPaginatedParams) ([]GetUsersPaginatedRow, error) {rows, err := q.db.QueryContext(ctx, getUsersPaginated,arg.Search,diff --git a/openapi.yaml b/openapi.yamlindex 9c1655c504..2626e8f01b 100644--- a/openapi.yaml+++ b/openapi.yaml@@ -809,7 +809,7 @@ paths:description: Filter users by statusschema:type: string- enum: [all, active, banned, moderators, bots]+ enum: [all, active, bots]responses:'200':description: A paginated list of usersdiff --git a/test/automated/api/010_auth.test.js b/test/automated/api/010_auth.test.jsindex 32d84877e8..c240a29bc8 100644--- a/test/automated/api/010_auth.test.js+++ b/test/automated/api/010_auth.test.js@@ -23,7 +23,7 @@ const paths = ['/admin/federation/followers/','/admin/chat/messages','/admin/viewer-info/',- '/admin/chat/users/',+ '/admin/users/','/admin/stream-health','/admin/hardware-info/',// Some APIs toodiff --git a/test/automated/api/012_usermanagement.test.js b/test/automated/api/012_usermanagement.test.jsindex 51af379040..d703e106c3 100644--- a/test/automated/api/012_usermanagement.test.js+++ b/test/automated/api/012_usermanagement.test.js@@ -60,24 +60,26 @@ test('authProviders is empty for an anonymous user', async () => {expect(match[0].authProviders || []).toHaveLength(0);});-test('status=moderators filter includes a moderator', async () => {+// Moderators and banned users come from their own endpoints, which return the+// complete set rather than a page of the users API.+test('moderators list includes a promoted moderator', async () => {await sendAdminPayload('chat/users/setmoderator', {userId: userId,isModerator: true,});- const response = await getAdminResponse(- 'users?status=moderators&search=' + encodeURIComponent(displayName),- );- const match = response.body.results.filter((user) => user.id === userId);+ const response = await getAdminResponse('chat/users/moderators');+ const match = response.body.filter((user) => user.id === userId);expect(match).toHaveLength(1);});-test('status=banned excludes an active user', async () => {- const response = await getAdminResponse(- 'users?status=banned&search=' + encodeURIComponent(displayName),- );- const match = response.body.results.filter((user) => user.id === userId);- expect(match).toHaveLength(0);+test('banned list includes a disabled user', async () => {+ await sendAdminPayload('chat/users/setenabled', {+ userId: userId,+ enabled: false,+ });+ const response = await getAdminResponse('chat/users/disabled');+ const match = response.body.filter((user) => user.id === userId);+ expect(match).toHaveLength(1);});test('status=bots excludes a normal user', async () => {diff --git a/web/pages/admin/users.tsx b/web/pages/admin/users.tsxindex 7018630ef0..8e819aa88c 100644--- a/web/pages/admin/users.tsx+++ b/web/pages/admin/users.tsx@@ -4,7 +4,14 @@ import { ColumnsType, SortOrder } from 'antd/lib/table/interface';import { useTranslation } from 'next-export-i18n';import { AdminLayout } from '../../components/layouts/AdminLayout';import { ServerStatusContext } from '../../utils/server-status-context';-import { USERS, CONNECTED_CLIENTS, BANNED_IPS, fetchData } from '../../utils/apis';+import {+ USERS,+ MODERATORS,+ DISABLED_USERS,+ CONNECTED_CLIENTS,+ BANNED_IPS,+ fetchData,+} from '../../utils/apis';import { User, Client } from '../../types/chat';import { formatDisplayDate } from '../../utils/format';import { ClientTable } from '../../components/admin/ClientTable';@@ -19,8 +26,6 @@ const LIVE_FETCH_INTERVAL = 10 * 1000; // 10 secconst STATUS_OPTIONS = [{ value: 'all', label: 'All' },{ value: 'active', label: 'Active' },- { value: 'banned', label: 'Banned' },- { value: 'moderators', label: 'Moderators' },{ value: 'bots', label: 'Bots' },];@@ -37,6 +42,10 @@ export default function UsersAdmin() {const [status, setStatus] = useState<string>('all');const [loading, setLoading] = useState<boolean>(false);+ // Exhaustive lists (the paginated endpoint can't return a complete set).+ const [moderators, setModerators] = useState<User[]>([]);+ const [bannedUsers, setBannedUsers] = useState<User[]>([]);+// Live tabs state (connected clients + IP bans).const [clients, setClients] = useState<Client[]>([]);const [ipBans, setIPBans] = useState([]);@@ -67,6 +76,23 @@ export default function UsersAdmin() {}};+ // Moderators and banned users are complete sets, not pages, so they come from+ // their dedicated endpoints rather than the paginated users API.+ const getLists = async () => {+ try {+ setModerators((await fetchData(MODERATORS, { auth: true })) || []);+ } catch (e) {+ // eslint-disable-next-line no-console+ console.error('error fetching moderators', e);+ }+ try {+ setBannedUsers((await fetchData(DISABLED_USERS, { auth: true })) || []);+ } catch (e) {+ // eslint-disable-next-line no-console+ console.error('error fetching banned users', e);+ }+ };+const getLiveInfo = async () => {try {setClients(await fetchData(CONNECTED_CLIENTS));@@ -82,10 +108,21 @@ export default function UsersAdmin() {}};+ // A user action (ban, moderator toggle, delete) can move a user between the+ // paginated view and either list, so refresh all three.+ const refresh = () => {+ getUsers();+ getLists();+ };+useEffect(() => {getUsers();}, [currentPage, search, status]);+ useEffect(() => {+ getLists();+ }, []);+useEffect(() => {getLiveInfo();const id = setInterval(getLiveInfo, LIVE_FETCH_INTERVAL);@@ -144,7 +181,7 @@ export default function UsersAdmin() {title: '',key: 'actions',className: 'actions-col',- render: (_, user) => <UserActionsDropdown user={user} onChanged={getUsers} />,+ render: (_, user) => <UserActionsDropdown user={user} onChanged={refresh} />,},];@@ -221,8 +258,30 @@ export default function UsersAdmin() {</p>);+ // Full, unpaginated tables for the dedicated lists.+ const listTable = (data: User[]) => (+ <Table+ className="table-container"+ columns={columns}+ dataSource={data}+ size="small"+ rowKey="id"+ pagination={{ pageSize: PAGE_SIZE, showSizeChanger: false, hideOnSinglePage: true }}+ />+ );+const items = [{ label: t('All Users'), key: 'all', children: allUsersTab },+ {+ label: <span>{`${t('Moderators')} (${moderators.length})`}</span>,+ key: 'moderators',+ children: listTable(moderators),+ },+ {+ label: <span>{`${t('Banned')} (${bannedUsers.length})`}</span>,+ key: 'banned',+ children: listTable(bannedUsers),+ },{label: <span>{`${t('Connected')} (${online ? clients.length : t('offline')})`}</span>,key: 'connected',diff --git a/web/utils/apis.ts b/web/utils/apis.tsindex c20169a1f1..1a40c64c87 100644--- a/web/utils/apis.ts+++ b/web/utils/apis.ts@@ -45,6 +45,12 @@ export const USERS = `${API_LOCATION}users`;// Permanently delete a userexport const DELETE_USER = `${API_LOCATION}users/delete`;+// Get the full list of disabled/banned users+export const DISABLED_USERS = `${API_LOCATION}chat/users/disabled`;++// Get the full list of moderators+export const MODERATORS = `${API_LOCATION}chat/users/moderators`;+// Get hardware statsexport const HARDWARE_STATS = `${API_LOCATION}hardwarestats`;