ProtectedHeadersRecipientController.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Http\Controllers\Controller;
  4. use App\Http\Resources\RecipientResource;
  5. use Illuminate\Http\Request;
  6. class ProtectedHeadersRecipientController extends Controller
  7. {
  8. public function store(Request $request)
  9. {
  10. $request->validate(['id' => 'required|string']);
  11. $recipient = user()->recipients()->findOrFail($request->id);
  12. if (! $recipient->fingerprint) {
  13. return response('You need to add a public key to this recipient before you can enable protected headers (hide subject)', 422);
  14. }
  15. if ($recipient->inline_encryption) {
  16. return response('You need to disable inline encryption before you can enable protected headers (hide subject)', 422);
  17. }
  18. $recipient->update(['protected_headers' => true]);
  19. return new RecipientResource($recipient->load('aliases'));
  20. }
  21. public function destroy($id)
  22. {
  23. $recipient = user()->recipients()->findOrFail($id);
  24. $recipient->update(['protected_headers' => false]);
  25. return response('', 204);
  26. }
  27. }