Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable symfony layout feature flag by default #35180

Merged
merged 4 commits into from Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/integration.yml
Expand Up @@ -69,8 +69,10 @@ jobs:
if: ${{ startsWith(matrix.php, '8.') }}
run: composer update -w --ignore-platform-reqs --no-interaction phpunit/phpunit

- name: Build theme assets
run: make front-classic
# Front assets are needed for the theme to be installed and image types to be inserted in DB, admin assets required especially in Symfony layout
# because some built files (like preload.html.twig) are included and cause errors when absent
- name: Build all assets
run: make assets

- name: Change MySQL authentication method
run: mysql -h127.0.0.1 -uroot -ppassword -e "ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'password'; FLUSH PRIVILEGES;"
Expand Down
2 changes: 1 addition & 1 deletion install-dev/data/xml/feature_flag.xml
Expand Up @@ -21,7 +21,7 @@
<feature_flag id="permission" name="permission" type="env,dotenv,db" label_wording="Permissions" label_domain="Admin.Advparameters.Feature" description_wording="Enable / Disable the migrated permissions page." description_domain="Admin.Advparameters.Help" state="0" stability="beta" />
<feature_flag id="tax_rules_group" name="tax_rules_group" type="env,dotenv,db" label_wording="Tax rule groups" label_domain="Admin.Advparameters.Feature" description_wording="Enable / Disable the migrated tax rules page." description_domain="Admin.Advparameters.Help" state="0" stability="beta" />
<feature_flag id="customer_threads" name="customer_threads" type="env,dotenv,db" label_wording="Customer threads" label_domain="Admin.Advparameters.Feature" description_wording="Enable / Disable the migrated customer threads page." description_domain="Admin.Advparameters.Help" state="0" stability="beta" />
<feature_flag id="symfony_layout" name="symfony_layout" type="env,query,dotenv,db" label_wording="Symfony layout" label_domain="Admin.Advparameters.Feature" description_wording="Enable / Disable symfony layout (in opposition to legacy layout)." description_domain="Admin.Advparameters.Help" state="0" stability="beta" />
<feature_flag id="symfony_layout" name="symfony_layout" type="env,query,dotenv,db" label_wording="Symfony layout" label_domain="Admin.Advparameters.Feature" description_wording="Enable / Disable symfony layout (in opposition to legacy layout)." description_domain="Admin.Advparameters.Help" state="1" stability="beta" />
<feature_flag id="front_container_v2" name="front_container_v2" type="env,dotenv,db" label_wording="New front container" label_domain="Admin.Advparameters.Feature" description_wording="Enable / Disable the new front container." description_domain="Admin.Advparameters.Help" state="0" stability="beta" />
</entities>
</entity_feature_flag>
Expand Up @@ -31,6 +31,8 @@
use PrestaShop\PrestaShop\Adapter\LegacyContext;
use PrestaShop\PrestaShop\Core\Context\EmployeeContextBuilder;
use PrestaShopBundle\EventListener\ExternalApiTrait;
use PrestaShopBundle\Security\Admin\Employee;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\HttpKernel\Event\RequestEvent;

