Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Lines marked **Upgrade step** need you to act after updating.
- Webhooks send their custom headers again, such as `Authorization` or an API key, and saving a webhook in the editor keeps headers set through the API. (#218)
- A webhook whose receiver is down or answers with a server error is tried up to 5 times in all, over about 1 hour 20 minutes. A webhook call stops after 10 seconds, a webhook URL must start with http:// or https://, and the webhook log shows a plain error text when the URL can't be reached. (#218)
- The webhook log shows how often a webhook was really tried. Before, it stopped counting at 2. (#218)
- A logo or background whose file is already gone, and shows as a broken image, can be removed again. (#219)

### Security

Expand Down
12 changes: 5 additions & 7 deletions app/Http/Controllers/Api/FormImagesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,13 @@ public function delete(Request $request, Form $form, DeleteUnusedFormImages $del
]);

$fieldname = $request->input('type').'_path';
$oldPath = $form->$fieldname;

if ($form->hasImage($request->input('type'))) {
$oldPath = $form->$fieldname;

$form->$fieldname = null;
$form->save();
// clear the path even when its file is already gone, so a broken image can be removed
$form->$fieldname = null;
$form->save();

$deleteUnusedImages->delete(collect([$oldPath]));
}
$deleteUnusedImages->delete(collect([$oldPath]));

return response()->json($form, 200);
}
Expand Down
11 changes: 11 additions & 0 deletions tests/Feature/FormImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,17 @@
expect($original->fresh()->hasImage($type))->toBeTrue();
})->with(['avatar', 'background']);

test('removing an image whose file is already gone clears its path', function (string $type) {
Storage::fake();
$form = Form::factory()->create([$type.'_path' => 'form/gone.png']);

$this->actingAs($form->user)
->json('DELETE', route('api.forms.images.delete', $form->uuid), ['type' => $type])
->assertStatus(200);

expect($form->fresh()->{$type.'_path'})->toBeNull();
})->with(['avatar', 'background']);

test('replacing or removing an image no other form uses deletes it and its resized copies', function (string $type) {
Storage::fake();
$form = Form::factory()->create([$type.'_path' => 'form/old.png']);
Expand Down
Loading