From 5ef59d7cc422fceb4f5643aca953f020e1215d4a Mon Sep 17 00:00:00 2001 From: atourneriePresta Date: Wed, 11 Aug 2021 19:02:02 +0200 Subject: [PATCH 01/30] feat: add public and private key when we create a new shop --- ps_accounts.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ps_accounts.php b/ps_accounts.php index 6f64c68d0..c696b9fcc 100644 --- a/ps_accounts.php +++ b/ps_accounts.php @@ -273,6 +273,18 @@ public function hookActionObjectShopAddAfter($params) $this->switchConfigMultishopMode(); } + $shopCreated = $params["object"]; + + /** @var \PrestaShop\Module\PsAccounts\Repository\ConfigurationRepository $config */ + $configuration = $this->getService(\PrestaShop\Module\PsAccounts\Repository\ConfigurationRepository::class); + $actualShopId = $configuration->getShopId(); + $configuration->setShopId($shopCreated->id); + + /** @var \PrestaShop\Module\PsAccounts\Provider\RsaKeysProvider $rsaKeyProvider */ + $rsaKeyProvider = $this->getService(\PrestaShop\Module\PsAccounts\Provider\RsaKeysProvider::class); + $rsaKeyProvider->generateKeys(); + $configuration->setShopId = $actualShopId; + return true; } From 2d9be767cfdd0449df811cb4206daf50288f7208 Mon Sep 17 00:00:00 2001 From: Antoine Metifeu Date: Wed, 18 Aug 2021 09:47:42 +0200 Subject: [PATCH 02/30] add properties to presenter for multishop selection * multishop, moduleName and psVersion keys on shop tree * type of shop context and it's ID (group ID or shop ID) --- classes/Context/ShopContext.php | 26 +++++++++++++++++++++++ classes/Presenter/PsAccountsPresenter.php | 4 ++++ classes/Provider/ShopProvider.php | 8 ++++++- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/classes/Context/ShopContext.php b/classes/Context/ShopContext.php index a792258b3..6a17e3265 100644 --- a/classes/Context/ShopContext.php +++ b/classes/Context/ShopContext.php @@ -68,6 +68,32 @@ public function isShop173() return version_compare(_PS_VERSION_, '1.7.3.0', '>='); } + /** + * @return bool + */ + public function getShopContext() + { + return \Shop::getContext(); + } + + /** + * ID of shop or group + * + * @return string | null + */ + public function getShopContextId() + { + if (\Shop::getContext() == \Shop::CONTEXT_SHOP) { + return \Shop::getContextShopID();; + } + + if (\Shop::getContext() == \Shop::CONTEXT_GROUP) { + return \Shop::getContextShopGroupID(); + } + + return null; + } + /** * @return bool */ diff --git a/classes/Presenter/PsAccountsPresenter.php b/classes/Presenter/PsAccountsPresenter.php index 0d5b7e924..eb1d823d9 100644 --- a/classes/Presenter/PsAccountsPresenter.php +++ b/classes/Presenter/PsAccountsPresenter.php @@ -109,6 +109,10 @@ public function present($psxName = 'ps_accounts') try { return array_merge( [ + 'currentContext' => [ + 'type' => $shopContext->getShopContext(), + 'id' => $shopContext->getShopContextId(), + ], 'psxName' => $psxName, 'psIs17' => $shopContext->isShop17(), diff --git a/classes/Provider/ShopProvider.php b/classes/Provider/ShopProvider.php index ac9590732..c38ae7b4b 100644 --- a/classes/Provider/ShopProvider.php +++ b/classes/Provider/ShopProvider.php @@ -120,7 +120,13 @@ public function getShopsTree($psxName) foreach (\Shop::getTree() as $groupId => $groupData) { $shops = []; foreach ($groupData['shops'] as $shopId => $shopData) { - $shops[] = $this->formatShopData($shopData, $psxName); + $data = $this->formatShopData($shopData, $psxName); + + $shops[] = array_merge($data, [ + 'multishop' => $this->shopContext->isMultishopActive(), + 'moduleName' => $psxName, + 'psVersion' => _PS_VERSION_, + ]); } $shopList[] = [ From e61a1302fbb4208d7555ba6c38111e255327753a Mon Sep 17 00:00:00 2001 From: Antoine Metifeu Date: Wed, 18 Aug 2021 10:05:40 +0200 Subject: [PATCH 03/30] fix php-cs-fixer and phpstan errors --- classes/Context/ShopContext.php | 6 +++--- ps_accounts.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/classes/Context/ShopContext.php b/classes/Context/ShopContext.php index 6a17e3265..19bcaeab4 100644 --- a/classes/Context/ShopContext.php +++ b/classes/Context/ShopContext.php @@ -69,7 +69,7 @@ public function isShop173() } /** - * @return bool + * @return int */ public function getShopContext() { @@ -79,12 +79,12 @@ public function getShopContext() /** * ID of shop or group * - * @return string | null + * @return int|null */ public function getShopContextId() { if (\Shop::getContext() == \Shop::CONTEXT_SHOP) { - return \Shop::getContextShopID();; + return \Shop::getContextShopID(); } if (\Shop::getContext() == \Shop::CONTEXT_GROUP) { diff --git a/ps_accounts.php b/ps_accounts.php index c696b9fcc..b4dbcbf08 100644 --- a/ps_accounts.php +++ b/ps_accounts.php @@ -273,9 +273,9 @@ public function hookActionObjectShopAddAfter($params) $this->switchConfigMultishopMode(); } - $shopCreated = $params["object"]; + $shopCreated = $params['object']; - /** @var \PrestaShop\Module\PsAccounts\Repository\ConfigurationRepository $config */ + /** @var \PrestaShop\Module\PsAccounts\Repository\ConfigurationRepository $configuration */ $configuration = $this->getService(\PrestaShop\Module\PsAccounts\Repository\ConfigurationRepository::class); $actualShopId = $configuration->getShopId(); $configuration->setShopId($shopCreated->id); From a5ce57439d4639d6d05c99999137173ce1815dc3 Mon Sep 17 00:00:00 2001 From: Antoine Metifeu Date: Wed, 18 Aug 2021 11:03:53 +0200 Subject: [PATCH 04/30] fix phpstan undefined property setShopId --- ps_accounts.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ps_accounts.php b/ps_accounts.php index b4dbcbf08..1f8f04004 100644 --- a/ps_accounts.php +++ b/ps_accounts.php @@ -283,7 +283,7 @@ public function hookActionObjectShopAddAfter($params) /** @var \PrestaShop\Module\PsAccounts\Provider\RsaKeysProvider $rsaKeyProvider */ $rsaKeyProvider = $this->getService(\PrestaShop\Module\PsAccounts\Provider\RsaKeysProvider::class); $rsaKeyProvider->generateKeys(); - $configuration->setShopId = $actualShopId; + $configuration->setShopId($actualShopId); return true; } From bf5a206303c51d57ac266f3af97d1b782cd3ca4b Mon Sep 17 00:00:00 2001 From: Antoine Metifeu Date: Wed, 25 Aug 2021 16:38:53 +0200 Subject: [PATCH 05/30] add user uuid and email on each shop in shop tree + adapt onboardingLink --- _dev/vue.config.js | 2 +- classes/Presenter/PsAccountsPresenter.php | 8 ++--- classes/Provider/ShopProvider.php | 41 +++++++++++++++++++++++ 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/_dev/vue.config.js b/_dev/vue.config.js index 0e8d964e3..67df241dd 100644 --- a/_dev/vue.config.js +++ b/_dev/vue.config.js @@ -29,7 +29,7 @@ module.exports = { extract: false, }, runtimeCompiler: true, - productionSourceMap: false, + // productionSourceMap: false, filenameHashing: false, outputDir: "../views/", assetsDir: "", diff --git a/classes/Presenter/PsAccountsPresenter.php b/classes/Presenter/PsAccountsPresenter.php index 6c23d2943..5c2758d91 100644 --- a/classes/Presenter/PsAccountsPresenter.php +++ b/classes/Presenter/PsAccountsPresenter.php @@ -106,10 +106,10 @@ public function present($psxName = 'ps_accounts') $moduleName = $this->module->name; - $currentShop = $this->shopProvider->getCurrentShop($psxName); - $shopBase64 = base64_encode((string) json_encode($currentShop)); + $unlinkedShops = $this->shopProvider->getUnlinkedShops($psxName); + $shopBase64 = base64_encode((string) json_encode(array_values($unlinkedShops))); $onboardingLink = $this->module->getParameter('ps_accounts.accounts_ui_url') - . '?shopPayload=' . $shopBase64; + . '?shops=' . $shopBase64; try { return array_merge( @@ -148,7 +148,7 @@ public function present($psxName = 'ps_accounts') 'employeeId' => $shopContext->getContext()->employee->id, 'isSuperAdmin' => $shopContext->getContext()->employee->isSuperAdmin(), ], - 'currentShop' => $currentShop, + 'currentShop' => $this->shopProvider->getCurrentShop($psxName), 'isShopContext' => $shopContext->isShopContext(), 'superAdminEmail' => $this->psAccountsService->getSuperAdminEmail(), diff --git a/classes/Provider/ShopProvider.php b/classes/Provider/ShopProvider.php index 67be0915c..10bea5035 100644 --- a/classes/Provider/ShopProvider.php +++ b/classes/Provider/ShopProvider.php @@ -83,6 +83,10 @@ public function formatShopData($shopData, $psxName = '') 'uuid' => $configuration->getShopUuid() ?: null, 'publicKey' => $configuration->getAccountsRsaPublicKey() ?: null, 'employeeId' => (int) $configuration->getEmployeeId() ?: null, + 'user' => [ + 'email' => $configuration->getFirebaseEmail() ?: null, + 'uuid' => $configuration->getUserFirebaseUuid() ?: null, + ], 'url' => $this->link->getAdminLink( 'AdminModules', @@ -157,6 +161,43 @@ public function getShopsTree($psxName) return $shopList; } + /** + * @param string $psxName + * + * @return array + * + * @throws \PrestaShopException + */ + public function getUnlinkedShops($psxName) + { + $shopTree = $this->getShopsTree($psxName); + $shops = []; + + switch ($this->getShopContext()->getShopContext()) { + case \Shop::CONTEXT_ALL: + $shops = array_reduce($shopTree, function ($carry, $shopGroup) { + return array_merge($carry, $shopGroup['shops']); + }, []); + break; + case \Shop::CONTEXT_GROUP: + $shops = array_reduce($shopTree, function ($carry, $shopGroup) { + if ($shopGroup['id'] != $this->getShopContext()->getShopContextId()) { + return $carry; + } + + return array_merge($carry, $shopGroup['shops']); + }, []); + break; + case \Shop::CONTEXT_SHOP: + $shops = [$this->getCurrentShop($psxName)]; + break; + } + + return array_filter($shops, function ($shop) { + return $shop['uuid'] === null; + }); + } + /** * @return ShopContext */ From e81ca232fe67075422e1e146643f619c6e4f3fe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= Date: Wed, 15 Sep 2021 16:33:18 +0200 Subject: [PATCH 06/30] fix: generate shop public keys when the shops are unlinked and the user is on a all shops context set module version to 5.1.0 and register hooks on 5.1.0 upgrade --- classes/Service/ShopLinkAccountService.php | 3 +++ config.xml | 2 +- ps_accounts.php | 4 ++-- upgrade/upgrade-5.1.0.php | 16 ++++++++++++++++ 4 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 upgrade/upgrade-5.1.0.php diff --git a/classes/Service/ShopLinkAccountService.php b/classes/Service/ShopLinkAccountService.php index b62b4243d..0bcabf969 100644 --- a/classes/Service/ShopLinkAccountService.php +++ b/classes/Service/ShopLinkAccountService.php @@ -120,6 +120,9 @@ public function resetLinkAccount() $this->shopTokenRepository->cleanupCredentials(); $this->userTokenRepository->cleanupCredentials(); $this->configuration->updateEmployeeId(''); + try { + $this->rsaKeysProvider->generateKeys(); + } catch (\Exception $e) {} } /** diff --git a/config.xml b/config.xml index 7a388f30b..9a93bae31 100644 --- a/config.xml +++ b/config.xml @@ -2,7 +2,7 @@ ps_accounts - + diff --git a/ps_accounts.php b/ps_accounts.php index 1f8f04004..fb35eee38 100644 --- a/ps_accounts.php +++ b/ps_accounts.php @@ -28,7 +28,7 @@ class Ps_accounts extends Module // Needed in order to retrieve the module version easier (in api call headers) than instanciate // the module each time to get the version - const VERSION = '5.0.0'; + const VERSION = '5.1.0'; /** * @var array @@ -86,7 +86,7 @@ public function __construct() // We cannot use the const VERSION because the const is not computed by addons marketplace // when the zip is uploaded - $this->version = '5.0.0'; + $this->version = '5.1.0'; $this->module_key = 'abf2cd758b4d629b2944d3922ef9db73'; diff --git a/upgrade/upgrade-5.1.0.php b/upgrade/upgrade-5.1.0.php new file mode 100644 index 000000000..32e07fbec --- /dev/null +++ b/upgrade/upgrade-5.1.0.php @@ -0,0 +1,16 @@ +registerHook($module->getHookToInstall()); + + return true; +} From e879787b28d0b1116b95b5d1f92fc51fa912fc3b Mon Sep 17 00:00:00 2001 From: Antoine Metifeu Date: Thu, 23 Sep 2021 09:49:49 +0200 Subject: [PATCH 07/30] fix: phpcs --- classes/Service/ShopLinkAccountService.php | 3 ++- upgrade/upgrade-5.1.0.php | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/classes/Service/ShopLinkAccountService.php b/classes/Service/ShopLinkAccountService.php index 0bcabf969..8caa509c5 100644 --- a/classes/Service/ShopLinkAccountService.php +++ b/classes/Service/ShopLinkAccountService.php @@ -122,7 +122,8 @@ public function resetLinkAccount() $this->configuration->updateEmployeeId(''); try { $this->rsaKeysProvider->generateKeys(); - } catch (\Exception $e) {} + } catch (\Exception $e) { + } } /** diff --git a/upgrade/upgrade-5.1.0.php b/upgrade/upgrade-5.1.0.php index 32e07fbec..243685c15 100644 --- a/upgrade/upgrade-5.1.0.php +++ b/upgrade/upgrade-5.1.0.php @@ -1,6 +1,5 @@ Date: Thu, 23 Sep 2021 16:37:11 +0200 Subject: [PATCH 08/30] feat: add emailIsValidated property on user object in shops tree --- classes/Context/ShopContext.php | 17 +++++++++++++++++ classes/Provider/ShopProvider.php | 3 +++ config/common.yml | 1 + 3 files changed, 21 insertions(+) diff --git a/classes/Context/ShopContext.php b/classes/Context/ShopContext.php index 19bcaeab4..c9f0ea954 100644 --- a/classes/Context/ShopContext.php +++ b/classes/Context/ShopContext.php @@ -22,6 +22,7 @@ use Context; use PrestaShop\Module\PsAccounts\Repository\ConfigurationRepository; +use PrestaShop\Module\PsAccounts\Repository\UserTokenRepository; /** * Get the shop context @@ -33,6 +34,11 @@ class ShopContext */ private $configuration; + /** + * @var UserTokenRepository + */ + private $userTokenRepository; + /** * @var Context */ @@ -42,13 +48,16 @@ class ShopContext * ShopContext constructor. * * @param ConfigurationRepository $configuration + * @param UserTokenRepository $userTokenRepository * @param Context $context */ public function __construct( ConfigurationRepository $configuration, + UserTokenRepository $userTokenRepository, Context $context ) { $this->configuration = $configuration; + $this->userTokenRepository = $userTokenRepository; $this->context = $context; } @@ -149,4 +158,12 @@ public function getConfiguration() { return $this->configuration; } + + /** + * @return UserTokenRepository + */ + public function getUser() + { + return $this->userTokenRepository; + } } diff --git a/classes/Provider/ShopProvider.php b/classes/Provider/ShopProvider.php index 10bea5035..eb39fd002 100644 --- a/classes/Provider/ShopProvider.php +++ b/classes/Provider/ShopProvider.php @@ -22,6 +22,7 @@ use PrestaShop\Module\PsAccounts\Adapter\Link; use PrestaShop\Module\PsAccounts\Context\ShopContext; +use PrestaShop\Module\PsAccounts\Repository\UserTokenRepository; use PrestaShop\Module\PsAccounts\Service\ShopLinkAccountService; class ShopProvider @@ -61,6 +62,7 @@ public function __construct( public function formatShopData($shopData, $psxName = '') { $configuration = $this->shopContext->getConfiguration(); + $user = $this->shopContext->getUser(); $shopId = $configuration->getShopId(); @@ -86,6 +88,7 @@ public function formatShopData($shopData, $psxName = '') 'user' => [ 'email' => $configuration->getFirebaseEmail() ?: null, 'uuid' => $configuration->getUserFirebaseUuid() ?: null, + 'emailIsValidated' => $user->getTokenEmailVerified(), ], 'url' => $this->link->getAdminLink( diff --git a/config/common.yml b/config/common.yml index 7bf390280..d805304e1 100644 --- a/config/common.yml +++ b/config/common.yml @@ -16,6 +16,7 @@ services: public: true arguments: - '@PrestaShop\Module\PsAccounts\Repository\ConfigurationRepository' + - '@PrestaShop\Module\PsAccounts\Repository\UserTokenRepository' - '@ps_accounts.context' PrestaShop\Module\PsAccounts\Adapter\Configuration: From a60aadc685d9753610aae70dd9f4a67f5636aef2 Mon Sep 17 00:00:00 2001 From: Antoine Metifeu Date: Tue, 28 Sep 2021 15:43:26 +0200 Subject: [PATCH 09/30] fix: php_cs --- classes/Provider/ShopProvider.php | 1 - 1 file changed, 1 deletion(-) diff --git a/classes/Provider/ShopProvider.php b/classes/Provider/ShopProvider.php index eb39fd002..929bd8391 100644 --- a/classes/Provider/ShopProvider.php +++ b/classes/Provider/ShopProvider.php @@ -22,7 +22,6 @@ use PrestaShop\Module\PsAccounts\Adapter\Link; use PrestaShop\Module\PsAccounts\Context\ShopContext; -use PrestaShop\Module\PsAccounts\Repository\UserTokenRepository; use PrestaShop\Module\PsAccounts\Service\ShopLinkAccountService; class ShopProvider From 1d48da339ba0597a8125b9f778dc6adc34220ae1 Mon Sep 17 00:00:00 2001 From: Antoine Metifeu Date: Mon, 4 Oct 2021 11:14:53 +0200 Subject: [PATCH 10/30] fix: padding --- _dev/src/core/settings/pages/SettingsApp.vue | 1 + 1 file changed, 1 insertion(+) diff --git a/_dev/src/core/settings/pages/SettingsApp.vue b/_dev/src/core/settings/pages/SettingsApp.vue index 81df78dc6..065b6327d 100644 --- a/_dev/src/core/settings/pages/SettingsApp.vue +++ b/_dev/src/core/settings/pages/SettingsApp.vue @@ -61,6 +61,7 @@ export default { text-align: left; .tab-content { + padding: 0; background: transparent; } } From 3f906795f3dc0a96f0cd38bcae7fbc37d973b662 Mon Sep 17 00:00:00 2001 From: Antoine Metifeu Date: Wed, 6 Oct 2021 09:07:30 +0200 Subject: [PATCH 11/30] fix: unlinkedShops with v4 linked shops --- _dev/src/core/settings/pages/SettingsApp.vue | 8 +++++++- classes/Provider/ShopProvider.php | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/_dev/src/core/settings/pages/SettingsApp.vue b/_dev/src/core/settings/pages/SettingsApp.vue index 065b6327d..98f3732af 100644 --- a/_dev/src/core/settings/pages/SettingsApp.vue +++ b/_dev/src/core/settings/pages/SettingsApp.vue @@ -20,7 +20,7 @@
- +
@@ -64,6 +64,12 @@ export default { padding: 0; background: transparent; } + + @media only screen and (max-width: 768px) { + .tab-content { + padding: 1rem; + } + } } #settingsApp .card-header, diff --git a/classes/Provider/ShopProvider.php b/classes/Provider/ShopProvider.php index 929bd8391..e825125c0 100644 --- a/classes/Provider/ShopProvider.php +++ b/classes/Provider/ShopProvider.php @@ -196,7 +196,7 @@ public function getUnlinkedShops($psxName) } return array_filter($shops, function ($shop) { - return $shop['uuid'] === null; + return $shop['uuid'] === null || ($shop['uuid'] && $shop['isLinkedV4']); }); } From 1d963473e4e583ec958b155f62c02d9a71888b77 Mon Sep 17 00:00:00 2001 From: Antoine Metifeu Date: Wed, 6 Oct 2021 14:48:52 +0200 Subject: [PATCH 12/30] fix: responsive --- _dev/src/core/settings/pages/OnBoardingApp.vue | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/_dev/src/core/settings/pages/OnBoardingApp.vue b/_dev/src/core/settings/pages/OnBoardingApp.vue index 9d12b8d21..013281aaf 100644 --- a/_dev/src/core/settings/pages/OnBoardingApp.vue +++ b/_dev/src/core/settings/pages/OnBoardingApp.vue @@ -17,7 +17,7 @@ * International Registered Trademark & Property of PrestaShop SA *-->