mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
feat: add watchlist patch with limitations
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import {Event, request, Watchlist} from "./index";
|
import {request, Watchlist} from "./index";
|
||||||
|
|
||||||
export async function getWatchlists() {
|
export async function getWatchlists() {
|
||||||
const response = await request({
|
const response = await request({
|
||||||
@@ -32,3 +32,15 @@ export async function deleteWatchlist(token: string): Promise<void> {
|
|||||||
url: 'watchlists/' + token
|
url: 'watchlists/' + token
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function patchWatchlist(watchlist: Partial<Watchlist> & { token: string }) {
|
||||||
|
const response = await request<Watchlist>({
|
||||||
|
method: 'PATCH',
|
||||||
|
url: 'watchlists/' + watchlist.token,
|
||||||
|
data: watchlist,
|
||||||
|
headers: {
|
||||||
|
"Content-Type": 'application/merge-patch+json'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return response.data
|
||||||
|
}
|
||||||
|
|||||||
@@ -44,22 +44,8 @@ class WatchListController extends AbstractController
|
|||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function verifyLimitations(WatchList $watchList)
|
||||||
* @throws \Exception
|
|
||||||
*/
|
|
||||||
#[Route(
|
|
||||||
path: '/api/watchlists',
|
|
||||||
name: 'watchlist_create',
|
|
||||||
defaults: [
|
|
||||||
'_api_resource_class' => WatchList::class,
|
|
||||||
'_api_operation_name' => 'create',
|
|
||||||
],
|
|
||||||
methods: ['POST']
|
|
||||||
)]
|
|
||||||
public function createWatchList(Request $request): WatchList
|
|
||||||
{
|
{
|
||||||
$watchList = $this->serializer->deserialize($request->getContent(), WatchList::class, 'json', ['groups' => 'watchlist:create']);
|
|
||||||
|
|
||||||
/** @var User $user */
|
/** @var User $user */
|
||||||
$user = $this->getUser();
|
$user = $this->getUser();
|
||||||
$watchList->setUser($user);
|
$watchList->setUser($user);
|
||||||
@@ -99,8 +85,53 @@ class WatchListController extends AbstractController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->logger->info('User {username} register a Watchlist ({token}).', [
|
/**
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
#[Route(
|
||||||
|
path: '/api/watchlists',
|
||||||
|
name: 'watchlist_create',
|
||||||
|
defaults: [
|
||||||
|
'_api_resource_class' => WatchList::class,
|
||||||
|
'_api_operation_name' => 'create',
|
||||||
|
],
|
||||||
|
methods: ['POST']
|
||||||
|
)]
|
||||||
|
public function createWatchList(Request $request): WatchList
|
||||||
|
{
|
||||||
|
$watchList = $this->serializer->deserialize($request->getContent(), WatchList::class, 'json', ['groups' => 'watchlist:create']);
|
||||||
|
$this->verifyLimitations($watchList);
|
||||||
|
|
||||||
|
$user = $this->getUser();
|
||||||
|
$this->logger->info('User {username} registers a Watchlist ({token}).', [
|
||||||
|
'username' => $user->getUserIdentifier(),
|
||||||
|
'token' => $watchList->getToken(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->em->persist($watchList);
|
||||||
|
$this->em->flush();
|
||||||
|
|
||||||
|
return $watchList;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Route(
|
||||||
|
path: '/api/watchlists/{token}',
|
||||||
|
name: 'watchlist_update',
|
||||||
|
defaults: [
|
||||||
|
'_api_resource_class' => WatchList::class,
|
||||||
|
'_api_operation_name' => 'update',
|
||||||
|
],
|
||||||
|
methods: ['PATCH']
|
||||||
|
)]
|
||||||
|
public function patchWatchList(Request $request): WatchList
|
||||||
|
{
|
||||||
|
$watchList = $this->serializer->deserialize($request->getContent(), WatchList::class, 'json', ['groups' => 'watchlist:create']);
|
||||||
|
$this->verifyLimitations($watchList);
|
||||||
|
|
||||||
|
$user = $this->getUser();
|
||||||
|
$this->logger->info('User {username} updates a Watchlist ({token}).', [
|
||||||
'username' => $user->getUserIdentifier(),
|
'username' => $user->getUserIdentifier(),
|
||||||
'token' => $watchList->getToken(),
|
'token' => $watchList->getToken(),
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -27,7 +27,16 @@ use Symfony\Component\Uid\Uuid;
|
|||||||
name: 'get_all_mine',
|
name: 'get_all_mine',
|
||||||
),
|
),
|
||||||
new Get(
|
new Get(
|
||||||
normalizationContext: ['groups' => 'watchlist:item'],
|
normalizationContext: ['groups' => [
|
||||||
|
'watchlist:item',
|
||||||
|
'domain:item',
|
||||||
|
'event:list',
|
||||||
|
'domain-entity:entity',
|
||||||
|
'nameserver-entity:nameserver',
|
||||||
|
'nameserver-entity:entity',
|
||||||
|
'tld:item',
|
||||||
|
],
|
||||||
|
],
|
||||||
security: 'object.user == user'
|
security: 'object.user == user'
|
||||||
),
|
),
|
||||||
new Get(
|
new Get(
|
||||||
@@ -58,26 +67,24 @@ use Symfony\Component\Uid\Uuid;
|
|||||||
denormalizationContext: ['groups' => 'watchlist:create'],
|
denormalizationContext: ['groups' => 'watchlist:create'],
|
||||||
name: 'create'
|
name: 'create'
|
||||||
),
|
),
|
||||||
/*
|
|
||||||
new Patch(
|
new Patch(
|
||||||
|
routeName: 'watchlist_update',
|
||||||
normalizationContext: ['groups' => 'watchlist:item'],
|
normalizationContext: ['groups' => 'watchlist:item'],
|
||||||
denormalizationContext: ['groups' => 'watchlist:update']
|
denormalizationContext: ['groups' => 'watchlist:create'],
|
||||||
|
name: 'update'
|
||||||
),
|
),
|
||||||
*/
|
|
||||||
new Delete(),
|
new Delete(),
|
||||||
],
|
],
|
||||||
)]
|
)]
|
||||||
class WatchList
|
class WatchList
|
||||||
{
|
{
|
||||||
|
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'watchLists')]
|
||||||
|
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
|
||||||
|
public ?User $user = null;
|
||||||
#[ORM\Id]
|
#[ORM\Id]
|
||||||
#[ORM\Column(type: 'uuid')]
|
#[ORM\Column(type: 'uuid')]
|
||||||
#[Groups(['watchlist:item', 'watchlist:list'])]
|
#[Groups(['watchlist:item', 'watchlist:list'])]
|
||||||
private string $token;
|
private string $token;
|
||||||
|
|
||||||
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'watchLists')]
|
|
||||||
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
|
|
||||||
public ?User $user = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Collection<int, Domain>
|
* @var Collection<int, Domain>
|
||||||
*/
|
*/
|
||||||
@@ -85,23 +92,23 @@ class WatchList
|
|||||||
#[ORM\JoinTable(name: 'watch_lists_domains',
|
#[ORM\JoinTable(name: 'watch_lists_domains',
|
||||||
joinColumns: [new ORM\JoinColumn(name: 'watch_list_token', referencedColumnName: 'token', onDelete: 'CASCADE')],
|
joinColumns: [new ORM\JoinColumn(name: 'watch_list_token', referencedColumnName: 'token', onDelete: 'CASCADE')],
|
||||||
inverseJoinColumns: [new ORM\JoinColumn(name: 'domain_ldh_name', referencedColumnName: 'ldh_name', onDelete: 'CASCADE')])]
|
inverseJoinColumns: [new ORM\JoinColumn(name: 'domain_ldh_name', referencedColumnName: 'ldh_name', onDelete: 'CASCADE')])]
|
||||||
#[Groups(['watchlist:list', 'watchlist:item', 'watchlist:create', 'watchlist:update'])]
|
#[Groups(['watchlist:list', 'watchlist:item', 'watchlist:create'])]
|
||||||
private Collection $domains;
|
private Collection $domains;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Collection<int, WatchListTrigger>
|
* @var Collection<int, WatchListTrigger>
|
||||||
*/
|
*/
|
||||||
#[ORM\OneToMany(targetEntity: WatchListTrigger::class, mappedBy: 'watchList', cascade: ['persist'], orphanRemoval: true)]
|
#[ORM\OneToMany(targetEntity: WatchListTrigger::class, mappedBy: 'watchList', cascade: ['persist'], orphanRemoval: true)]
|
||||||
#[Groups(['watchlist:list', 'watchlist:item', 'watchlist:create', 'watchlist:update'])]
|
#[Groups(['watchlist:list', 'watchlist:item', 'watchlist:create'])]
|
||||||
#[SerializedName('triggers')]
|
#[SerializedName('triggers')]
|
||||||
private Collection $watchListTriggers;
|
private Collection $watchListTriggers;
|
||||||
|
|
||||||
#[ORM\ManyToOne(inversedBy: 'watchLists')]
|
#[ORM\ManyToOne(inversedBy: 'watchLists')]
|
||||||
#[Groups(['watchlist:list', 'watchlist:item', 'watchlist:create', 'watchlist:update'])]
|
#[Groups(['watchlist:list', 'watchlist:item', 'watchlist:create'])]
|
||||||
private ?Connector $connector = null;
|
private ?Connector $connector = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 255, nullable: true)]
|
#[ORM\Column(length: 255, nullable: true)]
|
||||||
#[Groups(['watchlist:list', 'watchlist:item', 'watchlist:create', 'watchlist:update'])]
|
#[Groups(['watchlist:list', 'watchlist:item', 'watchlist:create'])]
|
||||||
private ?string $name = null;
|
private ?string $name = null;
|
||||||
|
|
||||||
#[ORM\Column]
|
#[ORM\Column]
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class WatchListTrigger
|
|||||||
{
|
{
|
||||||
#[ORM\Id]
|
#[ORM\Id]
|
||||||
#[ORM\Column(length: 255)]
|
#[ORM\Column(length: 255)]
|
||||||
#[Groups(['watchlist:list', 'watchlist:item', 'watchlist:create', 'watchlist:update'])]
|
#[Groups(['watchlist:list', 'watchlist:item', 'watchlist:create'])]
|
||||||
private ?string $event = null;
|
private ?string $event = null;
|
||||||
|
|
||||||
#[ORM\Id]
|
#[ORM\Id]
|
||||||
@@ -22,7 +22,7 @@ class WatchListTrigger
|
|||||||
|
|
||||||
#[ORM\Id]
|
#[ORM\Id]
|
||||||
#[ORM\Column(enumType: TriggerAction::class)]
|
#[ORM\Column(enumType: TriggerAction::class)]
|
||||||
#[Groups(['watchlist:list', 'watchlist:item', 'watchlist:create', 'watchlist:update'])]
|
#[Groups(['watchlist:list', 'watchlist:item', 'watchlist:create'])]
|
||||||
private ?TriggerAction $action = null;
|
private ?TriggerAction $action = null;
|
||||||
|
|
||||||
public function getEvent(): ?string
|
public function getEvent(): ?string
|
||||||
|
|||||||
Reference in New Issue
Block a user