From e2a0dd2cefe5265a9d3ba59de766f73302cf0082 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Tue, 27 Feb 2024 15:51:46 +0100 Subject: [PATCH] Axivion: Fix the condition inside onUnauthorizedGroupSetup We should execute this branch just once, when the server access is unknown. Introduce isServerAccessEstablished() helper. Change-Id: I28953f468be39ca49f088032aebb3fa81b814f3f Reviewed-by: hjk --- src/plugins/axivion/axivionplugin.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/plugins/axivion/axivionplugin.cpp b/src/plugins/axivion/axivionplugin.cpp index 43316c4f8b7..2152755fd14 100644 --- a/src/plugins/axivion/axivionplugin.cpp +++ b/src/plugins/axivion/axivionplugin.cpp @@ -333,11 +333,17 @@ static constexpr int httpStatusCodeOk = 200; constexpr char s_htmlContentType[] = "text/html"; constexpr char s_jsonContentType[] = "application/json"; +static bool isServerAccessEstablished() +{ + return dd->m_serverAccess == ServerAccess::NoAuthorization + || (dd->m_serverAccess == ServerAccess::WithAuthorization && dd->m_apiToken); +} + static Group fetchHtmlRecipe(const QUrl &url, const std::function &handler) { // TODO: Refactor so that it's a common code with fetchDataRecipe(). const auto onQuerySetup = [url](NetworkQuery &query) { - if (dd->m_serverAccess == ServerAccess::Unknown) + if (!isServerAccessEstablished()) return SetupResult::StopWithError; // TODO: start authorizationRecipe()? QNetworkRequest request(url); @@ -506,7 +512,7 @@ static Group authorizationRecipe() { const Storage> unauthorizedDashboardStorage; const auto onUnauthorizedGroupSetup = [unauthorizedDashboardStorage] { - if (dd->m_serverAccess != ServerAccess::NoAuthorization) + if (isServerAccessEstablished()) return SetupResult::StopWithSuccess; unauthorizedDashboardStorage->url = QUrl(settings().server.dashboard); @@ -636,10 +642,11 @@ static Group fetchDataRecipe(const QUrl &url, const std::function> dtoStorage; const auto onDtoSetup = [dtoStorage, url] { - if (!dd->m_apiToken) + if (!isServerAccessEstablished()) return SetupResult::StopWithError; - dtoStorage->credential = "AxToken " + *dd->m_apiToken; + if (dd->m_serverAccess == ServerAccess::WithAuthorization && dd->m_apiToken) + dtoStorage->credential = "AxToken " + *dd->m_apiToken; dtoStorage->url = url; return SetupResult::Continue; };