From 558e6c9dc60ff4f11bc0ef8a8e7a18e3ef574ab7 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Tue, 31 Jan 2023 00:16:01 +0530 Subject: [PATCH 01/58] added subscription in condition to delete account --- l10n/de.js | 3 ++- l10n/de.json | 3 ++- l10n/en.js | 3 ++- l10n/en.json | 3 ++- l10n/es.js | 3 ++- l10n/es.json | 3 ++- l10n/fr.js | 3 ++- l10n/fr.json | 3 ++- l10n/it.js | 3 ++- l10n/it.json | 3 ++- lib/Controller/ShopAccountController.php | 9 ++++++--- lib/Service/ShopAccountService.php | 11 +++++++++++ src/PersonalSettings.vue | 17 +++++++++++++---- 13 files changed, 50 insertions(+), 17 deletions(-) diff --git a/l10n/de.js b/l10n/de.js index 17cc4feb..62d1f079 100644 --- a/l10n/de.js +++ b/l10n/de.js @@ -33,6 +33,7 @@ OC.L10N.register( "Experimental": "Experimentelle", "Title is mandatory.": "Der Titel ist obligatorisch.", "Description is mandatory.": "Die Beschreibung ist obligatorisch.", - "Here is the list of currently available beta features:": "Hier ist die Liste der derzeit verfügbaren Beta-Funktionen:" + "Here is the list of currently available beta features:": "Hier ist die Liste der derzeit verfügbaren Beta-Funktionen:", + "A subscription is active in this account. Please cancel it or let it expire before deleting your account.": "Für dieses Konto ist ein Abonnement aktiv. Bitte kündigen Sie es oder lassen Sie es auslaufen, bevor Sie Ihr Konto löschen." }, "nplurals=2; plural=(n != 1);"); diff --git a/l10n/de.json b/l10n/de.json index a0cf4e19..16d4748d 100644 --- a/l10n/de.json +++ b/l10n/de.json @@ -32,7 +32,8 @@ "Experimental": "Experimentelle", "Title is mandatory.": "Der Titel ist obligatorisch.", "Description is mandatory.": "Die Beschreibung ist obligatorisch.", - "Here is the list of currently available beta features:": "Hier ist die Liste der derzeit verfügbaren Beta-Funktionen:" + "Here is the list of currently available beta features:": "Hier ist die Liste der derzeit verfügbaren Beta-Funktionen:", + "A subscription is active in this account. Please cancel it or let it expire before deleting your account.": "Für dieses Konto ist ein Abonnement aktiv. Bitte kündigen Sie es oder lassen Sie es auslaufen, bevor Sie Ihr Konto löschen." }, "pluralForm": "nplurals=2; plural=(n != 1);" } diff --git a/l10n/en.js b/l10n/en.js index 323d5a0d..b445aafa 100644 --- a/l10n/en.js +++ b/l10n/en.js @@ -33,6 +33,7 @@ OC.L10N.register( "Experimental": "Experimental", "Title is mandatory.": "Title is mandatory.", "Description is mandatory.": "Description is mandatory.", - "Here is the list of currently available beta features:": "Here is the list of currently available beta features:" + "Here is the list of currently available beta features:": "Here is the list of currently available beta features:", + "A subscription is active in this account. Please cancel it or let it expire before deleting your account.": "A subscription is active in this account. Please cancel it or let it expire before deleting your account." }, "nplurals=2; plural=(n != 1);"); diff --git a/l10n/en.json b/l10n/en.json index f4232e51..c4f43677 100644 --- a/l10n/en.json +++ b/l10n/en.json @@ -32,7 +32,8 @@ "Experimental": "Experimental", "Title is mandatory.": "Title is mandatory.", "Description is mandatory.": "Description is mandatory.", - "Here is the list of currently available beta features:": "Here is the list of currently available beta features:" + "Here is the list of currently available beta features:": "Here is the list of currently available beta features:", + "A subscription is active in this account. Please cancel it or let it expire before deleting your account.": "A subscription is active in this account. Please cancel it or let it expire before deleting your account." }, "pluralForm": "nplurals=2; plural=(n != 1);" } diff --git a/l10n/es.js b/l10n/es.js index 56a8a041..95706198 100644 --- a/l10n/es.js +++ b/l10n/es.js @@ -34,6 +34,7 @@ OC.L10N.register( "Experimental": "Experimento", "Title is mandatory.": "El título es obligatorio.", "Description is mandatory.": "La descripción es obligatoria.", - "Here is the list of currently available beta features:": "Esta es la lista de funciones de la versión beta disponibles actualmente:" + "Here is the list of currently available beta features:": "Esta es la lista de funciones de la versión beta disponibles actualmente:", + "A subscription is active in this account. Please cancel it or let it expire before deleting your account.": "Hay una suscripción activa en esta cuenta. Por favor, cancélala o deja que expire antes de eliminar tu cuenta." }, "nplurals=2; plural=(n != 1);"); diff --git a/l10n/es.json b/l10n/es.json index 4db89166..0f68fab5 100644 --- a/l10n/es.json +++ b/l10n/es.json @@ -32,7 +32,8 @@ "Experimental": "Experimento", "Title is mandatory.": "El título es obligatorio.", "Description is mandatory.": "La descripción es obligatoria.", - "Here is the list of currently available beta features:": "Esta es la lista de funciones de la versión beta disponibles actualmente:" + "Here is the list of currently available beta features:": "Esta es la lista de funciones de la versión beta disponibles actualmente:", + "A subscription is active in this account. Please cancel it or let it expire before deleting your account.": "Hay una suscripción activa en esta cuenta. Por favor, cancélala o deja que expire antes de eliminar tu cuenta." }, "pluralForm": "nplurals=2; plural=(n != 1);" } diff --git a/l10n/fr.js b/l10n/fr.js index 6cbd0393..3f96c915 100644 --- a/l10n/fr.js +++ b/l10n/fr.js @@ -33,6 +33,7 @@ OC.L10N.register( "Experimental": "Expérimental", "Title is mandatory.": "Le titre est obligatoire.", "Description is mandatory.": "La description est obligatoire.", - "Here is the list of currently available beta features:": "Voici la liste des fonctionnalités de la version bêta actuellement disponibles :" + "Here is the list of currently available beta features:": "Voici la liste des fonctionnalités de la version bêta actuellement disponibles :", + "A subscription is active in this account. Please cancel it or let it expire before deleting your account.": "Un abonnement est actif dans ce compte. Veuillez l'annuler ou le laisser expirer avant de supprimer votre compte." }, "nplurals=2; plural=(n != 1);"); diff --git a/l10n/fr.json b/l10n/fr.json index a91d2a2d..a785b22e 100644 --- a/l10n/fr.json +++ b/l10n/fr.json @@ -32,7 +32,8 @@ "Experimental": "Expérimental", "Title is mandatory.": "Le titre est obligatoire.", "Description is mandatory.": "La description est obligatoire.", - "Here is the list of currently available beta features:": "Voici la liste des fonctionnalités de la version bêta actuellement disponibles :" + "Here is the list of currently available beta features:": "Voici la liste des fonctionnalités de la version bêta actuellement disponibles :", + "A subscription is active in this account. Please cancel it or let it expire before deleting your account.": "Un abonnement est actif dans ce compte. Veuillez l'annuler ou le laisser expirer avant de supprimer votre compte." }, "pluralForm": "nplurals=2; plural=(n != 1);" } diff --git a/l10n/it.js b/l10n/it.js index 8a53507a..7237d9c3 100644 --- a/l10n/it.js +++ b/l10n/it.js @@ -33,6 +33,7 @@ OC.L10N.register( "Experimental": "Sperimentale", "Title is mandatory.": "Il titolo è obbligatorio.", "Description is mandatory.": "La descrizione è obbligatoria.", - "Here is the list of currently available beta features:": "Ecco l'elenco delle funzioni beta attualmente disponibili:" + "Here is the list of currently available beta features:": "Ecco l'elenco delle funzioni beta attualmente disponibili:", + "A subscription is active in this account. Please cancel it or let it expire before deleting your account.": "In questo account è attivo un abbonamento. Si prega di annullarlo o di lasciarlo scadere prima di cancellare l'account." }, "nplurals=2; plural=(n != 1);"); diff --git a/l10n/it.json b/l10n/it.json index 257703bc..b455055b 100644 --- a/l10n/it.json +++ b/l10n/it.json @@ -32,7 +32,8 @@ "Experimental": "Sperimentale", "Title is mandatory.": "Il titolo è obbligatorio.", "Description is mandatory.": "La descrizione è obbligatoria.", - "Here is the list of currently available beta features:": "Ecco l'elenco delle funzioni beta attualmente disponibili:" + "Here is the list of currently available beta features:": "Ecco l'elenco delle funzioni beta attualmente disponibili:", + "A subscription is active in this account. Please cancel it or let it expire before deleting your account.": "In questo account è attivo un abbonamento. Si prega di annullarlo o di lasciarlo scadere prima di cancellare l'account." }, "pluralForm": "nplurals=2; plural=(n != 1);" } diff --git a/lib/Controller/ShopAccountController.php b/lib/Controller/ShopAccountController.php index 78779a4b..61559f98 100644 --- a/lib/Controller/ShopAccountController.php +++ b/lib/Controller/ShopAccountController.php @@ -73,13 +73,16 @@ class ShopAccountController extends Controller { */ public function getOrderInfo(int $userId) { $response = new DataResponse(); - $data = ['count' => 0, 'my_orders_url' => $this->shopAccountService->getShopUrl() . '/my-account/orders']; + $data = ['count' => 0,'subscriptions' => 0, 'my_orders_url' => $this->shopAccountService->getShopUrl() . '/my-account/orders']; + $orders = $this->shopAccountService->getOrders($userId); - + $subscriptions = $this->shopAccountService->getSubscriptions($userId); if ($orders) { $data['count'] = count($orders); } - + if ($subscriptions) { + $data['subscriptions'] = count($subscriptions); + } $response->setData($data); return $response; } diff --git a/lib/Service/ShopAccountService.php b/lib/Service/ShopAccountService.php index cb2984a2..8fd7b63c 100644 --- a/lib/Service/ShopAccountService.php +++ b/lib/Service/ShopAccountService.php @@ -26,6 +26,7 @@ class ShopAccountService { $this->shopUserUrl = $this->shopUrl . "/wp-json/wp/v2/users"; $this->shopOrdersUrl = $this->shopUrl . "/wp-json/wc/v3/orders"; + $this->subscriptionUrl = $this->shopUrl . "/wp-json/wc/v3/subscriptions"; $this->shopCredentials = base64_encode($shopUsername . ":" . $shopPassword); $this->curl = $curlService; $this->logger = $logger; @@ -169,4 +170,14 @@ class ShopAccountService { public function isUserOIDC(array $user) { return !empty($user['openid-connect-generic-last-user-claim']); } + + public function getSubscriptions(int $userId): ?array { + try { + return $this->callShopAPI($this->subscriptionUrl, 'GET', ['customer' => $userId]); + } catch (Exception $e) { + $this->logger->error('There was an issue querying shop for subscriptions for user ' . strval($userId)); + $this->logger->logException($e, ['app' => Application::APP_ID]); + } + return null; + } } diff --git a/src/PersonalSettings.vue b/src/PersonalSettings.vue index ba188817..d1401007 100644 --- a/src/PersonalSettings.vue +++ b/src/PersonalSettings.vue @@ -5,6 +5,7 @@ t('ecloud-accounts', 'We are going to proceed with your cloud account suppression. Check the box below if you also want to delete the associated shop account.') }} +

