Skip to content

Commit

Permalink
endpoint to check if engine is installed
Browse files Browse the repository at this point in the history
  • Loading branch information
roncodes committed Oct 8, 2024
1 parent 572c135 commit 1e4468b
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 19 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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": "*",
Expand Down
7 changes: 0 additions & 7 deletions config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion extension.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
54 changes: 47 additions & 7 deletions server/src/Http/Controllers/Internal/v1/RegistryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

/**
Expand Down
3 changes: 2 additions & 1 deletion server/src/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
/*
Expand All @@ -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');
Expand Down

0 comments on commit 1e4468b

Please sign in to comment.