/**
Expand All @@ -42,7 +44,8 @@ class EmployeeContextListener

public function __construct(
private readonly EmployeeContextBuilder $employeeContextBuilder,
private readonly LegacyContext $legacyContext
private readonly LegacyContext $legacyContext,
private readonly Security $security,
) {
}

Expand All @@ -54,6 +57,8 @@ public function onKernelRequest(RequestEvent $event): void

if (!empty($this->legacyContext->getContext()->cookie->id_employee)) {
$this->employeeContextBuilder->setEmployeeId((int) $this->legacyContext->getContext()->cookie->id_employee);
} elseif ($this->security->getUser() instanceof Employee) {
$this->employeeContextBuilder->setEmployeeId($this->security->getUser()->getId());
}
}
}
Expand Up @@ -9,15 +9,15 @@
<title>{% if this.metaTitle %}{{ this.metaTitle }} • {% endif %}{{ this.shopName }}</title>

<script type="text/javascript">
var help_class_name = '{{ this.controllerName|e('js') }}';
var iso_user = '{{ this.isoUser|e('js') }}';
var help_class_name = '{{ this.controllerName }}';
var iso_user = '{{ this.isoUser }}';
var lang_is_rtl = '{{ this.langIsRtl|intCast }}';
var full_language_code = '{{ this.fullLanguageCode|e('js') }}';
var full_cldr_language_code = '{{ this.fullCldrLanguageCode|e('js') }}';
var country_iso_code = '{{ this.countryIsoCode|e('js') }}';
var _PS_VERSION_ = '{{ this.psVersion|e('js') }}';
var full_language_code = '{{ this.fullLanguageCode }}';
var full_cldr_language_code = '{{ this.fullCldrLanguageCode }}';
var country_iso_code = '{{ this.countryIsoCode }}';
var _PS_VERSION_ = '{{ this.psVersion }}';
var roundMode = {{ this.roundMode|intCast }};
var youEditFieldFor = '{{ this.editForLabel|e('js') }}';
var youEditFieldFor = '{{ this.editForLabel }}';
var new_order_msg = '{{ 'A new order has been placed on your store.'|trans({}, 'Admin.Navigation.Header') }}';
var order_number_msg = '{{ 'Order number:'|trans({}, 'Admin.Navigation.Header') }} ';
var total_msg = '{{ 'Total:'|trans({}, 'Admin.Global') }} ';
Expand All @@ -27,14 +27,14 @@
var customer_name_msg = '{{ 'Customer name:'|trans({}, 'Admin.Navigation.Header') }} ';
var new_msg = '{{ 'A new message was posted on your store.'|trans({}, 'Admin.Navigation.Header') }}';
var see_msg = '{{ 'Read this message'|trans({}, 'Admin.Navigation.Header') }}';
var token = '{{ this.legacyToken|e('js') }}';
var currentIndex = '{{ this.currentIndex|e('js') }}';
var employee_token = '{{ this.employeeToken|e('js') }}';
var token = '{{ this.legacyToken }}';
var currentIndex = '{{ this.currentIndex }}';
var employee_token = '{{ this.employeeToken }}';
var choose_language_translate = '{{ 'Choose language:'|trans({}, 'Admin.Actions') }}';
var default_language = '{{ this.defaultLanguage|intCast }}';
var admin_modules_link = '{{ path('admin_module_manage')|e('js')}}';
var admin_notification_get_link = '{{ path('admin_common_notifications')|e('js') }}';
var admin_notification_push_link = adminNotificationPushLink = '{{ path('admin_common_notifications_ack')|e('js') }}';
var admin_modules_link = '{{ path('admin_module_manage')}}';
var admin_notification_get_link = '{{ path('admin_common_notifications') }}';
var admin_notification_push_link = adminNotificationPushLink = '{{ path('admin_common_notifications_ack') }}';
var update_success_msg = '{{ 'Update successful'|trans({}, 'Admin.Notifications.Success') }}';
var search_product_msg = '{{ 'Search for a product'|trans({}, 'Admin.Orderscustomers.Feature') }}';
</script>
Expand Down
Expand Up @@ -33,15 +33,15 @@
<title>{% if this.metaTitle %}{{ this.metaTitle }} • {% endif %}{{ this.shopName }}</title>

<script type="text/javascript">
var help_class_name = '{{ this.controllerName|e('js') }}';
var iso_user = '{{ this.isoUser|e('js') }}';
var help_class_name = '{{ this.controllerName }}';
var iso_user = '{{ this.isoUser }}';
var lang_is_rtl = '{{ this.langIsRtl|intCast }}';
var full_language_code = '{{ this.fullLanguageCode|e('js') }}';
var full_cldr_language_code = '{{ this.fullCldrLanguageCode|e('js') }}';
var country_iso_code = '{{ this.countryIsoCode|e('js') }}';
var _PS_VERSION_ = '{{ this.psVersion|e('js') }}';
var full_language_code = '{{ this.fullLanguageCode }}';
var full_cldr_language_code = '{{ this.fullCldrLanguageCode }}';
var country_iso_code = '{{ this.countryIsoCode }}';
var _PS_VERSION_ = '{{ this.psVersion }}';
var roundMode = {{ this.roundMode|intCast }};
var youEditFieldFor = '{{ this.editForLabel|e('js') }}';
var youEditFieldFor = '{{ this.editForLabel }}';
var new_order_msg = '{{ 'A new order has been placed on your store.'|trans({}, 'Admin.Navigation.Header') }}';
var order_number_msg = '{{ 'Order number:'|trans({}, 'Admin.Navigation.Header') }} ';
var total_msg = '{{ 'Total:'|trans({}, 'Admin.Global') }} ';
Expand All @@ -51,17 +51,17 @@
var customer_name_msg = '{{ 'Customer name:'|trans({}, 'Admin.Navigation.Header') }} ';
var new_msg = '{{ 'A new message was posted on your store.'|trans({}, 'Admin.Navigation.Header') }}';
var see_msg = '{{ 'Read this message'|trans({}, 'Admin.Navigation.Header') }}';
var token = '{{ this.legacyToken|e('js') }}';
var token = '{{ this.legacyToken }}';
var token_admin_orders = tokenAdminOrders = '{{ legacy_admin_token('AdminOrders') }}';
var token_admin_customers = tokenAdminCustomers = '{{ legacy_admin_token('AdminCustomers') }}';
var token_admin_customer_threads = tokenAdminCustomerThreads = '{{ legacy_admin_token('AdminCustomerThreads') }}';
var currentIndex = '{{ this.currentIndex|e('js') }}';
var employee_token = '{{ this.employeeToken|e('js') }}';
var currentIndex = '{{ this.currentIndex }}';
var employee_token = '{{ this.employeeToken }}';
var choose_language_translate = '{{ 'Choose language:'|trans({}, 'Admin.Actions') }}';
var default_language = '{{ this.defaultLanguage|intCast }}';
var admin_modules_link = '{{ path('admin_module_manage')|e('js')}}';
var admin_notification_get_link = '{{ path('admin_common_notifications')|e('js') }}';
var admin_notification_push_link = adminNotificationPushLink = '{{ path('admin_common_notifications_ack')|e('js') }}';
var admin_modules_link = '{{ path('admin_module_manage')}}';
var admin_notification_get_link = '{{ path('admin_common_notifications') }}';
var admin_notification_push_link = adminNotificationPushLink = '{{ path('admin_common_notifications_ack') }}';
var update_success_msg = '{{ 'Successful update'|trans({}, 'Admin.Notifications.Success') }}';
var search_product_msg = '{{ 'Search for a product'|trans({}, 'Admin.Orderscustomers.Feature') }}';
</script>
Expand Down
Expand Up @@ -30,6 +30,8 @@

use PrestaShop\PrestaShop\Adapter\Employee\EmployeeRepository;
use PrestaShop\PrestaShop\Core\Context\EmployeeContextBuilder;
use PrestaShopBundle\Security\Admin\Employee;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\HttpFoundation\Request;
use Tests\Unit\PrestaShopBundle\EventListener\Context\ContextEventListenerTestCase;

Expand All @@ -42,7 +44,8 @@ public function testFindEmployee(): void
);
$listener = new EmployeeContextListener(
$employeeBuilder,
$this->mockLegacyContext(['id_employee' => 42])
$this->mockLegacyContext(['id_employee' => 42]),
$this->createMock(Security::class)
);

$event = $this->createRequestEvent(new Request());
Expand All @@ -58,9 +61,30 @@ public function testEmployeeNotFound(): void
);
$listener = new EmployeeContextListener(
$employeeBuilder,
$this->mockLegacyContext(['id_employee' => null])
$this->mockLegacyContext(['id_employee' => null]),
$this->createMock(Security::class)
);
$listener->onKernelRequest($event);
$this->assertEquals(null, $this->getPrivateField($employeeBuilder, 'employeeId'));
}

public function testEmployeeFromSymfonySecurity(): void
{
$employeeBuilder = new EmployeeContextBuilder(
$this->createMock(EmployeeRepository::class)
);
$employeeMock = $this->createMock(Employee::class);
$employeeMock->method('getId')->willReturn(51);
$securityMock = $this->createMock(Security::class);
$securityMock->method('getUser')->willReturn($employeeMock);
$listener = new EmployeeContextListener(
$employeeBuilder,
$this->mockLegacyContext(['id_employee' => null]),
$securityMock
);

$event = $this->createRequestEvent(new Request());
$listener->onKernelRequest($event);
$this->assertEquals(51, $this->getPrivateField($employeeBuilder, 'employeeId'));
}
}