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 {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 type {AxiosError} from 'axios'
|
||||
import {t} from 'ttag'
|
||||
@@ -19,7 +19,27 @@ interface FormValuesType {
|
||||
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())
|
||||
|
||||
return {
|
||||
@@ -37,7 +57,7 @@ export default function WatchlistPage() {
|
||||
const [connectors, setConnectors] = useState<Array<Connector & { id: string }>>()
|
||||
|
||||
const onCreateWatchlist = (values: FormValuesType) => {
|
||||
postWatchlist(getRequestDataFromForm(values)).then(() => {
|
||||
postWatchlist(getRequestDataFromFormCreation(values)).then(() => {
|
||||
form.resetFields()
|
||||
refreshWatchlists()
|
||||
messageApi.success(t`Watchlist created !`)
|
||||
@@ -48,7 +68,7 @@ export default function WatchlistPage() {
|
||||
|
||||
const onUpdateWatchlist = async (values: FormValuesType & { token: string }) => await putWatchlist({
|
||||
token: values.token,
|
||||
...getRequestDataFromForm(values)
|
||||
...getRequestDataFromFormUpdate(values)
|
||||
}
|
||||
).then(() => {
|
||||
refreshWatchlists()
|
||||
|
||||
@@ -26,35 +26,40 @@ use Symfony\Component\Uid\Uuid;
|
||||
operations: [
|
||||
new GetCollection(
|
||||
routeName: 'watchlist_get_all_mine',
|
||||
normalizationContext: ['groups' => [
|
||||
'watchlist:list',
|
||||
'domain:list',
|
||||
'event:list',
|
||||
]],
|
||||
normalizationContext: [
|
||||
'groups' => [
|
||||
'watchlist:list',
|
||||
'domain:list',
|
||||
'event:list',
|
||||
]
|
||||
],
|
||||
name: 'get_all_mine',
|
||||
),
|
||||
new GetCollection(
|
||||
uriTemplate: '/tracked',
|
||||
routeName: 'watchlist_get_tracked_domains',
|
||||
normalizationContext: ['groups' => [
|
||||
'domain:list',
|
||||
'tld:list',
|
||||
'event:list',
|
||||
'domain:list',
|
||||
'event:list',
|
||||
]],
|
||||
normalizationContext: [
|
||||
'groups' => [
|
||||
'domain:list',
|
||||
'tld:list',
|
||||
'event:list',
|
||||
'domain:list',
|
||||
'event:list',
|
||||
]
|
||||
],
|
||||
name: 'get_tracked_domains'
|
||||
),
|
||||
new Get(
|
||||
normalizationContext: ['groups' => [
|
||||
'watchlist:item',
|
||||
'domain:item',
|
||||
'event:list',
|
||||
'domain-entity:entity',
|
||||
'nameserver-entity:nameserver',
|
||||
'nameserver-entity:entity',
|
||||
'tld:item',
|
||||
],
|
||||
normalizationContext: [
|
||||
'groups' => [
|
||||
'watchlist:item',
|
||||
'domain:item',
|
||||
'event:list',
|
||||
'domain-entity:entity',
|
||||
'nameserver-entity:nameserver',
|
||||
'nameserver-entity:entity',
|
||||
'tld:item',
|
||||
],
|
||||
],
|
||||
security: 'object.user == user'
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user