Add CLI console commands to change an employee password & create a super admin#41526
Open
jf-viguier wants to merge 2 commits into
Open
Add CLI console commands to change an employee password & create a super admin#41526jf-viguier wants to merge 2 commits into
jf-viguier wants to merge 2 commits into
Conversation
…d CLI commands Two new Symfony console commands for back-office employee management from the CLI: * prestashop:employee:create — provisions a new SuperAdmin employee. The command is intentionally narrow (first-admin provisioning and emergency recovery, not BO replacement): it asks only for email, first/last name and password, and hardcodes the rest (SuperAdmin profile, default shop language, every shop, active, no Gravatar). Dispatches the existing AddEmployeeCommand through the CommandBus, so domain validation and the standard CQRS flow are reused unchanged. * prestashop:employee:change-password — resets an existing employee's password. Calls EmployeePasswordResetter::resetPassword() directly, the same code path used by the BO "forgot password" flow (hashing, persistence and "Your new password" notification email). Missing values are prompted interactively; the password prompt is hidden and confirmed twice. A small EmployeeContextInitializer adapter loads the first active SuperAdmin into the legacy context before dispatching the create command, so the ProfileAccessChecker allows it to create another SuperAdmin (the BO flow assumes a logged-in employee; the CLI has none). The adapter lives in src/Adapter/Employee/ where touching the legacy Context and Employee classes is allowed. Both commands are declared in command.yml with the explicit console.command tag, in line with the rest of the file. Covered by unit tests with mocked dependencies (12 tests, 46 assertions).
3f2f3eb to
28db5a3
Compare
Quetzacoalt91
approved these changes
May 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
prestashop:employee:*console commands.createprovisions a new back-office SuperAdmin employee (interactive prompts for email, first/last name and password; everything else is hardcoded). The CLI is intentionally narrow: it covers first-admin provisioning and recovery, not generic employee management (use the BO Team page for that).change-passwordresets an existing employee's password (interactive hidden prompts)Summary
src/PrestaShopBundle/Command/EmployeeCreateCommand.php— dispatchesAddEmployeeCommandvia theCommandBus. The new account is always a SuperAdmin (full back-office access); the CLI prints an explicit warning. No flags for profile / language / shops / active / gravatar — those are hardcoded to sensible defaults.src/PrestaShopBundle/Command/EmployeeChangePasswordCommand.php— callsEmployeePasswordResetter::resetPassword().tests/Unit/PrestaShopBundle/Command/EmployeeCreateCommandTest.php(5 scenarios) andtests/Unit/PrestaShopBundle/Command/EmployeeChangePasswordCommandTest.php(7 scenarios). All dependencies are mocked.src/Adapter/Employee/EmployeeContextInitializer.php— loads the first active SuperAdmin into the legacy context before dispatch, so the CQRSProfileAccessCheckerallows the CLI to create another SuperAdmin (the BO assumes a logged-in employee; the CLI has none).src/PrestaShopBundle/Resources/config/services/bundle/command.yml(the two commands) andsrc/PrestaShopBundle/Resources/config/services/adapter/employee.yml(the initializer).#[AsCommand]attribute, likeprestashop:api-client,prestashop:config, etc.Usage
Test plan
php bin/console list prestashoplistsprestashop:employee:createandprestashop:employee:change-password.prestashop:employee:createinteractive mode prompts for email, first name, last name and password (twice), creates the employee, and prints a success message stating the new account is a SuperAdmin plus an explicit "SuperAdmin privileges" warning.prestashop:employee:createnon-interactive mode (all values as options) succeeds and the resulting employee is SuperAdmin, active, on the default language, associated to every shop.prestashop:employee:change-passwordinteractive mode prompts for email then password twice; success path updates the password and exits 0.prestashop:employee:change-passwordnon-interactive mode (--password=...) succeeds.change-passwordreturns a clear error and a non-zero exit code.change-password(same template as the BO forgot-password flow).php vendor/bin/phpunit -c tests/Unit/phpunit.xml --filter 'EmployeeCreateCommandTest|EmployeeChangePasswordCommandTest'is green (12 tests, 46 assertions).