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 all 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
8 changes: 8 additions & 0 deletions .changeset/rare-eels-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@rocket.chat/model-typings': minor
'@rocket.chat/rest-typings': minor
'@rocket.chat/i18n': minor
'@rocket.chat/meteor': minor
---

**Added ‘Reported Users’ Tab to Moderation Console:** Enhances user monitoring by displaying reported users.
142 changes: 138 additions & 4 deletions apps/meteor/app/api/server/v1/moderation.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { IModerationReport, IUser } from '@rocket.chat/core-typings';
import type { IModerationReport, IUser, IUserEmail } from '@rocket.chat/core-typings';
import { ModerationReports, Users } from '@rocket.chat/models';
import {
isReportHistoryProps,
isArchiveReportProps,
isReportInfoParams,
isReportMessageHistoryParams,
isGetUserReportsParams,
isModerationReportUserPost,
isModerationDeleteMsgHistoryParams,
isReportsByMsgIdParams,
Expand Down Expand Up @@ -51,7 +51,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 +63,60 @@ API.v1.addRoute(
},
);

API.v1.addRoute(
'moderation.userReports',
{
authRequired: true,
validateParams: isReportHistoryProps,
permissionsRequired: ['view-moderation-console'],
},
{
async get() {
const { latest: _latest, oldest: _oldest, selector = '' } = this.queryParams;
Dnouv marked this conversation as resolved.
Show resolved Hide resolved

const { count = 20, offset = 0 } = await getPaginationItems(this.queryParams);

const { sort } = await this.parseJsonQuery();

const latest = _latest ? new Date(_latest) : new Date();

const oldest = _oldest ? new Date(_oldest) : new Date(0);

const escapedSelector = escapeRegExp(selector);

const reports = await ModerationReports.findUserReports(latest, oldest, escapedSelector, {
offset,
count,
sort,
}).toArray();

if (reports.length === 0) {
return API.v1.success({
reports,
count: 0,
offset,
total: 0,
});
}

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

const result = {
reports,
count: reports.length,
offset,
total,
};
return API.v1.success(result);
},
},
);

API.v1.addRoute(
'moderation.user.reportedMessages',
{
authRequired: true,
validateParams: isReportMessageHistoryParams,
validateParams: isGetUserReportsParams,
permissionsRequired: ['view-moderation-console'],
},
{
Expand Down Expand Up @@ -113,6 +162,64 @@ 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() {
const { userId, selector = '' } = this.queryParams;
const { sort } = await this.parseJsonQuery();
const { count = 50, offset = 0 } = await getPaginationItems(this.queryParams);

const user = await Users.findOneById<IUser>(userId, {
projection: {
_id: 1,
username: 1,
name: 1,
avatarETag: 1,
active: 1,
roles: 1,
emails: 1,
createdAt: 1,
},
});
debdutdeb marked this conversation as resolved.
Show resolved Hide resolved

const escapedSelector = escapeRegExp(selector);
const { cursor, totalCount } = ModerationReports.findUserReportsByReportedUserId(userId, escapedSelector, {
offset,
count,
sort,
});

const [reports, total] = await Promise.all([cursor.toArray(), totalCount]);

const emailSet = new Map<IUserEmail['address'], IUserEmail>();

reports.forEach((report) => {
const email = report.reportedUser?.emails?.[0];
if (email) {
emailSet.set(email.address, email);
}
});
if (user) {
user.emails = Array.from(emailSet.values());
}

return API.v1.success({
user,
reports,
count: reports.length,
total,
offset,
});
},
},
);

