Will Browning 5 лет назад
Родитель
Сommit
4d41e2c635
2 измененных файлов с 26 добавлено и 4 удалено
  1. 21 3
      app/Http/Controllers/Api/RecipientKeyController.php
  2. 5 1
      resources/js/pages/Recipients.vue

+ 21 - 3
app/Http/Controllers/Api/RecipientKeyController.php

@@ -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.
-        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)
             ->where('fingerprint', $recipient->fingerprint)
             ->each(function ($recipient) {
             ->each(function ($recipient) {
                 $recipient->update([
                 $recipient->update([

+ 5 - 1
resources/js/pages/Recipients.vue

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