From 33e7d3531595fe5173f786bb5f66e1bd7507ebb7 Mon Sep 17 00:00:00 2001 From: makmentins Date: Tue, 27 Jun 2023 15:26:56 +0200 Subject: [PATCH 1/2] Revert "Revert "JI-4911 Add support for account removed on hub"" This reverts commit 0a82667e00175dea55e37ad8bbebedbfed25b5b6. --- h5p.classes.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/h5p.classes.php b/h5p.classes.php index 55870672..60e64459 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -3961,6 +3961,11 @@ public function hubAccountInfo() { $this->h5pF->setErrorMessage($this->h5pF->t('Hub account authentication info is invalid. This may be fixed by an admin by restoring the hub secret or register a new account with the content hub.')); return false; } + + if ($accountInfo['status'] === 403) { + // Unauthenticated, cannot find site uuid + return 'Unauthenticated.'; + } if ($accountInfo['status'] !== 200) { $this->h5pF->setErrorMessage($this->h5pF->t('Unable to retrieve HUB account information. Please contact support.')); @@ -3969,6 +3974,19 @@ public function hubAccountInfo() { return json_decode($accountInfo['data'])->data; } + + /** + * Check if registered for HUB + * + * @return bool False if account is not setup, otherwise true + */ + public function hubRegistered() { + $accountInfo = $this->hubAccountInfo(); + if (!$accountInfo || $accountInfo === 'Unauthenticated.') { + return false; + } + return true; + } /** * Register account @@ -4000,7 +4018,7 @@ public function hubRegisterAccount($formData, $logo) { $headers = []; $endpoint = H5PHubEndpoints::REGISTER; // Update if already registered - $hasRegistered = $this->h5pF->getOption('hub_secret'); + $hasRegistered = $this->hubRegistered(); if ($hasRegistered) { $endpoint .= "/{$uuid}"; $formData['_method'] = 'PUT'; From bf3bf81d8e9da6c6347e663a270545dc7e22277f Mon Sep 17 00:00:00 2001 From: makmentins Date: Tue, 27 Jun 2023 15:27:01 +0200 Subject: [PATCH 2/2] Revert "Revert "JI-4911 Fix improved hub account removal"" This reverts commit 82c813d6d56bf3c58a475f31de007e5f16bd6b59. --- h5p.classes.php | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/h5p.classes.php b/h5p.classes.php index 60e64459..4363d7a4 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -666,6 +666,13 @@ public function getContentHubMetadataChecked($lang = 'en'); * @return bool True if successful */ public function setContentHubMetadataChecked($time, $lang = 'en'); + + /** + * Callback for reset hub data + * + * @return void + */ + public function resetHubOrganizationData(); } /** @@ -3961,10 +3968,11 @@ public function hubAccountInfo() { $this->h5pF->setErrorMessage($this->h5pF->t('Hub account authentication info is invalid. This may be fixed by an admin by restoring the hub secret or register a new account with the content hub.')); return false; } - + if ($accountInfo['status'] === 403) { // Unauthenticated, cannot find site uuid - return 'Unauthenticated.'; + $this->h5pF->resetHubOrganizationData(); + return false; } if ($accountInfo['status'] !== 200) { @@ -3974,19 +3982,6 @@ public function hubAccountInfo() { return json_decode($accountInfo['data'])->data; } - - /** - * Check if registered for HUB - * - * @return bool False if account is not setup, otherwise true - */ - public function hubRegistered() { - $accountInfo = $this->hubAccountInfo(); - if (!$accountInfo || $accountInfo === 'Unauthenticated.') { - return false; - } - return true; - } /** * Register account @@ -4018,7 +4013,7 @@ public function hubRegisterAccount($formData, $logo) { $headers = []; $endpoint = H5PHubEndpoints::REGISTER; // Update if already registered - $hasRegistered = $this->hubRegistered(); + $hasRegistered = $this->hubAccountInfo() ? true : false; if ($hasRegistered) { $endpoint .= "/{$uuid}"; $formData['_method'] = 'PUT'; @@ -4110,8 +4105,7 @@ public function getHubContentStatus($hubContentId, $syncStatus) { null, true, null, true, $headers); if (isset($response['status']) && $response['status'] === 403) { - $msg = $this->h5pF->t('The request for content status was unauthorized. This could be because the content belongs to a different account, or your account is not setup properly.'); - $this->h5pF->setErrorMessage($msg); + $this->h5pF->resetHubOrganizationData(); return false; } if (empty($response) || $response['status'] !== 200) {