[CSE] Implement the Folder Unlock api job

This commit is contained in:
Tomaz Canabrava 2017-11-01 17:54:17 +01:00
parent 1b1add5ead
commit 2698759525
2 changed files with 66 additions and 0 deletions

View file

@ -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<QPair<QString, QString>> 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());
}
}

View file

@ -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