Skip to main content
Version: v1 (Current)

Phase 1: Backend API Foundation

Historical design/implementation plan. It is retained as background, not a statement that every proposed feature is available. Use the current component/project guides and the deployed editor before following its recipes.

Estimated Effort: 2-3 hours Dependencies: None Jira: EZ-2206

Overview​

Implement the backend API endpoints needed for the app store modal. This includes updating the PluginPage index endpoint to support app store queries with source filtering, adding a details endpoint, and setting up routes.

Objectives​

  • Update PluginPageController index method to support app_store queries
  • Implement source filtering (all/public/team)
  • Add appStoreDetails endpoint
  • Add route for app-store-details
  • Test endpoints return correct data structure

Implementation Steps​

Step 1: Update PluginPageController Index Method​

File: app/Http/Controllers/Admin/Plugins/PageController.php

Changes:

  1. Add app_store query detection at the start of the AJAX request block:
if (isStandardAjaxRequest()) {
$isAppStore = $request->query('app_store');
$source = $request->query('source', 'all'); // 'all', 'public', 'team'

// ... existing code
}
  1. Modify the query builder to include app store data when needed:
$query = \App\Models\PluginPage::query()
->when($isAppStore, function($q) {
return $q->with(['currentVersion', 'systemTags' => function($query) {
$query->where('class', 'app-store');
}]);
})
// ... existing when clauses for forProjectId, tags, etc.
  1. Add source filtering logic before the final query execution:
->when($isAppStore && $source === 'public', function($query) {
return $query->where('plugin_pages.is_public', true);
})
->when($isAppStore && $source === 'team', function($query) use ($team) {
return $query->where('plugin_pages.team_id', $team->id);
})
->when($isAppStore && $source === 'all', function($query) use ($team) {
return $query->where(function($q) use ($team) {
$q->where('plugin_pages.is_public', true)
->orWhere('plugin_pages.team_id', $team->id);
});
})
  1. Adjust select fields based on whether it's an app store request:
$select = $isAppStore
? ['plugin_pages.id', 'plugin_pages.slug', 'plugin_pages.name',
'plugin_pages.description', 'plugin_pages.icon',
'plugin_pages.background_color', 'plugin_pages.current_version_id']
: ['plugin_pages.id', 'plugin_pages.name', 'plugin_pages.description'];

$pages = $query->select($select)->orderBy('name', 'asc')->get();
  1. Transform data for app store requests:
if ($isAppStore) {
$pages = $pages->map(function($page) {
return [
'id' => $page->id,
'slug' => $page->slug,
'name' => $page->name,
'short_description' => $page->description,
'icon' => $page->icon,
'background_color' => $page->background_color,
'default_version' => $page->currentVersion?->version,
'tags' => $page->systemTags->pluck('name')
];
});
}

Testing:

# Test all apps
curl "http://localhost/dashboard/plugins/pages?app_store=true&source=all"

# Test public only
curl "http://localhost/dashboard/plugins/pages?app_store=true&source=public"

# Test team only
curl "http://localhost/dashboard/plugins/pages?app_store=true&source=team"

Step 2: Add App Store Details Endpoint​

File: app/Http/Controllers/Admin/Plugins/PageController.php

Add new method after the show() method:

/**
* Get app store details for a plugin page.
* Returns detailed information including readme, screenshots, and dependencies.
*/
public function appStoreDetails(Request $request, PluginPage $page)
{
$this->authorize('view', $page);

$version = $page->currentVersion;

if (!$version) {
return response()->json([
'error' => 'No version available for this plugin page'
], 404);
}

return response()->json([
'long_description' => $page->long_description,
'readme' => $page->readme,
'default_version' => $version->version,
'screenshots' => $page->screenshots->map(fn($s) => [
'id' => $s->id,
'url' => $s->url,
'caption' => $s->caption
]),
'dependencies' => $version->dependencies ?? [],
]);
}

Testing:

# Test details endpoint
curl "http://localhost/dashboard/plugins/pages/{slug}/app-store-details"

Step 3: Add Route​

File: routes/admin/plugins.php (or wherever plugin routes are defined)

Add route:

Route::get('/plugins/pages/{page}/app-store-details',
[PageController::class, 'appStoreDetails']
)->name('dashboard.plugins.pages.app-store-details');

Verify route:

php artisan route:list --name=app-store-details

Step 4: Verify Database Schema​

Check that these columns exist:

docker compose exec app php artisan tinker
// Check plugin_pages table
Schema::hasColumn('plugin_pages', 'icon') // should return true
Schema::hasColumn('plugin_pages', 'background_color') // should return true
Schema::hasColumn('plugin_pages', 'long_description') // should return true
Schema::hasColumn('plugin_pages', 'readme') // should return true
Schema::hasColumn('plugin_pages', 'is_public') // should return true
Schema::hasColumn('plugin_pages', 'team_id') // should return true

If any are missing, create migration:

