Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into ACCOUNT-2595/feat/cre…
Browse files Browse the repository at this point in the history
…ate-identity-on-installation

# Conflicts:
#	_dev/package.json
#	config.xml
#	ps_accounts.php
  • Loading branch information
hschoenenberger committed Oct 4, 2024
2 parents a09caf7 + a657573 commit ac8cb66
Show file tree
Hide file tree
Showing 44 changed files with 488 additions and 646 deletions.
17 changes: 17 additions & 0 deletions .dir-scoped
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
symfony/cache
symfony/config
symfony/dependency-injection
symfony/expression-language
symfony/filesystem
symfony/yaml
psr
guzzlehttp
league
prestashopcorp
lcobucci
prestashop/module-lib-service-container
prestashop/module-lib-cache-directory-provider
monolog
ramsey/uuid
ralouphie/getallheaders
phpseclib/phpseclib/phpseclib
23 changes: 13 additions & 10 deletions .github/workflows/build-release-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,11 @@ jobs:
rm -rf _dev
- name: Create & upload artifact
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v4
with:
name: ${{ github.event.repository.name }}
path: ../
path: ${{ github.workspace }}
include-hidden-files: true

upload_release_asset_production:
name: Upload the production zip asset to the release
Expand All @@ -88,9 +89,10 @@ jobs:
echo "zip_file=${{ github.event.repository.name }}-${{ needs.build.outputs.version }}.zip" >> "$GITHUB_OUTPUT"
- name: Download artifact
uses: actions/download-artifact@v1
uses: actions/download-artifact@v4
with:
name: ${{ github.event.repository.name }}
path: ${{ github.workspace }}

- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v0
Expand All @@ -102,13 +104,13 @@ jobs:
- name: Copy env files
run: |
gcloud components install beta
gcloud beta secrets versions access latest --secret="accounts-module-config" > ps_accounts/ps_accounts/config/config.yml
gcloud beta secrets versions access latest --secret="accounts-module-config" > ${{ github.workspace }}/config/config.yml
env:
GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.G_CREDENTIAL_PRODUCTION }}

- name: Prepare the production zip
run: |
cd ${{ github.event.repository.name }}/${{ github.event.repository.name }}
cd ${{ github.workspace }}
sh ./scripts/bundle-module.sh ${{ env.zip_file }}
env:
ENV_FILE: ${{ secrets.PS_ACCOUNTS_ENV_PROD }}
Expand All @@ -119,7 +121,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./${{ github.event.repository.name }}/${{ github.event.repository.name }}/dist/${{ env.zip_file }}
asset_path: ${{ github.workspace }}/dist/${{ env.zip_file }}
asset_name: ${{ env.zip_file }}
asset_content_type: application/zip

Expand All @@ -134,9 +136,10 @@ jobs:
echo "zip_file=${{ github.event.repository.name }}_preprod-${{ needs.build.outputs.version }}.zip" >> "$GITHUB_ENV"
- name: Download artifact
uses: actions/download-artifact@v1
uses: actions/download-artifact@v4
with:
name: ${{ github.event.repository.name }}
path: ${{ github.workspace }}

- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v0
Expand All @@ -148,13 +151,13 @@ jobs:
- name: Copy env files
run: |
gcloud components install beta
gcloud beta secrets versions access latest --secret="accounts-module-config" > ps_accounts/ps_accounts/config/config.yml
gcloud beta secrets versions access latest --secret="accounts-module-config" > ${{ github.workspace }}/config/config.yml
env:
GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.G_CREDENTIAL_PREPROD }}

- name: Prepare the preprod zip
run: |
cd ${{ github.event.repository.name }}/${{ github.event.repository.name }}
cd ${{ github.workspace }}
sh ./scripts/bundle-module.sh ${{ env.zip_file }}
- name: Publish the preprod zip
Expand All @@ -163,7 +166,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./${{ github.event.repository.name }}/${{ github.event.repository.name }}/dist/${{ env.zip_file }}
asset_path: ${{ github.workspace }}/dist/${{ env.zip_file }}
asset_name: ${{ env.zip_file }}
asset_content_type: application/zip

Expand Down
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ php-cs-fixer-1.6.1.24-5.6-fpm-stretch: platform-1.6.1.24-5.6-fpm-stretch platfor
# PHP-SCOPER

#VENDOR_DIRS = guzzlehttp league prestashopcorp
PHP_SCOPER_VENDOR_DIRS = $(shell cat scoper.inc.php | grep 'dirScoped =' | sed 's/^.*\$dirScoped = \[\(.*\)\].*/\1/' | sed "s/[' ,]\+/ /g")
#PHP_SCOPER_VENDOR_DIRS = $(shell cat scoper.inc.php | grep 'dirScoped =' | sed 's/^.*\$dirScoped = \[\(.*\)\].*/\1/' | sed "s/[' ,]\+/ /g")
PHP_SCOPER_VENDOR_DIRS = $(shell cat .dir-scoped)
PHP_SCOPER_OUTPUT_DIR := vendor-scoped
PHP_SCOPER_VERSION := 0.18.11

