mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
fix: create triggers as watchlist is created, but not updated
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import React, {useEffect, useState} from 'react'
|
import React, {useEffect, useState} from 'react'
|
||||||
import {Card, Divider, Flex, Form, message} from 'antd'
|
import {Card, Divider, Flex, Form, message} from 'antd'
|
||||||
import type { Watchlist} from '../../utils/api'
|
import type {Watchlist, WatchlistTrigger} from '../../utils/api'
|
||||||
import {getWatchlists, postWatchlist, putWatchlist} from '../../utils/api'
|
import {getWatchlists, postWatchlist, putWatchlist} from '../../utils/api'
|
||||||
import type {AxiosError} from 'axios'
|
import type {AxiosError} from 'axios'
|
||||||
import {t} from 'ttag'
|
import {t} from 'ttag'
|
||||||
@@ -19,7 +19,27 @@ interface FormValuesType {
|
|||||||
dsn?: string[]
|
dsn?: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
const getRequestDataFromForm = (values: FormValuesType) => {
|
const getRequestDataFromFormCreation = (values: FormValuesType) => {
|
||||||
|
const domainsURI = values.domains.map(d => '/api/domains/' + d.toLowerCase())
|
||||||
|
let triggers: WatchlistTrigger[] = values.triggers.map(t => ({event: t, action: 'email'}))
|
||||||
|
|
||||||
|
if (values.dsn !== undefined) {
|
||||||
|
triggers = [...triggers, ...values.triggers.map((t): WatchlistTrigger => ({
|
||||||
|
event: t,
|
||||||
|
action: 'chat'
|
||||||
|
}))]
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
name: values.name,
|
||||||
|
domains: domainsURI,
|
||||||
|
triggers,
|
||||||
|
connector: values.connector !== undefined ? ('/api/connectors/' + values.connector) : undefined,
|
||||||
|
dsn: values.dsn
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const getRequestDataFromFormUpdate = (values: FormValuesType) => {
|
||||||
const domainsURI = values.domains.map(d => '/api/domains/' + d.toLowerCase())
|
const domainsURI = values.domains.map(d => '/api/domains/' + d.toLowerCase())
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -37,7 +57,7 @@ export default function WatchlistPage() {
|
|||||||
const [connectors, setConnectors] = useState<Array<Connector & { id: string }>>()
|
const [connectors, setConnectors] = useState<Array<Connector & { id: string }>>()
|
||||||
|
|
||||||
const onCreateWatchlist = (values: FormValuesType) => {
|
const onCreateWatchlist = (values: FormValuesType) => {
|
||||||
postWatchlist(getRequestDataFromForm(values)).then(() => {
|
postWatchlist(getRequestDataFromFormCreation(values)).then(() => {
|
||||||
form.resetFields()
|
form.resetFields()
|
||||||
refreshWatchlists()
|
refreshWatchlists()
|
||||||
messageApi.success(t`Watchlist created !`)
|
messageApi.success(t`Watchlist created !`)
|
||||||
@@ -48,7 +68,7 @@ export default function WatchlistPage() {
|
|||||||
|
|
||||||
const onUpdateWatchlist = async (values: FormValuesType & { token: string }) => await putWatchlist({
|
const onUpdateWatchlist = async (values: FormValuesType & { token: string }) => await putWatchlist({
|
||||||
token: values.token,
|
token: values.token,
|
||||||
...getRequestDataFromForm(values)
|
...getRequestDataFromFormUpdate(values)
|
||||||
}
|
}
|
||||||
).then(() => {
|
).then(() => {
|
||||||
refreshWatchlists()
|
refreshWatchlists()
|
||||||
|
|||||||
@@ -26,35 +26,40 @@ use Symfony\Component\Uid\Uuid;
|
|||||||
operations: [
|
operations: [
|
||||||
new GetCollection(
|
new GetCollection(
|
||||||
routeName: 'watchlist_get_all_mine',
|
routeName: 'watchlist_get_all_mine',
|
||||||
normalizationContext: ['groups' => [
|
normalizationContext: [
|
||||||
'watchlist:list',
|
'groups' => [
|
||||||
'domain:list',
|
'watchlist:list',
|
||||||
'event:list',
|
'domain:list',
|
||||||
]],
|
'event:list',
|
||||||
|
]
|
||||||
|
],
|
||||||
name: 'get_all_mine',
|
name: 'get_all_mine',
|
||||||
),
|
),
|
||||||
new GetCollection(
|
new GetCollection(
|
||||||
uriTemplate: '/tracked',
|
uriTemplate: '/tracked',
|
||||||
routeName: 'watchlist_get_tracked_domains',
|
routeName: 'watchlist_get_tracked_domains',
|
||||||
normalizationContext: ['groups' => [
|
normalizationContext: [
|
||||||
'domain:list',
|
'groups' => [
|
||||||
'tld:list',
|
'domain:list',
|
||||||
'event:list',
|
'tld:list',
|
||||||
'domain:list',
|
'event:list',
|
||||||
'event:list',
|
'domain:list',
|
||||||
]],
|
'event:list',
|
||||||
|
]
|
||||||
|
],
|
||||||
name: 'get_tracked_domains'
|
name: 'get_tracked_domains'
|
||||||
),
|
),
|
||||||
new Get(
|
new Get(
|
||||||
normalizationContext: ['groups' => [
|
normalizationContext: [
|
||||||
'watchlist:item',
|
'groups' => [
|
||||||
'domain:item',
|
'watchlist:item',
|
||||||
'event:list',
|
'domain:item',
|
||||||
'domain-entity:entity',
|
'event:list',
|
||||||
'nameserver-entity:nameserver',
|
'domain-entity:entity',
|
||||||
'nameserver-entity:entity',
|
'nameserver-entity:nameserver',
|
||||||
'tld:item',
|
'nameserver-entity:entity',
|
||||||
],
|
'tld:item',
|
||||||
|
],
|
||||||
],
|
],
|
||||||
security: 'object.user == user'
|
security: 'object.user == user'
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user