Skip to content

Commit

Permalink
Release/1.3.0 (#76)
Browse files Browse the repository at this point in the history
* Tidy actions texts and edgeapps index texts

* Moved per-app basic auth option inside an advanced options button

* Fixed fontawesome icons import

* Added support for browserdev actions and dashboard setting

* Added home actions for browser dev

* Added changelog file

* Fixed bug with getBrowserDevStatus when module does not exist in the system

* Fixed missing expected values when dev module is non existant

* Removed or empty array call

* Fixed default return on getBrowserDevPassword

* Fixed default value again

* Changed template directory to have pages on the side of blocks and partials directories

* Added app icons

* Added changelog page

* Test fix

* Added missing argument

* Fix remaining errors

* Another fix for unit test bad syntax

* Another fix for unit test bad syntax

* Another fix for unit test bad syntax

* Another fix for unit test bad syntax

* PHPStan fix

* More fixes

* Middleware subscriber properly supporting more than 1 argument

* Code fixes for RunMiddleware

* Removed var dump

* Another attempt at fixing variadic
  • Loading branch information
paulotruta authored Dec 7, 2024
1 parent 330c984 commit f977560
Show file tree
Hide file tree
Showing 44 changed files with 1,058 additions and 106 deletions.
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Changelog

## [Unreleased]

*

## [1.3.0] - 05-12-2020

* Added Edgebox Browser Development Environment Feature Support
* Added tasks for handling browser development environment into TaskFactory
* Added options for handling browser development environment data into OptionsRepository
* Added BrowserDevHelper class for handling browser development environment tasks in a more convenient way
* Added API route to ApiController for handling getBrowserDevStatus, enableBrowserDev, disableBrowserDev, setBrowserDevPassword tasks, and returning the status.
* Added section for handling browser development environment in the Settings page
* Added Javascript to handle browser development environment task buttons and status updates in the settings page section
* Added Browser Development Environment button to EdgeApps detail page when this feature is enabled

### Missing Past Releases

Release notes for past versions are not available in this file. Please refer to the [GitHub releases](https://hithub.com/edgebox-iot/api/releases) for more information. Feel free to contribute to this file by adding missing release notes.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/public/assets/img/edgeapps/hello.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/public/assets/img/edgeapps/rocketchat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/public/assets/img/edgeapps/syncthing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed src/public/assets/img/edgeapps/test_banner.jpg
Binary file not shown.
14 changes: 12 additions & 2 deletions src/src/Attribute/RunMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,17 @@
#[\Attribute(\Attribute::TARGET_METHOD)]
class RunMiddleware
{
protected array $args;

public function __construct(
public string $name
) {}
public string $name,
...$extras
) {
$this->extras = $extras;
}

public function getExtras(): array
{
return $this->extras;
}
}
32 changes: 32 additions & 0 deletions src/src/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Helper\DashboardHelper;
use App\Helper\EdgeAppsHelper;
use App\Helper\ShellHelper;
use App\Helper\BrowserDevHelper;
use App\Helper\TunnelHelper;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
Expand All @@ -23,6 +24,7 @@ class ApiController extends AbstractController
private DashboardHelper $dashboardHelper;
private TunnelHelper $tunnelHelper;
private ShellHelper $shellHelper;
private BrowserDevHelper $browserDevHelper;
private BackupsHelper $backupsHelper;
private EdgeAppsHelper $edgeAppsHelper;
private TaskFactory $taskFactory;
Expand All @@ -32,6 +34,7 @@ public function __construct(
DashboardHelper $dashboardHelper,
TunnelHelper $tunnelHelper,
ShellHelper $shellHelper,
BrowserDevHelper $browserDevHelper,
BackupsHelper $backupsHelper,
EdgeAppsHelper $edgeAppsHelper,
TaskFactory $taskFactory
Expand All @@ -40,6 +43,7 @@ public function __construct(
$this->dashboardHelper = $dashboardHelper;
$this->tunnelHelper = $tunnelHelper;
$this->shellHelper = $shellHelper;
$this->browserDevHelper = $browserDevHelper;
$this->backupsHelper = $backupsHelper;
$this->edgeAppsHelper = $edgeAppsHelper;
$this->taskFactory = $taskFactory;
Expand Down Expand Up @@ -131,6 +135,34 @@ public function settingsShell(Request $request): JsonResponse
return new JsonResponse($response);
}

#[Route('/api/settings/browserdev', name: 'api_settings_browserdev')]
public function settingsBrowserDev(Request $request): JsonResponse
{
if ($request->isMethod('post')) {
$data = json_decode($request->getContent(), true);
$response = [
'status' => 'error',
'message' => 'Invalid operation',
];

if (isset($data['op'])) {
if ('changepw' == $data['op'] && isset($data['password'])) {
$response = $this->browserDevHelper->setBrowserDevPassword($data['password']);
} elseif ('disable' == $data['op']) {
$response = $this->browserDevHelper->disableBrowserDev();
} elseif ('enable' == $data['op']) {
$response = $this->browserDevHelper->enableBrowserDev();
} elseif ('status' == $data['op']) {
$response = $this->browserDevHelper->getBrowserDevStatus();
}
}
} else {
$response = $this->browserDevHelper->getBrowserDevStatus(true);
}

return new JsonResponse($response);
}

#[Route('/api/backups', name: 'api_backups')]
public function backups(Request $request): JsonResponse
{
Expand Down
2 changes: 1 addition & 1 deletion src/src/Controller/BackupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(
#[Route('/backups', name: 'backups')]
public function index(): Response
{
return $this->render('backups/index.html.twig', [
return $this->render('pages/backups/index.html.twig', [
'controller_title' => 'Backups',
'controller_subtitle' => 'Safeguard Data',
'backup_status' => $this->backupsHelper->getBackupsStatus(),
Expand Down
4 changes: 2 additions & 2 deletions src/src/Controller/ChangelogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function hello(): Response

# If LAST_SEEN_CHANGELOG_VERSION is not set, redirect to the changelog page.

return $this->render('changelog/' . $target_version . '.html.twig', [
return $this->render('pages/changelog/' . $target_version . '.html.twig', [
// 'controller_title' => 'Dashboard',
// 'controller_subtitle' => 'Welcome back!',
// 'container_system_uptime' => $this->getSystemUptimeContainerVar(),
Expand All @@ -72,7 +72,7 @@ public function hello(): Response
#[Route('/changelog/{version}', name: 'changelog-version')]
public function changelog_version(string $version): Response
{
return $this->render('changelog/' . $version . '.html.twig', [
return $this->render('pages/changelog/' . $version . '.html.twig', [
// 'controller_title' => 'Dashboard',
// 'controller_subtitle' => 'Welcome back!',
// 'container_system_uptime' => $this->getSystemUptimeContainerVar(),
Expand Down
2 changes: 1 addition & 1 deletion src/src/Controller/DocsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class DocsController extends AbstractController
#[Route('/docs', name: 'docs')]
public function index(): Response
{
return $this->render('docs/index.html.twig', [
return $this->render('pages/docs/index.html.twig', [
'page_title' => 'Documentation',
'page_subtitle' => 'Documentation',
]);
Expand Down
11 changes: 8 additions & 3 deletions src/src/Controller/EdgeAppsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use App\Helper\DashboardHelper;
use App\Helper\EdgeAppsHelper;
use App\Helper\SystemHelper;
use App\Helper\BrowserDevHelper;
use App\Repository\OptionRepository;
use App\Repository\TaskRepository;
use App\Controller\BaseController;
Expand All @@ -25,6 +26,7 @@ class EdgeAppsController extends BaseController
private EntityManagerInterface $entityManager;
private EdgeAppsHelper $edgeAppsHelper;
private SystemHelper $systemHelper;
private BrowserDevHelper $browserDevHelper;
private TaskFactory $taskFactory;
protected DashboardHelper $dashboardHelper;

Expand Down Expand Up @@ -59,6 +61,7 @@ public function __construct(
EntityManagerInterface $entityManager,
EdgeAppsHelper $edgeAppsHelper,
SystemHelper $systemHelper,
BrowserDevHelper $browserDevHelper,
TaskFactory $taskFactory,
TaskRepository $taskRepository,
DashboardHelper $dashboardHelper
Expand All @@ -67,6 +70,7 @@ public function __construct(
$this->entityManager = $entityManager;
$this->edgeAppsHelper = $edgeAppsHelper;
$this->systemHelper = $systemHelper;
$this->browserDevHelper = $browserDevHelper;
$this->taskFactory = $taskFactory;
$this->taskRepository = $taskRepository;
$this->dashboardHelper = $dashboardHelper;
Expand All @@ -88,7 +92,7 @@ public function index(): Response
$framework_ready = true;
}

return $this->render('edgeapps/index.html.twig', [
return $this->render('pages/edgeapps/index.html.twig', [
'controller_title' => 'EdgeApps',
'controller_subtitle' => 'Applications control',
'framework_ready' => $framework_ready,
Expand Down Expand Up @@ -156,7 +160,7 @@ public function details(Request $request, string $edgeapp): Response
}
}

return $this->render('edgeapps/details.html.twig', [
return $this->render('pages/edgeapps/details.html.twig', [
'controller_title' => 'EdgeApps',
'controller_subtitle' => 'Application details',
'release_version' => $this->systemHelper->getReleaseVersion(),
Expand All @@ -165,6 +169,7 @@ public function details(Request $request, string $edgeapp): Response
'edgeapp' => $edgeapp_config,
'edgeapp_logs' => $logs,
'dashboard_settings' => $this->dashboardHelper->getSettings(),
'browserdev_status' => $this->browserDevHelper->getBrowserDevStatus(),
]);
}

Expand Down Expand Up @@ -203,7 +208,7 @@ public function action(string $action, string $edgeapp): Response
$action_result = 'edgeapp_not_found';
}

return $this->render('edgeapps/action.html.twig', [
return $this->render('pages/edgeapps/action.html.twig', [
'controller_title' => 'EdgeApps - '.$controller_title,
'controller_subtitle' => 'Please wait...',
'edgeapp' => $edgeapp,
Expand Down
24 changes: 22 additions & 2 deletions src/src/Controller/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function __construct(
#[Route('/hello', name: 'hello')]
public function hello(): Response
{
return $this->render('home/hello.html.twig', [
return $this->render('pages/home/hello.html.twig', [
// 'controller_title' => 'Dashboard',
// 'controller_subtitle' => 'Welcome back!',
// 'container_system_uptime' => $this->getSystemUptimeContainerVar(),
Expand All @@ -68,7 +68,7 @@ public function index(): Response

$actions_overview = $this->getActionsOverviewContainerVars();

return $this->render('home/index.html.twig', [
return $this->render('pages/home/index.html.twig', [
'controller_title' => 'Dashboard',
'controller_subtitle' => 'Welcome back!',
'container_system_uptime' => $this->getSystemUptimeContainerVar(),
Expand Down Expand Up @@ -243,6 +243,24 @@ private function getActionsOverviewContainerVars(): array
Task::STATUS_FINISHED => 'Stopped interactive shell',
Task::STATUS_ERROR => 'Failed to stop interactive shell',
],
'activate_browserdev' => [
Task::STATUS_CREATED => 'Waiting to activate Browser Dev Environment',
Task::STATUS_EXECUTING => 'Activating Browser Dev Environment',
Task::STATUS_FINISHED => 'Activated Browser Dev Environment',
Task::STATUS_ERROR => 'Failed to activate Browser Dev Environment',
],
'deactivate_browserdev' => [
Task::STATUS_CREATED => 'Waiting to deactivate Browser Dev Environment',
Task::STATUS_EXECUTING => 'Deactivating Browser Dev Environment',
Task::STATUS_FINISHED => 'Deactivated Browser Dev Environment',
Task::STATUS_ERROR => 'Failed to deactivate Browser Dev Environment',
],
'set_browserdev_password' => [
Task::STATUS_CREATED => 'Waiting to set Browser Dev Environment password',
Task::STATUS_EXECUTING => 'Setting Browser Dev Environment password',
Task::STATUS_FINISHED => 'Set Browser Dev Environment password',
Task::STATUS_ERROR => 'Failed to set Browser Dev Environment password',
],
];

$unknown_action_descriptions = [
Expand All @@ -263,6 +281,8 @@ private function getActionsOverviewContainerVars(): array
'disable_tunnel' => 'scissors',
'enable_public_dashboard' => 'ui-04',
'disable_public_dashboard' => 'ui-04',
'activate_browserdev' => 'button-play',
'deactivate_browserdev' => 'button-pause',
'unknown_action' => 'ui-04',
];

Expand Down
2 changes: 1 addition & 1 deletion src/src/Controller/RegistrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function register(Request $request, UserPasswordHasherInterface $password
);
}

return $this->render('registration/index.html.twig', [
return $this->render('pages/registration/index.html.twig', [
'registrationForm' => $form->createView(),
]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/src/Controller/SecurityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function login(AuthenticationUtils $authenticationUtils): Response
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();

return $this->render('security/login.html.twig', ['controller_title' => 'Login', 'controller_subtitle' => 'Access the dashboard', 'last_username' => $lastUsername, 'error' => $error]);
return $this->render('pages/security/login.html.twig', ['controller_title' => 'Login', 'controller_subtitle' => 'Access the dashboard', 'last_username' => $lastUsername, 'error' => $error]);
}

#[Route('/logout', name: 'app_logout')]
Expand Down
11 changes: 9 additions & 2 deletions src/src/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use App\Helper\EdgeAppsHelper;
use App\Helper\EdgeboxioApiConnector;
use App\Helper\ShellHelper;
use App\Helper\BrowserDevHelper;
use App\Helper\UpdatesHelper;
use App\Helper\SystemHelper;
use App\Helper\TunnelHelper;
Expand All @@ -33,6 +34,7 @@ class SettingsController extends BaseController
private EdgeAppsHelper $edgeAppsHelper;
private SystemHelper $systemHelper;
private ShellHelper $shellHelper;
private BrowserDevHelper $browserDevHelper;
private UpdatesHelper $updatesHelper;
private EntityManagerInterface $entityManager;
private TunnelHelper $tunnelHelper;
Expand Down Expand Up @@ -64,6 +66,7 @@ public function __construct(
EdgeAppsHelper $edgeAppsHelper,
SystemHelper $systemhelper,
ShellHelper $shellHelper,
BrowserDevHelper $browserDevHelper,
UpdatesHelper $updatesHelper,
EntityManagerInterface $entityManager,
DashboardHelper $dashboardHelper,
Expand All @@ -76,6 +79,7 @@ public function __construct(
$this->edgeAppsHelper = $edgeAppsHelper;
$this->systemHelper = $systemhelper;
$this->shellHelper = $shellHelper;
$this->browserDevHelper = $browserDevHelper;
$this->updatesHelper = $updatesHelper;
$this->entityManager = $entityManager;
$this->dashboardHelper = $dashboardHelper;
Expand Down Expand Up @@ -312,7 +316,9 @@ public function index(Request $request): Response

$updates_status = $this->updatesHelper->getUpdatesStatus();

return $this->render('settings/index.html.twig', [
$browserdev_status = $this->browserDevHelper->getBrowserDevStatus(true);

return $this->render('pages/settings/index.html.twig', [
'controller_title' => 'Settings',
'controller_subtitle' => 'Features & Security',
'alert' => $alert,
Expand All @@ -334,6 +340,7 @@ public function index(Request $request): Response
'dash_internet_url' => $dash_internet_url,
'dashboard_settings' => $this->dashboardHelper->getSettings(),
'updates_status' => $updates_status,
'browserdev_status' => $browserdev_status,
]);
}

Expand Down Expand Up @@ -378,7 +385,7 @@ public function action(string $action): Response
$this->entityManager->flush();
}

return $this->render('settings/action.html.twig', [
return $this->render('pages/settings/action.html.twig', [
'controller_title' => 'Settings - '.$controller_title,
'controller_subtitle' => 'Please wait...',
'framework_ready' => $framework_ready,
Expand Down
4 changes: 2 additions & 2 deletions src/src/Controller/StorageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function index(): Response
$storage_ready = true;
}

return $this->render('storage/index.html.twig', [
return $this->render('pages/storage/index.html.twig', [
'controller_title' => 'Storage',
'controller_subtitle' => 'Buckets & Drives',
'storage_ready' => $storage_ready,
Expand All @@ -45,7 +45,7 @@ public function index(): Response
#[Route('/storage/device/new', name: 'storage_device_new')]
public function storage_device_new(): Response
{
return $this->render('storage/device/new.html.twig', [
return $this->render('pages/storage/device/new.html.twig', [
'controller_title' => 'Storage',
'controller_subtitle' => 'Add new device',
'dashboard_settings' => $this->dashboardHelper->getSettings(),
Expand Down
21 changes: 15 additions & 6 deletions src/src/EventSubscriber/MiddlewareSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,26 @@ public function onKernelController(ControllerEvent $event): void
$run_middleware_instance = $attribute->newInstance();
$middleware = $run_middleware_instance;
}

$methodName = $middleware->name;

$firstMethodName = $middleware->name;
$otherMethodNames = $middleware->getExtras();

$methodNames = [$firstMethodName, ...$otherMethodNames];

$middleware_result = null;

if (method_exists($controller[0], $methodName)) {
$middleware_result = $controller[0]->$methodName();
foreach ($methodNames as $methodName) {
// If middleware result is not null, stop for loop
// If return of middleware is Response or RedirectResponse, return it
if ($middleware_result && ($middleware_result instanceof Response || $middleware_result instanceof RedirectResponse)) {
break;
}
if (method_exists($controller[0], $methodName)) {
$middleware_result = $controller[0]->$methodName();
}
}

// If return of middleware is Response or RedirectResponse, return it
if ($middleware_result && ($middleware_result instanceof Response || $middleware_result instanceof RedirectResonse)) {
if ($middleware_result) {
$event->setController(fn() => $middleware_result);
}
}
Expand Down
Loading

0 comments on commit f977560

Please sign in to comment.