Expand All @@ -221,8 +222,8 @@ php-scoper-add-prefix: scoper.inc.php vendor-clean vendor php-scoper-pull
docker run -v ${PWD}:/input -w /input -u ${CURRENT_UID}:${CURRENT_GID} \
humbugphp/php-scoper:${PHP_SCOPER_VERSION} add-prefix --output-dir ${PHP_SCOPER_OUTPUT_DIR} --force --quiet
#for d in ${VENDOR_DIRS}; do rm -rf ./vendor/$$d && mv ./${SCOPED_DIR}/$$d ./vendor/; done;
$(foreach DIR,$(PHP_SCOPER_VENDOR_DIRS), rm -rf "./vendor/${DIR}" && mv "./${PHP_SCOPER_OUTPUT_DIR}/${DIR}" ./vendor/;)
rmdir "./${PHP_SCOPER_OUTPUT_DIR}"
$(foreach DIR,$(PHP_SCOPER_VENDOR_DIRS), rm -rf "./vendor/${DIR}" && mv "./${PHP_SCOPER_OUTPUT_DIR}/${DIR}" ./vendor/${DIR};)
if [ ! -z ${PHP_SCOPER_OUTPUT_DIR} ]; then rm -rf "./${PHP_SCOPER_OUTPUT_DIR}"; fi

