Remove key for all recipients using the same one

This commit is contained in:
Will Browning 2019-10-29 13:39:35 +00:00
parent 1099b3c43c
commit 46be5d3e6d
2 changed files with 24 additions and 15 deletions

View file

@ -41,10 +41,15 @@ class RecipientKeyController extends Controller
return response('Key could not be deleted', 404); return response('Key could not be deleted', 404);
} }
$recipient->update([ // Remove the key from all recipients using that same fingerprint.
'should_encrypt' => false, Recipient::all()
'fingerprint' => null ->where('fingerprint', $recipient->fingerprint)
]); ->each(function ($recipient) {
$recipient->update([
'should_encrypt' => false,
'fingerprint' => null
]);
});
return response('', 204); return response('', 204);
} }

View file

@ -128,7 +128,7 @@
<icon <icon
name="delete" name="delete"
class="tooltip outline-none cursor-pointer block w-6 h-6 text-grey-200 fill-current" class="tooltip outline-none cursor-pointer block w-6 h-6 text-grey-200 fill-current"
@click.native="openDeleteRecipientKeyModal(props.row.id)" @click.native="openDeleteRecipientKeyModal(props.row)"
data-tippy-content="Remove public key" data-tippy-content="Remove public key"
/> />
</span> </span>
@ -263,12 +263,13 @@
Remove recipient public key Remove recipient public key
</h2> </h2>
<p class="mt-4 text-grey-700"> <p class="mt-4 text-grey-700">
Are you sure you want to remove the public key for this recipient? Are you sure you want to remove the public key for this recipient? It will also be removed
from any other recipients using the same key.
</p> </p>
<div class="mt-6"> <div class="mt-6">
<button <button
type="button" type="button"
@click="deleteRecipientKey(recipientKeyIdToDelete)" @click="deleteRecipientKey(recipientKeyToDelete)"
class="px-4 py-3 text-white font-semibold bg-red-500 hover:bg-red-600 border border-transparent rounded focus:outline-none" class="px-4 py-3 text-white font-semibold bg-red-500 hover:bg-red-600 border border-transparent rounded focus:outline-none"
:class="deleteRecipientKeyLoading ? 'cursor-not-allowed' : ''" :class="deleteRecipientKeyLoading ? 'cursor-not-allowed' : ''"
:disabled="deleteRecipientKeyLoading" :disabled="deleteRecipientKeyLoading"
@ -361,7 +362,7 @@ export default {
addRecipientLoading: false, addRecipientLoading: false,
addRecipientModalOpen: false, addRecipientModalOpen: false,
recipientIdToDelete: null, recipientIdToDelete: null,
recipientKeyIdToDelete: null, recipientKeyToDelete: null,
deleteRecipientLoading: false, deleteRecipientLoading: false,
deleteRecipientModalOpen: false, deleteRecipientModalOpen: false,
deleteRecipientKeyLoading: false, deleteRecipientKeyLoading: false,
@ -530,23 +531,26 @@ export default {
this.deleteRecipientModalOpen = false this.deleteRecipientModalOpen = false
}) })
}, },
openDeleteRecipientKeyModal(id) { openDeleteRecipientKeyModal(recipient) {
this.deleteRecipientKeyModalOpen = true this.deleteRecipientKeyModalOpen = true
this.recipientKeyIdToDelete = id this.recipientKeyToDelete = recipient
}, },
closeDeleteRecipientKeyModal() { closeDeleteRecipientKeyModal() {
this.deleteRecipientKeyModalOpen = false this.deleteRecipientKeyModalOpen = false
this.recipientKeyIdToDelete = null this.recipientKeyIdToDelete = null
}, },
deleteRecipientKey(id) { deleteRecipientKey(recipient) {
this.deleteRecipientKeyLoading = true this.deleteRecipientKeyLoading = true
axios axios
.delete(`/api/v1/recipient-keys/${id}`) .delete(`/api/v1/recipient-keys/${recipient.id}`)
.then(response => { .then(response => {
let recipient = _.find(this.rows, ['id', this.recipientKeyIdToDelete]) let recipients = _.filter(this.rows, ['fingerprint', recipient.fingerprint])
recipient.should_encrypt = false
recipient.fingerprint = null _.forEach(recipients, function(recipient) {
recipient.should_encrypt = false
recipient.fingerprint = null
})
this.deleteRecipientKeyModalOpen = false this.deleteRecipientKeyModalOpen = false
this.deleteRecipientKeyLoading = false this.deleteRecipientKeyLoading = false
}) })