@@ -14,6 +15,7 @@ type="checkbox" name="shop-accounts_confirm" class="checkbox" + :disabled='subscriptionCount > 0' @change="updateDeleteShopPreference()">
@@ -84,7 +87,9 @@ export default { onlyAdmin: false, onlyUser: false, orderCount: 0, + subscriptionCount: 0, ordersDescription: this.t('ecloud-accounts', "For your information you have %d order(s) in your account."), + subscriptionDescription: this.t('ecloud-accounts', "A subscription is active in this account. Please cancel it or let it expire before deleting your account."), } }, created() { @@ -155,13 +160,17 @@ export default { async getOrdersInfo() { try { const url = generateUrl( - `/apps/${this.appName}/shop-accounts/order_info?userId=${this.shopUser.id}` + `/apps/${this.appName}/shop-accounts/order_info?userId=11758` ) const { status, data } = await Axios.get(url) if (status === 200) { - if (data.count > 0) { - this.ordersDescription = this.ordersDescription.replace('%d', data.count).replace('%s', data.my_orders_url) - this.orderCount = data.count + this.orderCount = data.count + if (this.orderCount) { + this.ordersDescription = this.ordersDescription.replace('%d', this.orderCount).replace('%s', data.my_orders_url) + } + this.subscriptionCount = data.subscriptions + if (this.subscriptionCount) { + this.subscriptionDescription = this.subscriptionDescription.replace('%d', this.subscriptionCount).replace('%s', data.my_orders_url) } } } catch (e) { -- GitLab From 76f8f702b85b460d704908de663d4874cd3c5cb4 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Tue, 31 Jan 2023 00:20:01 +0530 Subject: [PATCH 02/58] reverted code --- src/PersonalSettings.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PersonalSettings.vue b/src/PersonalSettings.vue index d1401007..a34d15d9 100644 --- a/src/PersonalSettings.vue +++ b/src/PersonalSettings.vue @@ -160,7 +160,7 @@ export default { async getOrdersInfo() { try { const url = generateUrl( - `/apps/${this.appName}/shop-accounts/order_info?userId=11758` + `/apps/${this.appName}/shop-accounts/order_info?userId=${this.shopUser.id}` ) const { status, data } = await Axios.get(url) if (status === 200) { -- GitLab From f2aabbbdfafe61b13c2b7a65e52fd2c95af22165 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Tue, 31 Jan 2023 23:41:14 +0530 Subject: [PATCH 03/58] lint fix --- src/PersonalSettings.vue | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/PersonalSettings.vue b/src/PersonalSettings.vue index a34d15d9..0cf26344 100644 --- a/src/PersonalSettings.vue +++ b/src/PersonalSettings.vue @@ -15,7 +15,7 @@ type="checkbox" name="shop-accounts_confirm" class="checkbox" - :disabled='subscriptionCount > 0' + :disabled="subscriptionCount > 0" @change="updateDeleteShopPreference()">