-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
163 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace App\Dto; | ||
|
||
use App\Validator\Constraints\AliasDelete; | ||
use Symfony\Component\Validator\Constraints as Assert; | ||
|
||
class AliasQueryDto | ||
{ | ||
#[Assert\NotNull] | ||
#[Assert\NotBlank] | ||
#[Assert\Email] | ||
#[AliasDelete] | ||
public string $alias; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace App\Dto; | ||
|
||
use App\Validator\Constraints\WkdQuery; | ||
use Symfony\Component\Validator\Constraints as Assert; | ||
|
||
class WkdQueryDto | ||
{ | ||
public function __construct( | ||
#[Assert\NotBlank] | ||
#[Assert\Email] | ||
#[WkdQuery] | ||
public ?string $uid, | ||
|
||
public ?bool $scope, | ||
) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace App\Validator\Constraints; | ||
|
||
use Symfony\Component\Validator\Constraint; | ||
|
||
#[\Attribute] | ||
class AliasDelete extends Constraint | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace App\Validator\Constraints; | ||
|
||
use App\Entity\Alias; | ||
use App\Repository\AliasRepository; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Symfony\Component\Validator\Constraint; | ||
use Symfony\Component\Validator\ConstraintValidator; | ||
use Symfony\Component\Validator\Exception\UnexpectedTypeException; | ||
use Symfony\Bundle\SecurityBundle\Security; | ||
|
||
class AliasDeleteValidator extends ConstraintValidator | ||
{ | ||
private readonly AliasRepository $repository; | ||
|
||
public function __construct( | ||
private Security $security, | ||
private readonly EntityManagerInterface $manager, | ||
) { | ||
$this->security = $security; | ||
$this->repository = $manager->getRepository(Alias::class);; | ||
} | ||
|
||
/** | ||
*/ | ||
public function validate(mixed $value, Constraint $constraint): void | ||
{ | ||
if (!$constraint instanceof AliasDelete) { | ||
throw new UnexpectedTypeException('Wrong constraint type given', AliasDelete::class); | ||
} | ||
|
||
if (!$value instanceof String) { | ||
throw new UnexpectedTypeException('Wrong object type given', String::class); | ||
} | ||
|
||
$user = $this->security->getUser(); | ||
|
||
if (null === $alias = $this->repository->findOneByUserAndSource($user, $value)) { | ||
$this->context->addViolation('forbidden'); | ||
return; | ||
} | ||
|
||
if (!$alias->isRandom()) { | ||
$this->context->addViolation('not allowed to delete custom alias. contact your system administrator'); | ||
} | ||
} | ||
} |