From f2d5988e9134651ee8c1633ba8a6cb76031b3630 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Wed, 12 Jul 2023 22:39:57 +0800 Subject: [PATCH 1/4] Modernise ShareManager::slotSharesFetched Signed-off-by: Claudio Cambra --- src/gui/sharemanager.cpp | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/src/gui/sharemanager.cpp b/src/gui/sharemanager.cpp index 00f812c31e0a..442034fa88c0 100644 --- a/src/gui/sharemanager.cpp +++ b/src/gui/sharemanager.cpp @@ -13,10 +13,11 @@ */ #include "sharemanager.h" -#include "ocssharejob.h" #include "account.h" -#include "folderman.h" #include "accountstate.h" +#include "folderman.h" +#include "ocssharejob.h" +#include "sharee.h" #include #include @@ -508,29 +509,24 @@ void ShareManager::fetchShares(const QString &path) void ShareManager::slotSharesFetched(const QJsonDocument &reply) { - qDebug() << reply; - auto tmpShares = reply.object().value("ocs").toObject().value("data").toArray(); - const QString versionString = _account->serverVersion(); + qCDebug(lcSharing) << reply; + const auto tmpShares = reply.object().value("ocs").toObject().value("data").toArray(); + const auto versionString = _account->serverVersion(); qCDebug(lcSharing) << versionString << "Fetched" << tmpShares.count() << "shares"; QList shares; - foreach (const auto &share, tmpShares) { - auto data = share.toObject(); - - auto shareType = data.value("share_type").toInt(); - - SharePtr newShare; + for (const auto &share : tmpShares) { + const auto data = share.toObject(); + const auto shareType = data.value("share_type").toInt(); if (shareType == Share::TypeLink) { - newShare = parseLinkShare(data); - } else if (Share::isShareTypeUserGroupEmailRoomOrRemote(static_cast (shareType))) { - newShare = parseUserGroupShare(data); + shares.append(parseLinkShare(data)); + } else if (Share::isShareTypeUserGroupEmailRoomOrRemote(static_cast(shareType))) { + shares.append(parseUserGroupShare(data)); } else { - newShare = parseShare(data); + shares.append(parseShare(data)); } - - shares.append(SharePtr(newShare)); } qCDebug(lcSharing) << "Sending " << shares.count() << "shares"; From cc95a1e872c7e455ae52a49ac7eaa57b1f03ced9 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Wed, 12 Jul 2023 22:40:18 +0800 Subject: [PATCH 2/4] Make an early return when canShare() is false in ShareModel::initShareManager Signed-off-by: Claudio Cambra --- src/gui/filedetails/sharemodel.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/gui/filedetails/sharemodel.cpp b/src/gui/filedetails/sharemodel.cpp index 1a72cad299ef..bf8cb9d47931 100644 --- a/src/gui/filedetails/sharemodel.cpp +++ b/src/gui/filedetails/sharemodel.cpp @@ -325,18 +325,15 @@ void ShareModel::initShareManager() { if (!_accountState || _accountState->account().isNull()) { return; - } - - bool sharingPossible = true; - if (!canShare()) { + } else if (!canShare()) { qCWarning(lcSharing) << "The file cannot be shared because it does not have sharing permission."; - sharingPossible = false; + return; } - if (_manager.isNull() && sharingPossible) { + if (_manager.isNull()) { _manager.reset(new ShareManager(_accountState->account(), this)); connect(_manager.data(), &ShareManager::sharesFetched, this, &ShareModel::slotSharesFetched); - connect(_manager.data(), &ShareManager::shareCreated, this, [&] { + connect(_manager.data(), &ShareManager::shareCreated, this, [this] { _manager->fetchShares(_sharePath); }); connect(_manager.data(), &ShareManager::linkShareCreated, this, &ShareModel::slotAddShare); From 48f1dfaef5afbce2dba6fcf99e56e5895ae77d1c Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Wed, 12 Jul 2023 22:42:54 +0800 Subject: [PATCH 3/4] Ensure _sharePath is properly percent encoded by using QUrl::toPercentEncoding Signed-off-by: Claudio Cambra --- src/gui/filedetails/sharemodel.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gui/filedetails/sharemodel.cpp b/src/gui/filedetails/sharemodel.cpp index bf8cb9d47931..5cb04e98715e 100644 --- a/src/gui/filedetails/sharemodel.cpp +++ b/src/gui/filedetails/sharemodel.cpp @@ -253,7 +253,9 @@ void ShareModel::updateData() qCDebug(lcShareModel) << "Updating share model data now."; const auto relPath = _localPath.mid(_folder->cleanPath().length() + 1); - _sharePath = _folder->remotePathTrailingSlash() + relPath; + const auto sharePath = _folder->remotePathTrailingSlash() + relPath; + const auto percentEncoded = QUrl::toPercentEncoding(sharePath); + _sharePath = QString::fromUtf8(percentEncoded); SyncJournalFileRecord fileRecord; auto resharingAllowed = true; // lets assume the good From 7f1216e71dfe407fbb81f0516efe48d71fafc375 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Fri, 14 Jul 2023 10:23:12 +0800 Subject: [PATCH 4/4] Move share path setting in sharemodel into separate private method Signed-off-by: Claudio Cambra --- src/gui/filedetails/sharemodel.cpp | 11 ++++++++--- src/gui/filedetails/sharemodel.h | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/gui/filedetails/sharemodel.cpp b/src/gui/filedetails/sharemodel.cpp index 5cb04e98715e..8629c26559e9 100644 --- a/src/gui/filedetails/sharemodel.cpp +++ b/src/gui/filedetails/sharemodel.cpp @@ -253,9 +253,7 @@ void ShareModel::updateData() qCDebug(lcShareModel) << "Updating share model data now."; const auto relPath = _localPath.mid(_folder->cleanPath().length() + 1); - const auto sharePath = _folder->remotePathTrailingSlash() + relPath; - const auto percentEncoded = QUrl::toPercentEncoding(sharePath); - _sharePath = QString::fromUtf8(percentEncoded); + updateRelativeSharePath(relPath); SyncJournalFileRecord fileRecord; auto resharingAllowed = true; // lets assume the good @@ -323,6 +321,13 @@ void ShareModel::updateData() initShareManager(); } +void ShareModel::updateRelativeSharePath(const QString &relativePath) +{ + const auto unsanitisedSharePath = _folder->remotePathTrailingSlash() + relativePath; + const auto sanitisedSharePath = QUrl::toPercentEncoding(unsanitisedSharePath); + _sharePath = QString::fromUtf8(sanitisedSharePath); +} + void ShareModel::initShareManager() { if (!_accountState || _accountState->account().isNull()) { diff --git a/src/gui/filedetails/sharemodel.h b/src/gui/filedetails/sharemodel.h index 71458fcc7da2..c624013a3e99 100644 --- a/src/gui/filedetails/sharemodel.h +++ b/src/gui/filedetails/sharemodel.h @@ -187,6 +187,7 @@ private slots: void handleSecureFileDropLinkShare(); void handleLinkShare(); void setupInternalLinkShare(); + void updateRelativeSharePath(const QString &relativePath); void setSharePermissionChangeInProgress(const QString &shareId, const bool isInProgress); void setHideDownloadEnabledChangeInProgress(const QString &shareId, const bool isInProgress);