Updated delete key from keyring
This commit is contained in:
parent
043a7ed6ad
commit
4c95cb9ec5
4 changed files with 50 additions and 42 deletions
|
@ -37,37 +37,7 @@ class RecipientKeyController extends Controller
|
|||
{
|
||||
$recipient = user()->recipients()->findOrFail($id);
|
||||
|
||||
$key = $this->gnupg->keyinfo($recipient->fingerprint);
|
||||
|
||||
if (! isset($key[0]['uids'][0]['email'])) {
|
||||
return response('Key could not be deleted', 404);
|
||||
}
|
||||
|
||||
$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([
|
||||
'should_encrypt' => false,
|
||||
'fingerprint' => null
|
||||
]);
|
||||
});
|
||||
user()->deleteKeyFromKeyring($recipient->fingerprint);
|
||||
|
||||
return response('', 204);
|
||||
}
|
||||
|
|
|
@ -48,8 +48,7 @@ class Recipient extends Model
|
|||
|
||||
Recipient::deleting(function ($recipient) {
|
||||
if ($recipient->fingerprint) {
|
||||
$gnupg = new \gnupg();
|
||||
$gnupg->deletekey($recipient->fingerprint);
|
||||
$recipient->user->deleteKeyFromKeyring($recipient->fingerprint);
|
||||
}
|
||||
|
||||
$recipient->aliases()->detach();
|
||||
|
|
31
app/User.php
31
app/User.php
|
@ -255,4 +255,35 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||
})
|
||||
->contains($email);
|
||||
}
|
||||
|
||||
public function deleteKeyFromKeyring($fingerprint): void
|
||||
{
|
||||
$gnupg = new \gnupg();
|
||||
|
||||
$key = $gnupg->keyinfo($fingerprint);
|
||||
|
||||
// Check that the user has a verified recipient matching the keys email.
|
||||
collect($key[0]['uids'])
|
||||
->filter(function ($uid) {
|
||||
return ! $uid['invalid'];
|
||||
})
|
||||
->pluck('email')
|
||||
->each(function ($email) use ($gnupg, $fingerprint) {
|
||||
if ($this->isVerifiedRecipient($email)) {
|
||||
$gnupg->deletekey($fingerprint);
|
||||
}
|
||||
});
|
||||
|
||||
// Remove the key from all user recipients using that same fingerprint.
|
||||
$this
|
||||
->recipients()
|
||||
->get()
|
||||
->where('fingerprint', $fingerprint)
|
||||
->each(function ($recipient) {
|
||||
$recipient->update([
|
||||
'should_encrypt' => false,
|
||||
'fingerprint' => null
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -160,9 +160,10 @@
|
|||
</span>
|
||||
<span v-else class="flex items-center justify-center outline-none" tabindex="-1">
|
||||
<icon
|
||||
v-if="!isDefault(props.row.id)"
|
||||
name="trash"
|
||||
class="block w-6 h-6 text-grey-200 fill-current cursor-pointer"
|
||||
@click.native="openDeleteModal(props.row.id)"
|
||||
@click.native="openDeleteModal(props.row)"
|
||||
/>
|
||||
</span>
|
||||
</template>
|
||||
|
@ -298,7 +299,7 @@
|
|||
<div class="mt-6">
|
||||
<button
|
||||
type="button"
|
||||
@click="deleteRecipient(recipientIdToDelete)"
|
||||
@click="deleteRecipient(recipientToDelete)"
|
||||
class="px-4 py-3 text-white font-semibold bg-red-500 hover:bg-red-600 border border-transparent rounded focus:outline-none"
|
||||
:class="deleteRecipientLoading ? 'cursor-not-allowed' : ''"
|
||||
:disabled="deleteRecipientLoading"
|
||||
|
@ -361,7 +362,7 @@ export default {
|
|||
search: '',
|
||||
addRecipientLoading: false,
|
||||
addRecipientModalOpen: false,
|
||||
recipientIdToDelete: null,
|
||||
recipientToDelete: null,
|
||||
recipientKeyToDelete: null,
|
||||
deleteRecipientLoading: false,
|
||||
deleteRecipientModalOpen: false,
|
||||
|
@ -507,21 +508,28 @@ export default {
|
|||
}
|
||||
})
|
||||
},
|
||||
openDeleteModal(id) {
|
||||
openDeleteModal(recipient) {
|
||||
this.deleteRecipientModalOpen = true
|
||||
this.recipientIdToDelete = id
|
||||
this.recipientToDelete = recipient
|
||||
},
|
||||
closeDeleteModal() {
|
||||
this.deleteRecipientModalOpen = false
|
||||
this.recipientIdToDelete = null
|
||||
this.recipientToDelete = null
|
||||
},
|
||||
deleteRecipient(id) {
|
||||
deleteRecipient(recipient) {
|
||||
this.deleteRecipientLoading = true
|
||||
|
||||
axios
|
||||
.delete(`/api/v1/recipients/${id}`)
|
||||
.delete(`/api/v1/recipients/${recipient.id}`)
|
||||
.then(response => {
|
||||
this.rows = _.reject(this.rows, recipient => recipient.id === id)
|
||||
let recipients = _.filter(this.rows, ['fingerprint', recipient.fingerprint])
|
||||
|
||||
_.forEach(recipients, function(recipient) {
|
||||
recipient.should_encrypt = false
|
||||
recipient.fingerprint = null
|
||||
})
|
||||
|
||||
this.rows = _.reject(this.rows, row => row.id === recipient.id)
|
||||
this.deleteRecipientModalOpen = false
|
||||
this.deleteRecipientLoading = false
|
||||
})
|
||||
|
|
Loading…
Add table
Reference in a new issue