Merge pull request 'KAN-6 Project rely on project templates' (#88) from koda/kan-6-project-rely-on-project-templates into epic/kan-3

Reviewed-on: OpenSource/KanbanGit#88
This commit was merged in pull request #88.
This commit is contained in:
2026-06-04 20:06:22 +00:00
19 changed files with 281 additions and 14 deletions
+7
View File
@@ -43,6 +43,7 @@ class ProjectApiTest extends TestCase
$this->withApplicationKey($user)
->postJson(route('api.projects.store'), [
'creation_mode' => 'scratch',
'key' => 'api',
'name' => 'API Project',
])
@@ -52,8 +53,11 @@ class ProjectApiTest extends TestCase
->assertJsonPath('meta.message', 'API Project was created.');
$project = Project::query()->where('key', 'API')->firstOrFail();
$project->refresh();
$this->assertSame(2, $project->ticketTypes()->count());
$this->assertSame(1, $project->ticketStatuses()->count());
$this->assertNotNull($project->project_template_id);
}
public function test_users_can_create_projects_from_templates_via_api(): void
@@ -96,6 +100,9 @@ class ProjectApiTest extends TestCase
$project = Project::query()->where('key', 'TPL1')->firstOrFail();
$project->refresh();
$this->assertSame($template->id, $project->project_template_id);
$this->assertFalse($project->show_author);
$this->assertFalse($project->show_story_points);
$this->assertSame(['Spike'], $project->ticketTypes()->pluck('name')->all());
@@ -0,0 +1,73 @@
<?php
namespace Tests\Feature\Database;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class ProjectTemplateBaselineMigrationTest extends TestCase
{
public function test_migration_backfills_hidden_base_templates_for_existing_projects(): void
{
Artisan::call('migrate:fresh', [
'--path' => [
'database/migrations/0001_01_01_000000_create_users_table.php',
'database/migrations/0001_01_01_000001_create_cache_table.php',
'database/migrations/0001_01_01_000002_create_jobs_table.php',
'database/migrations/2025_08_14_170933_add_two_factor_columns_to_users_table.php',
'database/migrations/2026_03_24_234007_create_projects_table.php',
'database/migrations/2026_03_24_234734_create_teams_table.php',
'database/migrations/2026_03_24_234735_create_team_user_table.php',
'database/migrations/2026_03_25_002100_create_board_columns_table.php',
'database/migrations/2026_03_25_003100_create_ticket_types_table.php',
'database/migrations/2026_03_25_003101_create_ticket_priorities_table.php',
'database/migrations/2026_03_25_003102_create_ticket_field_definitions_table.php',
'database/migrations/2026_03_25_004098_create_ticket_statuses_table.php',
'database/migrations/2026_03_25_004099_create_ticket_statuses_transitionstable.php',
'database/migrations/2026_03_25_004100_create_tickets_table.php',
'database/migrations/2026_03_25_065302_create_ticket_worklog_entries_table.php',
'database/migrations/2026_03_25_070706_create_ticket_field_values_table.php',
'database/migrations/2026_03_25_073715_create_ticket_links_table.php',
'database/migrations/2026_03_25_073715_create_ticket_link_types_table.php',
'database/migrations/2026_03_26_074522_create_user_git_connections_table.php',
'database/migrations/2026_03_26_075849_create_repository_connections_table.php',
'database/migrations/2026_04_12_120000_create_permission_assignments_table.php',
'database/migrations/2026_04_20_174556_create_user_applications_table.php',
'database/migrations/2026_04_20_194646_create_notification_actions_table.php',
'database/migrations/2026_04_20_194646_create_notification_delivery_logs_table.php',
'database/migrations/2026_04_24_194800_add_filters_to_notification_actions_table.php',
'database/migrations/2026_04_24_203500_create_acceptance_criteria_table.php',
'database/migrations/2026_05_19_230500_drop_acceptance_criteria_from_tickets_table.php',
'database/migrations/2026_05_22_124700_add_must_change_password_on_next_login_to_users_table.php',
'database/migrations/2026_05_23_101900_add_counterpart_label_to_ticket_link_types_table.php',
'database/migrations/2026_05_25_011500_create_project_templates_table.php',
],
]);
DB::table('projects')->insert([
'name' => 'Legacy Project',
'key' => 'LGCY',
'show_author' => 0,
'show_story_points' => 1,
'created_at' => now(),
'updated_at' => now(),
]);
$projectId = (int) DB::table('projects')->where('key', 'LGCY')->value('id');
Artisan::call('migrate', [
'--path' => 'database/migrations/2026_05_25_013000_project_templates_as_project_baselines.php',
]);
$project = DB::table('projects')->where('id', $projectId)->first();
$template = DB::table('project_templates')->where('id', $project->project_template_id)->first();
$this->assertNotNull($project->project_template_id);
$this->assertNotNull($template);
$this->assertSame($projectId, $template->project_id);
$this->assertSame($projectId, $template->source_project_id);
$this->assertSame(0, $template->is_published);
$this->assertSame('lgcy-base-template', $template->slug);
}
}
@@ -121,6 +121,13 @@ class ProjectControllerTest extends TestCase
'slug' => 'reusable-setup',
'source_project_id' => $visibleProject->id,
]);
ProjectTemplate::factory()->create([
'name' => 'Hidden Base',
'slug' => 'hidden-base',
'project_id' => $visibleProject->id,
'source_project_id' => $visibleProject->id,
'is_published' => false,
]);
$this->syncProjectPermissions($visibleProject, $user, ['view']);
$this->actingAs($user)
@@ -160,6 +167,7 @@ class ProjectControllerTest extends TestCase
$response = $this->actingAs($user)
->post(route('projects.store'), [
'creation_mode' => 'scratch',
'name' => 'Kanban Foundation',
'key' => 'core',
]);
@@ -173,6 +181,18 @@ class ProjectControllerTest extends TestCase
'key' => 'CORE',
]);
$project->refresh();
$this->assertNotNull($project->project_template_id);
$this->assertDatabaseHas('project_templates', [
'id' => $project->project_template_id,
'project_id' => $project->id,
'source_project_id' => $project->id,
'is_published' => false,
'slug' => 'core-base-template',
]);
$this->assertDatabaseHas('permission_assignments', [
'assignee_id' => $user->id,
'assignee_type' => $user->getMorphClass(),
@@ -263,8 +283,11 @@ class ProjectControllerTest extends TestCase
$response->assertRedirect(route('projects.show', $project));
$this->assertSame(false, $project->fresh()->show_author);
$this->assertSame(false, $project->fresh()->show_story_points);
$project->refresh();
$this->assertSame($template->id, $project->project_template_id);
$this->assertSame(false, $project->show_author);
$this->assertSame(false, $project->show_story_points);
$this->assertDatabaseHas('ticket_types', [
'project_id' => $project->id,
'name' => 'Bug',
@@ -29,6 +29,13 @@ class ProjectTemplateControllerTest extends TestCase
'slug' => 'foundation-template',
'source_project_id' => $project->id,
]);
ProjectTemplate::factory()->create([
'name' => 'Hidden Base Template',
'slug' => 'hidden-base-template',
'project_id' => $project->id,
'source_project_id' => $project->id,
'is_published' => false,
]);
$this->syncGlobalPermissions($user, ['project:create']);
$this->syncProjectPermissions($project, $user, ['view']);
@@ -40,7 +47,8 @@ class ProjectTemplateControllerTest extends TestCase
->component('project-templates/Index')
->has('templates', 1)
->where('templates.0.id', $template->id)
->where('templates.0.slug', 'foundation-template'));
->where('templates.0.slug', 'foundation-template')
->where('templates.0.is_published', true));
$this->actingAs($user)
->get(route('projects.templates.create', $project))
@@ -99,6 +107,9 @@ class ProjectTemplateControllerTest extends TestCase
$template = ProjectTemplate::query()->where('slug', 'core-reusable')->firstOrFail();
$this->assertTrue($template->is_published);
$this->assertNull($template->project_id);
$this->assertSame([
DuplicateProjectConfiguration::COPY_PROJECT_SETTINGS => [
'show_author' => false,
@@ -121,4 +132,21 @@ class ProjectTemplateControllerTest extends TestCase
'id' => $template->id,
]);
}
public function test_hidden_base_templates_cannot_be_deleted_from_the_management_flow(): void
{
$user = User::factory()->create();
$project = Project::factory()->create();
$template = ProjectTemplate::factory()->create([
'project_id' => $project->id,
'source_project_id' => $project->id,
'is_published' => false,
]);
$this->syncGlobalPermissions($user, ['project:create']);
$this->actingAs($user)
->delete(route('project-templates.destroy', $template))
->assertNotFound();
}
}