Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Introduce User Report Section on Moderation Console #30554

Merged
merged 62 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
3e0d4eb
add method to fetch reported users
Dnouv Sep 26, 2023
d612b0f
revamp the date filter and revert back the leftover change on the mdo…
Dnouv Sep 27, 2023
ab39e74
add the tabs on main console
Dnouv Sep 29, 2023
790423f
add hide user reports endpoint
Dnouv Sep 29, 2023
cdaaa36
complete the user reports context bar display
Dnouv Oct 3, 2023
21d6068
fix ts error & improve the count
Dnouv Oct 5, 2023
0e499b6
add refresh avatar for user section & i18n
Dnouv Oct 6, 2023
23f02f7
add tests & rename api endpoint (moderation.user.reports <-> moderati…
Dnouv Oct 9, 2023
0089077
Merge branch 'develop' into new/MCreptUser
Dnouv Oct 9, 2023
87a72f9
componentize the mod filter & use userouter
Dnouv Oct 11, 2023
5bd4bfd
abstract & improve
Dnouv Oct 12, 2023
4a5f9f3
Merge branch 'develop' into new/MCreptUser
Dnouv Oct 13, 2023
a4d1a05
remove re-render key
Dnouv Oct 13, 2023
ca91e40
remove & resolve comments, fix sort, and a few cleanup
Dnouv Oct 13, 2023
24ee102
add changeset
Dnouv Oct 13, 2023
3758269
reset the default tab to Messages
Dnouv Oct 13, 2023
4d54a1a
Merge branch 'develop' into new/MCreptUser
casalsgh Oct 17, 2023
a288c85
define methods for API calls
Dnouv Oct 17, 2023
22da12d
Merge branch 'develop' into new/MCreptUser
casalsgh Oct 18, 2023
a9e8c62
Merge branch 'develop' into new/MCreptUser
casalsgh Oct 18, 2023
47bee49
Merge branch 'develop' into new/MCreptUser
debdutdeb Oct 18, 2023
f9dd713
Merge branch 'develop' into new/MCreptUser
debdutdeb Oct 18, 2023
4429340
remove userprofile;
Dnouv Oct 19, 2023
28ac3b6
type guard, method name rename, file rename, log error, remove usecal…
Dnouv Oct 19, 2023
7a23526
optimize indexes
Dnouv Oct 19, 2023
a3f5c5d
reduce no. of iteration
Dnouv Oct 19, 2023
a361985
keep seperate api functions on hold
Dnouv Oct 19, 2023
11134ca
ui changes
Dnouv Oct 20, 2023
78b3b85
return react element for table header
Dnouv Oct 20, 2023
9c83d0c
fix: flash of stale content
Dnouv Oct 20, 2023
ff9681b
add separate links for main tabs, wrap the ContextContent, improve de…
Dnouv Oct 24, 2023
53f5315
Merge branch 'develop' into new/MCreptUser
Dnouv Oct 24, 2023
33fa587
Merge branch 'develop' into new/MCreptUser
Dnouv Oct 25, 2023
ad82d9a
remove title from button
Dnouv Oct 30, 2023
9624fee
Add Serialized type to UserReport and IUser
Dnouv Oct 30, 2023
2a126af
add spacing
Dnouv Oct 31, 2023
613f02d
Merge branch 'develop' into new/MCreptUser
Dnouv Oct 31, 2023
6e39a12
Merge branch 'develop' into new/MCreptUser
Dnouv Nov 1, 2023
5df540a
chore: review tweaks
dougfabris Nov 3, 2023
9d1031a
Merge branch 'develop' into new/MCreptUser
Dnouv Nov 3, 2023
036a5ac
Merge branch 'develop' into new/MCreptUser
Dnouv Dec 18, 2023
35be92a
change query keys
Dnouv Dec 18, 2023
fd21f45
remove boolean prop
Dnouv Dec 18, 2023
3f387d2
remove Box
Dnouv Dec 18, 2023
d0969e5
add a generic api func
Dnouv Dec 18, 2023
9e2272a
Merge branch 'develop' into new/MCreptUser
Dnouv Dec 18, 2023
290cbb1
remove sub-function
Dnouv Dec 20, 2023
2c0cbaf
Merge branch 'develop' into new/MCreptUser
Dnouv Dec 20, 2023
952a6fb
Merge branch 'develop' into new/MCreptUser
casalsgh Jan 3, 2024
afa4b38
Merge branch 'develop' into new/MCreptUser
casalsgh Jan 3, 2024
7790c36
update indexes
Dnouv Jan 4, 2024
434b937
Merge branch 'develop' into new/MCreptUser
casalsgh Jan 4, 2024
aef780a
use agg for count
Dnouv Jan 4, 2024
339039d
Merge branch 'develop' into new/MCreptUser
Dnouv Jan 8, 2024
4a8b316
Merge develop
Dnouv Jan 22, 2024
6187d71
fix TS
Dnouv Jan 22, 2024
1727f05
Update apps/meteor/server/models/raw/ModerationReports.ts
Dnouv Jan 22, 2024
96233f0
change api name & remove try...catch
Dnouv Jan 22, 2024
e0ad38a
change changeset
Dnouv Jan 22, 2024
9e48dfc
revert api name
Dnouv Jan 22, 2024
4690b20
Merge branch 'develop' into new/MCreptUser
casalsgh Jan 23, 2024
0868710
Merge branch 'develop' into new/MCreptUser
kodiakhq[bot] Jan 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/rare-eels-fetch.md
tassoevan marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@rocket.chat/model-typings': minor
'@rocket.chat/rest-typings': minor
'@rocket.chat/i18n': minor
---

**Added ‘Reported Users’ Tab to Moderation Console:** Enhances user monitoring by displaying reported users.
76 changes: 73 additions & 3 deletions apps/meteor/app/api/server/v1/moderation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ import {
isReportHistoryProps,
isArchiveReportProps,
isReportInfoParams,
isReportMessageHistoryParams,
isGetUserReportsParams,
isModerationReportUserPost,
isModerationDeleteMsgHistoryParams,
isReportsByMsgIdParams,
} from '@rocket.chat/rest-typings';
import { escapeRegExp } from '@rocket.chat/string-helpers';

import { SystemLogger } from '../../../../server/lib/logger/system';
import { deleteReportedMessages } from '../../../../server/lib/moderation/deleteReportedMessages';
import { getUserReports } from '../../../../server/lib/moderation/getUserReports';
import { getUserReportsByUid } from '../../../../server/lib/moderation/getUserReportsByUid';
import { API } from '../api';
import { getPaginationItems } from '../helpers/getPaginationItems';

Expand Down Expand Up @@ -51,7 +54,7 @@ API.v1.addRoute(
});
}

