Updated delete key checks
This commit is contained in:
parent
46be5d3e6d
commit
4d41e2c635
2 changed files with 26 additions and 4 deletions
|
@ -37,12 +37,30 @@ class RecipientKeyController extends Controller
|
||||||
{
|
{
|
||||||
$recipient = user()->recipients()->findOrFail($id);
|
$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);
|
return response('Key could not be deleted', 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove the key from all recipients using that same fingerprint.
|
$recipientEmails = user()->verifiedRecipients()
|
||||||
Recipient::all()
|
->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)
|
->where('fingerprint', $recipient->fingerprint)
|
||||||
->each(function ($recipient) {
|
->each(function ($recipient) {
|
||||||
$recipient->update([
|
$recipient->update([
|
||||||
|
|
|
@ -555,7 +555,11 @@ export default {
|
||||||
this.deleteRecipientKeyLoading = false
|
this.deleteRecipientKeyLoading = false
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
if (error.response !== undefined) {
|
||||||
|
this.error(error.response.data)
|
||||||
|
} else {
|
||||||
this.error()
|
this.error()
|
||||||
|
}
|
||||||
this.deleteRecipientKeyLoading = false
|
this.deleteRecipientKeyLoading = false
|
||||||
this.deleteRecipientKeyModalOpen = false
|
this.deleteRecipientKeyModalOpen = false
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Reference in a new issue