Skip to content

Commit

Permalink
Merge pull request PrestaShop#15 from jolelievre/rename-api-client
Browse files Browse the repository at this point in the history
Rename ApiAccess into ApiClient
  • Loading branch information
jolelievre authored Feb 19, 2024
2 parents 7622942 + 58d6bd2 commit c0ca6de
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 51 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:

permissions:
contents: read # to clone the repos and get release assets (shivammathur/setup-php)
concurrency:
group: ${{ github.event_name }}-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
integration:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: PHP tests
on: [push, pull_request]
concurrency:
group: ${{ github.event_name }}-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
# Check there is no syntax errors in the project
php-linter:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,109 +34,109 @@
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use PrestaShop\PrestaShop\Core\Domain\ApiAccess\Command\AddApiAccessCommand;
use PrestaShop\PrestaShop\Core\Domain\ApiAccess\Command\DeleteApiAccessCommand;
use PrestaShop\PrestaShop\Core\Domain\ApiAccess\Command\EditApiAccessCommand;
use PrestaShop\PrestaShop\Core\Domain\ApiAccess\Exception\ApiAccessNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\ApiAccess\Query\GetApiAccessForEditing;
use PrestaShop\PrestaShop\Core\Domain\ApiClient\Command\AddApiClientCommand;
use PrestaShop\PrestaShop\Core\Domain\ApiClient\Command\DeleteApiClientCommand;
use PrestaShop\PrestaShop\Core\Domain\ApiClient\Command\EditApiClientCommand;
use PrestaShop\PrestaShop\Core\Domain\ApiClient\Exception\ApiClientNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\ApiClient\Query\GetApiClientForEditing;
use PrestaShopBundle\ApiPlatform\Processor\CommandProcessor;
use PrestaShopBundle\ApiPlatform\Provider\QueryProvider;

