Merge pull request 'KAN-8 Add project template context to API and MCP' (#90) from koda/kan-8-add-project-template-to-mcp-api into main
Reviewed-on: OpenSource/KanbanGit#90
This commit was merged in pull request #90.
This commit is contained in:
@@ -3,7 +3,12 @@
|
||||
namespace Tests\Feature\Api;
|
||||
|
||||
use App\Actions\ProjectTicketMetadata\InitializeProjectTicketMetadata;
|
||||
use App\Actions\Projects\DuplicateProjectConfiguration;
|
||||
use App\Models\BoardColumn;
|
||||
use App\Models\Project;
|
||||
use App\Models\ProjectTemplate;
|
||||
use App\Models\TicketStatus;
|
||||
use App\Models\TicketType;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
@@ -38,6 +43,7 @@ class ProjectApiTest extends TestCase
|
||||
|
||||
$this->withApplicationKey($user)
|
||||
->postJson(route('api.projects.store'), [
|
||||
'creation_mode' => 'scratch',
|
||||
'key' => 'api',
|
||||
'name' => 'API Project',
|
||||
])
|
||||
@@ -47,8 +53,209 @@ 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
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$this->syncGlobalPermissions($user, ['create']);
|
||||
|
||||
$template = ProjectTemplate::factory()->create([
|
||||
'name' => 'API Template',
|
||||
'slug' => 'api-template',
|
||||
'copy_areas' => [
|
||||
DuplicateProjectConfiguration::COPY_PROJECT_SETTINGS,
|
||||
DuplicateProjectConfiguration::COPY_TICKET_TYPES,
|
||||
],
|
||||
'configuration_snapshot' => [
|
||||
DuplicateProjectConfiguration::COPY_PROJECT_SETTINGS => [
|
||||
'show_author' => false,
|
||||
'show_story_points' => false,
|
||||
],
|
||||
DuplicateProjectConfiguration::COPY_TICKET_TYPES => [
|
||||
[
|
||||
'name' => 'Spike',
|
||||
'position' => 1,
|
||||
'is_parent' => false,
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->withApplicationKey($user)
|
||||
->postJson(route('api.projects.store'), [
|
||||
'key' => 'tpl1',
|
||||
'name' => 'Template API Project',
|
||||
'creation_mode' => 'template',
|
||||
'source_template_id' => $template->id,
|
||||
])
|
||||
->assertCreated()
|
||||
->assertJsonPath('data.key', 'TPL1')
|
||||
->assertJsonPath('data.name', 'Template API Project');
|
||||
|
||||
$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());
|
||||
}
|
||||
|
||||
public function test_project_api_exposes_template_context_and_overrides(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$project = Project::factory()->create([
|
||||
'key' => 'TMP1',
|
||||
'name' => 'Template Driven Project',
|
||||
'show_author' => false,
|
||||
'show_story_points' => false,
|
||||
]);
|
||||
$template = ProjectTemplate::factory()->create([
|
||||
'name' => 'Workflow Template',
|
||||
'slug' => 'workflow-template',
|
||||
'copy_areas' => [
|
||||
DuplicateProjectConfiguration::COPY_PROJECT_SETTINGS,
|
||||
DuplicateProjectConfiguration::COPY_TICKET_TYPES,
|
||||
],
|
||||
'configuration_snapshot' => [
|
||||
DuplicateProjectConfiguration::COPY_PROJECT_SETTINGS => [
|
||||
'show_author' => true,
|
||||
'show_story_points' => true,
|
||||
],
|
||||
DuplicateProjectConfiguration::COPY_TICKET_TYPES => [
|
||||
[
|
||||
'name' => 'Bug',
|
||||
'position' => 1,
|
||||
'is_parent' => false,
|
||||
],
|
||||
[
|
||||
'name' => 'Feature',
|
||||
'position' => 2,
|
||||
'is_parent' => false,
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$project->update([
|
||||
'project_template_id' => $template->id,
|
||||
]);
|
||||
$project->ticketTypes()->delete();
|
||||
TicketType::factory()->create([
|
||||
'project_id' => $project->id,
|
||||
'name' => 'Bug',
|
||||
'position' => 1,
|
||||
'is_parent' => false,
|
||||
]);
|
||||
TicketType::factory()->create([
|
||||
'project_id' => $project->id,
|
||||
'name' => 'Feature',
|
||||
'position' => 2,
|
||||
'is_parent' => false,
|
||||
]);
|
||||
|
||||
$this->syncProjectPermissions($project, $user, ['view']);
|
||||
|
||||
$this->withApplicationKey($user)
|
||||
->getJson(route('api.projects.show', $project))
|
||||
->assertOk()
|
||||
->assertJsonPath('data.project_template.id', $template->id)
|
||||
->assertJsonPath('data.project_template.slug', 'workflow-template')
|
||||
->assertJsonPath('data.project_template.configuration_snapshot.project_settings.show_author', true)
|
||||
->assertJsonPath('data.template_state.inherits_from_template', true)
|
||||
->assertJsonPath('data.template_state.template_id', $template->id)
|
||||
->assertJsonPath('data.template_state.template_configuration.project_settings.show_author', true)
|
||||
->assertJsonPath('data.template_state.effective_configuration.ticket_types.0.name', 'Bug')
|
||||
->assertJsonPath('data.template_state.inherited_configuration.ticket_types.1.name', 'Feature')
|
||||
->assertJsonPath('data.template_state.overridden_configuration.project_settings.show_author', false)
|
||||
->assertJsonPath('data.template_state.overridden_areas.0.value', DuplicateProjectConfiguration::COPY_PROJECT_SETTINGS);
|
||||
}
|
||||
|
||||
public function test_users_can_duplicate_projects_via_api(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$this->syncGlobalPermissions($user, ['create']);
|
||||
|
||||
$sourceProject = Project::factory()->create([
|
||||
'key' => 'SRC1',
|
||||
'show_author' => false,
|
||||
]);
|
||||
$this->syncProjectPermissions($sourceProject, $user, ['view']);
|
||||
|
||||
$sourceProject->ticketTypes()->delete();
|
||||
$sourceProject->ticketStatuses()->delete();
|
||||
$sourceProject->boardColumns()->delete();
|
||||
|
||||
$column = BoardColumn::factory()->create([
|
||||
'project_id' => $sourceProject->id,
|
||||
'name' => 'In Progress',
|
||||
'position' => 1,
|
||||
]);
|
||||
$backlogStatus = TicketStatus::factory()->create([
|
||||
'project_id' => $sourceProject->id,
|
||||
'name' => 'Queued',
|
||||
'position' => 1,
|
||||
]);
|
||||
$activeStatus = TicketStatus::factory()->create([
|
||||
'project_id' => $sourceProject->id,
|
||||
'board_column_id' => $column->id,
|
||||
'name' => 'Active',
|
||||
'position' => 1,
|
||||
]);
|
||||
$backlogStatus->allowedTargetStatuses()->sync([$activeStatus->id]);
|
||||
TicketType::factory()->create([
|
||||
'project_id' => $sourceProject->id,
|
||||
'name' => 'Spike',
|
||||
'position' => 1,
|
||||
]);
|
||||
|
||||
$this->withApplicationKey($user)
|
||||
->postJson(route('api.projects.store'), [
|
||||
'key' => 'dup2',
|
||||
'name' => 'Duplicated API Project',
|
||||
'creation_mode' => 'duplicate',
|
||||
'source_project_id' => $sourceProject->id,
|
||||
'copy_areas' => [
|
||||
DuplicateProjectConfiguration::COPY_PROJECT_SETTINGS,
|
||||
DuplicateProjectConfiguration::COPY_BOARD_WORKFLOW,
|
||||
DuplicateProjectConfiguration::COPY_TICKET_TYPES,
|
||||
],
|
||||
])
|
||||
->assertCreated()
|
||||
->assertJsonPath('data.key', 'DUP2')
|
||||
->assertJsonPath('data.name', 'Duplicated API Project');
|
||||
|
||||
$project = Project::query()->where('key', 'DUP2')->firstOrFail();
|
||||
|
||||
$this->assertFalse($project->show_author);
|
||||
$this->assertSame(['In Progress'], $project->boardColumns()->pluck('name')->all());
|
||||
$this->assertSame(['Queued', 'Active'], $project->ticketStatuses()->pluck('name')->all());
|
||||
$this->assertSame(['Spike'], $project->ticketTypes()->pluck('name')->all());
|
||||
$this->assertSame(['Active'], $project->ticketStatuses()->where('name', 'Queued')->firstOrFail()->allowedTargetStatuses()->pluck('name')->all());
|
||||
}
|
||||
|
||||
public function test_project_duplication_via_api_requires_visible_source_project(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$this->syncGlobalPermissions($user, ['create']);
|
||||
$sourceProject = Project::factory()->create();
|
||||
|
||||
$this->withApplicationKey($user)
|
||||
->postJson(route('api.projects.store'), [
|
||||
'key' => 'nope',
|
||||
'name' => 'No Access',
|
||||
'creation_mode' => 'duplicate',
|
||||
'source_project_id' => $sourceProject->id,
|
||||
])
|
||||
->assertStatus(422)
|
||||
->assertJsonValidationErrors(['source_project_id']);
|
||||
}
|
||||
|
||||
public function test_project_show_and_delete_enforce_permissions(): void
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ namespace Tests\Feature\Mcp;
|
||||
|
||||
use App\Actions\Notifications\DeliverNotificationAction;
|
||||
use App\Actions\ProjectTicketMetadata\InitializeProjectTicketMetadata;
|
||||
use App\Actions\Projects\DuplicateProjectConfiguration;
|
||||
use App\Enums\NotificationDeliveryStatus;
|
||||
use App\Mcp\Servers\KanbanGitServer;
|
||||
use App\Mcp\Tools\GetTicket;
|
||||
@@ -15,8 +16,10 @@ use App\Mcp\Tools\UpdateTicketDescription;
|
||||
use App\Models\BoardColumn;
|
||||
use App\Models\NotificationAction;
|
||||
use App\Models\Project;
|
||||
use App\Models\ProjectTemplate;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\TicketStatus;
|
||||
use App\Models\TicketType;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
@@ -207,6 +210,66 @@ class KanbanGitMcpTest extends TestCase
|
||||
->etc());
|
||||
}
|
||||
|
||||
public function test_get_ticket_exposes_project_template_context_and_overrides(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$project = $this->project('CORE', 'Core project');
|
||||
$template = ProjectTemplate::factory()->create([
|
||||
'name' => 'Agent Workflow Template',
|
||||
'slug' => 'agent-workflow-template',
|
||||
'copy_areas' => [
|
||||
DuplicateProjectConfiguration::COPY_PROJECT_SETTINGS,
|
||||
DuplicateProjectConfiguration::COPY_TICKET_TYPES,
|
||||
],
|
||||
'configuration_snapshot' => [
|
||||
DuplicateProjectConfiguration::COPY_PROJECT_SETTINGS => [
|
||||
'show_author' => true,
|
||||
'show_story_points' => true,
|
||||
],
|
||||
DuplicateProjectConfiguration::COPY_TICKET_TYPES => [
|
||||
[
|
||||
'name' => 'Bug',
|
||||
'position' => 1,
|
||||
'is_parent' => false,
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
$project->update([
|
||||
'project_template_id' => $template->id,
|
||||
'show_author' => false,
|
||||
'show_story_points' => false,
|
||||
]);
|
||||
$project->ticketTypes()->delete();
|
||||
TicketType::factory()->create([
|
||||
'project_id' => $project->id,
|
||||
'name' => 'Bug',
|
||||
'position' => 1,
|
||||
'is_parent' => false,
|
||||
]);
|
||||
$status = $project->ticketStatuses()->firstOrFail();
|
||||
$ticket = $this->ticket($project, $status, [
|
||||
'ticket_key' => 'CORE-1',
|
||||
'title' => 'Template aware ticket',
|
||||
]);
|
||||
|
||||
$this->syncProjectPermissions($project, $user, ['view']);
|
||||
|
||||
KanbanGitServer::actingAs($user)
|
||||
->tool(GetTicket::class, [
|
||||
'ticket_id' => $ticket->id,
|
||||
])
|
||||
->assertOk()
|
||||
->assertStructuredContent(fn (AssertableJson $json) => $json
|
||||
->where('data.project.project_template.id', $template->id)
|
||||
->where('data.project.project_template.slug', 'agent-workflow-template')
|
||||
->where('data.project.template_state.inherits_from_template', true)
|
||||
->where('data.project.template_state.template_configuration.project_settings.show_author', true)
|
||||
->where('data.project.template_state.overridden_configuration.project_settings.show_author', false)
|
||||
->where('data.project.template_state.effective_configuration.ticket_types.0.name', 'Bug')
|
||||
->etc());
|
||||
}
|
||||
|
||||
public function test_description_update_requires_write_permission_and_preserves_unrelated_fields(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
|
||||
@@ -3,8 +3,10 @@
|
||||
namespace Tests\Feature\Projects;
|
||||
|
||||
use App\Actions\ProjectTicketMetadata\InitializeProjectTicketMetadata;
|
||||
use App\Actions\Projects\DuplicateProjectConfiguration;
|
||||
use App\Models\BoardColumn;
|
||||
use App\Models\Project;
|
||||
use App\Models\ProjectTemplate;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\TicketStatus;
|
||||
use App\Models\User;
|
||||
@@ -31,6 +33,15 @@ class ProjectBoardSettingsControllerTest extends TestCase
|
||||
'position' => 1,
|
||||
]);
|
||||
|
||||
$template = ProjectTemplate::factory()->create([
|
||||
'configuration_snapshot' => app(DuplicateProjectConfiguration::class)->export($project, [
|
||||
DuplicateProjectConfiguration::COPY_BOARD_WORKFLOW,
|
||||
]),
|
||||
'copy_areas' => [DuplicateProjectConfiguration::COPY_BOARD_WORKFLOW],
|
||||
'name' => 'Starter Workflow',
|
||||
]);
|
||||
$project->update(['project_template_id' => $template->id]);
|
||||
|
||||
$this->syncProjectPermissions($project, $user, ['edit']);
|
||||
|
||||
$this->actingAs($user)
|
||||
@@ -41,7 +52,9 @@ class ProjectBoardSettingsControllerTest extends TestCase
|
||||
->where('project.id', $project->id)
|
||||
->where('backlogTicketStatuses.0.name', 'Backlog')
|
||||
->where('boardColumns.0.name', 'Todo')
|
||||
->where('ticketStatuses.0.name', 'Backlog'),
|
||||
->where('ticketStatuses.0.name', 'Backlog')
|
||||
->where('templateState.templateName', 'Starter Workflow')
|
||||
->where('templateState.inheritedAreas.0.value', DuplicateProjectConfiguration::COPY_BOARD_WORKFLOW),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,11 +3,19 @@
|
||||
namespace Tests\Feature\Projects;
|
||||
|
||||
use App\Actions\ProjectTicketMetadata\InitializeProjectTicketMetadata;
|
||||
use App\Actions\Projects\DuplicateProjectConfiguration;
|
||||
use App\Models\BoardColumn;
|
||||
use App\Models\NotificationAction;
|
||||
use App\Models\Project;
|
||||
use App\Models\ProjectTemplate;
|
||||
use App\Models\RepositoryConnection;
|
||||
use App\Models\Team;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\TicketFieldDefinition;
|
||||
use App\Models\TicketLinkType;
|
||||
use App\Models\TicketPriority;
|
||||
use App\Models\TicketStatus;
|
||||
use App\Models\TicketType;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
@@ -100,12 +108,40 @@ class ProjectControllerTest extends TestCase
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$this->syncGlobalPermissions($user, ['project:create']);
|
||||
$visibleProject = Project::factory()->create([
|
||||
'name' => 'Visible Source',
|
||||
'key' => 'SRC1',
|
||||
]);
|
||||
Project::factory()->create([
|
||||
'name' => 'Hidden Source',
|
||||
'key' => 'SRC2',
|
||||
]);
|
||||
$template = ProjectTemplate::factory()->create([
|
||||
'name' => 'Reusable Setup',
|
||||
'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)
|
||||
->get(route('projects.create'))
|
||||
->get(route('projects.create', ['template' => $template->id]))
|
||||
->assertOk()
|
||||
->assertInertia(fn (Assert $page) => $page
|
||||
->component('projects/Create'),
|
||||
->component('projects/Create')
|
||||
->has('copyAreaOptions', count(DuplicateProjectConfiguration::copyableAreas()))
|
||||
->has('sourceProjects', 1)
|
||||
->has('sourceTemplates', 1)
|
||||
->where('sourceProjects.0.id', $visibleProject->id)
|
||||
->where('sourceTemplates.0.id', $template->id)
|
||||
->where('selectedSourceTemplateId', $template->id)
|
||||
->where('copyAreaOptions.0.value', DuplicateProjectConfiguration::COPY_PROJECT_SETTINGS),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -131,6 +167,7 @@ class ProjectControllerTest extends TestCase
|
||||
|
||||
$response = $this->actingAs($user)
|
||||
->post(route('projects.store'), [
|
||||
'creation_mode' => 'scratch',
|
||||
'name' => 'Kanban Foundation',
|
||||
'key' => 'core',
|
||||
]);
|
||||
@@ -144,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(),
|
||||
@@ -187,6 +236,215 @@ class ProjectControllerTest extends TestCase
|
||||
->assertRedirect(route('projects.create'));
|
||||
}
|
||||
|
||||
public function test_authenticated_users_can_create_projects_from_saved_templates(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$this->syncGlobalPermissions($user, ['project:create']);
|
||||
|
||||
$sourceProject = Project::factory()->create([
|
||||
'key' => 'SRC1',
|
||||
'name' => 'Source Project',
|
||||
'show_author' => false,
|
||||
'show_story_points' => false,
|
||||
]);
|
||||
|
||||
$template = ProjectTemplate::factory()->create([
|
||||
'source_project_id' => $sourceProject->id,
|
||||
'name' => 'Kanban Template',
|
||||
'slug' => 'kanban-template',
|
||||
'copy_areas' => [
|
||||
DuplicateProjectConfiguration::COPY_PROJECT_SETTINGS,
|
||||
DuplicateProjectConfiguration::COPY_TICKET_TYPES,
|
||||
],
|
||||
'configuration_snapshot' => [
|
||||
DuplicateProjectConfiguration::COPY_PROJECT_SETTINGS => [
|
||||
'show_author' => false,
|
||||
'show_story_points' => false,
|
||||
],
|
||||
DuplicateProjectConfiguration::COPY_TICKET_TYPES => [
|
||||
[
|
||||
'name' => 'Bug',
|
||||
'position' => 1,
|
||||
'is_parent' => false,
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($user)
|
||||
->post(route('projects.store'), [
|
||||
'creation_mode' => 'template',
|
||||
'name' => 'Template Based Project',
|
||||
'key' => 'TMP1',
|
||||
'source_template_id' => $template->id,
|
||||
]);
|
||||
|
||||
$project = Project::query()->where('key', 'TMP1')->firstOrFail();
|
||||
|
||||
$response->assertRedirect(route('projects.show', $project));
|
||||
|
||||
$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',
|
||||
'position' => 1,
|
||||
'is_parent' => false,
|
||||
]);
|
||||
$this->assertDatabaseMissing('tickets', [
|
||||
'project_id' => $project->id,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_authenticated_users_can_duplicate_projects_with_selected_settings_only(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$this->syncGlobalPermissions($user, ['project:create']);
|
||||
|
||||
$sourceProject = Project::factory()->create([
|
||||
'key' => 'SRC1',
|
||||
'name' => 'Source Project',
|
||||
'show_author' => false,
|
||||
'show_story_points' => false,
|
||||
]);
|
||||
$this->syncProjectPermissions($sourceProject, $user, ['view']);
|
||||
|
||||
$sourceProject->ticketTypes()->delete();
|
||||
$sourceProject->ticketPriorities()->delete();
|
||||
$sourceProject->ticketStatuses()->delete();
|
||||
$sourceProject->boardColumns()->delete();
|
||||
|
||||
$todoColumn = BoardColumn::factory()->create([
|
||||
'project_id' => $sourceProject->id,
|
||||
'name' => 'Todo',
|
||||
'position' => 1,
|
||||
]);
|
||||
$doingColumn = BoardColumn::factory()->create([
|
||||
'project_id' => $sourceProject->id,
|
||||
'name' => 'Doing',
|
||||
'position' => 2,
|
||||
]);
|
||||
|
||||
$backlogStatus = TicketStatus::factory()->create([
|
||||
'project_id' => $sourceProject->id,
|
||||
'board_column_id' => null,
|
||||
'name' => 'Planned',
|
||||
'position' => 1,
|
||||
]);
|
||||
$todoStatus = TicketStatus::factory()->create([
|
||||
'project_id' => $sourceProject->id,
|
||||
'board_column_id' => $todoColumn->id,
|
||||
'name' => 'Todo',
|
||||
'position' => 1,
|
||||
]);
|
||||
$doingStatus = TicketStatus::factory()->create([
|
||||
'project_id' => $sourceProject->id,
|
||||
'board_column_id' => $doingColumn->id,
|
||||
'name' => 'Doing',
|
||||
'position' => 1,
|
||||
]);
|
||||
$todoStatus->allowedTargetStatuses()->sync([$doingStatus->id]);
|
||||
$backlogStatus->allowedTargetStatuses()->sync([$todoStatus->id]);
|
||||
|
||||
TicketType::factory()->create([
|
||||
'project_id' => $sourceProject->id,
|
||||
'name' => 'Bug',
|
||||
'position' => 1,
|
||||
]);
|
||||
TicketType::factory()->create([
|
||||
'project_id' => $sourceProject->id,
|
||||
'name' => 'Epic',
|
||||
'position' => 2,
|
||||
'is_parent' => true,
|
||||
]);
|
||||
TicketPriority::factory()->create([
|
||||
'project_id' => $sourceProject->id,
|
||||
'name' => 'Urgent',
|
||||
'position' => 1,
|
||||
]);
|
||||
TicketFieldDefinition::factory()->create([
|
||||
'project_id' => $sourceProject->id,
|
||||
'field_type' => 'number',
|
||||
'label' => 'Story estimate',
|
||||
'position' => 1,
|
||||
]);
|
||||
TicketLinkType::factory()->create([
|
||||
'project_id' => $sourceProject->id,
|
||||
'label' => 'Blocks',
|
||||
'counterpart_label' => 'Blocked by',
|
||||
'position' => 1,
|
||||
]);
|
||||
RepositoryConnection::factory()->create([
|
||||
'project_id' => $sourceProject->id,
|
||||
'repository_full_name' => 'OpenSource/source-project',
|
||||
]);
|
||||
NotificationAction::factory()->create([
|
||||
'project_id' => $sourceProject->id,
|
||||
'name' => 'Notify board changes',
|
||||
]);
|
||||
Ticket::factory()->create([
|
||||
'project_id' => $sourceProject->id,
|
||||
'sequence_number' => 42,
|
||||
'title' => 'Existing ticket',
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($user)
|
||||
->post(route('projects.store'), [
|
||||
'name' => 'Duplicated Project',
|
||||
'key' => 'dupe',
|
||||
'creation_mode' => 'duplicate',
|
||||
'source_project_id' => $sourceProject->id,
|
||||
'copy_areas' => [
|
||||
DuplicateProjectConfiguration::COPY_PROJECT_SETTINGS,
|
||||
DuplicateProjectConfiguration::COPY_BOARD_WORKFLOW,
|
||||
DuplicateProjectConfiguration::COPY_TICKET_TYPES,
|
||||
DuplicateProjectConfiguration::COPY_TICKET_FIELDS,
|
||||
],
|
||||
]);
|
||||
|
||||
$project = Project::query()->where('key', 'DUPE')->firstOrFail();
|
||||
|
||||
$response->assertRedirect(route('projects.show', $project));
|
||||
|
||||
$this->assertSame('Duplicated Project', $project->name);
|
||||
$this->assertFalse($project->show_author);
|
||||
$this->assertFalse($project->show_story_points);
|
||||
$this->assertSame(0, $project->tickets()->count());
|
||||
|
||||
$this->assertSame(['Todo', 'Doing'], $project->boardColumns()->pluck('name')->all());
|
||||
$this->assertSame(['Planned', 'Todo', 'Doing'], $project->ticketStatuses()->pluck('name')->all());
|
||||
$this->assertSame(['Bug', 'Epic'], $project->ticketTypes()->pluck('name')->all());
|
||||
$this->assertSame(['Story estimate'], $project->ticketFieldDefinitions()->pluck('label')->all());
|
||||
$this->assertSame(['Medium'], $project->ticketPriorities()->pluck('name')->all());
|
||||
$this->assertCount(0, $project->ticketLinkTypes);
|
||||
$this->assertCount(0, $project->repositoryConnections);
|
||||
$this->assertCount(0, $project->notificationActions);
|
||||
|
||||
$duplicatedTodoStatus = $project->ticketStatuses()->where('name', 'Todo')->firstOrFail();
|
||||
$this->assertSame(['Doing'], $duplicatedTodoStatus->allowedTargetStatuses()->pluck('name')->all());
|
||||
}
|
||||
|
||||
public function test_project_duplication_requires_accessible_source_projects(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$this->syncGlobalPermissions($user, ['project:create']);
|
||||
$sourceProject = Project::factory()->create();
|
||||
|
||||
$this->actingAs($user)
|
||||
->from(route('projects.create'))
|
||||
->post(route('projects.store'), [
|
||||
'name' => 'Denied Duplicate',
|
||||
'key' => 'deny',
|
||||
'creation_mode' => 'duplicate',
|
||||
'source_project_id' => $sourceProject->id,
|
||||
])
|
||||
->assertSessionHasErrors('source_project_id')
|
||||
->assertRedirect(route('projects.create'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure project keys cannot exceed five characters.
|
||||
*/
|
||||
|
||||
@@ -2,10 +2,12 @@
|
||||
|
||||
namespace Tests\Feature\Projects;
|
||||
|
||||
use App\Actions\Projects\DuplicateProjectConfiguration;
|
||||
use App\Enums\NotificationChannel;
|
||||
use App\Enums\NotificationEventType;
|
||||
use App\Models\NotificationAction;
|
||||
use App\Models\Project;
|
||||
use App\Models\ProjectTemplate;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
@@ -41,6 +43,15 @@ class ProjectNotificationSettingsControllerTest extends TestCase
|
||||
],
|
||||
]);
|
||||
|
||||
$template = ProjectTemplate::factory()->create([
|
||||
'configuration_snapshot' => app(DuplicateProjectConfiguration::class)->export($project, [
|
||||
DuplicateProjectConfiguration::COPY_NOTIFICATION_ACTIONS,
|
||||
]),
|
||||
'copy_areas' => [DuplicateProjectConfiguration::COPY_NOTIFICATION_ACTIONS],
|
||||
'name' => 'Alert Template',
|
||||
]);
|
||||
$project->update(['project_template_id' => $template->id]);
|
||||
|
||||
$this->syncProjectPermissions($project, $user, ['edit']);
|
||||
|
||||
$this->actingAs($user)
|
||||
@@ -72,6 +83,8 @@ class ProjectNotificationSettingsControllerTest extends TestCase
|
||||
->where('templateVariables.6.value', '$actor_name')
|
||||
->where('templateVariables.7.value', '$assignee_from')
|
||||
->where('templateVariables.8.value', '$assignee_to')
|
||||
->where('templateState.templateName', 'Alert Template')
|
||||
->where('templateState.inheritedAreas.0.value', DuplicateProjectConfiguration::COPY_NOTIFICATION_ACTIONS)
|
||||
->missing('notificationActions.0.delivery_url'),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
namespace Tests\Feature\Projects;
|
||||
|
||||
use App\Actions\Git\GitProviderKey;
|
||||
use App\Actions\Projects\DuplicateProjectConfiguration;
|
||||
use App\Models\Project;
|
||||
use App\Models\ProjectTemplate;
|
||||
use App\Models\RepositoryConnection;
|
||||
use App\Models\User;
|
||||
use App\Models\UserGitConnection;
|
||||
@@ -36,6 +38,15 @@ class ProjectRepositorySettingsControllerTest extends TestCase
|
||||
'repository_url' => 'https://git.example.test/core-team/kanbangit',
|
||||
]);
|
||||
|
||||
$template = ProjectTemplate::factory()->create([
|
||||
'configuration_snapshot' => app(DuplicateProjectConfiguration::class)->export($project, [
|
||||
DuplicateProjectConfiguration::COPY_REPOSITORY_CONNECTIONS,
|
||||
]),
|
||||
'copy_areas' => [DuplicateProjectConfiguration::COPY_REPOSITORY_CONNECTIONS],
|
||||
'name' => 'Connected Template',
|
||||
]);
|
||||
$project->update(['project_template_id' => $template->id]);
|
||||
|
||||
$this->syncProjectPermissions($project, $user, ['edit']);
|
||||
|
||||
$this->actingAs($user)
|
||||
@@ -46,7 +57,9 @@ class ProjectRepositorySettingsControllerTest extends TestCase
|
||||
->where('project.id', $project->id)
|
||||
->where('repositoryConnections.0.repository_full_name', 'core-team/kanbangit')
|
||||
->where('repositoryConnections.0.has_personal_access', false)
|
||||
->where('availableRepositorySources', []),
|
||||
->where('availableRepositorySources', [])
|
||||
->where('templateState.templateName', 'Connected Template')
|
||||
->where('templateState.inheritedAreas.0.value', DuplicateProjectConfiguration::COPY_REPOSITORY_CONNECTIONS),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Projects;
|
||||
|
||||
use App\Actions\Projects\DuplicateProjectConfiguration;
|
||||
use App\Models\BoardColumn;
|
||||
use App\Models\Project;
|
||||
use App\Models\ProjectTemplate;
|
||||
use App\Models\TicketStatus;
|
||||
use App\Models\TicketType;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ProjectTemplateControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_users_with_project_create_permission_can_view_templates_index_and_create_screen(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$project = Project::factory()->create([
|
||||
'name' => 'Core Platform',
|
||||
'key' => 'CORE',
|
||||
]);
|
||||
$template = ProjectTemplate::factory()->create([
|
||||
'name' => 'Foundation Template',
|
||||
'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']);
|
||||
|
||||
$this->actingAs($user)
|
||||
->get('/project-templates')
|
||||
->assertOk()
|
||||
->assertInertia(fn (Assert $page) => $page
|
||||
->component('project-templates/Index')
|
||||
->has('templates', 1)
|
||||
->where('templates.0.id', $template->id)
|
||||
->where('templates.0.slug', 'foundation-template')
|
||||
->where('templates.0.is_published', true));
|
||||
|
||||
$this->actingAs($user)
|
||||
->get(route('projects.templates.create', $project))
|
||||
->assertOk()
|
||||
->assertInertia(fn (Assert $page) => $page
|
||||
->component('project-templates/Create')
|
||||
->where('project.id', $project->id)
|
||||
->has('copyAreaOptions', count(DuplicateProjectConfiguration::copyableAreas())));
|
||||
}
|
||||
|
||||
public function test_users_can_save_and_delete_templates_from_projects(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$project = Project::factory()->create([
|
||||
'name' => 'Source Project',
|
||||
'key' => 'SRC1',
|
||||
'show_author' => false,
|
||||
'show_story_points' => false,
|
||||
]);
|
||||
|
||||
$this->syncGlobalPermissions($user, ['project:create']);
|
||||
$this->syncProjectPermissions($project, $user, ['view']);
|
||||
|
||||
$project->ticketTypes()->delete();
|
||||
$project->ticketStatuses()->delete();
|
||||
$project->boardColumns()->delete();
|
||||
|
||||
$boardColumn = BoardColumn::factory()->create([
|
||||
'project_id' => $project->id,
|
||||
'name' => 'Doing',
|
||||
'position' => 1,
|
||||
]);
|
||||
$ticketStatus = TicketStatus::factory()->create([
|
||||
'project_id' => $project->id,
|
||||
'board_column_id' => $boardColumn->id,
|
||||
'name' => 'Doing',
|
||||
'position' => 1,
|
||||
]);
|
||||
$ticketStatus->allowedTargetStatuses()->sync([$ticketStatus->id]);
|
||||
TicketType::factory()->create([
|
||||
'project_id' => $project->id,
|
||||
'name' => 'Bug',
|
||||
'position' => 1,
|
||||
]);
|
||||
|
||||
$this->actingAs($user)
|
||||
->post(route('projects.templates.store', $project), [
|
||||
'name' => 'Core Reusable',
|
||||
'slug' => 'core-reusable',
|
||||
'copy_areas' => [
|
||||
DuplicateProjectConfiguration::COPY_PROJECT_SETTINGS,
|
||||
DuplicateProjectConfiguration::COPY_TICKET_TYPES,
|
||||
],
|
||||
])
|
||||
->assertRedirect('/project-templates');
|
||||
|
||||
$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,
|
||||
'show_story_points' => false,
|
||||
],
|
||||
DuplicateProjectConfiguration::COPY_TICKET_TYPES => [
|
||||
[
|
||||
'name' => 'Bug',
|
||||
'position' => 1,
|
||||
'is_parent' => false,
|
||||
],
|
||||
],
|
||||
], $template->configuration_snapshot);
|
||||
|
||||
$this->actingAs($user)
|
||||
->delete(route('project-templates.destroy', $template))
|
||||
->assertRedirect('/project-templates');
|
||||
|
||||
$this->assertDatabaseMissing('project_templates', [
|
||||
'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();
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,9 @@
|
||||
namespace Tests\Feature\Projects;
|
||||
|
||||
use App\Actions\ProjectTicketMetadata\InitializeProjectTicketMetadata;
|
||||
use App\Actions\Projects\DuplicateProjectConfiguration;
|
||||
use App\Models\Project;
|
||||
use App\Models\ProjectTemplate;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\TicketFieldDefinition;
|
||||
use App\Models\TicketLinkType;
|
||||
@@ -37,6 +39,24 @@ class ProjectTicketMetadataSettingsControllerTest extends TestCase
|
||||
'position' => 1,
|
||||
]);
|
||||
|
||||
$template = ProjectTemplate::factory()->create([
|
||||
'configuration_snapshot' => app(DuplicateProjectConfiguration::class)->export($project, [
|
||||
DuplicateProjectConfiguration::COPY_PROJECT_SETTINGS,
|
||||
DuplicateProjectConfiguration::COPY_TICKET_TYPES,
|
||||
DuplicateProjectConfiguration::COPY_TICKET_LINK_TYPES,
|
||||
]),
|
||||
'copy_areas' => [
|
||||
DuplicateProjectConfiguration::COPY_PROJECT_SETTINGS,
|
||||
DuplicateProjectConfiguration::COPY_TICKET_TYPES,
|
||||
DuplicateProjectConfiguration::COPY_TICKET_LINK_TYPES,
|
||||
],
|
||||
'name' => 'Issue Tracker Template',
|
||||
]);
|
||||
$project->update([
|
||||
'project_template_id' => $template->id,
|
||||
'show_story_points' => false,
|
||||
]);
|
||||
|
||||
$this->syncProjectPermissions($project, $user, ['edit']);
|
||||
|
||||
$this->actingAs($user)
|
||||
@@ -45,12 +65,14 @@ class ProjectTicketMetadataSettingsControllerTest extends TestCase
|
||||
->assertInertia(fn (Assert $page) => $page
|
||||
->component('projects/settings/Metadata')
|
||||
->where('project.show_author', true)
|
||||
->where('project.show_story_points', true)
|
||||
->where('project.show_story_points', false)
|
||||
->where('ticketTypes.0.name', 'Task')
|
||||
->where('ticketTypes.1.name', 'Release')
|
||||
->where('ticketTypes.1.is_parent', true)
|
||||
->where('ticketTypes.2.name', 'Bug')
|
||||
->where('ticketLinkTypes.0.label', 'Relates to'),
|
||||
->where('ticketLinkTypes.0.label', 'Relates to')
|
||||
->where('templateState.templateName', 'Issue Tracker Template')
|
||||
->where('templateState.overriddenAreas.0.value', DuplicateProjectConfiguration::COPY_PROJECT_SETTINGS),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user