Skip to content

Commit

Permalink
Product Installer
Browse files Browse the repository at this point in the history
------------------------------------

- Update routes
  • Loading branch information
zoglo committed Jun 28, 2024
1 parent d7fdf25 commit 071761c
Show file tree
Hide file tree
Showing 18 changed files with 245 additions and 19 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
},
"extra": {
"branch-alias": {
"dev-main": "0.1.x-dev"
"dev-main": "1.x-dev"
},
"contao-manager-plugin": "Oveleon\\ProductInstaller\\ContaoManager\\Plugin"
}
Expand Down
13 changes: 12 additions & 1 deletion src/Controller/API/Composer/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

namespace Oveleon\ProductInstaller\Controller\API\Composer;

use Contao\BackendUser;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Security;

/**
* Class to write the "repositories" branch to the composer file.
Expand All @@ -20,7 +23,8 @@ class Repository
{
public function __construct(
private readonly Composer $composer,
private readonly RequestStack $requestStack
private readonly RequestStack $requestStack,
private readonly Security $security,
){}

#[Route('/set',
Expand All @@ -29,6 +33,13 @@ public function __construct(
)]
public function set(): JsonResponse
{
$user = $this->security->getUser();

if (!$user instanceof BackendUser || !$user->isAdmin)
{
return new JsonResponse([], Response::HTTP_UNAUTHORIZED);
}

$request = $this->requestStack->getCurrentRequest();
$hasChanges = false;

Expand Down
12 changes: 11 additions & 1 deletion src/Controller/API/ContaoManager/Authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace Oveleon\ProductInstaller\Controller\API\ContaoManager;

use Contao\BackendUser;
use Oveleon\ProductInstaller\ContaoManagerFile;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Security;

/**
* Class to handle authentication with the Contao Manager.
Expand All @@ -20,11 +22,19 @@ class Authentication
{
public function __construct(
private readonly ContaoManagerFile $managerFile,
private readonly RequestStack $requestStack
private readonly RequestStack $requestStack,
private readonly Security $security,
){}

public function __invoke(): void
{
$user = $this->security->getUser();

if (!$user instanceof BackendUser || !$user->isAdmin)
{
return;
}

$request = (object) $this->requestStack->getCurrentRequest()->toArray();

if(!$request->token)
Expand Down
40 changes: 39 additions & 1 deletion src/Controller/API/ContaoManager/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

namespace Oveleon\ProductInstaller\Controller\API\ContaoManager;

use Contao\BackendUser;
use Doctrine\DBAL\Exception;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Security;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

Expand All @@ -25,7 +27,8 @@ class Database
public function __construct(
private readonly ContaoManager $contaoManager,
private readonly TranslatorInterface $translator,
private readonly RequestStack $requestStack
private readonly RequestStack $requestStack,
private readonly Security $security,
){}

#[Route('/check',
Expand All @@ -34,6 +37,13 @@ public function __construct(
)]
public function check(): JsonResponse
{
$user = $this->security->getUser();

if (!$user instanceof BackendUser || !$user->isAdmin)
{
return new JsonResponse([], Response::HTTP_UNAUTHORIZED);
}

try {
$response = $this->contaoManager->call(
'server/database'
Expand Down Expand Up @@ -87,6 +97,13 @@ public function check(): JsonResponse
)]
public function migrateStatus(): JsonResponse
{
$user = $this->security->getUser();

if (!$user instanceof BackendUser || !$user->isAdmin)
{
return new JsonResponse([], Response::HTTP_UNAUTHORIZED);
}

try {
$response = $this->contaoManager->call(
'contao/database-migration'
Expand Down Expand Up @@ -128,6 +145,13 @@ public function migrateStatus(): JsonResponse
)]
public function createMigrate(): JsonResponse
{
$user = $this->security->getUser();

if (!$user instanceof BackendUser || !$user->isAdmin)
{
return new JsonResponse([], Response::HTTP_UNAUTHORIZED);
}

try {
$response = $this->contaoManager->call(
'contao/database-migration',
Expand Down Expand Up @@ -177,6 +201,13 @@ public function createMigrate(): JsonResponse
)]
public function startMigrate(): JsonResponse
{
$user = $this->security->getUser();

if (!$user instanceof BackendUser || !$user->isAdmin)
{
return new JsonResponse([], Response::HTTP_UNAUTHORIZED);
}

$request = $this->requestStack->getCurrentRequest();
$parameter = $request->toArray();

Expand Down Expand Up @@ -233,6 +264,13 @@ public function startMigrate(): JsonResponse
)]
public function deleteMigrate(): JsonResponse
{
$user = $this->security->getUser();

if (!$user instanceof BackendUser || !$user->isAdmin)
{
return new JsonResponse([], Response::HTTP_UNAUTHORIZED);
}

// Get status after creating
$this->contaoManager->call(
'contao/database-migration',
Expand Down
12 changes: 11 additions & 1 deletion src/Controller/API/ContaoManager/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Oveleon\ProductInstaller\Controller\API\ContaoManager;

use Contao\BackendUser;
use Contao\System;
use Doctrine\DBAL\Exception;
use Symfony\Component\HttpFoundation\JsonResponse;
Expand All @@ -10,6 +11,7 @@
use Symfony\Component\Mime\Part\Multipart\FormDataPart;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Security;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

Expand All @@ -28,7 +30,8 @@ class Package
public function __construct(
private readonly ContaoManager $contaoManager,
private readonly TranslatorInterface $translator,
private readonly RequestStack $requestStack
private readonly RequestStack $requestStack,
private readonly Security $security,
){}

/**
Expand All @@ -41,6 +44,13 @@ public function __construct(
)]
public function installPackage(): JsonResponse
{
$user = $this->security->getUser();

if (!$user instanceof BackendUser || !$user->isAdmin)
{
return new JsonResponse([], Response::HTTP_UNAUTHORIZED);
}

$request = $this->requestStack->getCurrentRequest();
$root = System::getContainer()->getParameter('kernel.project_dir');

Expand Down
13 changes: 12 additions & 1 deletion src/Controller/API/ContaoManager/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

namespace Oveleon\ProductInstaller\Controller\API\ContaoManager;

use Contao\BackendUser;
use Doctrine\DBAL\Exception;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\Annotation\Route;
Expand Down Expand Up @@ -34,7 +37,8 @@ public function __construct(
private readonly ContaoManager $contaoManager,
private readonly RouterInterface $router,
private readonly TranslatorInterface $translator,
private readonly RequestStack $requestStack
private readonly RequestStack $requestStack,
private readonly Security $security,
){}

/**
Expand All @@ -43,6 +47,13 @@ public function __construct(
*/
public function __invoke(): JsonResponse
{
$user = $this->security->getUser();

if (!$user instanceof BackendUser || !$user->isAdmin)
{
return new JsonResponse([], Response::HTTP_UNAUTHORIZED);
}

$request = $this->requestStack->getCurrentRequest();

// Check if the manager is installed
Expand Down
33 changes: 32 additions & 1 deletion src/Controller/API/ContaoManager/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

namespace Oveleon\ProductInstaller\Controller\API\ContaoManager;

use Contao\BackendUser;
use Doctrine\DBAL\Exception;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Security;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
Expand All @@ -29,7 +31,8 @@ class Task
public function __construct(
private readonly ContaoManager $contaoManager,
private readonly TranslatorInterface $translator,
private readonly RequestStack $requestStack
private readonly RequestStack $requestStack,
private readonly Security $security,
){}

#[Route('/set',
Expand All @@ -38,6 +41,13 @@ public function __construct(
)]
public function set(): JsonResponse
{
$user = $this->security->getUser();

if (!$user instanceof BackendUser || !$user->isAdmin)
{
return new JsonResponse([], Response::HTTP_UNAUTHORIZED);
}

$request = $this->requestStack->getCurrentRequest();
$tasks = $request->toArray();

Expand Down Expand Up @@ -110,6 +120,13 @@ public function set(): JsonResponse
)]
public function get(): JsonResponse
{
$user = $this->security->getUser();

if (!$user instanceof BackendUser || !$user->isAdmin)
{
return new JsonResponse([], Response::HTTP_UNAUTHORIZED);
}

try {
$response = $this->contaoManager->call('task');
$status = $response->getStatusCode();
Expand Down Expand Up @@ -139,6 +156,13 @@ public function get(): JsonResponse
)]
public function stop(): JsonResponse
{
$user = $this->security->getUser();

if (!$user instanceof BackendUser || !$user->isAdmin)
{
return new JsonResponse([], Response::HTTP_UNAUTHORIZED);
}

try {
$response = $this->contaoManager->call('task', 'PATCH');
$status = $response->getStatusCode();
Expand Down Expand Up @@ -168,6 +192,13 @@ public function stop(): JsonResponse
)]
public function delete(): JsonResponse
{
$user = $this->security->getUser();

if (!$user instanceof BackendUser || !$user->isAdmin)
{
return new JsonResponse([], Response::HTTP_UNAUTHORIZED);
}

try {
$response = $this->contaoManager->call('task', 'DELETE');
$status = $response->getStatusCode();
Expand Down
12 changes: 11 additions & 1 deletion src/Controller/API/Download/DownloadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Oveleon\ProductInstaller\Controller\API\Download;

use Contao\BackendUser;
use Contao\CoreBundle\ContaoCoreBundle;
use Contao\System;
use Exception;
Expand All @@ -12,6 +13,7 @@
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Security;
use Symfony\Contracts\Translation\TranslatorInterface;

/**
Expand All @@ -31,7 +33,8 @@ public function __construct(
private readonly FileDownloader $fileDownloader,
private readonly RepositoryDownloader $githubDownloader,
private readonly TranslatorInterface $translator,
private readonly ConnectorUtil $connectorUtil
private readonly ConnectorUtil $connectorUtil,
private readonly Security $security,
){}

/**
Expand All @@ -57,6 +60,13 @@ public function __construct(
*/
public function __invoke(): Response
{
$user = $this->security->getUser();

if (!$user instanceof BackendUser || !$user->isAdmin)
{
return new JsonResponse([], Response::HTTP_UNAUTHORIZED);
}

$requestStack = $this->requestStack->getCurrentRequest();
$request = (object) $requestStack->toArray();

Expand Down
Loading

0 comments on commit 071761c

Please sign in to comment.