File indexing completed on 2024-12-22 04:45:28
0001 /* 0002 SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "removeothertokensjob.h" 0008 #include "restapimethod.h" 0009 0010 #include <QJsonDocument> 0011 #include <QJsonObject> 0012 #include <QNetworkReply> 0013 using namespace RocketChatRestApi; 0014 RemoveOtherTokensJob::RemoveOtherTokensJob(QObject *parent) 0015 : RestApiAbstractJob(parent) 0016 { 0017 } 0018 0019 RemoveOtherTokensJob::~RemoveOtherTokensJob() = default; 0020 0021 bool RemoveOtherTokensJob::start() 0022 { 0023 if (!canStart()) { 0024 deleteLater(); 0025 return false; 0026 } 0027 addStartRestApiInfo("RemoveOtherTokensJob::start"); 0028 submitPostRequest(json()); 0029 return true; 0030 } 0031 0032 void RemoveOtherTokensJob::onPostRequestResponse(const QString &replyErrorString, const QJsonDocument &replyJson) 0033 { 0034 const QJsonObject replyObject = replyJson.object(); 0035 if (replyObject[QLatin1String("success")].toBool()) { 0036 addLoggerInfo(QByteArrayLiteral("RemoveOtherTokensJob: success: ") + replyJson.toJson(QJsonDocument::Indented)); 0037 Q_EMIT removeOtherTokensDone(); 0038 } else { 0039 emitFailedMessage(replyErrorString, replyObject); 0040 addLoggerWarning(QByteArrayLiteral("RemoveOtherTokensJob: Problem: ") + replyJson.toJson(QJsonDocument::Indented)); 0041 } 0042 } 0043 0044 bool RemoveOtherTokensJob::requireHttpAuthentication() const 0045 { 0046 return true; 0047 } 0048 0049 bool RemoveOtherTokensJob::canStart() const 0050 { 0051 if (!RestApiAbstractJob::canStart()) { 0052 return false; 0053 } 0054 return true; 0055 } 0056 0057 QNetworkRequest RemoveOtherTokensJob::request() const 0058 { 0059 const QUrl url = mRestApiMethod->generateUrl(RestApiUtil::RestApiUrlType::UsersRemoveOtherTokens); 0060 QNetworkRequest request(url); 0061 addAuthRawHeader(request); 0062 addRequestAttribute(request); 0063 return request; 0064 } 0065 0066 QJsonDocument RemoveOtherTokensJob::json() const 0067 { 0068 return {}; 0069 } 0070 0071 #include "moc_removeothertokensjob.cpp"