diff --git a/README.md b/README.md
index 981b5c7..d371432 100644
--- a/README.md
+++ b/README.md
@@ -26,7 +26,7 @@ business), so the add-on asks only whether a customer needs documents at all.
number) and Delete; one upload box; and Download all, one zip of the customer's documents for an audit. ID
numbers are shown masked (`xxxx xxxx 4821`); **Show** reveals the full number.
- **Nothing is lost by accident:** Delete hides a document; **Deleted documents** (a button in this add-on's
- settings) restores it or erases it for good. Uploading a type the customer already has replaces the file (it asks
+ settings) opens it to look, restores it or erases it for good. Uploading a type the customer already has replaces the file (it asks
first on the customer page) and hides the old one the same way. Documents stay when a customer is deleted.
- **Everything is on record:** every view, Show, download, upload, change, delete, restore, erase and export is
written to the Activity log (never the number or the file).
diff --git a/resources/views/livewire/deleted/deleted.blade.php b/resources/views/livewire/deleted/deleted.blade.php
index 83fa10d..c87a6a8 100644
--- a/resources/views/livewire/deleted/deleted.blade.php
+++ b/resources/views/livewire/deleted/deleted.blade.php
@@ -30,6 +30,7 @@
{{ $row['type'] }}
{{ __(':date by :name', ['date' => $row['deleted'], 'name' => $row['by']]) }}
+ {{ __('View') }}
{{ __('Restore') }}
@if ($this->canErase)
user()?->can(Abilities::VIEW), 403);
- $row = Document::query()->with('type')->findOrFail($document);
+ $row = Document::withTrashed()->with('type')->findOrFail($document);
+ abort_if($row->trashed() && ! auth()->user()->can(Abilities::RESTORE), 404);
$account = Account::withTrashed()->findOrFail($row->account_id);
- $documents->log('document-viewed', $account, $row->type->name, auth()->user());
+ $documents->log('document-viewed', $account, $row->type->name, auth()->user(), $row->trashed() ? ['deleted' => true] : []);
return PrivateFile::contentResponse(
$files->read($row),
diff --git a/tests/Feature/CustomerCardTest.php b/tests/Feature/CustomerCardTest.php
index c431d97..31ef745 100644
--- a/tests/Feature/CustomerCardTest.php
+++ b/tests/Feature/CustomerCardTest.php
@@ -54,9 +54,23 @@ function card(Account $account): Testable
->and(Activity::query()->where('event', 'document-viewed')->sole()->subject_id)->toBe($this->account->id);
});
-it('does not open a hidden document from the card route', function () {
+it('opens a hidden document only for staff who may restore it, and logs it as deleted', function () {
+ app(CustomerDocuments::class)->delete($this->document, $this->admin);
+
+ $this->actingAs(staffWith(Abilities::VIEW));
+ $this->get(route('documents.file', $this->document))->assertNotFound();
+
+ $this->actingAs(staffWith(Abilities::RESTORE));
+ $response = $this->get(route('documents.file', $this->document))->assertOk()->assertHeader('Content-Type', 'image/png');
+
+ expect($response->getContent())->toBe(pngBytes())
+ ->and(Activity::query()->where('event', 'document-viewed')->sole()->properties['deleted'])->toBeTrue();
+});
+
+it('does not open an erased document', function () {
$this->actingAs($this->admin);
app(CustomerDocuments::class)->delete($this->document, $this->admin);
+ app(CustomerDocuments::class)->erase(Document::onlyTrashed()->findOrFail($this->document->id), $this->admin);
$this->get(route('documents.file', $this->document))->assertNotFound();
});
diff --git a/tests/Feature/ListPagesTest.php b/tests/Feature/ListPagesTest.php
index 1df2eb5..3617266 100644
--- a/tests/Feature/ListPagesTest.php
+++ b/tests/Feature/ListPagesTest.php
@@ -69,6 +69,14 @@
expect($document->fresh())->not->toBeNull();
});
+it('links each deleted document to its file', function () {
+ $this->actingAs($this->admin);
+ $document = $this->documents->upload(Account::factory()->create(), $this->aadhaar, pngUpload(), null, $this->admin);
+ $this->documents->delete($document, $this->admin);
+
+ Livewire::test('documents::deleted')->assertSee(route('documents.file', $document->id));
+});
+
it('needs Restore deleted documents for the page', function () {
$this->actingAs(staffWith(Abilities::VIEW, Abilities::EDIT));