mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-22 04:55:48 +03:00
Use verification job within edit locally job
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
parent
1422df733a
commit
a5713fc233
2 changed files with 4 additions and 41 deletions
|
@ -18,7 +18,7 @@
|
|||
#include <QDesktopServices>
|
||||
#include <QtConcurrent>
|
||||
|
||||
#include "editlocallymanager.h"
|
||||
#include "editlocallyverificationjob.h"
|
||||
#include "folder.h"
|
||||
#include "folderman.h"
|
||||
#include "syncengine.h"
|
||||
|
@ -84,45 +84,9 @@ void EditLocallyJob::startSetup()
|
|||
|
||||
void EditLocallyJob::startTokenRemoteCheck()
|
||||
{
|
||||
if (!_accountState || _relPath.isEmpty() || _token.isEmpty()) {
|
||||
qCWarning(lcEditLocallyJob) << "Could not start token check."
|
||||
<< "accountState:" << _accountState
|
||||
<< "relPath:" << _relPath
|
||||
<< "token:" << _token;
|
||||
|
||||
showError(tr("Could not start editing locally."),
|
||||
tr("An error occurred trying to verify the request to edit locally."));
|
||||
return;
|
||||
}
|
||||
|
||||
const auto encodedToken = QString::fromUtf8(QUrl::toPercentEncoding(_token)); // Sanitise the token
|
||||
const auto encodedRelPath = QUrl::toPercentEncoding(_relPath); // Sanitise the relPath
|
||||
|
||||
const auto checkTokenJob = new SimpleApiJob(_accountState->account(),
|
||||
QStringLiteral("/ocs/v2.php/apps/files/api/v1/openlocaleditor/%1").arg(encodedToken));
|
||||
|
||||
QUrlQuery params;
|
||||
params.addQueryItem(QStringLiteral("path"), prefixSlashToPath(encodedRelPath));
|
||||
checkTokenJob->addQueryParams(params);
|
||||
checkTokenJob->setVerb(SimpleApiJob::Verb::Post);
|
||||
connect(checkTokenJob, &SimpleApiJob::resultReceived, this, &EditLocallyJob::remoteTokenCheckResultReceived);
|
||||
|
||||
checkTokenJob->start();
|
||||
}
|
||||
|
||||
void EditLocallyJob::remoteTokenCheckResultReceived(const int statusCode)
|
||||
{
|
||||
qCInfo(lcEditLocallyJob) << "token check result" << statusCode;
|
||||
|
||||
constexpr auto HTTP_OK_CODE = 200;
|
||||
_tokenVerified = statusCode == HTTP_OK_CODE;
|
||||
|
||||
if (!_tokenVerified) {
|
||||
showError(tr("Could not validate the request to open a file from server."), tr("Please try again."));
|
||||
return;
|
||||
}
|
||||
|
||||
findAfolderAndConstructPaths();
|
||||
const auto verificationJob = new EditLocallyVerificationJob(_accountState, _relPath, _token);
|
||||
connect(verificationJob, &EditLocallyVerificationJob::error, this, &EditLocallyJob::showError);
|
||||
connect(verificationJob, &EditLocallyVerificationJob::finished, this, &EditLocallyJob::findAfolderAndConstructPaths);
|
||||
}
|
||||
|
||||
void EditLocallyJob::proceedWithSetup()
|
||||
|
|
|
@ -63,7 +63,6 @@ private slots:
|
|||
void showErrorNotification(const QString &message, const QString &informativeText) const;
|
||||
void showErrorMessageBox(const QString &message, const QString &informativeText) const;
|
||||
|
||||
void remoteTokenCheckResultReceived(const int statusCode);
|
||||
void slotItemDiscovered(const OCC::SyncFileItemPtr &item);
|
||||
void slotItemCompleted(const OCC::SyncFileItemPtr &item);
|
||||
|
||||
|
|
Loading…
Reference in a new issue