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

[ACCOUNT-2595/2604] feat: create & verify shop identity #433

Open
wants to merge 57 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
5420ba2
feat: working identity creation
atourneriePresta Sep 4, 2024
1f28a58
feat: refactor after review
atourneriePresta Sep 9, 2024
3fef8f3
feat: csfixer and test
atourneriePresta Sep 9, 2024
8863bf9
feat: remove reonboard methods
atourneriePresta Sep 10, 2024
61d961e
feat: merge MASTER
atourneriePresta Sep 10, 2024
3be2a0d
feat: php cs fixer
atourneriePresta Sep 10, 2024
e590cae
feat: php stan + remove reonboard
atourneriePresta Sep 10, 2024
fd688df
fix: phpstan
atourneriePresta Sep 11, 2024
9431cdc
feat: update phpunit
atourneriePresta Sep 11, 2024
8a80fcd
feat: phpstan fix
atourneriePresta Sep 11, 2024
c18cb84
feat: phpunit test fix
atourneriePresta Sep 11, 2024
09f0353
Update config/command.yml
atourneriePresta Sep 23, 2024
abd7830
Update config/command.yml
atourneriePresta Sep 23, 2024
a09caf7
fix: change endpoint path
antoinemetifeu Sep 30, 2024
ac8cb66
Merge remote-tracking branch 'origin/main' into ACCOUNT-2595/feat/cre…
hschoenenberger Oct 4, 2024
19e9cbf
fix: refactor multi handler
hschoenenberger Oct 4, 2024
0dbf451
fix: refactor multi handler
hschoenenberger Oct 4, 2024
2a21362
fix: refactor multi handler
hschoenenberger Oct 7, 2024
f56cee3
fix: remove abstract suffix
hschoenenberger Oct 7, 2024
02b7b05
fix: injected dependencies
hschoenenberger Oct 7, 2024
2cf5f0e
fix: unit tests, php-cs-fixer, phpstan
hschoenenberger Oct 7, 2024
1d16a87
fix: unit tests, php-cs-fixer, phpstan
hschoenenberger Oct 7, 2024
2b2ae27
Merge remote-tracking branch 'origin/main' into ACCOUNT-2595/feat/cre…
hschoenenberger Oct 10, 2024
7584e4a
feat: improve scoping & hack autoloading for upgrade
hschoenenberger Oct 11, 2024
f7b7c84
feat: improve scoping & hack autoloading for upgrade
hschoenenberger Oct 11, 2024
952cee4
feat: verify url authenticity
antoinemetifeu Oct 14, 2024
a118cc8
Merge branch 'ACCOUNT-2595/feat/create-identity-on-installation' into…
antoinemetifeu Oct 16, 2024
84428bd
fix: adapt command handler
antoinemetifeu Oct 16, 2024
ad4ce6f
fix: unlinked on error conf key
antoinemetifeu Oct 18, 2024
57ec74d
feat: improve scoping & hack autoloading for upgrade
hschoenenberger Oct 18, 2024
0bbb5b3
feat: improve scoping & hack autoloading for upgrade
hschoenenberger Oct 21, 2024
a7a1787
Merge branch 'ACCOUNT-2595/feat/create-identity-on-installation' into…
antoinemetifeu Oct 30, 2024
4e9fc82
feat: add v2 of abstract rest controller
antoinemetifeu Nov 6, 2024
3df359e
Merge remote-tracking branch 'origin/main' into ACCOUNT-2595/feat/cre…
hschoenenberger Nov 18, 2024
8bf4cc6
chore: reset prefix
hschoenenberger Nov 18, 2024
e20d9a7
refactor: return early
hschoenenberger Nov 18, 2024
10d53a5
fix: more readable throwable catching
hschoenenberger Nov 19, 2024
2243ddf
fix: more readable throwable catching
hschoenenberger Nov 19, 2024
17b8f31
Merge remote-tracking branch 'origin/main' into ACCOUNT-2595/feat/cre…
hschoenenberger Nov 20, 2024
62fa244
fix: php-cs-fixer
hschoenenberger Nov 20, 2024
b98e07a
fix: scoper config
hschoenenberger Nov 20, 2024
7d84939
fix: phpstan
hschoenenberger Nov 20, 2024
8c8d0fa
Merge remote-tracking branch 'origin/main' into ACCOUNT-2595/feat/cre…
hschoenenberger Nov 26, 2024
c6cfb1c
fix: inverted condition
hschoenenberger Nov 26, 2024
3b06080
fix: skip a few tests
hschoenenberger Nov 26, 2024
be9c383
feat: add x-multishop-enabled header
hschoenenberger Nov 28, 2024
af92938
feat: cleanup handler and throw exception on failure
hschoenenberger Nov 28, 2024
d462c7a
feat: cleanup handler and throw exception on failure
hschoenenberger Nov 28, 2024
e6b642d
Merge remote-tracking branch 'origin/main' into ACCOUNT-2595/feat/cre…
hschoenenberger Dec 2, 2024
7cd0084
chore: adapt service container wiring
hschoenenberger Dec 2, 2024
b56764b
Merge remote-tracking branch 'origin/ACCOUNT-2604/feat/verify-shop-au…
hschoenenberger Dec 4, 2024
42fcf92
chore: post merge fixes
hschoenenberger Dec 4, 2024
d99f4bb
chore: rename to cloudShopId
hschoenenberger Dec 4, 2024
d1834f1
refactor: some refactoring
hschoenenberger Dec 10, 2024
5e4d7a8
chore: some raw wiring
hschoenenberger Dec 11, 2024
7182678
chore: some renaming
hschoenenberger Dec 11, 2024
5579a35
chore: some renaming
hschoenenberger Dec 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion _dev/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ps_accounts",
"version": "7.0.4",
"version": "8.0.0",
"private": true,
"scripts": {
"dev": "vite",
Expand Down
2 changes: 1 addition & 1 deletion config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<module>
<name>ps_accounts</name>
<displayName><![CDATA[PrestaShop Account]]></displayName>
<version><![CDATA[7.0.4]]></version>
<version><![CDATA[8.0.0]]></version>
<description><![CDATA[Link your store to your PrestaShop account to activate and manage your subscriptions in your back office. Do not uninstall this module if you have a current subscription.]]></description>
<author><![CDATA[PrestaShop]]></author>
<tab><![CDATA[administration]]></tab>
Expand Down
17 changes: 17 additions & 0 deletions config/command.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,20 @@ services:
arguments:
- '@PrestaShop\Module\PsAccounts\Cqrs\CommandBus'
- '@PrestaShop\Module\PsAccounts\Repository\ConfigurationRepository'

PrestaShop\Module\PsAccounts\Account\CommandHandler\Oauth2InstallHandler:
class: PrestaShop\Module\PsAccounts\Account\CommandHandler\Oauth2InstallHandler
atourneriePresta marked this conversation as resolved.
Show resolved Hide resolved
public: true
arguments:
- '@PrestaShop\Module\PsAccounts\Api\Client\AccountsClient'
- '@PrestaShop\Module\PsAccounts\Provider\ShopProvider'
- '@PrestaShop\Module\PsAccounts\Provider\OAuth2\Oauth2Client'
- '@PrestaShop\Module\PsAccounts\Context\ShopContext'
- '@PrestaShop\Module\PsAccounts\Account\LinkShop'

PrestaShop\Module\PsAccounts\Account\CommandHandler\Oauth2InstallMultiHandler:
class: PrestaShop\Module\PsAccounts\Account\CommandHandler\Oauth2InstallMultiHandler
atourneriePresta marked this conversation as resolved.
Show resolved Hide resolved
public: true
arguments:
- '@PrestaShop\Module\PsAccounts\Cqrs\CommandBus'
- '@PrestaShop\Module\PsAccounts\Repository\ConfigurationRepository'
25 changes: 5 additions & 20 deletions ps_accounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,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 = '7.0.4';
const VERSION = '8.0.0';

/**
* Admin tabs
Expand Down Expand Up @@ -131,7 +131,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 = '7.0.4';
$this->version = '8.0.0';

$this->module_key = 'abf2cd758b4d629b2944d3922ef9db73';

Expand Down Expand Up @@ -476,22 +476,6 @@ public function getSession()
}
}

/**
* @deprecated
*
* @return void
*
* @throws PrestaShopException
*
* @phpstan-ignore-next-line
*/
private function autoReonboardOnV5()
{
/** @var \PrestaShop\Module\PsAccounts\Service\PsAccountsService $psAccountsService */
$psAccountsService = $this->getService(\PrestaShop\Module\PsAccounts\Service\PsAccountsService::class);
$psAccountsService->autoReonboardOnV5();
}

/**
* @return void
*
Expand All @@ -511,8 +495,9 @@ public function onModuleReset()
$uninstaller = new PrestaShop\Module\PsAccounts\Module\Uninstall($this, Db::getInstance());
$uninstaller->deleteAdminTab('AdminLogin');

// $this->installEventBus();
// $this->autoReonboardOnV5();
/** @var \PrestaShop\Module\PsAccounts\Cqrs\CommandBus $commandBus */
$commandBus = $this->getService(\PrestaShop\Module\PsAccounts\Cqrs\CommandBus::class);
$commandBus->handle(new \PrestaShop\Module\PsAccounts\Account\Command\MultiCreateIdentityCommand([]));
hschoenenberger marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
Expand All @@ -20,10 +21,10 @@

namespace PrestaShop\Module\PsAccounts\Account\Command;

class MigrateAndLinkV4ShopCommand
class CreateIdentityCommand
{
/**
* @var int
* @var int|null
*/
public $shopId;

Expand All @@ -33,7 +34,7 @@ class MigrateAndLinkV4ShopCommand
public $payload;

/**
* @param int $shopId
* @param int|null $shopId
* @param array $payload
*/
public function __construct($shopId, array $payload)
Expand Down
38 changes: 38 additions & 0 deletions src/Account/Command/MultiCreateIdentityCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <[email protected]>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

namespace PrestaShop\Module\PsAccounts\Account\Command;

class MultiCreateIdentityCommand
{
/**
* @var array
*/
public $payload;

/**
* @param array $payload
*/
public function __construct(array $payload)
{
$this->payload = $payload;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <[email protected]>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

namespace PrestaShop\Module\PsAccounts\Account\CommandHandler\AbstractClass;

class MultiShopHandlerAbstract
{
/**
* @param bool $multishop
*
* @return array|null[]
*/
protected function getShops($multishop)
{
$shops = [null];
if ($multishop) {
$shops = [];
$db = \Db::getInstance();
try {
$result = $db->query('SELECT id_shop FROM ' . _DB_PREFIX_ . 'shop');
while ($row = $db->nextRow($result)) {
/* @phpstan-ignore-next-line */
$shops[] = $row['id_shop'];
}
} catch (\Throwable $e) {
return [];
}
}

return $shops;
}
}
103 changes: 103 additions & 0 deletions src/Account/CommandHandler/CreateIdentityHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <[email protected]>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

namespace PrestaShop\Module\PsAccounts\Account\CommandHandler;

use PrestaShop\Module\PsAccounts\Account\Command\CreateIdentityCommand;
use PrestaShop\Module\PsAccounts\Account\LinkShop;
use PrestaShop\Module\PsAccounts\Api\Client\AccountsClient;
use PrestaShop\Module\PsAccounts\Context\ShopContext;
use PrestaShop\Module\PsAccounts\Provider\OAuth2\Oauth2Client;
use PrestaShop\Module\PsAccounts\Provider\ShopProvider;

class CreateIdentityHandler
{
/**
* @var AccountsClient
*/
private $accountsClient;

/**
* @var Oauth2Client
*/
private $oauth2Client;

/**
* @var ShopProvider
*/
private $shopProvider;

/**
* @var ShopContext
*/
private $shopContext;

/**
* @var LinkShop
*/
private $linkShop;

/**
* @param AccountsClient $accountsClient
* @param ShopProvider $shopProvider
* @param Oauth2Client $oauth2Client
* @param ShopContext $shopContext
* @param LinkShop $linkShop
*/
public function __construct(
AccountsClient $accountsClient,
ShopProvider $shopProvider,
Oauth2Client $oauth2Client,
ShopContext $shopContext,
LinkShop $linkShop
) {
$this->accountsClient = $accountsClient;
$this->shopProvider = $shopProvider;
$this->oauth2Client = $oauth2Client;
$this->shopContext = $shopContext;
$this->linkShop = $linkShop;
}

/**
* @param CreateIdentityCommand $command
*
* @return void
*
* @throws \PrestaShopException
* @throws \Exception
*/
public function handle(CreateIdentityCommand $command)
{
$this->shopContext->execInShopContext($command->shopId, function () {
if (!$this->oauth2Client->exists()) {
$currentShop = $this->shopProvider->getCurrentShop();
$url = rtrim($currentShop['frontUrl'], '/');
$backOfficeUrl = explode('/index.php', $currentShop['url'])[0];
$resp = $this->accountsClient->createShopIdentity($backOfficeUrl, $url, intval($currentShop['id']));
if ($resp['status'] === true && $resp['body']) {
$this->oauth2Client->update($resp['body']['clientId'], $resp['body']['clientSecret']);
$this->linkShop->setShopUuid($resp['body']['cloudShopId']);
} else {
// TODO Add bad request handling here
}
}
});
}
}
75 changes: 0 additions & 75 deletions src/Account/CommandHandler/MigrateAndLinkV4ShopHandler.php

This file was deleted.

Loading
Loading