docker compose exec app php artisan make:migration add_app_store_fields_to_plugin_pages

Step 5: Write Feature Tests​

File: tests/Feature/PluginPage/PluginPageAppStoreTest.php

Create test:

<?php

namespace Tests\Feature\PluginPage;

use App\Models\PluginPage;
use App\Models\PluginPageVersion;
use App\Models\SystemTag;
use App\Models\Team;
use App\Models\Admin;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class PluginPageAppStoreTest extends TestCase
{
use RefreshDatabase;

protected $admin;
protected $team;

protected function setUp(): void
{
parent::setUp();

$this->team = Team::factory()->create();
$this->admin = Admin::factory()->create();
$this->admin->teams()->attach($this->team);
}

public function test_app_store_index_returns_correct_structure()
{
$tag = SystemTag::factory()->create(['class' => 'app-store']);

$page = PluginPage::factory()->create([
'is_public' => true,
'icon' => 'users',
'background_color' => '#3490dc'
]);

$version = PluginPageVersion::factory()->create([
'plugin_page_id' => $page->id,
'version' => '1.0.0'
]);

$page->update(['current_version_id' => $version->id]);
$page->systemTags()->attach($tag);

$response = $this->actingAs($this->admin)
->get(route('dashboard.plugins.pages.index', [
'app_store' => true,
'source' => 'all'
]));

$response->assertOk();
$response->assertJsonStructure([
'*' => [
'id',
'slug',
'name',
'short_description',
'icon',
'background_color',
'default_version',
'tags'
]
]);
}

public function test_source_filter_public_only()
{
$publicPage = PluginPage::factory()->create(['is_public' => true]);
$teamPage = PluginPage::factory()->create([
'is_public' => false,
'team_id' => $this->team->id
]);

$response = $this->actingAs($this->admin)
->get(route('dashboard.plugins.pages.index', [
'app_store' => true,
'source' => 'public'
]));

$response->assertOk();
$data = $response->json();

$this->assertCount(1, $data);
$this->assertEquals($publicPage->id, $data[0]['id']);
}

public function test_source_filter_team_only()
{
$publicPage = PluginPage::factory()->create(['is_public' => true]);
$teamPage = PluginPage::factory()->create([
'is_public' => false,
'team_id' => $this->team->id
]);

$response = $this->actingAs($this->admin)
->get(route('dashboard.plugins.pages.index', [
'app_store' => true,
'source' => 'team'
]));

$response->assertOk();
$data = $response->json();

$this->assertCount(1, $data);
$this->assertEquals($teamPage->id, $data[0]['id']);
}

public function test_source_filter_all()
{
$publicPage = PluginPage::factory()->create(['is_public' => true]);
$teamPage = PluginPage::factory()->create([
'is_public' => false,
'team_id' => $this->team->id
]);
$otherTeamPage = PluginPage::factory()->create([
'is_public' => false,
'team_id' => Team::factory()->create()->id
]);

$response = $this->actingAs($this->admin)
->get(route('dashboard.plugins.pages.index', [
'app_store' => true,
'source' => 'all'
]));

$response->assertOk();
$data = $response->json();

$this->assertCount(2, $data);
}

public function test_app_store_details_endpoint()
{
$page = PluginPage::factory()->create([
'long_description' => 'This is a detailed description',
'readme' => '# Documentation\n\nSome docs here'
]);

$version = PluginPageVersion::factory()->create([
'plugin_page_id' => $page->id,
'version' => '1.0.0',
'dependencies' => [
[
'identifier' => 'form',
'model' => 'ProjectForm',
'permissions' => ['read', 'write']
]
]
]);

$page->update(['current_version_id' => $version->id]);

$response = $this->actingAs($this->admin)
->get(route('dashboard.plugins.pages.app-store-details', [
'page' => $page->slug
]));

$response->assertOk();
$response->assertJsonStructure([
'long_description',
'readme',
'default_version',
'screenshots',
'dependencies'
]);

$this->assertEquals('This is a detailed description', $response->json('long_description'));
$this->assertCount(1, $response->json('dependencies'));
}
}

Run tests:

docker compose exec app ./vendor/bin/phpunit tests/Feature/PluginPage/PluginPageAppStoreTest.php

Acceptance Criteria​

  • App store index endpoint returns correct data structure with icon, background_color, tags
  • Source filter "all" returns public apps + current team apps
  • Source filter "public" returns only public apps
  • Source filter "team" returns only current team apps
  • Details endpoint returns long_description, readme, screenshots, dependencies
  • All feature tests pass
  • Routes are properly registered and accessible

Files Modified​

  • app/Http/Controllers/Admin/Plugins/PageController.php
  • routes/admin/plugins.php (or equivalent)
  • tests/Feature/PluginPage/PluginPageAppStoreTest.php (new)

Next Phase​

After this phase is complete and all tests pass, proceed to Phase 2: Core Modal Components.