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