Skip to content

Commit

Permalink
Delete Handler: check if owner to pgp key exists
Browse files Browse the repository at this point in the history
  • Loading branch information
y3n4 committed Apr 25, 2024
1 parent a436388 commit d908dc5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
15 changes: 10 additions & 5 deletions src/Handler/DeleteHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ class DeleteHandler
/**
* DeleteHandler constructor.
*/
public function __construct(private readonly PasswordUpdater $passwordUpdater, private readonly EntityManagerInterface $manager, private readonly WkdHandler $wkdHandler)
{
public function __construct(
private readonly PasswordUpdater $passwordUpdater,
private readonly EntityManagerInterface $manager,
private readonly WkdHandler $wkdHandler
) {
}

public function deleteAlias(Alias $alias, User $user = null)
Expand Down Expand Up @@ -52,12 +55,14 @@ public function deleteUser(User $user)
$user->eraseMailCryptPublicKey();
$user->eraseMailCryptSecretBox();

// Delete OpenPGP key from WKD
$this->wkdHandler->deleteKey($user->getEmail());

// Flag user as deleted
$user->setDeleted(true);

// Delete OpenPGP key from WKD if no other user owns mail handle
if (!$this->wkdHandler->userToUserIdExists($user->getEmail())) {
$this->wkdHandler->deleteKey($user->getEmail());
}

$this->manager->flush();
}
}
3 changes: 2 additions & 1 deletion src/Handler/WkdHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ public function userToUserIdExists(string $uid): bool
if ($this->manager->getRepository(Alias::class)->findOneBySource($uid, false)) {
return true;
}
if ($this->manager->getRepository(User::class)->findOneBy($uid, false)) {

if ($this->manager->getRepository(User::class)->findByEmail($uid, false)) {
return true;
}
return false;
Expand Down

0 comments on commit d908dc5

Please sign in to comment.