Updated delete key checks

This commit is contained in:
Will Browning 2019-10-29 14:08:38 +00:00
parent 46be5d3e6d
commit 4d41e2c635
2 changed files with 26 additions and 4 deletions

View file

@ -37,12 +37,30 @@ class RecipientKeyController extends Controller
{
$recipient = user()->recipients()->findOrFail($id);
if (!$this->gnupg->deletekey($recipient->fingerprint)) {
$key = $this->gnupg->keyinfo($recipient->fingerprint);
if (! isset($key[0]['uids'][0]['email'])) {
return response('Key could not be deleted', 404);
}
// Remove the key from all recipients using that same fingerprint.
Recipient::all()
$recipientEmails = user()->verifiedRecipients()
->get()
->map(function ($item) {
return $item->email;
})
->toArray();
// Check that the user can delete the key.
if (in_array(strtolower($key[0]['uids'][0]['email']), $recipientEmails)) {
if (!$this->gnupg->deletekey($recipient->fingerprint)) {
return response('Key could not be deleted', 404);
}
}
// Remove the key from all user recipients using that same fingerprint.
user()
->recipients()
->get()
->where('fingerprint', $recipient->fingerprint)
->each(function ($recipient) {
$recipient->update([

View file

@ -555,7 +555,11 @@ export default {
this.deleteRecipientKeyLoading = false
})
.catch(error => {
this.error()
if (error.response !== undefined) {
this.error(error.response.data)
} else {
this.error()
}
this.deleteRecipientKeyLoading = false
this.deleteRecipientKeyModalOpen = false
})