php-scoper-dump-autoload:
${COMPOSER} dump-autoload --classmap-authoritative
Expand Down
27 changes: 26 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,32 @@
"PrestaShop\\Module\\PsAccounts\\Vendor\\GuzzleHttp\\Promise\\": "vendor/guzzlehttp/promises/src",
"PrestaShop\\Module\\PsAccounts\\Vendor\\GuzzleHttp\\Psr7\\": "vendor/guzzlehttp/psr7/src",
"PrestaShop\\Module\\PsAccounts\\Vendor\\League\\OAuth2\\Client\\": "vendor/league/oauth2-client/src",
"PrestaShop\\Module\\PsAccounts\\Vendor\\Lcobucci\\JWT\\": "vendor/lcobucci/jwt/src"
"PrestaShop\\Module\\PsAccounts\\Vendor\\Lcobucci\\JWT\\": "vendor/lcobucci/jwt/src",
"PrestaShop\\Module\\PsAccounts\\Vendor\\Monolog\\": "vendor/monolog/monolog/src/Monolog",
"PrestaShop\\Module\\PsAccounts\\Vendor\\PhpCsFixer\\": "vendor/friendsofphp/php-cs-fixer/src",
"PrestaShop\\Module\\PsAccounts\\Vendor\\PhpCsFixer\\Tests\\": "vendor/friendsofphp/php-cs-fixer/tests",
"PrestaShop\\Module\\PsAccounts\\Vendor\\phpseclib\\": "vendor/phpseclib/phpseclib/phpseclib",
"PrestaShop\\Module\\PsAccounts\\Vendor\\Psr\\Cache\\": "vendor/psr/cache/src",
"PrestaShop\\Module\\PsAccounts\\Vendor\\Psr\\Container\\": "vendor/psr/container/src",
"PrestaShop\\Module\\PsAccounts\\Vendor\\Psr\\Http\\Message\\": "vendor/psr/http-message/src",
"PrestaShop\\Module\\PsAccounts\\Vendor\\Psr\\Log\\": "vendor/psr/log/Psr/Log",
"PrestaShop\\Module\\PsAccounts\\Vendor\\Psr\\SimpleCache\\": "vendor/psr/simple-cache/src",
"PrestaShop\\Module\\PsAccounts\\Vendor\\Ramsey\\Uuid\\": "vendor/ramsey/uuid/src",
"PrestaShop\\Module\\PsAccounts\\Vendor\\Symfony\\Component\\Cache\\": "vendor/symfony/cache",
"PrestaShop\\Module\\PsAccounts\\Vendor\\Symfony\\Component\\Config\\": "vendor/symfony/config",
"PrestaShop\\Module\\PsAccounts\\Vendor\\Symfony\\Component\\Console\\": "vendor/symfony/console",
"PrestaShop\\Module\\PsAccounts\\Vendor\\Symfony\\Component\\Debug\\": "vendor/symfony/debug",
"PrestaShop\\Module\\PsAccounts\\Vendor\\Symfony\\Component\\DependencyInjection\\": "vendor/symfony/dependency-injection",
"PrestaShop\\Module\\PsAccounts\\Vendor\\Symfony\\Component\\EventDispatcher\\": "vendor/symfony/event-dispatcher",
"PrestaShop\\Module\\PsAccounts\\Vendor\\Symfony\\Component\\ExpressionLanguage\\": "vendor/symfony/expression-language",
"PrestaShop\\Module\\PsAccounts\\Vendor\\Symfony\\Component\\Filesystem\\": "vendor/symfony/filesystem",
"PrestaShop\\Module\\PsAccounts\\Vendor\\Symfony\\Component\\Finder\\": "vendor/symfony/finder",
"PrestaShop\\Module\\PsAccounts\\Vendor\\Symfony\\Component\\OptionsResolver\\": "vendor/symfony/options-resolver",
"PrestaShop\\Module\\PsAccounts\\Vendor\\Symfony\\Component\\Process\\": "vendor/symfony/process",
"PrestaShop\\Module\\PsAccounts\\Vendor\\Symfony\\Component\\Stopwatch\\": "vendor/symfony/stopwatch",
"PrestaShop\\Module\\PsAccounts\\Vendor\\Symfony\\Component\\Yaml\\": "vendor/symfony/yaml",
"PrestaShop\\Module\\PsAccounts\\Vendor\\PrestaShop\\ModuleLibServiceContainer\\": "vendor/prestashop/module-lib-service-container/src,",
"PrestaShop\\Module\\PsAccounts\\Vendor\\PrestaShop\\ModuleLibCacheDirectoryProvider\\": "vendor/prestashop/module-lib-cache-directory-provider/src"
},
"classmap": [
"ps_accounts.php",
Expand Down
1 change: 0 additions & 1 deletion config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@
<confirmUninstall><![CDATA[This action will prevent immediately your PrestaShop services and Community services from working as they are using PrestaShop Accounts module for authentication.]]></confirmUninstall>
<is_configurable>1</is_configurable>
<need_instance>0</need_instance>
<limited_countries></limited_countries>
</module>
2 changes: 1 addition & 1 deletion config/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ services:
factory: [ 'Context', 'getContext' ]

ps_accounts.logger:
class: Monolog\Logger
class: PrestaShop\Module\PsAccounts\Vendor\Monolog\Logger
public: true
factory: [ 'PrestaShop\Module\PsAccounts\Factory\PsAccountsLogger', 'create' ]

Expand Down
2 changes: 1 addition & 1 deletion controllers/admin/AdminAjaxPsAccountsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use PrestaShop\Module\PsAccounts\Account\Session\Firebase\ShopSession;
use PrestaShop\Module\PsAccounts\Api\Client\IndirectChannelClient;
use PrestaShop\Module\PsAccounts\Cqrs\CommandBus;
use PrestaShop\Module\PsAccounts\Polyfill\Traits\AjaxRender;
use PrestaShop\Module\PsAccounts\Polyfill\Traits\Controller\AjaxRender;
use PrestaShop\Module\PsAccounts\Presenter\PsAccountsPresenter;
use PrestaShop\Module\PsAccounts\Provider\OAuth2\PrestaShopSession;
use PrestaShop\Module\PsAccounts\Repository\ConfigurationRepository;
Expand Down
11 changes: 3 additions & 8 deletions controllers/admin/AdminLoginPsAccountsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

use PrestaShop\Module\PsAccounts\Polyfill\Traits\AdminController\IsAnonymousAllowed;
use PrestaShop\Module\PsAccounts\Provider\OAuth2\ShopProvider;

class AdminLoginPsAccountsController extends \AdminController
{
use IsAnonymousAllowed;

const PARAM_MODE_LOCAL = 'local';

/** @var string */
Expand Down Expand Up @@ -78,14 +81,6 @@ public function initContent()
$this->context->smarty->assign('modals', null);
}

/**
* @return bool
*/
protected function isAnonymousAllowed()
{
return true;
}

/**
* @return bool
*/
Expand Down
41 changes: 11 additions & 30 deletions controllers/admin/AdminOAuth2PsAccountsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,23 @@
use PrestaShop\Module\PsAccounts\Exception\AccountLogin\AccountLoginException;
use PrestaShop\Module\PsAccounts\Exception\AccountLogin\EmailNotVerifiedException;
use PrestaShop\Module\PsAccounts\Exception\AccountLogin\EmployeeNotFoundException;
use PrestaShop\Module\PsAccounts\Exception\AccountLogin\Oauth2Exception;
use PrestaShop\Module\PsAccounts\Exception\AccountLogin\OtherErrorException;
use PrestaShop\Module\PsAccounts\Polyfill\Traits\AdminController\IsAnonymousAllowed;
use PrestaShop\Module\PsAccounts\Provider\OAuth2\PrestaShopLoginTrait;
use PrestaShop\Module\PsAccounts\Provider\OAuth2\PrestaShopSession;
use PrestaShop\Module\PsAccounts\Provider\OAuth2\ShopProvider;
use PrestaShop\Module\PsAccounts\Repository\EmployeeAccountRepository;
use PrestaShop\Module\PsAccounts\Service\AnalyticsService;
use PrestaShop\Module\PsAccounts\Service\PsAccountsService;
use PrestaShop\Module\PsAccounts\Session\Session;
use PrestaShop\Module\PsAccounts\Vendor\League\OAuth2\Client\Provider\Exception\IdentityProviderException;
use PrestaShop\OAuth2\Client\Provider\PrestaShopUser;
use Symfony\Component\HttpFoundation\Session\SessionInterface;

/**
* Controller for all ajax calls.
*/
class AdminOAuth2PsAccountsController extends \ModuleAdminController
{
use PrestaShopLoginTrait;
use IsAnonymousAllowed;

/**
* @var Ps_accounts
Expand Down Expand Up @@ -71,14 +70,6 @@ public function __construct()
$this->content_only = true;
}

/**
* @return bool
*/
protected function isAnonymousAllowed()
{
return true;
}

/**
* @return bool
*/
Expand Down Expand Up @@ -109,14 +100,10 @@ public function init()
{
try {
$this->oauth2Login();
} catch (IdentityProviderException $e) {
$this->onLoginFailed(new Oauth2Exception(null, $e->getMessage()));
} catch (EmailNotVerifiedException $e) {
$this->onLoginFailed($e);
} catch (EmployeeNotFoundException $e) {
} catch (AccountLoginException $e) {
$this->onLoginFailed($e);
} catch (Exception $e) {
$this->onLoginFailed(new OtherErrorException(null, $e->getMessage()));
$this->onLoginFailed(new AccountLoginException($e->getMessage(), null, $e));
}
parent::init();
}
Expand Down Expand Up @@ -144,9 +131,9 @@ private function initUserSession(PrestaShopUser $user)
$context->employee->logout();

if (empty($emailVerified)) {
throw new EmailNotVerifiedException($user);
throw new EmailNotVerifiedException('Your account email is not verified', $user);
}
throw new EmployeeNotFoundException($user);
throw new EmployeeNotFoundException('The email address is not associated to a PrestaShop backoffice account.', $user);
}

$context->employee->remote_addr = (int) ip2long(Tools::getRemoteAddr());
Expand Down Expand Up @@ -228,9 +215,7 @@ private function redirectAfterLogin()
}

