File indexing completed on 2024-12-22 04:45:21
0001 /* 0002 SPDX-FileCopyrightText: 2018-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "getgrouprolesjob.h" 0008 #include "restapimethod.h" 0009 #include "rocketchatqtrestapi_debug.h" 0010 #include <KLocalizedString> 0011 #include <QJsonDocument> 0012 #include <QJsonObject> 0013 #include <QNetworkReply> 0014 #include <QUrlQuery> 0015 using namespace RocketChatRestApi; 0016 GetGroupRolesJob::GetGroupRolesJob(QObject *parent) 0017 : ChannelGroupBaseJob(parent) 0018 { 0019 } 0020 0021 GetGroupRolesJob::~GetGroupRolesJob() = default; 0022 0023 bool GetGroupRolesJob::canStart() const 0024 { 0025 if (!hasIdentifier()) { 0026 qCWarning(ROCKETCHATQTRESTAPI_LOG) << "GetGroupRolesJob: RoomId and RoomName are empty"; 0027 return false; 0028 } 0029 if (!RestApiAbstractJob::canStart()) { 0030 return false; 0031 } 0032 return true; 0033 } 0034 0035 bool GetGroupRolesJob::start() 0036 { 0037 if (!canStart()) { 0038 qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start server info job"; 0039 deleteLater(); 0040 return false; 0041 } 0042 0043 submitGetRequest(); 0044 addStartRestApiInfo("GetGroupRolesJob::start"); 0045 0046 return true; 0047 } 0048 0049 QNetworkRequest GetGroupRolesJob::request() const 0050 { 0051 QUrl url = mRestApiMethod->generateUrl(RestApiUtil::RestApiUrlType::GroupsRoles); 0052 addQueryItem(url); 0053 QNetworkRequest request(url); 0054 addRequestAttribute(request, false); 0055 addAuthRawHeader(request); 0056 return request; 0057 } 0058 0059 bool GetGroupRolesJob::requireHttpAuthentication() const 0060 { 0061 return true; 0062 } 0063 0064 QString GetGroupRolesJob::jobName() const 0065 { 0066 return i18n("Extract Roles"); 0067 } 0068 0069 void GetGroupRolesJob::onGetRequestResponse(const QString &replyErrorString, const QJsonDocument &replyJson) 0070 { 0071 const QJsonObject replyObject = replyJson.object(); 0072 if (replyObject[QLatin1String("success")].toBool()) { 0073 addLoggerInfo(QByteArrayLiteral("GetGroupRolesJob: success: ") + replyJson.toJson(QJsonDocument::Indented)); 0074 Q_EMIT groupRolesDone(replyObject, channelGroupInfo()); 0075 } else { 0076 emitFailedMessage(replyErrorString, replyObject); 0077 addLoggerWarning(QByteArrayLiteral("GetGroupRolesJob problem: ") + replyJson.toJson(QJsonDocument::Indented)); 0078 } 0079 } 0080 0081 #include "moc_getgrouprolesjob.cpp"