Skip to content

Commit

Permalink
Merge pull request #14 from fleetbase/dev-v0.0.15
Browse files Browse the repository at this point in the history
v0.1.15 - endpoint to check if engine is installed
  • Loading branch information
roncodes authored Oct 8, 2024
2 parents 572c135 + 55290a0 commit 2554590
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 31 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
6 changes: 3 additions & 3 deletions 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 Expand Up @@ -39,8 +39,8 @@
},
"dependencies": {
"@babel/core": "^7.23.2",
"@fleetbase/ember-core": "^0.2.19",
"@fleetbase/ember-ui": "^0.2.32",
"@fleetbase/ember-core": "^0.2.21",
"@fleetbase/ember-ui": "^0.2.34",
"@fortawesome/ember-fontawesome": "^2.0.0",
"@fortawesome/fontawesome-svg-core": "6.4.0",
"@fortawesome/free-solid-svg-icons": "6.4.0",
Expand Down
20 changes: 10 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 2554590

Please sign in to comment.