Skip to content

Commit

Permalink
[ACCOUNT-2375] refactor: upgrade oauth2-prestashop & cleanup obsolete…
Browse files Browse the repository at this point in the history
… code (#396)

* feat: automate build_front for version number

* refactor: update oauth2-prestashop & cleanup obsolete code

* feat: module stats
  • Loading branch information
hschoenenberger authored May 30, 2024
1 parent f32299e commit feb53e1
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 96 deletions.
36 changes: 22 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,17 @@ default: bundle
help:
@egrep "^# target" Makefile

clean:
git -c core.excludesfile=/dev/null clean -X -d -f

##########################################################
# target: version

VERSION ?= $(shell git describe --tags | sed 's/^v//' | cut -d'-' -f1)

version:
@echo "...$(VERSION)..."
sed -i -e "s/\(VERSION = \).*/\1\'${VERSION}\';/" ps_accounts.php
sed -i -e "s/\($this->version = \).*/\1\'${VERSION}\';/" ps_accounts.php
sed -i -e 's/\(<version><!\[CDATA\[\)[0-9a-z\.\-]\{1,\}.*\]\]><\/version>/\1'${VERSION}']]><\/version>/' config.xml
sed -i -e "s/\(\"version\"\: \).*/\1\"${VERSION}\",/" ./_dev/package.json
@echo "Setting up version number : $(VERSION)..."
@sed -i -e "s/\(VERSION = \).*/\1\'${VERSION}\';/" ps_accounts.php
@sed -i -e "s/\($this->version = \).*/\1\'${VERSION}\';/" ps_accounts.php
@sed -i -e 's/\(<version><!\[CDATA\[\)[0-9a-z\.\-]\{1,\}.*\]\]><\/version>/\1'${VERSION}']]><\/version>/' config.xml
@sed -i -e "s/\(\"version\"\: \).*/\1\"${VERSION}\",/" ./_dev/package.json

##########################################################
# target: tests
Expand Down Expand Up @@ -165,29 +162,40 @@ php-scoper: php-scoper-add-prefix php-scoper-dump-autoload php-scoper-fix-autolo

BUNDLE_ENV ?= # ex: local|preprod|prod
BUNDLE_ZIP ?= # ex: ps_accounts_flavor.zip
BUNDLE_VERSION ?= $(shell grep "<version>" config.xml | sed 's/^.*\([0-9]\+\.[0-9]\+\.[0-9]\+\).*/\1/')
BUNDLE_JS ?= views/js/app.${BUNDLE_VERSION}.js

bundle: php-scoper config/config.yml
bundle: php-scoper config/config.yml build-front
@./scripts/bundle-module.sh "${BUNDLE_ZIP}" "${BUNDLE_ENV}"

bundle-prod: php-scoper config/config.yml.prod
bundle-prod: php-scoper config/config.yml.prod build-front
@./scripts/bundle-module.sh "ps_accounts.zip" "prod"

bundle-preprod: php-scoper config/config.yml.preprod
bundle-preprod: php-scoper config/config.yml.preprod build-front
@./scripts/bundle-module.sh "ps_accounts_preprod.zip" "preprod"

build-front:
define build_front
yarn --cwd ./_dev --frozen-lockfile
yarn --cwd ./_dev build
endef

${BUNDLE_JS}:
ifndef YARN
$(error "YARN is unavailable on your system, try `npm i -g yarn`")
endif
yarn --cwd ./_dev --frozen-lockfile
yarn --cwd ./_dev build
$(call build_front)

build-front: ${BUNDLE_JS}

composer.phar:
ifndef PHP
$(error "PHP is unavailable on your system")
endif
./scripts/composer-install.sh

#clean:
# git -c core.excludesfile=/dev/null clean -X -d -f

##########################################################
# target: php-cs-fixer
# target: autoindex
Expand Down
30 changes: 14 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@

# PrestaShop Account

[![Source Code](https://img.shields.io/badge/source-PrestaShopCorp/ps_accounts-blue.svg?style=flat-square)](https://github.com/PrestaShopCorp/ps_accounts)
[![Latest Version](https://img.shields.io/github/release/PrestaShopCorp/ps_accounts.svg?style=flat-square)](https://github.com/PrestaShopCorp/ps_accounts/releases)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](https://github.com/PrestaShopCorp/oauth2-prestashop/blob/main/LICENSE)
[![Build Status](https://img.shields.io/github/actions/workflow/status/PrestaShopCorp/ps_accounts/.github/workflows/php.yml?label=CI&logo=github&style=flat-square)](https://github.com/PrestaShopCorp/ps_accounts/actions?query=workflow%3ACI)
[![Total Downloads](https://img.shields.io/packagist/dt/PrestaShopCorp/ps_accounts.svg?style=flat-square)](https://packagist.org/packages/prestashopcorp/ps_accounts)

The module **ps_accounts** is the interface between your module and PrestaShop's services. It manages:
- Shop association and dissociation processes.
- Maintain secure communication between shop and Prestashop services.
Expand Down Expand Up @@ -67,15 +74,15 @@ This modules manages the following tokens:

This module has three parts:
- [PS Accounts module](http://github.com/PrestaShopCorp/ps_accounts)
- This module must be installed.
- It's your interface between your module and PrestaShop Accounts service.
- This module must be installed.
- It's your interface between your module and PrestaShop Accounts service.
- [PS Accounts Installer (Composer Library)](http://github.com/PrestaShopCorp/prestashop-accounts-installer)
- This library's role is here to compensate a lack of security between modules dependencies. If PS Accounts is removed while your module is still installed: it causes a crash of the PrestaShop module's page/feature.
- This library is here to install automatically PS Accounts if it's missing.
- It's your interface between your module and PrestaShop Accounts module
- You should never require directly PrestaShop\Module\PsAccounts namespace classes
- This library's role is here to compensate a lack of security between modules dependencies. If PS Accounts is removed while your module is still installed: it causes a crash of the PrestaShop module's page/feature.
- This library is here to install automatically PS Accounts if it's missing.
- It's your interface between your module and PrestaShop Accounts module
- You should never require directly PrestaShop\Module\PsAccounts namespace classes
- [PrestaShop Accounts Vue Components](http://github.com/PrestaShopCorp/prestashop_accounts_vue_components)
- It's the front-end component you need to integrate into your module's configuration page.
- It's the front-end component you need to integrate into your module's configuration page.

## How to start working with PS Accounts as a PSx or Community Service developer?

Expand Down Expand Up @@ -149,12 +156,3 @@ Those API has been removed:
- `/orders`
- `/products`
- `/themes`

## Custom hooks

Here are listed custom hooks provided with this module :

| Hook name | Payload | Description |
|------------------------------|------------------|------------------------------------------------------|
| actionShopAccountLinkAfter | shopId, shopUuid | Triggered after link has been acknowledged by shop |
| actionShopAccountUnlinkAfter | shopId, shopUuid | Triggered after unlink has been acknowledged by shop |
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.1",
"version": "7.0.2",
"private": true,
"scripts": {
"dev": "vite",
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"sentry/sentry": "^1.0",
"segmentio/analytics-php": "^1.8",
"ramsey/uuid": "^3.9",
"prestashopcorp/oauth2-prestashop": "dev-refactor/php-compat-range",
"prestashopcorp/oauth2-prestashop": "^2.0",
"guzzlehttp/guzzle": "^6.0"
},
"require-dev": {
Expand All @@ -55,4 +55,4 @@
"author": "PrestaShop",
"license": "AFL-3.0",
"type": "prestashop-module"
}
}
28 changes: 13 additions & 15 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.1]]></version>
<version><![CDATA[7.0.2]]></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
4 changes: 2 additions & 2 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.1';
const VERSION = '7.0.2';

/**
* 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.1';
$this->version = '7.0.2';

$this->module_key = 'abf2cd758b4d629b2944d3922ef9db73';

Expand Down
45 changes: 0 additions & 45 deletions src/Provider/OAuth2/ShopProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
use PrestaShop\Module\PsAccounts\Adapter\Link;
use PrestaShop\Module\PsAccounts\Vendor\League\OAuth2\Client\Provider\AbstractProvider;
use PrestaShop\OAuth2\Client\Provider\PrestaShop;
use PrestaShop\OAuth2\Client\Provider\WellKnown;

class ShopProvider extends PrestaShop
{
Expand Down Expand Up @@ -161,50 +160,6 @@ protected function getAuthorizationParameters(array $options)
return parent::getAuthorizationParameters($options);
}

/**
* @return WellKnown
*/
public function getWellKnown()
{
if (!isset($this->wellKnown)) {
try {
$this->wellKnown = new WellKnown(
$this->fetchWellKnown($this->getOauth2Url(), $this->verify)
);
} catch (\Error $e) {
} catch (\Exception $e) {
}
if (isset($e)) {
$this->wellKnown = new WellKnown();
}
}

return $this->wellKnown;
}

/**
* @param string $url
* @param bool $secure
*
* @return array
*
* @throws \Exception
*/
protected function fetchWellKnown($url, $secure = true)
{
$wellKnownUrl = $url;
if (strpos($wellKnownUrl, '/.well-known') === false) {
$wellKnownUrl = preg_replace('/\/?$/', '/.well-known/openid-configuration', $wellKnownUrl);
}

return json_decode((string) \Tools::file_get_contents($wellKnownUrl, false, stream_context_create([
'ssl' => [
'verify_peer' => $secure,
'verify_peer_name' => $secure,
],
])), true) ?: [];
}

/**
* @return void
*/
Expand Down

0 comments on commit feb53e1

Please sign in to comment.