/**
* @return Session
*
* @throws Exception
* @return SessionInterface
*/
private function getSession()
{
Expand All @@ -241,8 +226,6 @@ private function getSession()
* @param mixed $error
*
* @return void
*
* @throws Exception
*/
private function setLoginError($error)
{
Expand All @@ -251,8 +234,6 @@ private function setLoginError($error)

/**
* @return PrestaShopSession
*
* @throws Exception
*/
protected function getOauth2Session()
{
Expand Down Expand Up @@ -294,7 +275,7 @@ private function trackLoginEvent(PrestaShopUser $user)
*/
private function trackLoginFailedEvent($e)
{
$user = $e->getPrestaShopUser();
$user = $e->getUser();
$this->analyticsService->identify(
$user->getId(),
$user->getName(),
Expand Down Expand Up @@ -323,7 +304,7 @@ private function getEmployeeByUidOrEmail($uid, $email)
{
$repository = new EmployeeAccountRepository();

if ($repository->isCompatPs16()) {
try {
$employeeAccount = $repository->findByUid($uid);

/* @phpstan-ignore-next-line */
Expand All @@ -344,7 +325,7 @@ private function getEmployeeByUidOrEmail($uid, $email)
->setEmail($email)
);
}
} else {
} catch (\Exception $e) {
$employee = new Employee();
$employee->getByEmail($email);
}
Expand Down
3 changes: 2 additions & 1 deletion fix-autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
*
* More information also found here: https://github.com/humbug/php-scoper/issues/298
*/
$match = 'guzzlehttp';
// TODO: fix all scoped deps
$match = '(guzzlehttp|symfony|lcobucci\/jwt|ramsey\/uuid|paragonie\/random_compat|ralouphie\/getallheaders|phpseclib\/phpseclib\/phpseclib)';
$scoper_path = __DIR__ . '/vendor/composer';
$static_loader_path = $scoper_path . '/autoload_static.php';
echo "Fixing $static_loader_path \n";
Expand Down
Loading

0 comments on commit ac8cb66

Please sign in to comment.