Skip to content

Commit 342121a

Browse files
authored
feat(ips): enabling anti-spam unblocking (#19931)
ref: #MANAGER-19425 Signed-off-by: aderghamov <[email protected]>
1 parent fdfa1df commit 342121a

File tree

15 files changed

+392
-22
lines changed

15 files changed

+392
-22
lines changed

packages/manager/apps/ips/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"@tanstack/react-query": "^5.51.21",
3434
"@tanstack/react-query-devtools": "^5.51.21",
3535
"@tanstack/react-table": "^8.20.1",
36+
"date-fns": "4.1.0",
3637
"export-to-csv": "^1.4.0",
3738
"i18next": "^23.8.2",
3839
"i18next-http-backend": "^2.4.2",
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"unblock_anti_spam_title": "Déblocage de l'anti-spam pour l'IP {{ipBlocked}}",
3+
"unblock_anti_spam_ip_success": "L'adresse IP {{ipBlocked}} a été débloquée avec succès",
4+
"unblock_anti_spam_ip_error": "Une erreur a eu lieu au cours du débloquage de {{ipBlocked}}: {{error}}",
5+
"unblock_anti_spam_ip_action": "Débloquer l'IP",
6+
"anti_spam_status": "Status",
7+
"anti_spam_status_BLOCKED": "Bloquée",
8+
"anti_spam_blocked_since": "Bloquée depuis",
9+
"anti_spam_estimation_unblocking_date": "Date possible de déblocage",
10+
"anti_spam_stat_date": "Date",
11+
"anti_spam_stat_score": "Score",
12+
"anti_spam_stat_total": "Total",
13+
"anti_spam_stat_nb_emails": "Nombre d'emails spammés"
14+
}

packages/manager/apps/ips/public/translations/listing/Messages_fr_FR.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
"listingActionSlice": "Segmenter",
8080
"listingActionAggregate": "Agréger",
8181
"listingActionUnblockHackedIP": "Déblocage anti-hack",
82+
"listingActionUnblockSpammedIP": "Déblocage anti-spam",
8283
"listingUpsertDescription": "Description",
8384
"listingUpsertDescriptionSuccessMessage": "La description de l'IP {{value}} a été modifiée.",
8485
"listingTerminateIp_confirm_Headline": "Résilier mon IP",

packages/manager/apps/ips/src/data/api/get/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export * from './dedicatedServerVmac';
55
export * from './dedicatedServerVmacVirtualAddress';
66
export * from './ipMitigation';
77
export * from './ipSpam';
8+
export * from './ipSpamStats';
89
export * from './ipAntihack';
910
export * from './ipEdgeFirewall';
1011
export * from './ipExport';
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { IcebergFetchResultV6, fetchIcebergV6 } from '@ovh-ux/manager-core-api';
2+
3+
export type GetIpSpamStatsParams = {
4+
ip: string;
5+
ipSpamming: string;
6+
};
7+
8+
type DetectedSpams = {
9+
date: number;
10+
destinationIp: string;
11+
messageId: string;
12+
spamscore: number;
13+
};
14+
15+
export type IpSpamStatType = {
16+
averageSpamscore: number;
17+
detectedSpams: DetectedSpams[];
18+
numberOfSpams: number;
19+
timestamp: number;
20+
total: number;
21+
};
22+
23+
export const getIpSpamStatsQueryKey = (params: GetIpSpamStatsParams) => [
24+
`get/ip/${encodeURIComponent(params.ip)}/spam/${encodeURIComponent(
25+
params.ipSpamming,
26+
)}/stats`,
27+
];
28+
29+
/**
30+
* Your IP : Get this object properties
31+
*/
32+
export const getIpSpamStats = async (
33+
params: GetIpSpamStatsParams,
34+
): Promise<IcebergFetchResultV6<IpSpamStatType>> =>
35+
fetchIcebergV6<IpSpamStatType>({
36+
route: `/ip/${encodeURIComponent(params.ip)}/spam/${encodeURIComponent(
37+
params.ipSpamming,
38+
)}/stats`,
39+
page: 1,
40+
});

packages/manager/apps/ips/src/data/api/postorput/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ export * from './addVirtualMacToIp';
66
export * from './addIpToVirtualMac';
77
export * from './postMoveIp';
88
export * from './unblockAntiHackIp';
9+
export * from './unblockAntiSpamIp';
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { ApiResponse, apiClient } from '@ovh-ux/manager-core-api';
2+
3+
export type UnblockAntiSpamIpParams = {
4+
ip: string;
5+
ipBlocked: string;
6+
};
7+
8+
export const unblockAntiSpamIpQueryKey = (params: UnblockAntiSpamIpParams) => [
9+
`post/ip/${encodeURIComponent(params.ip)}/spam/${encodeURIComponent(
10+
params.ipBlocked,
11+
)}/unblock`,
12+
];
13+
14+
export const unblockAntiSpamIp = async ({
15+
ip,
16+
ipBlocked,
17+
}: UnblockAntiSpamIpParams): Promise<ApiResponse<void>> => {
18+
return apiClient.v6.post<void>(
19+
`/ip/${encodeURIComponent(ip)}/spam/${encodeURIComponent(
20+
ipBlocked,
21+
)}/unblock`,
22+
{},
23+
);
24+
};

packages/manager/apps/ips/src/data/hooks/ip/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ export * from './useGetIpEdgeFirewall';
99
export * from './useGetIpGameFirewall';
1010
export * from './useIpHasAlerts';
1111
export * from './useGetIpAntihack';
12+
export * from './useGetIpSpam';
13+
export * from './useGetIpSpamStats';
1214
export * from './useUpdateIpReverse';
1315
export * from './useDeleteIpReverse';
1416
export * from './useUpdateIpGameFirewall';
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { useQuery } from '@tanstack/react-query';
2+
import { ApiError, IcebergFetchResultV6 } from '@ovh-ux/manager-core-api';
3+
import {
4+
getIpSpamStats,
5+
getIpSpamStatsQueryKey,
6+
IpSpamStatType,
7+
} from '@/data/api';
8+
9+
export type UseGetIpSpamStatsParams = {
10+
ip: string;
11+
ipSpamming: string;
12+
enabled?: boolean;
13+
};
14+
15+
export const useGetIpSpamStats = ({
16+
ip,
17+
ipSpamming,
18+
enabled = true,
19+
}: UseGetIpSpamStatsParams) => {
20+
const { data: ipSpamStatsResponse, isLoading, isError, error } = useQuery<
21+
IcebergFetchResultV6<IpSpamStatType>,
22+
ApiError
23+
>({
24+
queryKey: getIpSpamStatsQueryKey({ ip, ipSpamming }),
25+
queryFn: () => getIpSpamStats({ ip, ipSpamming }),
26+
enabled,
27+
staleTime: Number.POSITIVE_INFINITY,
28+
retry: false,
29+
});
30+
31+
return { ipSpamStats: ipSpamStatsResponse.data, isLoading, isError, error };
32+
};

0 commit comments

Comments
 (0)