const total = await ModerationReports.countMessageReportsInRange(latest, oldest, escapedSelector);
const total = await ModerationReports.getTotalUniqueReportedUsers(latest, oldest, escapedSelector, true);

return API.v1.success({
reports,
Expand All @@ -63,11 +66,31 @@ API.v1.addRoute(
},
);

API.v1.addRoute(
'moderation.userReports',
{
authRequired: true,
validateParams: isReportHistoryProps,
permissionsRequired: ['view-moderation-console'],
},
{
async get() {
Dnouv marked this conversation as resolved.
Show resolved Hide resolved
try {
const result = await getUserReports(this.queryParams, this.parseJsonQuery.bind(this));
Dnouv marked this conversation as resolved.
Show resolved Hide resolved
return API.v1.success(result);
} catch (error) {
SystemLogger.error(error);
return API.v1.failure('Error while fetching user reports');
}
tassoevan marked this conversation as resolved.
Show resolved Hide resolved
},
},
);

API.v1.addRoute(
'moderation.user.reportedMessages',
{
authRequired: true,
validateParams: isReportMessageHistoryParams,
validateParams: isGetUserReportsParams,
permissionsRequired: ['view-moderation-console'],
},
{
Expand Down Expand Up @@ -113,6 +136,26 @@ API.v1.addRoute(
},
);

API.v1.addRoute(
'moderation.user.reportsByUserId',
sampaiodiego marked this conversation as resolved.
Show resolved Hide resolved
{
authRequired: true,
validateParams: isGetUserReportsParams,
permissionsRequired: ['view-moderation-console'],
},
{
async get() {
try {
const result = await getUserReportsByUid(this.queryParams, this.parseJsonQuery.bind(this));
Dnouv marked this conversation as resolved.
Show resolved Hide resolved
return API.v1.success(result);
} catch (error) {
SystemLogger.error(error);
return API.v1.failure('Error while fetching user reports');
}
tassoevan marked this conversation as resolved.
Show resolved Hide resolved
},
},
);

API.v1.addRoute(
'moderation.user.deleteReportedMessages',
{
Expand Down Expand Up @@ -196,6 +239,33 @@ API.v1.addRoute(
},
);

API.v1.addRoute(
'moderation.dismissUserReports',
{
authRequired: true,
validateParams: isArchiveReportProps,
permissionsRequired: ['manage-moderation-actions'],
},
{
async post() {
const { userId, reason, action: actionParam } = this.bodyParams;

if (!userId) {
return API.v1.failure('error-user-id-param-not-provided');
}

const sanitizedReason: string = reason ?? 'No reason provided';
const action: string = actionParam ?? 'None';
debdutdeb marked this conversation as resolved.
Show resolved Hide resolved

const { userId: moderatorId } = this;

await ModerationReports.hideUserReportsByUserId(userId, moderatorId, sanitizedReason, action);

return API.v1.success();
},
},
);

API.v1.addRoute(
'moderation.reports',
{
Expand Down
dougfabris marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const MessageContextFooter: FC<{ userId: string; deleted: boolean }> = ({ userId
const deleteMessagesAction = useDeleteMessagesAction(userId);

return (
<ButtonGroup width='full' stretch>
<ButtonGroup flexGrow={0} width='full' stretch>
Dnouv marked this conversation as resolved.
Show resolved Hide resolved
<Button onClick={dismissUserAction.onClick} title={t('Moderation_Dismiss_all_reports')} aria-label={t('Moderation_Dismiss_reports')}>
{t('Moderation_Dismiss_all_reports')}
</Button>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import type { IUser } from '@rocket.chat/core-typings';
import { Tabs, TabsItem, ContextualbarHeader, ContextualbarTitle } from '@rocket.chat/fuselage';
import { type TranslationKey, useTranslation, useRouter } from '@rocket.chat/ui-contexts';
import React, { useState } from 'react';

import { Contextualbar, ContextualbarClose } from '../../../components/Contextualbar';
import UserMessages from './UserMessages';
import UserReportInfo from './UserReports/UserReportInfo';

type ModConsoleReportDetailsProps = {
userId: IUser['_id'];
default: string;
onRedirect: (mid: string) => void;
};

const tabs = ['Messages', 'Users'];

const ModConsoleReportDetails = ({ userId, default: defaultTab, onRedirect }: ModConsoleReportDetailsProps): JSX.Element => {
Dnouv marked this conversation as resolved.
Show resolved Hide resolved
const t = useTranslation();
const [tab, setTab] = useState<string>(defaultTab);
const moderationRoute = useRouter();

const handleTabClick = (tab: string) => (): void => setTab(tab);
Dnouv marked this conversation as resolved.
Show resolved Hide resolved

return (
<Contextualbar>
<ContextualbarHeader>
<ContextualbarTitle>{t('Reports')}</ContextualbarTitle>
<ContextualbarClose onClick={() => moderationRoute.navigate('/admin/moderation', { replace: true })} />
</ContextualbarHeader>
<Tabs>
{tabs.map((tabName) => (
<TabsItem key={tabName || ''} selected={tab === tabName} onClick={handleTabClick(tabName)}>
Dnouv marked this conversation as resolved.
Show resolved Hide resolved
{t(tabName as TranslationKey)}
</TabsItem>
))}
</Tabs>

{tab === 'Messages' && <UserMessages userId={userId} onRedirect={onRedirect} />}
{tab === 'Users' && <UserReportInfo userId={userId} />}
</Contextualbar>
);
};

export default ModConsoleReportDetails;
Original file line number Diff line number Diff line change
@@ -1,37 +1,52 @@
import { useTranslation, useRouteParameter, useToastMessageDispatch } from '@rocket.chat/ui-contexts';
import React from 'react';
import { Tabs, TabsItem } from '@rocket.chat/fuselage';
import { useTranslation, useRouteParameter, useToastMessageDispatch, type TranslationKey } from '@rocket.chat/ui-contexts';
import React, { useCallback, useState } from 'react';

import { Contextualbar } from '../../../components/Contextualbar';
import Page from '../../../components/Page';
import { getPermaLink } from '../../../lib/getPermaLink';
import ModConsoleReportDetails from './ModConsoleReportDetails';
import ModerationConsoleTable from './ModerationConsoleTable';
import UserMessages from './UserMessages';
import ModConsoleUsersTable from './UserReports/ModConsoleUsersTable';

const tabs = ['Messages', 'Users'];

const ModerationConsolePage = () => {
const t = useTranslation();
const context = useRouteParameter('context');
const id = useRouteParameter('id');
const dispatchToastMessage = useToastMessageDispatch();
const [tab, setTab] = useState('Messages');

const handleRedirect = useCallback(
async (mid: string) => {
try {
const permalink = await getPermaLink(mid);
window.open(permalink, '_self');
} catch (error) {
dispatchToastMessage({ type: 'error', message: error });
}
},
[dispatchToastMessage],
);
debdutdeb marked this conversation as resolved.
Show resolved Hide resolved

const handleRedirect = async (mid: string) => {
try {
const permalink = await getPermaLink(mid);
// open the permalink in same tab
window.open(permalink, '_self');
} catch (error) {
dispatchToastMessage({ type: 'error', message: error });
}
};
const handleTabClick = (tab: string) => () => setTab(tab);

Dnouv marked this conversation as resolved.
Show resolved Hide resolved
return (
<Page flexDirection='row'>
<Page>
<Page.Header title={t('Moderation')} />
<Page.Content>
<ModerationConsoleTable />
<Tabs>
{tabs.map((tabName) => (
Dnouv marked this conversation as resolved.
Show resolved Hide resolved
<TabsItem key={tabName || ''} selected={tab === tabName} onClick={handleTabClick(tabName)}>
{t(`Reported_${tabName}` as TranslationKey)}
Dnouv marked this conversation as resolved.
Show resolved Hide resolved
</TabsItem>
))}
</Tabs>
{tab === 'Messages' && <ModerationConsoleTable />} {tab === 'Users' && <ModConsoleUsersTable />}
</Page.Content>
</Page>
{context && <Contextualbar>{context === 'info' && id && <UserMessages userId={id} onRedirect={handleRedirect} />}</Contextualbar>}
{context === 'info' && id && <ModConsoleReportDetails userId={id} onRedirect={handleRedirect} default={tab} />}
</Page>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Pagination, Field, FieldLabel, FieldRow } from '@rocket.chat/fuselage';
import { Pagination } from '@rocket.chat/fuselage';
import { useDebouncedValue, useMediaQuery, useMutableCallback } from '@rocket.chat/fuselage-hooks';
import { useEndpoint, useToastMessageDispatch, useRoute, useTranslation } from '@rocket.chat/ui-contexts';
import { useEndpoint, useToastMessageDispatch, useRouter, useTranslation } from '@rocket.chat/ui-contexts';
import { useQuery } from '@tanstack/react-query';
import type { FC } from 'react';
import React, { useMemo, useState } from 'react';

import FilterByText from '../../../components/FilterByText';
import GenericNoResults from '../../../components/GenericNoResults';
import {
GenericTable,
Expand All @@ -17,12 +16,12 @@ import {
import { usePagination } from '../../../components/GenericTable/hooks/usePagination';
import { useSort } from '../../../components/GenericTable/hooks/useSort';
import ModerationConsoleTableRow from './ModerationConsoleTableRow';
import DateRangePicker from './helpers/DateRangePicker';
import ModerationFilter from './helpers/ModerationFilter';

// TODO: Missing error state
const ModerationConsoleTable: FC = () => {
const [text, setText] = useState('');
const moderationRoute = useRoute('moderation-console');
const router = useRouter();
const t = useTranslation();
const isDesktopOrLarger = useMediaQuery('(min-width: 1024px)');

Expand Down Expand Up @@ -64,13 +63,15 @@ const ModerationConsoleTable: FC = () => {
});

const handleClick = useMutableCallback((id): void => {
moderationRoute.push({
context: 'info',
id,
router.navigate({
name: 'moderation-console',
params: {
context: 'info',
id,
},
});
});

// header sequence would be: name, reportedMessage, room, postdate, reports, actions
const headers = useMemo(
() => [
<GenericTableHeaderCell
Expand All @@ -80,20 +81,9 @@ const ModerationConsoleTable: FC = () => {
onClick={setSort}
sort='reports.message.u.username'
>
{t('Name')}
{t('User')}
</GenericTableHeaderCell>,
isDesktopOrLarger && (
<GenericTableHeaderCell
w='x140'
key='username'
direction={sortDirection}
active={sortBy === 'reports.message.u.username'}
onClick={setSort}
sort='reports.message.u.username'
>
{t('Username')}
</GenericTableHeaderCell>
),

<GenericTableHeaderCell
key='reportedMessage'
direction={sortDirection}
Expand All @@ -114,18 +104,12 @@ const ModerationConsoleTable: FC = () => {
</GenericTableHeaderCell>,
<GenericTableHeaderCell key='actions' width='x48' />,
],
[sortDirection, sortBy, setSort, t, isDesktopOrLarger],
[sortDirection, sortBy, setSort, t],
);

return (
<>
<FilterByText autoFocus placeholder={t('Search')} onChange={({ text }): void => setText(text)} />
<Field alignSelf='stretch'>
<FieldLabel>{t('Date')}</FieldLabel>
<FieldRow>
<DateRangePicker display='flex' flexGrow={1} onChange={setDateRange} />
</FieldRow>
</Field>
<ModerationFilter setText={setText} setDateRange={setDateRange} />
{isLoading && (
<GenericTable>
<GenericTableHeader>{headers}</GenericTableHeader>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import type { IModerationAudit, IUser } from '@rocket.chat/core-typings';
import { Box } from '@rocket.chat/fuselage';
import React from 'react';

import { GenericTableCell, GenericTableRow } from '../../../components/GenericTable';
import UserAvatar from '../../../components/avatar/UserAvatar';
import { useFormatDateAndTime } from '../../../hooks/useFormatDateAndTime';
import ModerationConsoleActions from './ModerationConsoleActions';
import UserColumn from './helpers/UserColumn';

export type ModerationConsoleRowProps = {
report: IModerationAudit;
Expand All @@ -30,34 +29,8 @@ const ModerationConsoleTableRow = ({ report, onClick, isDesktopOrLarger }: Moder
return (
<GenericTableRow key={_id} onClick={(): void => onClick(_id)} tabIndex={0} role='link' action>
<GenericTableCell withTruncatedText>
<Box display='flex' alignItems='center'>
{username && (
<Box>
<UserAvatar size={isDesktopOrLarger ? 'x20' : 'x40'} username={username} />
</Box>
)}
<Box display='flex' mi={8} withTruncatedText>
<Box display='flex' flexDirection='column' alignSelf='center' withTruncatedText>
<Box fontScale='p2m' color='default' withTruncatedText>
{name || username}
</Box>
{!isDesktopOrLarger && name && (
<Box fontScale='p2' color='hint' withTruncatedText>
{' '}
{`@${username}`}{' '}
</Box>
)}
</Box>
</Box>
</Box>
<UserColumn name={name} username={username} isDesktopOrLarger={isDesktopOrLarger} />
</GenericTableCell>
{isDesktopOrLarger && (
<GenericTableCell>
<Box fontScale='p2m' color='hint' withTruncatedText>
{username}
</Box>
</GenericTableCell>
)}
<GenericTableCell withTruncatedText>{message}</GenericTableCell>
<GenericTableCell withTruncatedText>{concatenatedRoomNames}</GenericTableCell>
<GenericTableCell withTruncatedText>{formatDateAndTime(ts)}</GenericTableCell>
Expand Down
Loading
Loading