From 1e4468b4f234edd8aae2bdb515a4d1c527004ff5 Mon Sep 17 00:00:00 2001 From: "Ronald A. Richardson" Date: Tue, 8 Oct 2024 20:46:28 +0800 Subject: [PATCH] endpoint to check if engine is installed --- composer.json | 4 +- config/environment.js | 7 --- extension.json | 2 +- package.json | 2 +- .../Internal/v1/RegistryController.php | 54 ++++++++++++++++--- server/src/routes.php | 3 +- 6 files changed, 53 insertions(+), 19 deletions(-) diff --git a/composer.json b/composer.json index 153893e..3058906 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "fleetbase/registry-bridge", - "version": "0.0.14", + "version": "0.0.15", "description": "Internal Bridge between Fleetbase API and Extensions Registry", "keywords": [ "fleetbase-extension", @@ -20,7 +20,7 @@ ], "require": { "php": "^8.0", - "fleetbase/core-api": "^1.5.9", + "fleetbase/core-api": "^1.5.10", "laravel/cashier": "^15.2.1", "php-http/guzzle7-adapter": "^1.0", "psr/http-factory-implementation": "*", diff --git a/config/environment.js b/config/environment.js index aed9cc0..68951f9 100644 --- a/config/environment.js +++ b/config/environment.js @@ -10,16 +10,9 @@ module.exports = function (environment) { modulePrefix: name, environment, mountedEngineRoutePrefix: getMountedEngineRoutePrefix(), - stripe: { publishableKey: getenv('STRIPE_KEY'), }, - - 'ember-leaflet': { - excludeCSS: true, - excludeJS: true, - excludeImages: true, - }, }; return ENV; diff --git a/extension.json b/extension.json index 170c157..461173b 100644 --- a/extension.json +++ b/extension.json @@ -1,6 +1,6 @@ { "name": "Registry Bridge", - "version": "0.0.14", + "version": "0.0.15", "description": "Internal Bridge between Fleetbase API and Extensions Registry", "repository": "https://github.com/fleetbase/registry-bridge", "license": "AGPL-3.0-or-later", diff --git a/package.json b/package.json index 11f9909..7fa055c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@fleetbase/registry-bridge-engine", - "version": "0.0.14", + "version": "0.0.15", "description": "Internal Bridge between Fleetbase API and Extensions Registry", "fleetbase": { "route": "extensions" diff --git a/server/src/Http/Controllers/Internal/v1/RegistryController.php b/server/src/Http/Controllers/Internal/v1/RegistryController.php index 4b563cf..e588b3b 100644 --- a/server/src/Http/Controllers/Internal/v1/RegistryController.php +++ b/server/src/Http/Controllers/Internal/v1/RegistryController.php @@ -42,15 +42,55 @@ public function categories() * @return \Illuminate\Http\JsonResponse * A JSON response containing a list of installed engines with their metadata */ - public function getInstalledEngines() + public function getInstalledEngines(Request $request) { - $installedExtensions = RegistryExtension::disableCache()->whereHas('installs', function ($query) { - $query->where('company_uuid', session('company')); - })->get()->map(function ($extension) { - return $extension->currentBundle->meta['package.json'] ?? []; - }); + if ($request->user() && $request->session()->has('company')) { + $installedExtensions = RegistryExtension::disableCache()->whereHas('installs', function ($query) { + $query->where('company_uuid', session('company')); + })->get()->map(function ($extension) { + return $extension->currentBundle->meta['package.json'] ?? []; + }); - return response()->json($installedExtensions); + return response()->json($installedExtensions); + } + + return []; + } + + /** + * Determines if a specified engine is installed for the authenticated user's company. + * + * Retrieves the 'engine' input from the request and checks if the user is authenticated, + * the session has a 'company', and the 'engine' parameter is provided. It then queries + * the `RegistryExtension` model to determine if the engine is installed for the company. + * + * @param Request $request the incoming HTTP request containing the 'engine' parameter + * + * @return array An associative array with the installation status, e.g., ['installed' => true]. + */ + public function getEngineInstallStatus(Request $request) + { + $engine = $request->input('engine'); + + if ($request->user() && $request->session()->has('company') && $engine) { + $installed = RegistryExtension::disableCache() + ->whereHas( + 'currentBundle', + function ($query) use ($engine) { + $query->where('meta->package.json->name', $engine); + } + ) + ->whereHas( + 'installs', + function ($query) { + $query->where('company_uuid', session('company')); + } + )->exists(); + + return ['installed' => $installed]; + } + + return ['installed' => false]; } /** diff --git a/server/src/routes.php b/server/src/routes.php index 034becc..5dac42c 100644 --- a/server/src/routes.php +++ b/server/src/routes.php @@ -14,6 +14,8 @@ */ // Lookup package endpoint Route::get(config('internals.api.routing.prefix', '~registry') . '/v1/lookup', 'Fleetbase\RegistryBridge\Http\Controllers\Internal\v1\RegistryController@lookupPackage'); +Route::get(config('internals.api.routing.prefix', '~registry') . '/v1/engines', 'Fleetbase\RegistryBridge\Http\Controllers\Internal\v1\RegistryController@getInstalledEngines'); +Route::get(config('internals.api.routing.prefix', '~registry') . '/v1/engine-install-status', 'Fleetbase\RegistryBridge\Http\Controllers\Internal\v1\RegistryController@getEngineInstallStatus'); Route::prefix(config('internals.api.routing.prefix', '~registry'))->middleware(['fleetbase.registry'])->namespace('Fleetbase\RegistryBridge\Http\Controllers')->group( function ($router) { /* @@ -36,7 +38,6 @@ function ($router) { $router->group(['middleware' => ['fleetbase.protected', 'throttle:60,1']], function ($router) { $router->get('categories', 'RegistryController@categories'); - $router->get('engines', 'RegistryController@getInstalledEngines'); $router->group(['prefix' => 'installer'], function ($router) { $router->post('install', 'ExtensionInstallerController@install');