File indexing completed on 2024-12-22 04:45:22

0001 /*
0002    SPDX-FileCopyrightText: 2022-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "licensesisenterprisejob.h"
0008 #include "restapimethod.h"
0009 #include "rocketchatqtrestapi_debug.h"
0010 #include <QJsonDocument>
0011 #include <QJsonObject>
0012 #include <QNetworkReply>
0013 using namespace RocketChatRestApi;
0014 LicensesIsEnterpriseJob::LicensesIsEnterpriseJob(QObject *parent)
0015     : RestApiAbstractJob(parent)
0016 {
0017 }
0018 
0019 LicensesIsEnterpriseJob::~LicensesIsEnterpriseJob() = default;
0020 
0021 bool LicensesIsEnterpriseJob::requireHttpAuthentication() const
0022 {
0023     return true;
0024 }
0025 
0026 bool LicensesIsEnterpriseJob::start()
0027 {
0028     if (!canStart()) {
0029         qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start LicensesIsEnterpriseJob";
0030         deleteLater();
0031         return false;
0032     }
0033     submitGetRequest();
0034     addStartRestApiInfo(QByteArrayLiteral("LicensesIsEnterpriseJob: Ask for licenses"));
0035     return true;
0036 }
0037 
0038 void LicensesIsEnterpriseJob::onGetRequestResponse(const QString &replyErrorString, const QJsonDocument &replyJson)
0039 {
0040     const QJsonObject replyObject = replyJson.object();
0041 
0042     if (replyObject[QLatin1String("success")].toBool()) {
0043         addLoggerInfo(QByteArrayLiteral("LicensesIsEnterpriseJob: success: ") + replyJson.toJson(QJsonDocument::Indented));
0044         Q_EMIT licensesIsEnterpriseDone(replyObject[QLatin1String("isEnterprise")].toBool());
0045     } else {
0046         emitFailedMessage(replyErrorString, replyObject);
0047         addLoggerWarning(QByteArrayLiteral("LicensesIsEnterpriseJob: Problem: ") + replyJson.toJson(QJsonDocument::Indented));
0048     }
0049 }
0050 
0051 QNetworkRequest LicensesIsEnterpriseJob::request() const
0052 {
0053     const QUrl url = mRestApiMethod->generateUrl(RestApiUtil::RestApiUrlType::LicensesIsEntreprise);
0054     QNetworkRequest request(url);
0055     addAuthRawHeader(request);
0056     addRequestAttribute(request, false);
0057 
0058     return request;
0059 }
0060 
0061 #include "moc_licensesisenterprisejob.cpp"