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 <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2024-02-27 15:51:46 +01:00
parent 97077f4d26
commit e2a0dd2cef

View File

@@ -333,11 +333,17 @@ static constexpr int httpStatusCodeOk = 200;
constexpr char s_htmlContentType[] = "text/html"; constexpr char s_htmlContentType[] = "text/html";
constexpr char s_jsonContentType[] = "application/json"; 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<void(const QByteArray &)> &handler) static Group fetchHtmlRecipe(const QUrl &url, const std::function<void(const QByteArray &)> &handler)
{ {
// TODO: Refactor so that it's a common code with fetchDataRecipe(). // TODO: Refactor so that it's a common code with fetchDataRecipe().
const auto onQuerySetup = [url](NetworkQuery &query) { const auto onQuerySetup = [url](NetworkQuery &query) {
if (dd->m_serverAccess == ServerAccess::Unknown) if (!isServerAccessEstablished())
return SetupResult::StopWithError; // TODO: start authorizationRecipe()? return SetupResult::StopWithError; // TODO: start authorizationRecipe()?
QNetworkRequest request(url); QNetworkRequest request(url);
@@ -506,7 +512,7 @@ static Group authorizationRecipe()
{ {
const Storage<GetDtoStorage<Dto::DashboardInfoDto>> unauthorizedDashboardStorage; const Storage<GetDtoStorage<Dto::DashboardInfoDto>> unauthorizedDashboardStorage;
const auto onUnauthorizedGroupSetup = [unauthorizedDashboardStorage] { const auto onUnauthorizedGroupSetup = [unauthorizedDashboardStorage] {
if (dd->m_serverAccess != ServerAccess::NoAuthorization) if (isServerAccessEstablished())
return SetupResult::StopWithSuccess; return SetupResult::StopWithSuccess;
unauthorizedDashboardStorage->url = QUrl(settings().server.dashboard); unauthorizedDashboardStorage->url = QUrl(settings().server.dashboard);
@@ -636,10 +642,11 @@ static Group fetchDataRecipe(const QUrl &url, const std::function<void(const Dto
const Storage<GetDtoStorage<DtoType>> dtoStorage; const Storage<GetDtoStorage<DtoType>> dtoStorage;
const auto onDtoSetup = [dtoStorage, url] { const auto onDtoSetup = [dtoStorage, url] {
if (!dd->m_apiToken) if (!isServerAccessEstablished())
return SetupResult::StopWithError; 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; dtoStorage->url = url;
return SetupResult::Continue; return SetupResult::Continue;
}; };