Skip to content

Commit

Permalink
[v0.3] Version release
Browse files Browse the repository at this point in the history
  • Loading branch information
ksroga committed Jan 11, 2025
1 parent 3c82cf4 commit 207f4fd
Show file tree
Hide file tree
Showing 17 changed files with 47 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/symfony.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
chmod -R 775 var public/uploads
- name: Run PHPUnit Tests
run: vendor/bin/phpunit --testdox --colors=always --log-junit junit.xml --coverage-text --coverage-clover=coverage.xml
run: vendor/bin/phpunit ./src/Core/Tests/Unit/ --testdox --colors=always --log-junit junit.xml --coverage-text --coverage-clover=coverage.xml
env:
DATABASE_URL: 'mysql://test_user:test_password@127.0.0.1:3306/test_db'

Expand Down
2 changes: 0 additions & 2 deletions src/Core/Controller/API/ServerConfigurationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;

class ServerConfigurationController extends APIAbstractController
{
public function __construct(
private readonly ServerRepository $serverRepository,
private readonly ServerLogService $serverLogService,
private readonly TranslatorInterface $translator,
) {}

#[Route('/panel/api/server/{id}/startup/variable', name: 'server_startup_variable_update', methods: ['POST'])]
Expand Down
5 changes: 4 additions & 1 deletion src/Core/Controller/RegistrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
use App\Core\Security\UserAuthenticator;
use App\Core\Service\Authorization\RegistrationService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\UserAuthenticatorInterface;
use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

class RegistrationController extends AbstractController
Expand All @@ -24,7 +26,8 @@ public function __construct(
public function register(
Request $request,
UserAuthenticatorInterface $userAuthenticator,
UserAuthenticator $authenticator,
#[Autowire(service: 'App\Core\Security\UserAuthenticator')]
AuthenticatorInterface $authenticator,
): Response {
$user = new User();
$form = $this->createForm(RegistrationFormType::class, $user);
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Controller/ServerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function server(
throw $this->createNotFoundException();
}

/** @var Server $server */
/** @var ?Server $server */
$server = current($serverRepository->findBy(['pterodactylServerIdentifier' => $serverId]));
if (empty($server)) {
throw $this->createNotFoundException();
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Controller/StoreController.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function buy(
ServerService $serverService,
): Response {
$this->checkPermission();
$serverId = $request->request->getInt('server');
$serverId = $request->query->getString('server');
if (!empty($serverId)) {
$server = $serverService->getServer($serverId);
if (empty($server)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Core/DTO/ServerDataDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class ServerDataDTO
{
public function __construct(
public array $serverDetails,
public ServerDetailsDTO $serverDetails,
public array $pterodactylServer,
public array $dockerImages,
public array $pterodactylClientServer,
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Service/Mailer/BoughtConfirmationEmailService.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function sendBoughtConfirmationEmail(
'product' => $product,
'currency' => $this->settingService->getSetting(SettingEnum::INTERNAL_CURRENCY_NAME->value),
'server' => [
'ip' => $serverDetails['ip'],
'ip' => $serverDetails->ip,
'expiresAt' => $server->getExpiresAt()->format('Y-m-d H:i'),
],
'panel' => [
Expand All @@ -64,7 +64,7 @@ public function sendRenewConfirmationEmail(User $user, Product $product, Server
'product' => $product,
'currency' => $this->settingService->getSetting(SettingEnum::INTERNAL_CURRENCY_NAME->value),
'server' => [
'ip' => $serverDetails['ip'],
'ip' => $serverDetails->ip,
'expiresAt' => $server->getExpiresAt()->format('Y-m-d H:i'),
],
'panel' => [
Expand Down
6 changes: 2 additions & 4 deletions src/Core/Service/Pterodactyl/PterodactylAccountService.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@ public function __construct(
{
}

public function createPterodactylAccount(User $user, string $plainPassword): ?PterodactylUser
public function createPterodactylAccount(User $user, string $plainPassword): PterodactylUser
{
$createdPterodactylUser = $this->pterodactylService->getApi()->users->create([
return $this->pterodactylService->getApi()->users->create([
'email' => $user->getEmail(),
'username' => $this->usernameService->generateUsername($user->getEmail()),
'first_name' => $user->getName(),
'last_name' => $user->getSurname(),
'password' => $plainPassword,
]);

return $createdPterodactylUser ?? null;
}

public function deletePterodactylAccount(User $user): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ protected function getServerDetails(Server $server, array $include = []): array
{
$serverDetails = $this->pterodactylService->getApi()->servers->get($server->getPterodactylServerId(), [
'include' => $include,
]);
])?->toArray();

if (empty($serverDetails)) {
throw new \Exception('Server not found');
}

return $serverDetails->toArray();
return $serverDetails;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,17 @@ private function validateVariable(Server $server, array $serverDetails, array $s
$constraints = [];

foreach ($rules as $rule) {
if (str_contains($rule, ':')) {
$partedRules = explode(':', $rule);
$rule = $partedRules[0];
}

if (isset($ruleMap[$rule])) {
if (in_array($rule, ['string', 'numeric', 'boolean'], true)) {
$constraints[] = new $ruleMap[$rule](['type' => $rule]);
} else {
$constraints[] = new $ruleMap[$rule]();
}
$constraints[] = match ($rule) {
'string', 'numeric', 'boolean' => new $ruleMap[$rule](['type' => $rule]),
'regex' => new $ruleMap[$rule](['pattern' => $partedRules[1] ?? '']),
default => new $ruleMap[$rule]([]),
};
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function testRenewProductPageLoads(): void
$product = $this->createTestProduct($category);
$server = $this->createTestServer($user, $product);

$crawler = $this->client->request('GET', '/panel?routeName=store_server_renew&id=' . $server->getId());
$crawler = $this->client->request('GET', '/panel?routeName=store_server_renew&id=' . $server->getPterodactylServerIdentifier());

$this->assertResponseIsSuccessful();
$this->assertSelectorExists('.product-details');
Expand Down
26 changes: 16 additions & 10 deletions src/Core/Tests/Unit/Service/Server/ServerServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use PHPUnit\Framework\TestCase;
use Timdesm\PterodactylPhpApi\Managers\ServerManager;
use Timdesm\PterodactylPhpApi\PterodactylApi;
use Timdesm\PterodactylPhpApi\Resources\Egg;
use Timdesm\PterodactylPhpApi\Resources\Server as PterodactylServer;

class ServerServiceTest extends TestCase
Expand Down Expand Up @@ -43,24 +44,27 @@ public function testGetServerDetailsWithValidServer(): void
'port' => 25565,
]
],
'egg' => new Egg(['name' => 'Test Egg']),
],
],
];

$pterodactylServer = new PterodactylServer($pterodactylServerData, $pterodactylApi);
$pterodactylServer->set('name', 'Test Server');
$pterodactylServer->set('description', 'Test Description');

$pterodactylApi->servers = $this->createMock(ServerManager::class);
$pterodactylApi->servers
->method('get')
->with(123, ['include' => ['allocations']])
->with(123, ['include' => ['allocations', 'egg']])
->willReturn($pterodactylServer);

$result = $this->serverService->getServerDetails($server);

$this->assertNotNull($result);
$this->assertEquals('192.168.1.1:25565', $result['ip']);
$this->assertEquals(['memory' => 2048], $result['limits']);
$this->assertEquals(['databases' => 3], $result['feature-limits']);
$this->assertEquals('192.168.1.1:25565', $result->ip);
$this->assertEquals(['memory' => 2048], $result->limits);
$this->assertEquals(['databases' => 3], $result->featureLimits);
}

public function testGetServerDetailsWithInvalidServer(): void
Expand All @@ -74,7 +78,7 @@ public function testGetServerDetailsWithInvalidServer(): void
$pterodactylApi->servers = $this->createMock(ServerManager::class);
$pterodactylApi->servers
->method('get')
->with(123, ['include' => ['allocations']])
->with(123, ['include' => ['allocations', 'egg']])
->willReturn(new PterodactylServer([], $pterodactylApi));

$result = $this->serverService->getServerDetails($server);
Expand All @@ -85,21 +89,23 @@ public function testGetServerDetailsWithInvalidServer(): void
public function testGetServer(): void
{
$server = new Server();
$server->setPterodactylServerIdentifier(123);

$this->serverRepository
->method('find')
->with(123)
->method('findOneBy')
->with(['pterodactylServerIdentifier' => $server->getPterodactylServerIdentifier()])
->willReturn($server);

$result = $this->serverService->getServer(123);
$result = $this->serverService->getServer($server->getPterodactylServerIdentifier());

$this->assertSame($server, $result);
}

public function testGetServerNotFound(): void
{
$this->serverRepository
->method('find')
->with(123)
->method('findOneBy')
->with(['pterodactylServerIdentifier' => 123])
->willReturn(null);

$result = $this->serverService->getServer(123);
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Tests/Unit/Service/StoreServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function testGetActiveProductWithNonExistentProduct(): void
public function testPrepareProduct(): void
{
$product = $this->createMock(Product::class);
$product->expects($this->once())
$product->expects($this->exactly(2))
->method('getImagePath')
->willReturn('product1.jpg');

Expand Down
4 changes: 2 additions & 2 deletions templates/panel/login/login.html.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends ea is defined ? ea.templatePath('layout') : '@EasyAdmin/page/login_minimal.html.twig' %}
{% extends '@EasyAdmin/page/login_minimal.html.twig' %}

{% block body_class 'page-login' %}
{% block page_title %}{{ get_title() }} | {{ 'pteroca.login.title'|trans }}{% endblock %}
Expand Down Expand Up @@ -55,7 +55,7 @@
<input type="hidden" name="_csrf_token" value="{{ csrf_token(csrf_token_intention) }}">
{% endif %}

<input type="hidden" name="{{ target_path_parameter|default('_target_path') }}" value="{{ target_path|default(ea is defined ? path(ea.dashboardRouteName) : '/') }}" />
<input type="hidden" name="{{ target_path_parameter|default('_target_path') }}" value="/" />

<div class="form-group">
<label class="form-control-label required" for="username">{{ 'pteroca.login.email_address'|trans }}</label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</div>
</div>
<div class="col-8 offset-2">
<a href="{{ path('panel', { routeName: 'store_server_renew', id: server.id }) }}" class="btn btn-primary w-100">
<a href="{{ path('panel', { routeName: 'store_server_renew', id: server.pterodactylServerIdentifier }) }}" class="btn btn-primary w-100">
{{ 'pteroca.server.extend_server'|trans }}
</a>
</div>
Expand Down
8 changes: 0 additions & 8 deletions templates/panel/servers/components/server.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,6 @@
<strong>{{ 'pteroca.servers.cpu'|trans }}:</strong>
<span class="placeholder col-6 float-end mt-1 rounded-1" data-limits-cpu data-unit="%"></span>
</li>
<li class="list-group-item">
<strong>{{ 'pteroca.servers.databases'|trans }}:</strong>
<span class="placeholder col-6 float-end mt-1 rounded-1" data-feature-limits-databases></span>
</li>
<li class="list-group-item">
<strong>{{ 'pteroca.servers.backups'|trans }}:</strong>
<span class="placeholder col-6 float-end mt-1 rounded-1" data-feature-limits-backups></span>
</li>
<li class="list-group-item">
<strong>{{ 'pteroca.servers.valid_until'|trans }}:</strong>
<span class="col-6 float-end mt-1">{{ server.expiresAt|date('Y-m-d H:i') }}</span>
Expand Down
2 changes: 1 addition & 1 deletion templates/panel/store/renew.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
</div>
<div class="col-md-4">
<h2>{{ 'pteroca.renew.renew'|trans }}</h2>
<form action="{{ path('panel', { routeName: 'store_product_buy', id: server.id }) }}" method="post">
<form action="{{ path('panel', { routeName: 'store_product_buy', id: product.id }) }}&server={{ server.pterodactylServerIdentifier }}" method="post">
<input type="hidden" name="server" value="{{ server.id }}">
<div class="form-group">
<label for="duration">{{ 'pteroca.renew.period'|trans }}</label>
Expand Down

0 comments on commit 207f4fd

Please sign in to comment.