Skip to content

Commit

Permalink
Merge branch 'main' into feature/css-files-versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
ksroga committed Sep 9, 2024
2 parents 6805caa + f92da2d commit 33e90ef
Show file tree
Hide file tree
Showing 36 changed files with 77 additions and 73 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/symfony.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ jobs:
- name: Wait for MySQL to be ready
run: until mysqladmin ping -h127.0.0.1 -uroot -proot --silent; do sleep 1; done

- name: Create Test Database
run: php bin/console doctrine:database:create --if-not-exists --env=test
env:
DATABASE_URL: 'mysql://test_user:test_password@127.0.0.1:3306/test_db'

- name: Run Database Migrations
run: php bin/console doctrine:migrations:migrate --no-interaction --env=test
env:
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Controller/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

abstract class AbstractController extends SymfonyAbstractController
{
public function checkPermission(string $permission = UserRoleEnum::ROLE_USER->value): void
public function checkPermission(string $permission = UserRoleEnum::ROLE_USER->name): void
{
$user = $this->getUser();
if (empty($user)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Controller/Panel/CategoryCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function configureCrud(Crud $crud): Crud
return $crud
->setEntityLabelInSingular($this->translator->trans('pteroca.crud.category.category'))
->setEntityLabelInPlural($this->translator->trans('pteroca.crud.category.category'))
->setEntityPermission(UserRoleEnum::ROLE_ADMIN->value);
->setEntityPermission(UserRoleEnum::ROLE_ADMIN->name);
}

public function configureFilters(Filters $filters): Filters
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Controller/Panel/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function configureMenuItems(): iterable
yield MenuItem::linkToRoute($this->translator->trans('pteroca.crud.menu.shop'), 'fa fa-shopping-cart', 'store');
yield MenuItem::linkToRoute($this->translator->trans('pteroca.crud.menu.wallet'), 'fa fa-wallet', 'recharge_balance');

if ($this->isGranted(UserRoleEnum::ROLE_ADMIN->value)) {
if ($this->isGranted(UserRoleEnum::ROLE_ADMIN->name)) {
yield MenuItem::section($this->translator->trans('pteroca.crud.menu.administration'));
yield MenuItem::linkToCrud($this->translator->trans('pteroca.crud.menu.categories'), 'fa fa-list', Category::class);
yield MenuItem::linkToCrud($this->translator->trans('pteroca.crud.menu.products'), 'fa fa-sliders-h', Product::class);
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Controller/Panel/LogCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function configureCrud(Crud $crud): Crud
return $crud
->setEntityLabelInSingular($this->translator->trans('pteroca.crud.log.log'))
->setEntityLabelInPlural($this->translator->trans('pteroca.crud.log.logs'))
->setEntityPermission(UserRoleEnum::ROLE_ADMIN->value)
->setEntityPermission(UserRoleEnum::ROLE_ADMIN->name)
->setDefaultSort(['createdAt' => 'DESC'])
->showEntityActionsInlined();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Controller/Panel/PaymentCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function configureCrud(Crud $crud): Crud
return $crud
->setEntityLabelInSingular($this->translator->trans('pteroca.crud.payment.payment'))
->setEntityLabelInPlural($this->translator->trans('pteroca.crud.payment.payments'))
->setEntityPermission(UserRoleEnum::ROLE_ADMIN->value)
->setEntityPermission(UserRoleEnum::ROLE_ADMIN->name)
->setDefaultSort(['createdAt' => 'DESC'])
->showEntityActionsInlined();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Controller/Panel/ProductCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function configureCrud(Crud $crud): Crud
->setEntityLabelInSingular($this->translator->trans('pteroca.crud.product.product'))
->setEntityLabelInPlural($this->translator->trans('pteroca.crud.product.products'))
->setDefaultSort(['createdAt' => 'DESC'])
->setEntityPermission(UserRoleEnum::ROLE_ADMIN->value);
->setEntityPermission(UserRoleEnum::ROLE_ADMIN->name);
}

public function configureFilters(Filters $filters): Filters
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Controller/Panel/ServerCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function configureCrud(Crud $crud): Crud
return $crud
->setEntityLabelInSingular($this->translator->trans('pteroca.crud.server.server'))
->setEntityLabelInPlural($this->translator->trans('pteroca.crud.server.servers'))
->setEntityPermission(UserRoleEnum::ROLE_ADMIN->value)
->setEntityPermission(UserRoleEnum::ROLE_ADMIN->name)
->setDefaultSort(['createdAt' => 'DESC']);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Core/Controller/Panel/SettingCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function configureCrud(Crud $crud): Crud
return $crud
->setEntityLabelInSingular($this->translator->trans('pteroca.crud.setting.setting'))
->setEntityLabelInPlural($this->translator->trans('pteroca.crud.setting.settings'))
->setEntityPermission(UserRoleEnum::ROLE_ADMIN->value);
->setEntityPermission(UserRoleEnum::ROLE_ADMIN->name);
}

public function configureFilters(Filters $filters): Filters
Expand Down
6 changes: 3 additions & 3 deletions src/Core/Controller/Panel/UserCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public function configureFields(string $pageName): iterable
TextField::new('email', $this->translator->trans('pteroca.crud.user.email')),
ChoiceField::new('roles', $this->translator->trans('pteroca.crud.user.roles'))
->setChoices([
'User' => UserRoleEnum::ROLE_USER->value,
'Admin' => UserRoleEnum::ROLE_ADMIN->value,
'User' => UserRoleEnum::ROLE_USER->name,
'Admin' => UserRoleEnum::ROLE_ADMIN->name,
])
->allowMultipleChoices(),
NumberField::new('balance', $this->translator->trans('pteroca.crud.user.balance'))
Expand Down Expand Up @@ -92,7 +92,7 @@ public function configureCrud(Crud $crud): Crud
return $crud
->setEntityLabelInSingular($this->translator->trans('pteroca.crud.user.user'))
->setEntityLabelInPlural($this->translator->trans('pteroca.crud.user.users'))
->setEntityPermission(UserRoleEnum::ROLE_ADMIN->value)
->setEntityPermission(UserRoleEnum::ROLE_ADMIN->name)
->setDefaultSort(['createdAt' => 'DESC']);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Core/Controller/UserAccountCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function configureCrud(Crud $crud): Crud
return $crud
->setEntityLabelInSingular($this->translator->trans('pteroca.dashboard.account_settings'))
->setEntityLabelInPlural($this->translator->trans('pteroca.dashboard.account_settings'))
->setEntityPermission(UserRoleEnum::ROLE_USER->value);
->setEntityPermission(UserRoleEnum::ROLE_USER->name);
}

public function createIndexQueryBuilder(SearchDto $searchDto, EntityDto $entityDto, FieldCollection $fields, FilterCollection $filters): QueryBuilder
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function getRoles(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = UserRoleEnum::ROLE_USER->value;
$roles[] = UserRoleEnum::ROLE_USER->name;

return array_unique($roles);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Entity/UserAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function getRoles(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = UserRoleEnum::ROLE_USER->value;
$roles[] = UserRoleEnum::ROLE_USER->name;

return array_unique($roles);
}
Expand Down
24 changes: 12 additions & 12 deletions src/Core/Enum/LogActionEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@

namespace App\Core\Enum;

enum LogActionEnum: string
enum LogActionEnum
{
case LOGIN = 'login';
case LOGIN;

case LOGOUT = 'logout';
case LOGOUT;

case CREATE_PAYMENT = 'create_payment';
case CREATE_PAYMENT;

case BOUGHT_BALANCE = 'bought_balance';
case BOUGHT_BALANCE;

case BOUGHT_SERVER = 'bought_server';
case BOUGHT_SERVER;

case RENEW_SERVER = 'renew_server';
case RENEW_SERVER;

case ENTITY_ADD = 'entity_add';
case ENTITY_ADD;

case ENTITY_EDIT = 'entity_edit';
case ENTITY_EDIT;

case ENTITY_DELETE = 'entity_delete';
case ENTITY_DELETE;

case USER_REGISTERED = 'user_registered';
case USER_REGISTERED;

case USER_VERIFY_EMAIL = 'user_verify_email';
case USER_VERIFY_EMAIL;
}
6 changes: 3 additions & 3 deletions src/Core/Enum/UserRoleEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace App\Core\Enum;

enum UserRoleEnum: string
enum UserRoleEnum
{
case ROLE_USER = 'ROLE_USER';
case ROLE_USER;

case ROLE_ADMIN = 'ROLE_ADMIN';
case ROLE_ADMIN;
}
2 changes: 1 addition & 1 deletion src/Core/Handler/CreateNewUserHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function handle(): void
$user = (new User())
->setEmail($this->userEmail)
->setPassword('')
->setRoles([UserRoleEnum::ROLE_USER->value, UserRoleEnum::ROLE_ADMIN->value])
->setRoles([UserRoleEnum::ROLE_USER->name, UserRoleEnum::ROLE_ADMIN->name])
->setBalance(0)
->setName('Admin')
->setSurname('Admin');
Expand Down
1 change: 1 addition & 0 deletions src/Core/Resources/translations/messages.cn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pteroca:
email_required: '电子邮件地址是必填项。'
invalid_email: '电子邮件地址无效。'
email_already_exists: '该电子邮件地址的账户已存在。'
already_have_account: '已经有账户?登录!'

recovery:
title: '找回密码'
Expand Down
1 change: 1 addition & 0 deletions src/Core/Resources/translations/messages.de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pteroca:
email_required: 'E-Mail-Adresse ist erforderlich.'
invalid_email: 'Ungültige E-Mail-Adresse.'
email_already_exists: 'Ein Konto mit dieser E-Mail-Adresse existiert bereits.'
already_have_account: 'Bereits registriert? Jetzt einloggen!'

recovery:
title: 'Passwort zurücksetzen'
Expand Down
1 change: 1 addition & 0 deletions src/Core/Resources/translations/messages.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pteroca:
email_required: 'Email address is required.'
invalid_email: 'Email address is invalid.'
email_already_exists: 'An account with that email address already exists.'
already_have_account: 'Already have an account? Sign in now!'

recovery:
title: 'Password Recovery'
Expand Down
1 change: 1 addition & 0 deletions src/Core/Resources/translations/messages.es.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pteroca:
email_required: 'Se requiere una dirección de correo electrónico.'
invalid_email: 'Dirección de correo electrónico no válida.'
email_already_exists: 'Ya existe una cuenta con esta dirección de correo electrónico.'
already_have_account: '¿Ya tienes una cuenta? ¡Inicia sesión!'

recovery:
title: 'Recuperar contraseña'
Expand Down
1 change: 1 addition & 0 deletions src/Core/Resources/translations/messages.fr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pteroca:
email_required: 'L’adresse e-mail est requise.'
invalid_email: 'Adresse e-mail invalide.'
email_already_exists: 'Un compte avec cette adresse e-mail existe déjà.'
already_have_account: 'Vous avez déjà un compte ? Connectez-vous !'

recovery:
title: 'Réinitialisation du mot de passe'
Expand Down
1 change: 1 addition & 0 deletions src/Core/Resources/translations/messages.it.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pteroca:
email_required: 'L’indirizzo e-mail è obbligatorio.'
invalid_email: 'Indirizzo e-mail non valido.'
email_already_exists: 'Esiste già un account con questo indirizzo e-mail.'
already_have_account: 'Hai già un account? Accedi!'

recovery:
title: 'Recupera password'
Expand Down
1 change: 1 addition & 0 deletions src/Core/Resources/translations/messages.pl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pteroca:
email_required: 'Adres e-mail jest wymagany.'
invalid_email: 'Nieprawidłowy adres e-mail.'
email_already_exists: 'Konto o podanym adresie e-mail już istnieje.'
already_have_account: 'Masz już konto? Zaloguj się!'

recovery:
title: 'Przypomnij hasło'
Expand Down
1 change: 1 addition & 0 deletions src/Core/Resources/translations/messages.pt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pteroca:
email_required: 'O endereço de e-mail é obrigatório.'
invalid_email: 'Endereço de e-mail inválido.'
email_already_exists: 'Já existe uma conta com este endereço de e-mail.'
already_have_account: 'Já tem uma conta? Faça login!'

recovery:
title: 'Recuperar senha'
Expand Down
1 change: 1 addition & 0 deletions src/Core/Resources/translations/messages.ua.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pteroca:
email_required: 'Електронна пошта обов’язкова.'
invalid_email: 'Неправильна електронна пошта.'
email_already_exists: 'Обліковий запис з такою електронною поштою вже існує.'
already_have_account: 'Вже є обліковий запис? Увійдіть!'

recovery:
title: 'Відновити пароль'
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Service/Authorization/RegistrationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function registerUser(User $user, string $plainPassword): User
$user->setIsVerified(false);
$pterodactylAccount = $this->createPterodactylAccount($user, $plainPassword);
$user->setPterodactylUserId($pterodactylAccount->id ?? null);
$user->setRoles([UserRoleEnum::ROLE_USER->value]);
$user->setRoles([UserRoleEnum::ROLE_USER->name]);
$this->userRepository->save($user);
$this->logService->logAction($user, LogActionEnum::USER_REGISTERED);
$this->sendRegistrationEmail($user);
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Service/LogService.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __construct(
public function logAction(User $user, LogActionEnum $action, array $details = []): void
{
$newLog = (new Log())
->setActionId($action->value)
->setActionId(strtolower($action->name))
->setUser($user)
->setDetails(json_encode($details))
->setIpAddress($this->ipAddressProviderService->getIpAddress() ?? 'Unknown');
Expand Down
11 changes: 5 additions & 6 deletions src/Core/Tests/Integration/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Core\Tests\Integration;

use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Tools\SchemaTool;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

Expand All @@ -26,11 +25,11 @@ protected function setUp(): void

protected function resetDatabase(): void
{
$metadata = $this->entityManager->getMetadataFactory()->getAllMetadata();
$schemaTool = new SchemaTool($this->entityManager);

$schemaTool->dropSchema($metadata);
$schemaTool->createSchema($metadata);
$this->entityManager->getConnection()->executeQuery('SET FOREIGN_KEY_CHECKS = 0');
$this->entityManager->getConnection()->executeQuery('TRUNCATE TABLE server');
$this->entityManager->getConnection()->executeQuery('TRUNCATE TABLE user');
$this->entityManager->getConnection()->executeQuery('SET FOREIGN_KEY_CHECKS = 1');
$this->entityManager->clear();
}

protected function tearDown(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function testCreateUser(): void
'User[plainPassword]' => 'testpassword123',
'User[name]' => 'Test',
'User[surname]' => 'User',
'User[roles]' => [UserRoleEnum::ROLE_USER->value],
'User[roles]' => [UserRoleEnum::ROLE_USER->name],
'User[balance]' => '100.00',
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function testRegisterUser(): void

$this->assertSame($hashedPassword, $user->getPassword());
$this->assertFalse($user->isVerified());
$this->assertSame([UserRoleEnum::ROLE_USER->value], $user->getRoles());
$this->assertSame([UserRoleEnum::ROLE_USER->name], $user->getRoles());
$this->assertSame($user, $result);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Core/Tests/Unit/Service/LogServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function testLogAction(): void
->method('save')
->with($this->callback(function (Log $log) use ($user, $action, $details) {
return $log->getUser() === $user &&
$log->getActionId() === $action->value &&
$log->getActionId() === strtolower($action->name) &&
$log->getDetails() === json_encode($details) &&
$log->getIpAddress() === '127.0.0.1';
}));
Expand All @@ -64,7 +64,7 @@ public function testLogActionWithUnknownIp(): void
->method('save')
->with($this->callback(function (Log $log) use ($user, $action) {
return $log->getUser() === $user &&
$log->getActionId() === $action->value &&
$log->getActionId() === strtolower($action->name) &&
$log->getIpAddress() === 'Unknown';
}));

Expand Down
6 changes: 6 additions & 0 deletions templates/panel/registration/register.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@
<button type="submit" name="register-submit" class="btn btn-lg btn-block">{{ 'pteroca.register.submit'|trans }}</button>
</div>
{{ form_end(registrationForm) }}

<div class="text-center small">
<a href="{{ path('app_login') }}">
{{ 'pteroca.register.already_have_account'|trans }}
</a>
</div>
</section>
<div class="col-12 text-center mt-2 powered-by">
Powered by <a href="https://pteroca.com" target="_blank">Pteroca v{{ get_app_version() }}</a> &copy; {{ 'now'|date('Y') }}
Expand Down
10 changes: 10 additions & 0 deletions templates/panel/store/components/category.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<div class="card">
<a href="{{ path('panel', { routeName: 'store_category', id: category.id }) }}">
<img src="{{ category.imagePath ?? asset('/assets/img/placeholders/300x150.png') }}" class="card-img-top" alt="{{ category.name }}">
</a>
<div class="card-body">
<h5 class="card-title">{{ category.name }}</h5>
<p class="card-text">{{ category.description }}</p>
<a href="{{ path('panel', { routeName: 'store_category', id: category.id }) }}" class="btn btn-primary">{{ 'pteroca.store.show_offer'|trans }}</a>
</div>
</div>
8 changes: 8 additions & 0 deletions templates/panel/store/components/product.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div class="card">
<img src="{{ product.imagePath ?? asset('/assets/img/placeholders/300x150.png') }}" class="card-img-top" alt="{{ product.name }}">
<div class="card-body">
<h5 class="card-title">{{ product.name }}</h5>
<p class="card-text">{{ product.description }}</p>
<a href="{{ path('panel', { routeName: 'store_product', id: product.id }) }}" class="btn btn-primary w-100">{{ 'pteroca.store.order'|trans }}</a>
</div>
</div>
Loading

0 comments on commit 33e90ef

Please sign in to comment.