#[ApiResource(
operations: [
new Get(
uriTemplate: '/api-access/{apiAccessId}',
requirements: ['apiAccessId' => '\d+'],
uriTemplate: '/api-client/{apiClientId}',
requirements: ['apiClientId' => '\d+'],
openapiContext: [
'summary' => 'Get API Access details',
'description' => 'Get API Access public details only, sensitive information like secrets is not returned',
'summary' => 'Get API Client details',
'description' => 'Get API Client public details only, sensitive information like secrets is not returned',
'parameters' => [
[
'name' => 'apiAccessId',
'name' => 'apiClientId',
'in' => 'path',
'required' => true,
'schema' => [
'type' => 'string',
],
'description' => 'Id of the API Access you are requesting the details from',
'description' => 'Id of the API Client you are requesting the details from',
],
[
'name' => 'Authorization',
'in' => 'scopes',
'description' => 'api_access_read',
'description' => 'api_client_read',
],
],
],
provider: QueryProvider::class,
extraProperties: [
'query' => GetApiAccessForEditing::class,
'CQRSQuery' => GetApiAccessForEditing::class,
'scopes' => ['api_access_read'],
'query' => GetApiClientForEditing::class,
'CQRSQuery' => GetApiClientForEditing::class,
'scopes' => ['api_client_read'],
]
),
new Delete(
uriTemplate: '/api-access/{apiAccessId}',
requirements: ['apiAccessId' => '\d+'],
uriTemplate: '/api-client/{apiClientId}',
requirements: ['apiClientId' => '\d+'],
openapiContext: [
'summary' => 'Delete API Access details',
'description' => 'Delete API Access public details only, sensitive information like secrets is not returned',
'summary' => 'Delete API Client details',
'description' => 'Delete API Client public details only, sensitive information like secrets is not returned',
'parameters' => [
[
'name' => 'apiAccessId',
'name' => 'apiClientId',
'in' => 'path',
'required' => true,
'schema' => [
'type' => 'string',
],
'description' => 'Id of the API Access you are deleting',
'description' => 'Id of the API Client you are deleting',
],
[
'name' => 'Authorization',
'in' => 'scopes',
'description' => 'api_access_write',
'description' => 'api_client_write',
],
],
],
output: false,
provider: QueryProvider::class,
extraProperties: [
'query' => DeleteApiAccessCommand::class,
'CQRSQuery' => DeleteApiAccessCommand::class,
'scopes' => ['api_access_write'],
'query' => DeleteApiClientCommand::class,
'CQRSQuery' => DeleteApiClientCommand::class,
'scopes' => ['api_client_write'],
]
),
new Post(
uriTemplate: '/api-access',
uriTemplate: '/api-client',
processor: CommandProcessor::class,
extraProperties: [
'command' => AddApiAccessCommand::class,
'CQRSCommand' => AddApiAccessCommand::class,
'scopes' => ['api_access_write'],
'command' => AddApiClientCommand::class,
'CQRSCommand' => AddApiClientCommand::class,
'scopes' => ['api_client_write'],
]
),
new Put(
uriTemplate: '/api-access/{apiAccessId}',
uriTemplate: '/api-client/{apiClientId}',
read: false,
processor: CommandProcessor::class,
extraProperties: [
'command' => EditApiAccessCommand::class,
'query' => GetApiAccessForEditing::class,
'CQRSCommand' => EditApiAccessCommand::class,
'CQRSQuery' => GetApiAccessForEditing::class,
'scopes' => ['api_access_write'],
'command' => EditApiClientCommand::class,
'query' => GetApiClientForEditing::class,
'CQRSCommand' => EditApiClientCommand::class,
'CQRSQuery' => GetApiClientForEditing::class,
'scopes' => ['api_client_write'],
]
),
],
exceptionToStatus: [ApiAccessNotFoundException::class => 404],
exceptionToStatus: [ApiClientNotFoundException::class => 404],
)]
class ApiAccess
class ApiClient
{
#[ApiProperty(identifier: true)]
public int $apiAccessId;
public int $apiClientId;

public string $secret;

public string $apiClientId;
public string $clientId;

public string $clientName;

Expand Down
18 changes: 9 additions & 9 deletions tests/Integration/ApiPlatform/ApiTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@

use ApiPlatform\Symfony\Bundle\Test\ApiTestCase as SymfonyApiTestCase;
use ApiPlatform\Symfony\Bundle\Test\Client;
use PrestaShop\PrestaShop\Core\Domain\ApiAccess\Command\AddApiAccessCommand;
use PrestaShop\PrestaShop\Core\Domain\ApiClient\Command\AddApiClientCommand;
use PrestaShop\PrestaShop\Core\Domain\Configuration\ShopConfigurationInterface;
use PrestaShop\PrestaShop\Core\Domain\Language\Command\AddLanguageCommand;
use PrestaShop\PrestaShop\Core\Domain\Shop\ValueObject\ShopConstraint;
use Tests\Resources\DatabaseDump;
use Tests\Resources\Resetter\ApiClientResetter;

abstract class ApiTestCase extends SymfonyApiTestCase
{
Expand All @@ -46,13 +46,13 @@ abstract class ApiTestCase extends SymfonyApiTestCase
public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
DatabaseDump::restoreTables(['api_access']);
ApiClientResetter::resetApiClient();
}

public static function tearDownAfterClass(): void
{
parent::tearDownAfterClass();
DatabaseDump::restoreTables(['api_access']);
ApiClientResetter::resetApiClient();
self::$clientSecret = null;
}

Expand All @@ -72,7 +72,7 @@ protected static function createClient(array $kernelOptions = [], array $default
protected function getBearerToken(array $scopes = []): string
{
if (null === self::$clientSecret) {
self::createApiAccess($scopes);
self::createApiClient($scopes);
}
$client = static::createClient();
$parameters = ['parameters' => [
Expand All @@ -92,10 +92,10 @@ protected function getBearerToken(array $scopes = []): string
return json_decode($response->getContent())->access_token;
}

protected static function createApiAccess(array $scopes = [], int $lifetime = 10000): void
protected static function createApiClient(array $scopes = [], int $lifetime = 10000): void
{
$client = static::createClient();
$command = new AddApiAccessCommand(
$command = new AddApiClientCommand(
static::CLIENT_NAME,
static::CLIENT_ID,
true,
Expand All @@ -106,9 +106,9 @@ protected static function createApiAccess(array $scopes = [], int $lifetime = 10

$container = $client->getContainer();
$commandBus = $container->get('prestashop.core.command_bus');
$createdApiAccess = $commandBus->handle($command);
$createdApiClient = $commandBus->handle($command);

self::$clientSecret = $createdApiAccess->getSecret();
self::$clientSecret = $createdApiClient->getSecret();
}

protected static function addLanguageByLocale(string $locale): int
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/ApiPlatform/CustomerGroupApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
DatabaseDump::restoreTables(['group', 'group_lang', 'group_reduction', 'group_shop', 'category_group']);
self::createApiAccess(['customer_group_write', 'customer_group_read']);
self::createApiClient(['customer_group_write', 'customer_group_read']);
}

public static function tearDownAfterClass(): void
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/ApiPlatform/ProductEndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static function setUpBeforeClass(): void
ProductResetter::resetProducts();
LanguageResetter::resetLanguages();
self::$frenchLangId = self::addLanguageByLocale('fr-FR');
self::createApiAccess(['product_write', 'product_read']);
self::createApiClient(['product_write', 'product_read']);
}

public static function tearDownAfterClass(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static function setUpBeforeClass(): void
self::$secondShopId = self::addShop('Second shop', self::DEFAULT_SHOP_GROUP_ID);
self::$thirdShopId = self::addShop('Third shop', self::$secondShopGroupId);
self::$fourthShopId = self::addShop('Fourth shop', self::$secondShopGroupId);
self::createApiAccess(['product_write', 'product_read']);
self::createApiClient(['product_write', 'product_read']);

self::$defaultProductData = [
'type' => ProductType::TYPE_STANDARD,
Expand Down

0 comments on commit c0ca6de

Please sign in to comment.