diff --git a/src/libsync/clientsideencryption.cpp b/src/libsync/clientsideencryption.cpp index e7dc1f1a1..ec4c0a113 100644 --- a/src/libsync/clientsideencryption.cpp +++ b/src/libsync/clientsideencryption.cpp @@ -1032,6 +1032,43 @@ bool LockEncryptFolderApiJob::finished() QJsonParseError error; auto json = QJsonDocument::fromJson(reply()->readAll(), &error); emit jsonReceived(json, reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt()); + //TODO: Parse the token and submit. +} + + +UnlockEncryptFolderApiJob::UnlockEncryptFolderApiJob(const AccountPtr& account, + const QString& fileId, + const QString& token, + QObject* parent) +: AbstractNetworkJob(account, baseUrl() + QStringLiteral("lock/") + fileId, parent), _fileId(fileId), _token(token) +{ +} + +void UnlockEncryptFolderApiJob::start() +{ + QNetworkRequest req; + req.setRawHeader("OCS-APIREQUEST", "true"); + QUrl url = Utility::concatUrlPath(account()->url(), path()); + QList> params = { + qMakePair(QString::fromLatin1("format"), QString::fromLatin1("json")), + qMakePair(QString::fromLatin1("token"), _token) + }; + url.setQueryItems(params); + + qCInfo(lcCseJob()) << "unlocking the folder with id" << _fileId << "as encrypted"; + sendRequest("DELETE", url, req); + AbstractNetworkJob::start(); +} + +bool UnlockEncryptFolderApiJob::finished() +{ + int retCode = reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); + if (retCode != 200) + qCInfo(lcCseJob()) << "error unlocking file" << path() << errorString() << retCode; + + QJsonParseError error; + auto json = QJsonDocument::fromJson(reply()->readAll(), &error); + emit jsonReceived(json, reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt()); } } diff --git a/src/libsync/clientsideencryption.h b/src/libsync/clientsideencryption.h index 61cc3282c..b6f3e6143 100644 --- a/src/libsync/clientsideencryption.h +++ b/src/libsync/clientsideencryption.h @@ -228,5 +228,34 @@ private: QString _fileId; }; +class OWNCLOUDSYNC_EXPORT UnlockEncryptFolderApiJob : public AbstractNetworkJob +{ + Q_OBJECT +public: + explicit UnlockEncryptFolderApiJob ( + const AccountPtr &account, + const QString& fileId, + const QString& token, + QObject *parent = 0); + +public slots: + void start() override; + +protected: + bool finished() override; + +signals: + + /** + * @brief jsonReceived - signal to report the json answer from ocs + * @param json - the parsed json document + * @param statusCode - the OCS status code: 200 for success + */ + void jsonReceived(const QJsonDocument &json, int statusCode); +private: + QString _fileId; + QString _token; +}; + } // namespace OCC #endif