API.v1.addRoute(
'moderation.user.deleteReportedMessages',
{
Expand Down Expand Up @@ -196,6 +303,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
@@ -1,4 +1,4 @@
import { Button, ButtonGroup } from '@rocket.chat/fuselage';
import { Button, ButtonGroup, Box } from '@rocket.chat/fuselage';
import { useTranslation } from '@rocket.chat/ui-contexts';
import React from 'react';
import type { FC } from 'react';
Expand All @@ -17,27 +17,22 @@ const MessageContextFooter: FC<{ userId: string; deleted: boolean }> = ({ userId

return (
<ButtonGroup stretch>
<Button onClick={dismissUserAction.onClick} title={t('Moderation_Dismiss_all_reports')} aria-label={t('Moderation_Dismiss_reports')}>
{t('Moderation_Dismiss_all_reports')}
</Button>
<Button
onClick={deleteMessagesAction.onClick}
title={t('delete-message')}
aria-label={t('Moderation_Delete_all_messages')}
secondary
danger
>
<Button onClick={dismissUserAction.onClick}>{t('Moderation_Dismiss_all_reports')}</Button>
<Button onClick={deleteMessagesAction.onClick} secondary danger>
{t('Moderation_Delete_all_messages')}
</Button>

<GenericMenu
title={t('More')}
items={[
{ ...useDeactivateUserAction(userId), ...(deleted && { disabled: true }) },
{ ...useResetAvatarAction(userId), ...(deleted && { disabled: true }) },
]}
placement='top-end'
/>
<Box flexGrow={0} marginInlineStart={8}>
<GenericMenu
large
title={t('More')}
items={[
{ ...useDeactivateUserAction(userId), ...(deleted && { disabled: true }) },
{ ...useResetAvatarAction(userId), ...(deleted && { disabled: true }) },
]}
placement='top-end'
/>
</Box>
</ButtonGroup>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const MessageReportInfo = ({ msgId }: { msgId: string }): JSX.Element => {
isSuccess: isSuccessReportsByMessage,
isError: isErrorReportsByMessage,
} = useQuery(
['moderation.reports', { msgId }],
['moderation', 'msgReports', 'fetchReasons', { msgId }],
async () => {
const reports = await getReportsByMessage({ msgId });
return reports;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import type { IUser } from '@rocket.chat/core-typings';
import { Tabs, TabsItem, ContextualbarHeader, ContextualbarTitle } from '@rocket.chat/fuselage';
import { useTranslation, useRouter, useRouteParameter } 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 ModConsoleReportDetails = ({ userId, default: defaultTab, onRedirect }: ModConsoleReportDetailsProps) => {
const t = useTranslation();
const [tab, setTab] = useState<string>(defaultTab);
const moderationRoute = useRouter();

const activeTab = useRouteParameter('tab');

return (
<Contextualbar>
<ContextualbarHeader>
<ContextualbarTitle>{t('Reports')}</ContextualbarTitle>
<ContextualbarClose onClick={() => moderationRoute.navigate(`/admin/moderation/${activeTab}`, { replace: true })} />
</ContextualbarHeader>
<Tabs paddingBlockStart={8}>
<TabsItem selected={tab === 'messages'} onClick={() => setTab('messages')}>
{t('Messages')}
</TabsItem>
<TabsItem selected={tab === 'users'} onClick={() => setTab('users')}>
{t('User')}
</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,62 @@
import { Tabs, TabsItem } from '@rocket.chat/fuselage';
import { useTranslation, useRouteParameter, useToastMessageDispatch } from '@rocket.chat/ui-contexts';
import React from 'react';
import React, { useCallback } from 'react';

import { Contextualbar } from '../../../components/Contextualbar';
import { Page, PageHeader, PageContent } 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 ModerationConsolePage = () => {
type TabType = 'users' | 'messages';

type ModerationConsolePageProps = {
tab: TabType;
onSelectTab?: (tab: TabType) => void;
};

const ModerationConsolePage = ({ tab = 'messages', onSelectTab }: ModerationConsolePageProps) => {
const t = useTranslation();
const context = useRouteParameter('context');
const id = useRouteParameter('id');
const dispatchToastMessage = useToastMessageDispatch();

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 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 handleTabClick = useCallback(
(tab: TabType): undefined | (() => void) => (onSelectTab ? (): void => onSelectTab(tab) : undefined),
[onSelectTab],
);

return (
<Page flexDirection='row'>
<Page>
<PageHeader title={t('Moderation')} />

<Tabs>
<TabsItem selected={tab === 'messages'} onClick={handleTabClick('messages')}>
{t('Reported_Messages')}
</TabsItem>
<TabsItem selected={tab === 'users'} onClick={handleTabClick('users')}>
{t('Reported_Users')}
</TabsItem>
</Tabs>
<PageContent>
<ModerationConsoleTable />
{tab === 'messages' && <ModerationConsoleTable />}
{tab === 'users' && <ModConsoleUsersTable />}
</PageContent>
</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
Loading
Loading