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
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

use Database\Seeders\GrassrootsGrantsSeeder;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up(): void
{
if (! Schema::hasTable('grassroots_grants_project_images')) {
return;
}

$ids = DB::table('grassroots_grants_project_images')
->pluck('url', 'id')
->filter(function ($url): bool {
$path = parse_url((string) $url, PHP_URL_PATH) ?: (string) $url;
$filename = rawurldecode(basename($path));

return in_array($filename, GrassrootsGrantsSeeder::EXCLUDED_EVIDENCE_FILES, true);
})
->keys();

if ($ids->isEmpty()) {
return;
}

DB::table('grassroots_grants_project_images')->whereIn('id', $ids->all())->delete();
}

public function down(): void
{
// Internal reports stay unpublished.
}
};
18 changes: 18 additions & 0 deletions database/seeders/GrassrootsGrantsSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@

class GrassrootsGrantsSeeder extends Seeder
{
/**
* Internal grant reports that must not be published with project evidence.
*
* @var list<string>
*/
public const EXCLUDED_EVIDENCE_FILES = [
'Pazin City Library_Final narrative report in English.pdf',
'Article about workshops_My first code.pdf',
'BETA_Evidence of conducted workshops.pdf',
'BETA_Final narrative report in English.pdf',
'BETA_Narrative report with evidence.pdf',
'HROBOS_Final narrative report with evidence.pdf',
];

public function run(): void
{
if (! Schema::hasTable('grassroots_grants_page')) {
Expand Down Expand Up @@ -95,6 +109,10 @@ private function seedProjectImages(

$position = 0;
foreach ($finder as $file) {
if (in_array($file->getFilename(), self::EXCLUDED_EVIDENCE_FILES, true)) {
continue;
}

$url = '/images/grants/'.$hubFolder.'/'.$projectFolder.'/'.$file->getFilename();

$extension = strtolower($file->getExtension());
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
45 changes: 45 additions & 0 deletions tests/Feature/GrassrootsGrantsInternalReportsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Tests\Feature;

use App\GrassrootsGrantsProjectImage;
use Database\Seeders\GrassrootsGrantsSeeder;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;

final class GrassrootsGrantsInternalReportsTest extends TestCase
{
use DatabaseMigrations;

#[Test]
public function internal_profil_klett_reports_are_not_published(): void
{
$this->seed(GrassrootsGrantsSeeder::class);

$published = GrassrootsGrantsProjectImage::query()->pluck('url');

foreach (GrassrootsGrantsSeeder::EXCLUDED_EVIDENCE_FILES as $filename) {
$this->assertFileDoesNotExist($this->grantEvidencePath($filename));

$this->assertFalse(
$published->contains(fn (string $url): bool => rawurldecode(basename(parse_url($url, PHP_URL_PATH) ?: $url)) === $filename),
$filename.' is still linked on the grassroots grants page.'
);
}
}

private function grantEvidencePath(string $filename): string
{
$folders = [
'Pazin City Library_Final narrative report in English.pdf' => 'MY FIRST CODE First steps into the world of coding with LEGO',
'Article about workshops_My first code.pdf' => 'MY FIRST CODE First steps into the world of coding with LEGO',
'BETA_Evidence of conducted workshops.pdf' => 'Holiday creative workshops at the Garage for Children 13+',
'BETA_Final narrative report in English.pdf' => 'Holiday creative workshops at the Garage for Children 13+',
'BETA_Narrative report with evidence.pdf' => 'Holiday creative workshops at the Garage for Children 13+',
'HROBOS_Final narrative report with evidence.pdf' => 'Preparatory workshops for WRO 2025 Ljubljana',
];

return public_path('images/grants/Croatia & Slovenia/'.$folders[$filename].'/'.$filename);
}
}
Loading