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
8 changes: 8 additions & 0 deletions app/Http/Controllers/FrontEnd/DownloadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use App\Models\Prosedur;
use App\Models\Regulasi;
use App\Models\FormDokumen;
use Illuminate\Support\Carbon;
use Yajra\DataTables\DataTables;

class DownloadController extends FrontEndController
Expand Down Expand Up @@ -136,6 +137,13 @@ public function getDataByJenisDokumen($slug)

public function downloadDokumen(FormDokumen $file)
{
// Terapkan filter yang sama dengan daftar publik agar dokumen yang
// belum dipublikasi atau sudah kedaluwarsa tidak bisa diunduh (404).
$isPublished = (bool) $file->is_published;
$isActive = $file->expired_at === null || Carbon::parse($file->expired_at)->isFuture();

abort_unless($isPublished && $isActive, 404);

return response()->download($file->file_dokumen);
}
}
1 change: 1 addition & 0 deletions catatan_rilis.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Terimakasih [isi disini] yang telah berkontribusi langsung mengembangkan aplikas
12. [#1797](https://github.com/OpenSID/OpenDK/issues/1797) Persentase belanja barang/jasa salah dan division by zero di AnggaranRealisasiChartService.
13. [#1798](https://github.com/OpenSID/OpenDK/issues/1798) Perbaikan Cache listDesa terus diperpanjang dan tidak membedakan parameter $all.
14. [#1799](https://github.com/OpenSID/OpenDK/issues/1799) Perbaikan getFeeds() error jika item RSS tidak punya author dan gagal per feed.
15. [#1813](https://github.com/OpenSID/OpenDK/issues/1813) Perbaikan Batasi unduh dokumen hanya untuk dokumen terbit dan belum kedaluwarsa.


#### TEKNIS
Expand Down
66 changes: 66 additions & 0 deletions tests/Feature/Frontend/DownloadDokumenVisibilityTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

use App\Models\FormDokumen;

/*
* Regresi untuk issue #1813: endpoint unduh dokumen publik tidak boleh
* menyajikan dokumen yang belum dipublikasi atau sudah kedaluwarsa.
*/

beforeEach(function () {
$this->filePath = tempnam(sys_get_temp_dir(), 'dokumen_');
file_put_contents($this->filePath, 'isi dokumen');
});

afterEach(function () {
if (isset($this->filePath) && is_file($this->filePath)) {
unlink($this->filePath);
}
});

function makeFormDokumen(array $attributes, string $filePath): FormDokumen
{
return FormDokumen::create(array_merge([
'nama_dokumen' => 'Dokumen Uji',
'description' => 'Deskripsi uji',
'file_dokumen' => $filePath,
'is_published' => true,
'published_at' => now(),
'expired_at' => null,
], $attributes));
}

it('serves a published document that has no expiry date', function () {
$dokumen = makeFormDokumen([], $this->filePath);

$this->get(route('unduhan.form-dokumen.download', $dokumen->id))
->assertOk()
->assertDownload();
});

it('serves a published document whose expiry date is in the future', function () {
$dokumen = makeFormDokumen(['expired_at' => now()->addDay()], $this->filePath);

$this->get(route('unduhan.form-dokumen.download', $dokumen->id))
->assertOk()
->assertDownload();
});

it('returns 404 for an unpublished document', function () {
$dokumen = makeFormDokumen(['is_published' => false], $this->filePath);

$this->get(route('unduhan.form-dokumen.download', $dokumen->id))
->assertNotFound();
});

it('returns 404 for an expired document', function () {
$dokumen = makeFormDokumen(['expired_at' => now()->subDay()], $this->filePath);

$this->get(route('unduhan.form-dokumen.download', $dokumen->id))
->assertNotFound();
});

it('returns 404 for an unknown document id', function () {
$this->get(route('unduhan.form-dokumen.download', 999999))
->assertNotFound();
});
Loading