2015-09-07 14:50:01 +03:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Roeland Jago Douma <roeland@famdouma.nl>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2016-10-25 12:00:07 +03:00
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
2015-09-07 14:50:01 +03:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ocssharejob.h"
|
|
|
|
#include "networkjobs.h"
|
|
|
|
#include "account.h"
|
|
|
|
|
|
|
|
#include <QBuffer>
|
2017-04-26 12:38:10 +03:00
|
|
|
#include <QJsonDocument>
|
2015-09-07 14:50:01 +03:00
|
|
|
|
|
|
|
namespace OCC {
|
|
|
|
|
2015-11-11 15:28:20 +03:00
|
|
|
OcsShareJob::OcsShareJob(AccountPtr account)
|
|
|
|
: OcsJob(account)
|
2015-09-07 14:50:01 +03:00
|
|
|
{
|
2022-09-02 12:48:52 +03:00
|
|
|
setPath(_pathForSharesRequest);
|
2017-09-20 11:14:48 +03:00
|
|
|
connect(this, &OcsJob::jobFinished, this, &OcsShareJob::jobDone);
|
2015-09-07 14:50:01 +03:00
|
|
|
}
|
|
|
|
|
2022-09-02 12:48:52 +03:00
|
|
|
void OcsShareJob::getShares(const QString &path, const QMap<QString, QString> ¶ms)
|
2015-09-07 14:50:01 +03:00
|
|
|
{
|
|
|
|
setVerb("GET");
|
|
|
|
|
2015-10-15 22:58:16 +03:00
|
|
|
addParam(QString::fromLatin1("path"), path);
|
2019-05-09 23:11:25 +03:00
|
|
|
addParam(QString::fromLatin1("reshares"), QString("true"));
|
2022-09-02 12:48:52 +03:00
|
|
|
|
|
|
|
for (auto it = std::cbegin(params); it != std::cend(params); ++it) {
|
|
|
|
addParam(it.key(), it.value());
|
|
|
|
}
|
|
|
|
|
2015-09-07 14:50:01 +03:00
|
|
|
addPassStatusCode(404);
|
|
|
|
|
|
|
|
start();
|
|
|
|
}
|
|
|
|
|
2015-10-29 13:09:10 +03:00
|
|
|
void OcsShareJob::deleteShare(const QString &shareId)
|
2015-09-07 14:50:01 +03:00
|
|
|
{
|
2015-10-16 09:28:13 +03:00
|
|
|
appendPath(shareId);
|
2015-09-07 14:50:01 +03:00
|
|
|
setVerb("DELETE");
|
|
|
|
|
|
|
|
start();
|
|
|
|
}
|
|
|
|
|
2015-10-29 13:09:10 +03:00
|
|
|
void OcsShareJob::setExpireDate(const QString &shareId, const QDate &date)
|
2015-09-07 14:50:01 +03:00
|
|
|
{
|
2015-10-16 09:28:13 +03:00
|
|
|
appendPath(shareId);
|
2015-09-07 14:50:01 +03:00
|
|
|
setVerb("PUT");
|
|
|
|
|
|
|
|
if (date.isValid()) {
|
2015-10-15 22:58:16 +03:00
|
|
|
addParam(QString::fromLatin1("expireDate"), date.toString("yyyy-MM-dd"));
|
2015-09-07 14:50:01 +03:00
|
|
|
} else {
|
2015-10-15 22:58:16 +03:00
|
|
|
addParam(QString::fromLatin1("expireDate"), QString());
|
2015-09-07 14:50:01 +03:00
|
|
|
}
|
2015-10-29 13:09:10 +03:00
|
|
|
_value = date;
|
2015-09-07 14:50:01 +03:00
|
|
|
|
|
|
|
start();
|
|
|
|
}
|
|
|
|
|
2015-10-29 13:09:10 +03:00
|
|
|
void OcsShareJob::setPassword(const QString &shareId, const QString &password)
|
2015-09-07 14:50:01 +03:00
|
|
|
{
|
2015-10-16 09:28:13 +03:00
|
|
|
appendPath(shareId);
|
2015-09-07 14:50:01 +03:00
|
|
|
setVerb("PUT");
|
|
|
|
|
2015-10-15 22:58:16 +03:00
|
|
|
addParam(QString::fromLatin1("password"), password);
|
2015-10-29 13:09:10 +03:00
|
|
|
_value = password;
|
2015-09-07 14:50:01 +03:00
|
|
|
|
|
|
|
start();
|
|
|
|
}
|
2019-09-18 14:37:49 +03:00
|
|
|
|
|
|
|
void OcsShareJob::setNote(const QString &shareId, const QString ¬e)
|
|
|
|
{
|
|
|
|
appendPath(shareId);
|
|
|
|
setVerb("PUT");
|
|
|
|
|
|
|
|
addParam(QString::fromLatin1("note"), note);
|
|
|
|
_value = note;
|
|
|
|
|
|
|
|
start();
|
|
|
|
}
|
2015-09-07 14:50:01 +03:00
|
|
|
|
2015-10-29 13:09:10 +03:00
|
|
|
void OcsShareJob::setPublicUpload(const QString &shareId, bool publicUpload)
|
2015-10-15 21:34:56 +03:00
|
|
|
{
|
2015-10-16 09:28:13 +03:00
|
|
|
appendPath(shareId);
|
2015-10-15 21:34:56 +03:00
|
|
|
setVerb("PUT");
|
|
|
|
|
|
|
|
const QString value = QString::fromLatin1(publicUpload ? "true" : "false");
|
2015-10-15 22:58:16 +03:00
|
|
|
addParam(QString::fromLatin1("publicUpload"), value);
|
2015-10-29 13:09:10 +03:00
|
|
|
_value = publicUpload;
|
2015-10-15 21:34:56 +03:00
|
|
|
|
|
|
|
start();
|
|
|
|
}
|
|
|
|
|
2017-04-12 12:09:20 +03:00
|
|
|
void OcsShareJob::setName(const QString &shareId, const QString &name)
|
|
|
|
{
|
|
|
|
appendPath(shareId);
|
|
|
|
setVerb("PUT");
|
|
|
|
addParam(QString::fromLatin1("name"), name);
|
|
|
|
_value = name;
|
|
|
|
|
|
|
|
start();
|
|
|
|
}
|
|
|
|
|
2015-10-31 15:39:08 +03:00
|
|
|
void OcsShareJob::setPermissions(const QString &shareId,
|
|
|
|
const Share::Permissions permissions)
|
|
|
|
{
|
|
|
|
appendPath(shareId);
|
|
|
|
setVerb("PUT");
|
|
|
|
|
|
|
|
addParam(QString::fromLatin1("permissions"), QString::number(permissions));
|
|
|
|
_value = (int)permissions;
|
|
|
|
|
|
|
|
start();
|
|
|
|
}
|
|
|
|
|
2021-09-14 15:10:44 +03:00
|
|
|
void OcsShareJob::setLabel(const QString &shareId, const QString &label)
|
|
|
|
{
|
|
|
|
appendPath(shareId);
|
|
|
|
setVerb("PUT");
|
|
|
|
|
|
|
|
addParam(QStringLiteral("label"), label);
|
|
|
|
_value = label;
|
|
|
|
|
|
|
|
start();
|
|
|
|
}
|
|
|
|
|
2023-04-19 21:28:07 +03:00
|
|
|
void OcsShareJob::setHideDownload(const QString &shareId, const bool hideDownload)
|
|
|
|
{
|
|
|
|
appendPath(shareId);
|
|
|
|
setVerb("PUT");
|
|
|
|
|
|
|
|
const auto value = QString::fromLatin1(hideDownload ? QByteArrayLiteral("true") : QByteArrayLiteral("false"));
|
|
|
|
addParam(QStringLiteral("hideDownload"), value);
|
|
|
|
_value = hideDownload;
|
|
|
|
|
|
|
|
start();
|
|
|
|
}
|
|
|
|
|
2017-04-05 10:38:46 +03:00
|
|
|
void OcsShareJob::createLinkShare(const QString &path,
|
|
|
|
const QString &name,
|
2015-10-31 15:39:08 +03:00
|
|
|
const QString &password)
|
2015-09-07 14:50:01 +03:00
|
|
|
{
|
|
|
|
setVerb("POST");
|
|
|
|
|
2015-10-15 22:58:16 +03:00
|
|
|
addParam(QString::fromLatin1("path"), path);
|
2015-10-31 15:39:08 +03:00
|
|
|
addParam(QString::fromLatin1("shareType"), QString::number(Share::TypeLink));
|
2015-09-07 14:50:01 +03:00
|
|
|
|
2017-04-05 10:38:46 +03:00
|
|
|
if (!name.isEmpty()) {
|
|
|
|
addParam(QString::fromLatin1("name"), name);
|
|
|
|
}
|
2015-09-07 14:50:01 +03:00
|
|
|
if (!password.isEmpty()) {
|
2023-01-12 20:55:04 +03:00
|
|
|
addParam(QString::fromLatin1("password"), password);
|
|
|
|
}
|
|
|
|
|
|
|
|
addPassStatusCode(403);
|
|
|
|
|
|
|
|
start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OcsShareJob::createSecureFileDropLinkShare(const QString &path, const QString &name, const QString &password)
|
|
|
|
{
|
|
|
|
setVerb("POST");
|
|
|
|
|
|
|
|
addParam(QString::fromLatin1("path"), path);
|
|
|
|
addParam(QString::fromLatin1("shareType"), QString::number(Share::TypeLink));
|
|
|
|
addParam(QString::fromLatin1("permissions"), QString::number(4));
|
|
|
|
|
|
|
|
if (!name.isEmpty()) {
|
|
|
|
addParam(QString::fromLatin1("name"), name);
|
|
|
|
}
|
|
|
|
if (!password.isEmpty()) {
|
2015-10-29 15:31:36 +03:00
|
|
|
addParam(QString::fromLatin1("password"), password);
|
2015-09-07 14:50:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
addPassStatusCode(403);
|
|
|
|
|
|
|
|
start();
|
|
|
|
}
|
|
|
|
|
2015-10-31 15:39:08 +03:00
|
|
|
void OcsShareJob::createShare(const QString &path,
|
|
|
|
const Share::ShareType shareType,
|
|
|
|
const QString &shareWith,
|
2021-04-20 17:36:42 +03:00
|
|
|
const Share::Permissions permissions,
|
|
|
|
const QString &password)
|
2015-10-31 15:39:08 +03:00
|
|
|
{
|
2020-08-19 17:32:57 +03:00
|
|
|
Q_UNUSED(permissions)
|
2015-10-31 15:39:08 +03:00
|
|
|
setVerb("POST");
|
|
|
|
|
|
|
|
addParam(QString::fromLatin1("path"), path);
|
|
|
|
addParam(QString::fromLatin1("shareType"), QString::number(shareType));
|
|
|
|
addParam(QString::fromLatin1("shareWith"), shareWith);
|
|
|
|
|
2021-04-20 17:36:42 +03:00
|
|
|
if (!password.isEmpty()) {
|
|
|
|
addParam(QString::fromLatin1("password"), password);
|
|
|
|
}
|
|
|
|
|
2015-10-31 15:39:08 +03:00
|
|
|
start();
|
|
|
|
}
|
|
|
|
|
2016-01-21 16:10:37 +03:00
|
|
|
void OcsShareJob::getSharedWithMe()
|
|
|
|
{
|
|
|
|
setVerb("GET");
|
|
|
|
addParam(QLatin1String("shared_with_me"), QLatin1String("true"));
|
|
|
|
start();
|
|
|
|
}
|
|
|
|
|
2017-04-26 12:38:10 +03:00
|
|
|
void OcsShareJob::jobDone(QJsonDocument reply)
|
2015-10-29 13:09:10 +03:00
|
|
|
{
|
|
|
|
emit shareJobFinished(reply, _value);
|
|
|
|
}
|
2022-09-02 12:48:52 +03:00
|
|
|
|
|
|
|
QString const OcsShareJob::_pathForSharesRequest = QStringLiteral("ocs/v2.php/apps/files_sharing/api/v1/shares");
|
2015-09-07 14:50:01 +03:00
|
|
|
}
|