2015-10-29 13:09:10 +03:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Roeland Jago Douma <rullzer@owncloud.com>
|
|
|
|
*
|
|
|
|
* 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-10-29 13:09:10 +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.
|
|
|
|
*/
|
|
|
|
|
2016-09-14 16:31:05 +03:00
|
|
|
#include "sharemanager.h"
|
2015-10-29 13:09:10 +03:00
|
|
|
#include "ocssharejob.h"
|
|
|
|
#include "account.h"
|
2017-10-23 20:08:46 +03:00
|
|
|
#include "folderman.h"
|
|
|
|
#include "accountstate.h"
|
2015-10-29 13:09:10 +03:00
|
|
|
|
|
|
|
#include <QUrl>
|
2017-04-26 12:38:10 +03:00
|
|
|
#include <QJsonDocument>
|
|
|
|
#include <QJsonObject>
|
|
|
|
#include <QJsonArray>
|
2015-10-29 13:09:10 +03:00
|
|
|
|
2021-04-16 14:17:09 +03:00
|
|
|
Q_LOGGING_CATEGORY(lcUserGroupShare, "nextcloud.gui.usergroupshare", QtInfoMsg)
|
|
|
|
|
2015-10-29 13:09:10 +03:00
|
|
|
namespace OCC {
|
|
|
|
|
2017-10-23 20:08:46 +03:00
|
|
|
/**
|
|
|
|
* When a share is modified, we need to tell the folders so they can adjust overlay icons
|
|
|
|
*/
|
|
|
|
static void updateFolder(const AccountPtr &account, const QString &path)
|
|
|
|
{
|
|
|
|
foreach (Folder *f, FolderMan::instance()->map()) {
|
|
|
|
if (f->accountState()->account() != account)
|
|
|
|
continue;
|
|
|
|
auto folderPath = f->remotePath();
|
|
|
|
if (path.startsWith(folderPath) && (path == folderPath || folderPath.endsWith('/') || path[folderPath.size()] == '/')) {
|
|
|
|
// Workaround the fact that the server does not invalidate the etags of parent directories
|
|
|
|
// when something is shared.
|
2019-01-25 09:46:16 +03:00
|
|
|
auto relative = path.midRef(f->remotePathTrailingSlash().length());
|
2019-02-13 16:18:54 +03:00
|
|
|
f->journalDb()->schedulePathForRemoteDiscovery(relative.toString());
|
2017-10-23 20:08:46 +03:00
|
|
|
|
|
|
|
// Schedule a sync so it can update the remote permission flag and let the socket API
|
|
|
|
// know about the shared icon.
|
|
|
|
f->scheduleThisFolderSoon();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-14 16:31:05 +03:00
|
|
|
Share::Share(AccountPtr account,
|
2017-05-17 11:55:42 +03:00
|
|
|
const QString &id,
|
2019-06-21 19:36:45 +03:00
|
|
|
const QString &uidowner,
|
|
|
|
const QString &ownerDisplayName,
|
2017-05-17 11:55:42 +03:00
|
|
|
const QString &path,
|
|
|
|
const ShareType shareType,
|
2021-04-20 17:36:42 +03:00
|
|
|
bool isPasswordSet,
|
2017-05-17 11:55:42 +03:00
|
|
|
const Permissions permissions,
|
|
|
|
const QSharedPointer<Sharee> shareWith)
|
|
|
|
: _account(account)
|
|
|
|
, _id(id)
|
2019-06-21 19:36:45 +03:00
|
|
|
, _uidowner(uidowner)
|
|
|
|
, _ownerDisplayName(ownerDisplayName)
|
2017-05-17 11:55:42 +03:00
|
|
|
, _path(path)
|
|
|
|
, _shareType(shareType)
|
2021-04-20 17:36:42 +03:00
|
|
|
, _isPasswordSet(isPasswordSet)
|
2017-05-17 11:55:42 +03:00
|
|
|
, _permissions(permissions)
|
|
|
|
, _shareWith(shareWith)
|
2015-10-29 13:09:10 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-12-08 14:58:56 +03:00
|
|
|
AccountPtr Share::account() const
|
|
|
|
{
|
|
|
|
return _account;
|
|
|
|
}
|
|
|
|
|
2017-10-23 20:08:46 +03:00
|
|
|
QString Share::path() const
|
|
|
|
{
|
|
|
|
return _path;
|
|
|
|
}
|
|
|
|
|
2015-10-29 15:48:53 +03:00
|
|
|
QString Share::getId() const
|
2015-10-29 13:09:10 +03:00
|
|
|
{
|
|
|
|
return _id;
|
|
|
|
}
|
|
|
|
|
2019-06-21 19:36:45 +03:00
|
|
|
QString Share::getUidOwner() const
|
|
|
|
{
|
|
|
|
return _uidowner;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Share::getOwnerDisplayName() const
|
|
|
|
{
|
|
|
|
return _ownerDisplayName;
|
|
|
|
}
|
|
|
|
|
2015-10-29 23:47:47 +03:00
|
|
|
Share::ShareType Share::getShareType() const
|
2015-10-29 13:09:10 +03:00
|
|
|
{
|
|
|
|
return _shareType;
|
|
|
|
}
|
|
|
|
|
2015-11-05 00:00:35 +03:00
|
|
|
QSharedPointer<Sharee> Share::getShareWith() const
|
|
|
|
{
|
|
|
|
return _shareWith;
|
|
|
|
}
|
|
|
|
|
2021-04-20 17:36:42 +03:00
|
|
|
void Share::setPassword(const QString &password)
|
|
|
|
{
|
2021-04-28 12:43:27 +03:00
|
|
|
auto * const job = new OcsShareJob(_account);
|
2021-04-20 17:36:42 +03:00
|
|
|
connect(job, &OcsShareJob::shareJobFinished, this, &Share::slotPasswordSet);
|
|
|
|
connect(job, &OcsJob::ocsError, this, &Share::slotSetPasswordError);
|
|
|
|
job->setPassword(getId(), password);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Share::isPasswordSet() const
|
|
|
|
{
|
|
|
|
return _isPasswordSet;
|
|
|
|
}
|
|
|
|
|
2015-10-31 15:39:08 +03:00
|
|
|
void Share::setPermissions(Permissions permissions)
|
|
|
|
{
|
2020-05-18 21:54:23 +03:00
|
|
|
auto *job = new OcsShareJob(_account);
|
2017-09-20 11:14:48 +03:00
|
|
|
connect(job, &OcsShareJob::shareJobFinished, this, &Share::slotPermissionsSet);
|
|
|
|
connect(job, &OcsJob::ocsError, this, &Share::slotOcsError);
|
2015-10-31 15:39:08 +03:00
|
|
|
job->setPermissions(getId(), permissions);
|
|
|
|
}
|
|
|
|
|
2017-04-26 12:38:10 +03:00
|
|
|
void Share::slotPermissionsSet(const QJsonDocument &, const QVariant &value)
|
2015-10-31 15:39:08 +03:00
|
|
|
{
|
|
|
|
_permissions = (Permissions)value.toInt();
|
|
|
|
emit permissionsSet();
|
|
|
|
}
|
|
|
|
|
2015-10-29 23:47:47 +03:00
|
|
|
Share::Permissions Share::getPermissions() const
|
2015-10-29 13:09:10 +03:00
|
|
|
{
|
|
|
|
return _permissions;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Share::deleteShare()
|
|
|
|
{
|
2020-05-18 21:54:23 +03:00
|
|
|
auto *job = new OcsShareJob(_account);
|
2017-09-20 11:14:48 +03:00
|
|
|
connect(job, &OcsShareJob::shareJobFinished, this, &Share::slotDeleted);
|
|
|
|
connect(job, &OcsJob::ocsError, this, &Share::slotOcsError);
|
2015-10-29 13:09:10 +03:00
|
|
|
job->deleteShare(getId());
|
|
|
|
}
|
|
|
|
|
2015-10-29 18:56:23 +03:00
|
|
|
void Share::slotDeleted()
|
2015-10-29 13:09:10 +03:00
|
|
|
{
|
2017-10-23 20:08:46 +03:00
|
|
|
updateFolder(_account, _path);
|
2020-10-14 19:35:12 +03:00
|
|
|
emit shareDeleted();
|
2015-10-29 13:09:10 +03:00
|
|
|
}
|
|
|
|
|
2015-10-29 18:56:23 +03:00
|
|
|
void Share::slotOcsError(int statusCode, const QString &message)
|
|
|
|
{
|
2016-09-14 16:31:05 +03:00
|
|
|
emit serverError(statusCode, message);
|
2015-10-29 18:56:23 +03:00
|
|
|
}
|
|
|
|
|
2021-04-20 17:36:42 +03:00
|
|
|
void Share::slotPasswordSet(const QJsonDocument &, const QVariant &value)
|
|
|
|
{
|
|
|
|
_isPasswordSet = !value.toString().isEmpty();
|
|
|
|
emit passwordSet();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Share::slotSetPasswordError(int statusCode, const QString &message)
|
|
|
|
{
|
|
|
|
emit passwordSetError(statusCode, message);
|
|
|
|
}
|
|
|
|
|
2015-10-29 15:48:53 +03:00
|
|
|
QUrl LinkShare::getLink() const
|
2015-10-29 13:09:10 +03:00
|
|
|
{
|
|
|
|
return _url;
|
|
|
|
}
|
|
|
|
|
2017-05-02 13:58:01 +03:00
|
|
|
QUrl LinkShare::getDirectDownloadLink() const
|
|
|
|
{
|
|
|
|
QUrl url = _url;
|
|
|
|
url.setPath(url.path() + "/download");
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
2015-10-29 15:48:53 +03:00
|
|
|
QDate LinkShare::getExpireDate() const
|
2015-10-29 13:09:10 +03:00
|
|
|
{
|
|
|
|
return _expireDate;
|
|
|
|
}
|
|
|
|
|
|
|
|
LinkShare::LinkShare(AccountPtr account,
|
2017-05-17 11:55:42 +03:00
|
|
|
const QString &id,
|
2019-06-21 19:36:45 +03:00
|
|
|
const QString &uidowner,
|
|
|
|
const QString &ownerDisplayName,
|
2017-05-17 11:55:42 +03:00
|
|
|
const QString &path,
|
|
|
|
const QString &name,
|
|
|
|
const QString &token,
|
|
|
|
Permissions permissions,
|
2021-04-20 17:36:42 +03:00
|
|
|
bool isPasswordSet,
|
2017-05-17 11:55:42 +03:00
|
|
|
const QUrl &url,
|
2021-09-14 21:57:28 +03:00
|
|
|
const QDate &expireDate,
|
2021-09-14 15:10:44 +03:00
|
|
|
const QString ¬e,
|
|
|
|
const QString &label)
|
2021-04-20 17:36:42 +03:00
|
|
|
: Share(account, id, uidowner, ownerDisplayName, path, Share::TypeLink, isPasswordSet, permissions)
|
2017-05-17 11:55:42 +03:00
|
|
|
, _name(name)
|
|
|
|
, _token(token)
|
2021-09-14 21:57:28 +03:00
|
|
|
, _note(note)
|
2017-05-17 11:55:42 +03:00
|
|
|
, _expireDate(expireDate)
|
|
|
|
, _url(url)
|
2021-09-14 15:10:44 +03:00
|
|
|
, _label(label)
|
2015-10-29 13:09:10 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-06-15 16:38:22 +03:00
|
|
|
bool LinkShare::getPublicUpload() const
|
2015-10-29 13:47:14 +03:00
|
|
|
{
|
2017-06-15 16:38:22 +03:00
|
|
|
return _permissions & SharePermissionCreate;
|
2015-10-29 13:47:14 +03:00
|
|
|
}
|
|
|
|
|
2017-06-15 16:38:22 +03:00
|
|
|
bool LinkShare::getShowFileListing() const
|
2015-10-29 13:09:10 +03:00
|
|
|
{
|
2017-06-15 16:38:22 +03:00
|
|
|
return _permissions & SharePermissionRead;
|
2015-10-29 13:09:10 +03:00
|
|
|
}
|
|
|
|
|
2017-04-05 10:38:46 +03:00
|
|
|
QString LinkShare::getName() const
|
|
|
|
{
|
|
|
|
return _name;
|
|
|
|
}
|
|
|
|
|
2019-09-18 14:37:49 +03:00
|
|
|
QString LinkShare::getNote() const
|
|
|
|
{
|
|
|
|
return _note;
|
|
|
|
}
|
|
|
|
|
2021-09-14 15:10:44 +03:00
|
|
|
QString LinkShare::getLabel() const
|
|
|
|
{
|
|
|
|
return _label;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
void LinkShare::setName(const QString &name)
|
2017-04-12 12:09:20 +03:00
|
|
|
{
|
2020-05-18 21:54:23 +03:00
|
|
|
auto *job = new OcsShareJob(_account);
|
2017-09-20 11:14:48 +03:00
|
|
|
connect(job, &OcsShareJob::shareJobFinished, this, &LinkShare::slotNameSet);
|
|
|
|
connect(job, &OcsJob::ocsError, this, &LinkShare::slotOcsError);
|
2017-04-12 12:09:20 +03:00
|
|
|
job->setName(getId(), name);
|
|
|
|
}
|
|
|
|
|
2019-09-18 14:37:49 +03:00
|
|
|
void LinkShare::setNote(const QString ¬e)
|
|
|
|
{
|
2020-05-18 21:54:23 +03:00
|
|
|
auto *job = new OcsShareJob(_account);
|
2019-09-18 14:37:49 +03:00
|
|
|
connect(job, &OcsShareJob::shareJobFinished, this, &LinkShare::slotNoteSet);
|
|
|
|
connect(job, &OcsJob::ocsError, this, &LinkShare::slotOcsError);
|
|
|
|
job->setNote(getId(), note);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LinkShare::slotNoteSet(const QJsonDocument &, const QVariant ¬e)
|
|
|
|
{
|
|
|
|
_note = note.toString();
|
|
|
|
emit noteSet();
|
|
|
|
}
|
|
|
|
|
2017-04-12 12:09:20 +03:00
|
|
|
QString LinkShare::getToken() const
|
|
|
|
{
|
|
|
|
return _token;
|
|
|
|
}
|
|
|
|
|
2015-10-29 13:09:10 +03:00
|
|
|
void LinkShare::setExpireDate(const QDate &date)
|
|
|
|
{
|
2020-05-18 21:54:23 +03:00
|
|
|
auto *job = new OcsShareJob(_account);
|
2017-09-20 11:14:48 +03:00
|
|
|
connect(job, &OcsShareJob::shareJobFinished, this, &LinkShare::slotExpireDateSet);
|
|
|
|
connect(job, &OcsJob::ocsError, this, &LinkShare::slotOcsError);
|
2015-10-29 13:09:10 +03:00
|
|
|
job->setExpireDate(getId(), date);
|
|
|
|
}
|
|
|
|
|
2021-09-14 15:10:44 +03:00
|
|
|
void LinkShare::setLabel(const QString &label)
|
|
|
|
{
|
|
|
|
auto *job = new OcsShareJob(_account);
|
|
|
|
connect(job, &OcsShareJob::shareJobFinished, this, &LinkShare::slotLabelSet);
|
|
|
|
connect(job, &OcsJob::ocsError, this, &LinkShare::slotOcsError);
|
|
|
|
job->setLabel(getId(), label);
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
void LinkShare::slotExpireDateSet(const QJsonDocument &reply, const QVariant &value)
|
2015-10-29 13:09:10 +03:00
|
|
|
{
|
2017-04-26 12:38:10 +03:00
|
|
|
auto data = reply.object().value("ocs").toObject().value("data").toObject();
|
2016-04-19 12:22:32 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the reply provides a data back (more REST style)
|
|
|
|
* they use this date.
|
|
|
|
*/
|
2017-04-26 12:38:10 +03:00
|
|
|
if (data.value("expiration").isString()) {
|
2017-05-17 11:55:42 +03:00
|
|
|
_expireDate = QDate::fromString(data.value("expiration").toString(), "yyyy-MM-dd 00:00:00");
|
2016-04-19 12:22:32 +03:00
|
|
|
} else {
|
|
|
|
_expireDate = value.toDate();
|
|
|
|
}
|
2015-10-29 13:09:10 +03:00
|
|
|
emit expireDateSet();
|
|
|
|
}
|
|
|
|
|
2017-04-26 12:38:10 +03:00
|
|
|
void LinkShare::slotNameSet(const QJsonDocument &, const QVariant &value)
|
2017-04-12 12:09:20 +03:00
|
|
|
{
|
|
|
|
_name = value.toString();
|
|
|
|
emit nameSet();
|
|
|
|
}
|
|
|
|
|
2021-09-14 15:10:44 +03:00
|
|
|
void LinkShare::slotLabelSet(const QJsonDocument &, const QVariant &label)
|
|
|
|
{
|
|
|
|
if (_label != label.toString()) {
|
|
|
|
_label = label.toString();
|
|
|
|
emit labelSet();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-14 17:36:16 +03:00
|
|
|
UserGroupShare::UserGroupShare(AccountPtr account,
|
|
|
|
const QString &id,
|
|
|
|
const QString &owner,
|
|
|
|
const QString &ownerDisplayName,
|
|
|
|
const QString &path,
|
|
|
|
const ShareType shareType,
|
2021-04-20 17:36:42 +03:00
|
|
|
bool isPasswordSet,
|
2021-04-14 17:36:16 +03:00
|
|
|
const Permissions permissions,
|
2021-04-15 14:06:53 +03:00
|
|
|
const QSharedPointer<Sharee> shareWith,
|
2021-04-15 16:47:10 +03:00
|
|
|
const QDate &expireDate,
|
|
|
|
const QString ¬e)
|
2021-04-20 17:36:42 +03:00
|
|
|
: Share(account, id, owner, ownerDisplayName, path, shareType, isPasswordSet, permissions, shareWith)
|
2021-04-15 16:47:10 +03:00
|
|
|
, _note(note)
|
2021-04-20 17:36:42 +03:00
|
|
|
, _expireDate(expireDate)
|
2021-04-14 17:36:16 +03:00
|
|
|
{
|
2021-08-17 16:39:18 +03:00
|
|
|
Q_ASSERT(shareType == TypeUser || shareType == TypeGroup || shareType == TypeEmail || shareType == TypeRoom);
|
2021-04-14 17:36:16 +03:00
|
|
|
Q_ASSERT(shareWith);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UserGroupShare::setNote(const QString ¬e)
|
|
|
|
{
|
|
|
|
auto *job = new OcsShareJob(_account);
|
|
|
|
connect(job, &OcsShareJob::shareJobFinished, this, &UserGroupShare::slotNoteSet);
|
2021-04-16 19:16:34 +03:00
|
|
|
connect(job, &OcsJob::ocsError, this, &UserGroupShare::noteSetError);
|
2021-04-14 17:36:16 +03:00
|
|
|
job->setNote(getId(), note);
|
|
|
|
}
|
|
|
|
|
2021-04-15 16:47:10 +03:00
|
|
|
QString UserGroupShare::getNote() const
|
|
|
|
{
|
|
|
|
return _note;
|
|
|
|
}
|
|
|
|
|
2021-04-14 17:36:16 +03:00
|
|
|
void UserGroupShare::slotNoteSet(const QJsonDocument &, const QVariant ¬e)
|
|
|
|
{
|
|
|
|
_note = note.toString();
|
|
|
|
emit noteSet();
|
|
|
|
}
|
|
|
|
|
2021-04-15 14:06:53 +03:00
|
|
|
QDate UserGroupShare::getExpireDate() const
|
|
|
|
{
|
|
|
|
return _expireDate;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UserGroupShare::setExpireDate(const QDate &date)
|
|
|
|
{
|
2021-08-17 16:39:18 +03:00
|
|
|
if (_expireDate == date) {
|
|
|
|
emit expireDateSet();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-04-15 14:06:53 +03:00
|
|
|
auto *job = new OcsShareJob(_account);
|
|
|
|
connect(job, &OcsShareJob::shareJobFinished, this, &UserGroupShare::slotExpireDateSet);
|
|
|
|
connect(job, &OcsJob::ocsError, this, &UserGroupShare::slotOcsError);
|
|
|
|
job->setExpireDate(getId(), date);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UserGroupShare::slotExpireDateSet(const QJsonDocument &reply, const QVariant &value)
|
|
|
|
{
|
|
|
|
auto data = reply.object().value("ocs").toObject().value("data").toObject();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the reply provides a data back (more REST style)
|
|
|
|
* they use this date.
|
|
|
|
*/
|
|
|
|
if (data.value("expiration").isString()) {
|
|
|
|
_expireDate = QDate::fromString(data.value("expiration").toString(), "yyyy-MM-dd 00:00:00");
|
|
|
|
} else {
|
|
|
|
_expireDate = value.toDate();
|
|
|
|
}
|
|
|
|
emit expireDateSet();
|
|
|
|
}
|
|
|
|
|
2015-10-29 13:09:10 +03:00
|
|
|
ShareManager::ShareManager(AccountPtr account, QObject *parent)
|
2017-05-17 11:55:42 +03:00
|
|
|
: QObject(parent)
|
|
|
|
, _account(account)
|
2015-10-29 13:09:10 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShareManager::createLinkShare(const QString &path,
|
2017-05-17 11:55:42 +03:00
|
|
|
const QString &name,
|
|
|
|
const QString &password)
|
2015-10-29 13:09:10 +03:00
|
|
|
{
|
2020-05-18 21:54:23 +03:00
|
|
|
auto *job = new OcsShareJob(_account);
|
2017-09-20 11:14:48 +03:00
|
|
|
connect(job, &OcsShareJob::shareJobFinished, this, &ShareManager::slotLinkShareCreated);
|
|
|
|
connect(job, &OcsJob::ocsError, this, &ShareManager::slotOcsError);
|
2017-04-05 10:38:46 +03:00
|
|
|
job->createLinkShare(path, name, password);
|
2015-10-29 13:09:10 +03:00
|
|
|
}
|
|
|
|
|
2017-04-26 12:38:10 +03:00
|
|
|
void ShareManager::slotLinkShareCreated(const QJsonDocument &reply)
|
2015-10-29 13:09:10 +03:00
|
|
|
{
|
|
|
|
QString message;
|
|
|
|
int code = OcsShareJob::getJsonReturnCode(reply, message);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Before we had decent sharing capabilities on the server a 403 "generally"
|
2015-10-29 15:39:29 +03:00
|
|
|
* meant that a share was password protected
|
2015-10-29 13:09:10 +03:00
|
|
|
*/
|
|
|
|
if (code == 403) {
|
2016-01-19 16:03:13 +03:00
|
|
|
emit linkShareRequiresPassword(message);
|
2015-10-29 15:31:36 +03:00
|
|
|
return;
|
2016-09-14 16:31:05 +03:00
|
|
|
}
|
2015-10-29 13:09:10 +03:00
|
|
|
|
|
|
|
//Parse share
|
2017-04-26 12:38:10 +03:00
|
|
|
auto data = reply.object().value("ocs").toObject().value("data").toObject();
|
2015-10-29 13:09:10 +03:00
|
|
|
QSharedPointer<LinkShare> share(parseLinkShare(data));
|
|
|
|
|
|
|
|
emit linkShareCreated(share);
|
2017-10-23 20:08:46 +03:00
|
|
|
|
|
|
|
updateFolder(_account, share->path());
|
2015-10-29 13:09:10 +03:00
|
|
|
}
|
|
|
|
|
2016-01-21 16:10:37 +03:00
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
void ShareManager::createShare(const QString &path,
|
|
|
|
const Share::ShareType shareType,
|
|
|
|
const QString shareWith,
|
2021-04-20 17:36:42 +03:00
|
|
|
const Share::Permissions desiredPermissions,
|
|
|
|
const QString &password)
|
2015-10-31 15:39:08 +03:00
|
|
|
{
|
2016-01-21 16:10:37 +03:00
|
|
|
auto job = new OcsShareJob(_account);
|
2017-09-20 11:14:48 +03:00
|
|
|
connect(job, &OcsJob::ocsError, this, &ShareManager::slotOcsError);
|
2017-10-17 18:29:48 +03:00
|
|
|
connect(job, &OcsShareJob::shareJobFinished, this,
|
|
|
|
[=](const QJsonDocument &reply) {
|
|
|
|
// Find existing share permissions (if this was shared with us)
|
|
|
|
Share::Permissions existingPermissions = SharePermissionDefault;
|
|
|
|
foreach (const QJsonValue &element, reply.object()["ocs"].toObject()["data"].toArray()) {
|
|
|
|
auto map = element.toObject();
|
|
|
|
if (map["file_target"] == path)
|
|
|
|
existingPermissions = Share::Permissions(map["permissions"].toInt());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Limit the permissions we request for a share to the ones the item
|
|
|
|
// was shared with initially.
|
2018-02-09 16:39:12 +03:00
|
|
|
auto validPermissions = desiredPermissions;
|
|
|
|
if (validPermissions == SharePermissionDefault) {
|
|
|
|
validPermissions = existingPermissions;
|
|
|
|
}
|
|
|
|
if (existingPermissions != SharePermissionDefault) {
|
|
|
|
validPermissions &= existingPermissions;
|
2017-10-17 18:29:48 +03:00
|
|
|
}
|
|
|
|
|
2020-05-18 21:54:23 +03:00
|
|
|
auto *job = new OcsShareJob(_account);
|
2017-10-17 18:29:48 +03:00
|
|
|
connect(job, &OcsShareJob::shareJobFinished, this, &ShareManager::slotShareCreated);
|
|
|
|
connect(job, &OcsJob::ocsError, this, &ShareManager::slotOcsError);
|
2021-04-20 17:36:42 +03:00
|
|
|
job->createShare(path, shareType, shareWith, validPermissions, password);
|
2017-10-17 18:29:48 +03:00
|
|
|
});
|
2016-01-21 16:10:37 +03:00
|
|
|
job->getSharedWithMe();
|
|
|
|
}
|
|
|
|
|
2015-10-31 15:39:08 +03:00
|
|
|
|
2017-04-26 12:38:10 +03:00
|
|
|
void ShareManager::slotShareCreated(const QJsonDocument &reply)
|
2015-10-31 15:39:08 +03:00
|
|
|
{
|
|
|
|
//Parse share
|
2017-04-26 12:38:10 +03:00
|
|
|
auto data = reply.object().value("ocs").toObject().value("data").toObject();
|
2015-10-31 15:39:08 +03:00
|
|
|
QSharedPointer<Share> share(parseShare(data));
|
|
|
|
|
|
|
|
emit shareCreated(share);
|
2017-10-23 20:08:46 +03:00
|
|
|
|
|
|
|
updateFolder(_account, share->path());
|
2015-10-31 15:39:08 +03:00
|
|
|
}
|
|
|
|
|
2015-10-29 13:09:10 +03:00
|
|
|
void ShareManager::fetchShares(const QString &path)
|
|
|
|
{
|
2020-05-18 21:54:23 +03:00
|
|
|
auto *job = new OcsShareJob(_account);
|
2017-09-20 11:14:48 +03:00
|
|
|
connect(job, &OcsShareJob::shareJobFinished, this, &ShareManager::slotSharesFetched);
|
|
|
|
connect(job, &OcsJob::ocsError, this, &ShareManager::slotOcsError);
|
2015-10-29 13:09:10 +03:00
|
|
|
job->getShares(path);
|
|
|
|
}
|
|
|
|
|
2017-04-26 12:38:10 +03:00
|
|
|
void ShareManager::slotSharesFetched(const QJsonDocument &reply)
|
2015-10-29 13:09:10 +03:00
|
|
|
{
|
2017-04-26 12:38:10 +03:00
|
|
|
auto tmpShares = reply.object().value("ocs").toObject().value("data").toArray();
|
2015-10-29 13:09:10 +03:00
|
|
|
const QString versionString = _account->serverVersion();
|
2017-05-09 15:24:11 +03:00
|
|
|
qCDebug(lcSharing) << versionString << "Fetched" << tmpShares.count() << "shares";
|
2015-10-29 13:09:10 +03:00
|
|
|
|
|
|
|
QList<QSharedPointer<Share>> shares;
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
foreach (const auto &share, tmpShares) {
|
2017-04-26 12:38:10 +03:00
|
|
|
auto data = share.toObject();
|
2015-10-29 13:09:10 +03:00
|
|
|
|
|
|
|
auto shareType = data.value("share_type").toInt();
|
|
|
|
|
2015-10-29 16:27:49 +03:00
|
|
|
QSharedPointer<Share> newShare;
|
2015-10-29 13:09:10 +03:00
|
|
|
|
2015-10-29 23:47:47 +03:00
|
|
|
if (shareType == Share::TypeLink) {
|
2015-10-29 13:09:10 +03:00
|
|
|
newShare = parseLinkShare(data);
|
2021-08-17 16:39:18 +03:00
|
|
|
} else if (shareType == Share::TypeGroup || shareType == Share::TypeUser || shareType == Share::TypeEmail || shareType == Share::TypeRoom) {
|
2021-04-14 17:36:16 +03:00
|
|
|
newShare = parseUserGroupShare(data);
|
2015-10-29 13:09:10 +03:00
|
|
|
} else {
|
2015-10-31 15:39:08 +03:00
|
|
|
newShare = parseShare(data);
|
2015-10-29 13:09:10 +03:00
|
|
|
}
|
|
|
|
|
2016-09-14 16:31:05 +03:00
|
|
|
shares.append(QSharedPointer<Share>(newShare));
|
2015-10-29 13:09:10 +03:00
|
|
|
}
|
|
|
|
|
2017-05-09 15:24:11 +03:00
|
|
|
qCDebug(lcSharing) << "Sending " << shares.count() << "shares";
|
2015-10-29 13:09:10 +03:00
|
|
|
emit sharesFetched(shares);
|
|
|
|
}
|
|
|
|
|
2021-04-14 17:36:16 +03:00
|
|
|
QSharedPointer<UserGroupShare> ShareManager::parseUserGroupShare(const QJsonObject &data)
|
|
|
|
{
|
|
|
|
QSharedPointer<Sharee> sharee(new Sharee(data.value("share_with").toString(),
|
|
|
|
data.value("share_with_displayname").toString(),
|
|
|
|
static_cast<Sharee::Type>(data.value("share_type").toInt())));
|
|
|
|
|
2021-04-15 14:06:53 +03:00
|
|
|
QDate expireDate;
|
|
|
|
if (data.value("expiration").isString()) {
|
|
|
|
expireDate = QDate::fromString(data.value("expiration").toString(), "yyyy-MM-dd 00:00:00");
|
|
|
|
}
|
|
|
|
|
2021-04-15 16:47:10 +03:00
|
|
|
QString note;
|
|
|
|
if (data.value("note").isString()) {
|
|
|
|
note = data.value("note").toString();
|
|
|
|
}
|
|
|
|
|
2021-04-14 17:36:16 +03:00
|
|
|
return QSharedPointer<UserGroupShare>(new UserGroupShare(_account,
|
|
|
|
data.value("id").toVariant().toString(), // "id" used to be an integer, support both
|
|
|
|
data.value("uid_owner").toVariant().toString(),
|
|
|
|
data.value("displayname_owner").toVariant().toString(),
|
|
|
|
data.value("path").toString(),
|
|
|
|
static_cast<Share::ShareType>(data.value("share_type").toInt()),
|
2021-04-20 17:36:42 +03:00
|
|
|
!data.value("password").toString().isEmpty(),
|
2021-04-14 17:36:16 +03:00
|
|
|
static_cast<Share::Permissions>(data.value("permissions").toInt()),
|
2021-04-15 14:06:53 +03:00
|
|
|
sharee,
|
2021-04-15 16:47:10 +03:00
|
|
|
expireDate,
|
|
|
|
note));
|
2021-04-14 17:36:16 +03:00
|
|
|
}
|
|
|
|
|
2017-04-26 12:38:10 +03:00
|
|
|
QSharedPointer<LinkShare> ShareManager::parseLinkShare(const QJsonObject &data)
|
2017-04-12 12:09:20 +03:00
|
|
|
{
|
2015-10-29 13:09:10 +03:00
|
|
|
QUrl url;
|
|
|
|
|
|
|
|
// From ownCloud server 8.2 the url field is always set for public shares
|
|
|
|
if (data.contains("url")) {
|
|
|
|
url = QUrl(data.value("url").toString());
|
2017-03-14 17:57:57 +03:00
|
|
|
} else if (_account->serverVersionInt() >= Account::makeServerVersion(8, 0, 0)) {
|
2015-10-29 13:09:10 +03:00
|
|
|
// From ownCloud server version 8 on, a different share link scheme is used.
|
2017-02-23 16:54:17 +03:00
|
|
|
url = QUrl(Utility::concatUrlPath(_account->url(), QLatin1String("index.php/s/") + data.value("token").toString())).toString();
|
2015-10-29 13:09:10 +03:00
|
|
|
} else {
|
2017-12-08 12:10:28 +03:00
|
|
|
QUrlQuery queryArgs;
|
|
|
|
queryArgs.addQueryItem(QLatin1String("service"), QLatin1String("files"));
|
|
|
|
queryArgs.addQueryItem(QLatin1String("t"), data.value("token").toString());
|
2016-10-25 13:04:22 +03:00
|
|
|
url = QUrl(Utility::concatUrlPath(_account->url(), QLatin1String("public.php"), queryArgs).toString());
|
2015-10-29 13:09:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
QDate expireDate;
|
2017-04-26 12:38:10 +03:00
|
|
|
if (data.value("expiration").isString()) {
|
2017-05-17 11:55:42 +03:00
|
|
|
expireDate = QDate::fromString(data.value("expiration").toString(), "yyyy-MM-dd 00:00:00");
|
2015-10-29 13:09:10 +03:00
|
|
|
}
|
2021-09-14 21:57:28 +03:00
|
|
|
|
|
|
|
QString note;
|
|
|
|
if (data.value("note").isString()) {
|
|
|
|
note = data.value("note").toString();
|
|
|
|
}
|
2015-10-29 13:09:10 +03:00
|
|
|
|
2015-10-29 16:27:49 +03:00
|
|
|
return QSharedPointer<LinkShare>(new LinkShare(_account,
|
2017-05-18 13:41:28 +03:00
|
|
|
data.value("id").toVariant().toString(), // "id" used to be an integer, support both
|
2019-06-21 19:36:45 +03:00
|
|
|
data.value("uid_owner").toString(),
|
|
|
|
data.value("displayname_owner").toString(),
|
2017-05-17 11:55:42 +03:00
|
|
|
data.value("path").toString(),
|
|
|
|
data.value("name").toString(),
|
|
|
|
data.value("token").toString(),
|
|
|
|
(Share::Permissions)data.value("permissions").toInt(),
|
|
|
|
data.value("share_with").isString(), // has password?
|
|
|
|
url,
|
2021-09-14 21:57:28 +03:00
|
|
|
expireDate,
|
2021-09-14 15:10:44 +03:00
|
|
|
note,
|
|
|
|
data.value("label").toString()));
|
2015-10-29 13:09:10 +03:00
|
|
|
}
|
|
|
|
|
2017-04-26 12:38:10 +03:00
|
|
|
QSharedPointer<Share> ShareManager::parseShare(const QJsonObject &data)
|
2015-11-05 00:00:35 +03:00
|
|
|
{
|
|
|
|
QSharedPointer<Sharee> sharee(new Sharee(data.value("share_with").toString(),
|
2017-05-17 11:55:42 +03:00
|
|
|
data.value("share_with_displayname").toString(),
|
|
|
|
(Sharee::Type)data.value("share_type").toInt()));
|
2016-09-14 16:31:05 +03:00
|
|
|
|
2015-10-31 15:39:08 +03:00
|
|
|
return QSharedPointer<Share>(new Share(_account,
|
2017-05-18 13:41:28 +03:00
|
|
|
data.value("id").toVariant().toString(), // "id" used to be an integer, support both
|
2019-06-21 19:36:45 +03:00
|
|
|
data.value("uid_owner").toVariant().toString(),
|
|
|
|
data.value("displayname_owner").toVariant().toString(),
|
2017-05-17 11:55:42 +03:00
|
|
|
data.value("path").toString(),
|
|
|
|
(Share::ShareType)data.value("share_type").toInt(),
|
2021-04-20 17:36:42 +03:00
|
|
|
!data.value("password").toString().isEmpty(),
|
2017-05-17 11:55:42 +03:00
|
|
|
(Share::Permissions)data.value("permissions").toInt(),
|
|
|
|
sharee));
|
2015-10-31 15:39:08 +03:00
|
|
|
}
|
|
|
|
|
2015-10-29 18:56:23 +03:00
|
|
|
void ShareManager::slotOcsError(int statusCode, const QString &message)
|
|
|
|
{
|
2016-01-21 16:10:37 +03:00
|
|
|
emit serverError(statusCode, message);
|
2015-10-29 18:56:23 +03:00
|
|
|
}
|
2015-10-29 13:09:10 +03:00
|
|
|
}
|