From 59d84759e4e3f6ba7b0d8d5ba5c3fb916cc50b69 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Fri, 4 Nov 2022 19:30:22 +0100 Subject: [PATCH 1/6] Add an internal link share to the share dialog Signed-off-by: Claudio Cambra --- src/gui/filedetails/ShareDelegate.qml | 5 +-- src/gui/filedetails/sharemodel.cpp | 44 +++++++++++++++++++++--- src/gui/filedetails/sharemodel.h | 4 +++ src/gui/filedetails/sortedsharemodel.cpp | 13 ++++++- src/gui/sharemanager.h | 1 + 5 files changed, 60 insertions(+), 7 deletions(-) diff --git a/src/gui/filedetails/ShareDelegate.qml b/src/gui/filedetails/ShareDelegate.qml index 5768cc44de347..e95cd1fa2b3d0 100644 --- a/src/gui/filedetails/ShareDelegate.qml +++ b/src/gui/filedetails/ShareDelegate.qml @@ -53,6 +53,7 @@ GridLayout { readonly property bool isLinkShare: model.shareType === ShareModel.ShareTypeLink readonly property bool isPlaceholderLinkShare: model.shareType === ShareModel.ShareTypePlaceholderLink + readonly property bool isInternalLinkShare: model.shareType === ShareModel.ShareTypeInternalLink readonly property string text: model.display ?? "" readonly property string detailText: model.detailText ?? "" @@ -183,7 +184,7 @@ GridLayout { icon.width: 16 icon.height: 16 - visible: root.isLinkShare + visible: root.isLinkShare || root.isInternalLinkShare enabled: visible onClicked: { @@ -210,7 +211,7 @@ GridLayout { imageSource: "image://svgimage-custom-color/more.svg/" + Style.ncTextColor - visible: !root.isPlaceholderLinkShare + visible: !root.isPlaceholderLinkShare && !root.isInternalLinkShare enabled: visible onClicked: root.rootStackView.push(shareDetailsPageComponent, {}, StackView.PushTransition) diff --git a/src/gui/filedetails/sharemodel.cpp b/src/gui/filedetails/sharemodel.cpp index d4891ac775e3a..9679cf5bf189c 100644 --- a/src/gui/filedetails/sharemodel.cpp +++ b/src/gui/filedetails/sharemodel.cpp @@ -24,7 +24,8 @@ namespace { -static const QString placeholderLinkShareId = QStringLiteral("__placeholderLinkShareId__"); +static const auto placeholderLinkShareId = QStringLiteral("__placeholderLinkShareId__"); +static const auto internalLinkShareId = QStringLiteral("__internalLinkShareId__"); QString createRandomPassword() { @@ -129,6 +130,11 @@ QVariant ShareModel::data(const QModelIndex &index, const int role) const return startOfExpireDayUTC.toMSecsSinceEpoch(); } } + } else if (share->getShareType() == Share::TypeInternalLink) { + switch(role) { + case LinkRole: + return _privateLinkUrl; + } } switch(role) { @@ -190,6 +196,8 @@ void ShareModel::resetData() _sharePath.clear(); _maxSharingPermissions = {}; _numericFileId.clear(); + _privateLinkUrl.clear(); + _filelockState = {}; _manager.clear(); _shares.clear(); _fetchOngoing = false; @@ -256,12 +264,19 @@ void ShareModel::updateData() _sharePath, Share::TypePlaceholderLink)); + _internalLinkShare.reset(new Share(_accountState->account(), + internalLinkShareId, + _accountState->account()->id(), + _accountState->account()->davDisplayName(), + _sharePath, + Share::TypeInternalLink)); + auto job = new PropfindJob(_accountState->account(), _sharePath); job->setProperties( QList() - << "https://open-collaboration-services.org/ns:share-permissions" - << "https://owncloud.org/ns:fileid" // numeric file id for fallback private link generation - << "https://owncloud.org/ns:privatelink"); + << "http://open-collaboration-services.org/ns:share-permissions" + << "http://owncloud.org/ns:fileid" // numeric file id for fallback private link generation + << "http://owncloud.org/ns:privatelink"); job->setTimeout(10 * 1000); connect(job, &PropfindJob::result, this, &ShareModel::slotPropfindReceived); connect(job, &PropfindJob::finishedWithError, this, [&](const QNetworkReply *reply) { @@ -359,6 +374,8 @@ void ShareModel::slotPropfindReceived(const QVariantMap &result) qCInfo(lcShareModel) << "Received numeric file id for" << _sharePath << numericFileId; _privateLinkUrl = _accountState->account()->deprecatedPrivateLinkUrl(numericFileId).toString(QUrl::FullyEncoded); } + + setupInternalLinkShare(); } void ShareModel::slotSharesFetched(const QList &shares) @@ -384,6 +401,21 @@ void ShareModel::slotSharesFetched(const QList &shares) handlePlaceholderLinkShare(); } +void ShareModel::setupInternalLinkShare() +{ + if (!_accountState || + _accountState->account().isNull() || + _localPath.isEmpty() || + _privateLinkUrl.isEmpty()) { + return; + } + + beginInsertRows({}, _shares.count(), _shares.count()); + _shares.append(_internalLinkShare); + endInsertRows(); + Q_EMIT internalLinkReady(); +} + void ShareModel::slotAddShare(const SharePtr &share) { if (share.isNull()) { @@ -508,6 +540,8 @@ QString ShareModel::displayStringForShare(const SharePtr &share) const return displayString; } else if (share->getShareType() == Share::TypePlaceholderLink) { return tr("Link share"); + } else if (share->getShareType() == Share::TypeInternalLink) { + return tr("Internal link"); } else if (share->getShareWith()) { return share->getShareWith()->format(); } @@ -521,6 +555,8 @@ QString ShareModel::iconUrlForShare(const SharePtr &share) const const auto iconsPath = QStringLiteral("image://svgimage-custom-color/"); switch(share->getShareType()) { + case Share::TypeInternalLink: + return QString(iconsPath + QStringLiteral("external.svg")); case Share::TypePlaceholderLink: case Share::TypeLink: return QString(iconsPath + QStringLiteral("public.svg")); diff --git a/src/gui/filedetails/sharemodel.h b/src/gui/filedetails/sharemodel.h index 0c2eb62dd79fa..05e08fbdca264 100644 --- a/src/gui/filedetails/sharemodel.h +++ b/src/gui/filedetails/sharemodel.h @@ -74,6 +74,7 @@ class ShareModel : public QAbstractListModel ShareTypeCircle = Share::TypeCircle, ShareTypeRoom = Share::TypeRoom, ShareTypePlaceholderLink = Share::TypePlaceholderLink, + ShareTypeInternalLink = Share::TypeInternalLink, }; Q_ENUM(ShareType); @@ -109,6 +110,7 @@ class ShareModel : public QAbstractListModel void fetchOngoingChanged(); void hasInitialShareFetchCompletedChanged(); void shareesChanged(); + void internalLinkReady(); void serverError(const int code, const QString &message); void passwordSetError(const QString &shareId, const int code, const QString &message); @@ -157,6 +159,7 @@ private slots: void updateData(); void initShareManager(); void handlePlaceholderLinkShare(); + void setupInternalLinkShare(); void slotPropfindReceived(const QVariantMap &result); void slotServerError(const int code, const QString &message); @@ -183,6 +186,7 @@ private slots: bool _fetchOngoing = false; bool _hasInitialShareFetchCompleted = false; SharePtr _placeholderLinkShare; + SharePtr _internalLinkShare; // DO NOT USE QSHAREDPOINTERS HERE. // QSharedPointers MUST NOT be used with pointers already assigned to other shared pointers. diff --git a/src/gui/filedetails/sortedsharemodel.cpp b/src/gui/filedetails/sortedsharemodel.cpp index 9906cfc57e4e1..4658060e10b48 100644 --- a/src/gui/filedetails/sortedsharemodel.cpp +++ b/src/gui/filedetails/sortedsharemodel.cpp @@ -73,12 +73,23 @@ bool SortedShareModel::lessThan(const QModelIndex &sourceLeft, const QModelIndex const auto leftShareType = leftShare->getShareType(); // Placeholder link shares always go at top - if(leftShareType == Share::TypePlaceholderLink) { + if (leftShareType == Share::TypePlaceholderLink) { return true; + } else if (leftShareType == Share::TypeInternalLink) { + // Internal links always at bottom + return false; } const auto rightShareType = rightShare->getShareType(); + // Placeholder link shares always go at top + if (rightShareType == Share::TypePlaceholderLink) { + return false; + } else if (rightShareType == Share::TypeInternalLink) { + // Internal links always at bottom + return true; + } + // We want to place link shares at the top if (leftShareType == Share::TypeLink && rightShareType != Share::TypeLink) { return true; diff --git a/src/gui/sharemanager.h b/src/gui/sharemanager.h index c3462377a7fb8..7afae8afaca19 100644 --- a/src/gui/sharemanager.h +++ b/src/gui/sharemanager.h @@ -52,6 +52,7 @@ class Share : public QObject * Need to be in sync with Sharee::Type */ enum ShareType { + TypeInternalLink = -2, TypePlaceholderLink = -1, TypeUser = Sharee::User, TypeGroup = Sharee::Group, From 9b5be727b155d2fda0a353e0ef034bc7629c0a7b Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Sat, 5 Nov 2022 13:19:37 +0100 Subject: [PATCH 2/6] Incorporate internal link share into tests Signed-off-by: Claudio Cambra --- test/testsharemodel.cpp | 89 +++++++++++++++++++++-------------- test/testsortedsharemodel.cpp | 23 ++++++--- 2 files changed, 71 insertions(+), 41 deletions(-) diff --git a/test/testsharemodel.cpp b/test/testsharemodel.cpp index 9a3b10853048f..50dd8c3fc14be 100644 --- a/test/testsharemodel.cpp +++ b/test/testsharemodel.cpp @@ -143,7 +143,7 @@ private slots: model.setLocalPath(helper.fakeFolder.localPath() + helper.testFileName); QVERIFY(sharesChanged.wait(5000)); - QCOMPARE(model.rowCount(), helper.shareCount()); + QCOMPARE(model.rowCount(), helper.shareCount() + 1); // Internal link share } void testFetchSharesFailedError() @@ -163,7 +163,7 @@ private slots: model.setLocalPath(helper.fakeFolder.localPath() + "wrong-filename-oops.md"); QVERIFY(serverError.wait(3000)); QCOMPARE(model.hasInitialShareFetchCompleted(), true); - QCOMPARE(model.rowCount(), 0); // Make sure no placeholder + QCOMPARE(model.rowCount(), 0); // Make sure no placeholder nor internal link share } void testCorrectFetchOngoingSignalling() @@ -250,8 +250,13 @@ private slots: model.setLocalPath(helper.fakeFolder.localPath() + helper.testFileName); QVERIFY(sharesChanged.wait(5000)); - QCOMPARE(model.rowCount(), helper.shareCount()); + QCOMPARE(model.rowCount(), helper.shareCount() + 1); // Remember internal link share! + // Placeholder link share gets added after we are done parsing fetched shares, and the + // internal link share is added after we receive a reply from the PROPFIND, which we + // send before fetching the shares, so it will be added first. + // + // Hence we grab the remote share in between. const auto shareIndex = model.index(model.rowCount() - 1, 0, {}); QVERIFY(!shareIndex.data(Qt::DisplayRole).toString().isEmpty()); QCOMPARE(shareIndex.data(ShareModel::ShareTypeRole).toInt(), _testLinkShareDefinition.shareType); @@ -291,9 +296,14 @@ private slots: model.setLocalPath(helper.fakeFolder.localPath() + helper.testFileName); QVERIFY(sharesChanged.wait(5000)); - QCOMPARE(model.rowCount(), 2); // Remember about placeholder link share - - const auto shareIndex = model.index(0, 0, {}); // Placeholder link share gets added after we are done parsing fetched shares + QCOMPARE(model.rowCount(), 3); // Remember about placeholder and internal link share + + // Placeholder link share gets added after we are done parsing fetched shares, and the + // internal link share is added after we receive a reply from the PROPFIND, which we + // send before fetching the shares, so it will be added first. + // + // Hence we grab the remote share in between. + const auto shareIndex = model.index(1, 0, {}); QVERIFY(!shareIndex.data(Qt::DisplayRole).toString().isEmpty()); QCOMPARE(shareIndex.data(ShareModel::ShareTypeRole).toInt(), _testEmailShareDefinition.shareType); QCOMPARE(shareIndex.data(ShareModel::ShareIdRole).toString(), _testEmailShareDefinition.shareId); @@ -329,9 +339,14 @@ private slots: model.setLocalPath(helper.fakeFolder.localPath() + helper.testFileName); QVERIFY(sharesChanged.wait(5000)); - QCOMPARE(model.rowCount(), 2); // Remember about placeholder link share - - const auto shareIndex = model.index(0, 0, {}); // Placeholder link share gets added after we are done parsing fetched shares + QCOMPARE(model.rowCount(), 3); // Remember about placeholder and internal link share + + // Placeholder link share gets added after we are done parsing fetched shares, and the + // internal link share is added after we receive a reply from the PROPFIND, which we + // send before fetching the shares, so it will be added first. + // + // Hence we grab the remote share in between. + const auto shareIndex = model.index(1, 0, {}); QVERIFY(!shareIndex.data(Qt::DisplayRole).toString().isEmpty()); QCOMPARE(shareIndex.data(ShareModel::ShareTypeRole).toInt(), _testUserShareDefinition.shareType); QCOMPARE(shareIndex.data(ShareModel::ShareIdRole).toString(), _testUserShareDefinition.shareId); @@ -376,13 +391,13 @@ private slots: QVERIFY(sharesChanged.wait(5000)); QCOMPARE(helper.shareCount(), 1); // Check our test is working! - QCOMPARE(model.rowCount(), helper.shareCount()); + QCOMPARE(model.rowCount(), helper.shareCount() + 1); // Internal link share! // Test if it gets added model.createNewLinkShare(); QVERIFY(sharesChanged.wait(5000)); QCOMPARE(helper.shareCount(), 2); // Check our test is working! - QCOMPARE(model.rowCount(), helper.shareCount()); + QCOMPARE(model.rowCount(), helper.shareCount() + 1); // Internal link share! // Test if it's the type we wanted const auto newLinkShareIndex = model.index(model.rowCount() - 1, 0, {}); @@ -393,7 +408,7 @@ private slots: model.createNewUserGroupShare(sharee); QVERIFY(sharesChanged.wait(5000)); QCOMPARE(helper.shareCount(), 3); // Check our test is working! - QCOMPARE(model.rowCount(), helper.shareCount()); + QCOMPARE(model.rowCount(), helper.shareCount() + 1); // Internal link share! // Test if it's the type we wanted const auto newUserGroupShareIndex = model.index(model.rowCount() - 1, 0, {}); @@ -404,12 +419,12 @@ private slots: model.createNewLinkShareWithPassword(password); QVERIFY(sharesChanged.wait(5000)); QCOMPARE(helper.shareCount(), 4); // Check our test is working! - QCOMPARE(model.rowCount(), helper.shareCount()); + QCOMPARE(model.rowCount(), helper.shareCount() + 1); // Internal link share! model.createNewUserGroupShareWithPassword(sharee, password); QVERIFY(sharesChanged.wait(5000)); QCOMPARE(helper.shareCount(), 5); // Check our test is working! - QCOMPARE(model.rowCount(), helper.shareCount()); + QCOMPARE(model.rowCount(), helper.shareCount() + 1); // Internal link share! helper.resetTestData(); } @@ -468,7 +483,7 @@ private slots: model.setLocalPath(helper.fakeFolder.localPath() + helper.testFileName); QVERIFY(sharesChanged.wait(5000)); - QCOMPARE(model.rowCount(), helper.shareCount()); + QCOMPARE(model.rowCount(), helper.shareCount() + 1); // Internal link share! // Confirm that the model requests a password QSignalSpy requestPasswordForLinkShare(&model, &ShareModel::requestPasswordForLinkShare); @@ -547,17 +562,21 @@ private slots: model.setLocalPath(helper.fakeFolder.localPath() + helper.testFileName); QVERIFY(sharesChanged.wait(5000)); - QCOMPARE(model.rowCount(), helper.shareCount()); + QCOMPARE(model.rowCount(), helper.shareCount() + 1); // Internal link share! // Test that the model data is correctly reporting that expire dates are enforced for all share types for(auto i = 0; i < model.rowCount(); ++i) { const auto shareIndex = model.index(i, 0, {}); - QCOMPARE(shareIndex.data(ShareModel::ExpireDateEnforcedRole).toBool(), true); + const auto shareType = shareIndex.data(ShareModel::ShareTypeRole).toInt(); + const auto expectTrue = shareType != ShareModel::ShareTypePlaceholderLink && + shareType != ShareModel::ShareTypeInternalLink; + QCOMPARE(shareIndex.data(ShareModel::ExpireDateEnforcedRole).toBool(), expectTrue); QDateTime expectedExpireDateTime; - switch(shareIndex.data(ShareModel::ShareTypeRole).toInt()) { + switch(shareType) { + case Share::TypeInternalLink: case Share::TypePlaceholderLink: - break; + return; case Share::TypeUser: case Share::TypeGroup: case Share::TypeCircle: @@ -596,13 +615,13 @@ private slots: QVERIFY(sharesChanged.wait(5000)); QCOMPARE(helper.shareCount(), 1); // Check our test is working! - QCOMPARE(model.rowCount(), helper.shareCount()); + QCOMPARE(model.rowCount(), helper.shareCount() + 1); // Internal link share! // Create share model.createNewLinkShare(); QVERIFY(sharesChanged.wait(5000)); QCOMPARE(helper.shareCount(), 2); // Check our test is working! - QCOMPARE(model.rowCount(), helper.shareCount()); + QCOMPARE(model.rowCount(), helper.shareCount() + 1); // Internal link share! // Test if it gets deleted properly const auto latestLinkShare = model.index(model.rowCount() - 1, 0, {}).data(ShareModel::ShareRole).value(); @@ -610,7 +629,7 @@ private slots: model.deleteShare(latestLinkShare); QVERIFY(shareDeleted.wait(5000)); QCOMPARE(helper.shareCount(), 1); // Check our test is working! - QCOMPARE(model.rowCount(), helper.shareCount()); + QCOMPARE(model.rowCount(), helper.shareCount() + 1); // Internal link share! helper.resetTestData(); } @@ -630,7 +649,7 @@ private slots: model.setLocalPath(helper.fakeFolder.localPath() + helper.testFileName); QVERIFY(hasInitialShareFetchCompletedChanged.wait(5000)); QVERIFY(model.hasInitialShareFetchCompleted()); - QCOMPARE(model.rowCount(), 1); // There should be a placeholder now + QCOMPARE(model.rowCount(), 2); // There should be a placeholder and internal link share now const QPersistentModelIndex placeholderLinkShareIndex(model.index(model.rowCount() - 1, 0, {})); QCOMPARE(placeholderLinkShareIndex.data(ShareModel::ShareTypeRole).toInt(), Share::TypePlaceholderLink); @@ -641,7 +660,7 @@ private slots: model.createNewUserGroupShare(sharee); QVERIFY(sharesChanged.wait(5000)); QCOMPARE(helper.shareCount(), 1); // Check our test is working! - QCOMPARE(model.rowCount(), helper.shareCount() + 1); + QCOMPARE(model.rowCount(), helper.shareCount() + 2); // Internal link share too! QVERIFY(placeholderLinkShareIndex.isValid()); QCOMPARE(placeholderLinkShareIndex.data(ShareModel::ShareTypeRole).toInt(), Share::TypePlaceholderLink); @@ -650,7 +669,7 @@ private slots: model.createNewLinkShare(); QVERIFY(sharesChanged.wait(5000)); QCOMPARE(helper.shareCount(), 2); // Check our test is working! - QCOMPARE(model.rowCount(), helper.shareCount()); + QCOMPARE(model.rowCount(), helper.shareCount() + 1); // Internal link share! QVERIFY(!placeholderLinkShareIndex.isValid()); @@ -660,7 +679,7 @@ private slots: model.deleteShare(latestLinkShare); QVERIFY(shareDeleted.wait(5000)); QCOMPARE(helper.shareCount(), 1); // Check our test is working! - QCOMPARE(model.rowCount(), helper.shareCount() + 1); + QCOMPARE(model.rowCount(), helper.shareCount() + 2); // Internal link share too! const auto newPlaceholderLinkShareIndex = model.index(model.rowCount() - 1, 0, {}); QCOMPARE(newPlaceholderLinkShareIndex.data(ShareModel::ShareTypeRole).toInt(), Share::TypePlaceholderLink); @@ -687,7 +706,7 @@ private slots: QVERIFY(sharesChanged.wait(5000)); QCOMPARE(helper.shareCount(), 1); // Check our test is working! - QCOMPARE(model.rowCount(), helper.shareCount()); + QCOMPARE(model.rowCount(), helper.shareCount() + 1); // Internal link share! const auto shareIndex = model.index(model.rowCount() - 1, 0, {}); QCOMPARE(shareIndex.data(ShareModel::EditingAllowedRole).toBool(), SharePermissions(_testLinkShareDefinition.sharePermissions).testFlag(SharePermissionUpdate)); @@ -720,7 +739,7 @@ private slots: QVERIFY(sharesChanged.wait(5000)); QCOMPARE(helper.shareCount(), 1); // Check our test is working! - QCOMPARE(model.rowCount(), helper.shareCount()); + QCOMPARE(model.rowCount(), helper.shareCount() + 1); // Internal link share! const auto shareIndex = model.index(model.rowCount() - 1, 0, {}); QCOMPARE(shareIndex.data(ShareModel::PasswordProtectEnabledRole).toBool(), true); @@ -761,7 +780,7 @@ private slots: QVERIFY(sharesChanged.wait(5000)); QCOMPARE(helper.shareCount(), 1); // Check our test is working! - QCOMPARE(model.rowCount(), helper.shareCount()); + QCOMPARE(model.rowCount(), helper.shareCount() + 1); // Internal link share! // Check what we know const auto shareIndex = model.index(model.rowCount() - 1, 0, {}); @@ -811,7 +830,7 @@ private slots: QVERIFY(sharesChanged.wait(5000)); QCOMPARE(helper.shareCount(), 1); // Check our test is working! - QCOMPARE(model.rowCount(), helper.shareCount()); + QCOMPARE(model.rowCount(), helper.shareCount() + 1); // Internal link share! const auto shareIndex = model.index(model.rowCount() - 1, 0, {}); QCOMPARE(shareIndex.data(ShareModel::NoteEnabledRole).toBool(), true); @@ -852,7 +871,7 @@ private slots: QVERIFY(sharesChanged.wait(5000)); QCOMPARE(helper.shareCount(), 1); // Check our test is working! - QCOMPARE(model.rowCount(), helper.shareCount()); + QCOMPARE(model.rowCount(), helper.shareCount() + 1); // Internal link share! const auto shareIndex = model.index(model.rowCount() - 1, 0, {}); QCOMPARE(shareIndex.data(ShareModel::LinkShareLabelRole).toBool(), true); @@ -885,7 +904,7 @@ private slots: model.setLocalPath(helper.fakeFolder.localPath() + helper.testFileName); QVERIFY(sharesChanged.wait(5000)); - QCOMPARE(model.rowCount(), helper.shareCount()); + QCOMPARE(model.rowCount(), helper.shareCount() + 1); // Internal link share! QCOMPARE(model.sharees().count(), 2); // Link shares don't have sharees @@ -894,7 +913,7 @@ private slots: model.createNewUserGroupShare(sharee); QVERIFY(sharesChanged.wait(5000)); QCOMPARE(helper.shareCount(), 4); // Check our test is working! - QCOMPARE(model.rowCount(), helper.shareCount()); + QCOMPARE(model.rowCount(), helper.shareCount() + 1); // Internal link share! const auto sharees = model.sharees(); QCOMPARE(sharees.count(), 3); // Link shares don't have sharees @@ -906,7 +925,7 @@ private slots: const auto sharePtr = shareIndex.data(ShareModel::ShareRole).value(); model.deleteShare(sharePtr); QVERIFY(sharesChanged.wait(5000)); - QCOMPARE(model.rowCount(), helper.shareCount()); + QCOMPARE(model.rowCount(), helper.shareCount() + 1); // Internal link share! // Now check the sharee is gone QCOMPARE(model.sharees().count(), 2); @@ -934,7 +953,7 @@ private slots: QVERIFY(sharesChanged.wait(5000)); QCOMPARE(helper.shareCount(), 1); // Check our test is working! - QCOMPARE(model.rowCount(), helper.shareCount()); + QCOMPARE(model.rowCount(), helper.shareCount() + 1); // Internal link share! // Reset the fake server to pretend like nothing is wrong there helper.resetTestShares(); diff --git a/test/testsortedsharemodel.cpp b/test/testsortedsharemodel.cpp index 5619d7bb5b213..0f3a0dfe134af 100644 --- a/test/testsortedsharemodel.cpp +++ b/test/testsortedsharemodel.cpp @@ -31,6 +31,11 @@ public slots: { // Let's insert them in the opposite order we want from the model for (auto it = _expectedOrder.crbegin(); it != _expectedOrder.crend(); ++it) { + const auto shareDef = *it; + if(it->shareType == Share::TypeInternalLink || it->shareType == Share::TypePlaceholderLink) { + continue; // Don't add the shares that are only internal in the client + } + helper.appendShareReplyData(*it); } } @@ -50,10 +55,11 @@ public slots: FakeShareDefinition _remoteBDefinition; FakeShareDefinition _roomADefinition; FakeShareDefinition _roomBDefinition; + FakeShareDefinition _internalLinkDefinition; QVector _expectedOrder; - static constexpr auto _expectedShareCount = 12; + static constexpr auto _expectedRemoteShareCount = 12; private slots: void initTestCase() @@ -108,6 +114,10 @@ private slots: const auto roomBShareWithDisplayName = QStringLiteral("Room B"); _roomBDefinition = FakeShareDefinition(&helper, Share::TypeRoom, roomBShareWith, roomBShareWithDisplayName); + // Dummy internal link share, just use it to check position + _internalLinkDefinition.shareId = QStringLiteral("__internalLinkShareId__"); + _internalLinkDefinition.shareType = Share::TypeInternalLink; + _expectedOrder = {// Placeholder link shares always go first, followed by normal link shares. _linkADefinition, _linkBDefinition, @@ -121,21 +131,22 @@ private slots: _remoteADefinition, _remoteBDefinition, _roomADefinition, - _roomBDefinition}; + _roomBDefinition, + _internalLinkDefinition}; } void testSetModel() { helper.resetTestData(); addAllTestShares(); - QCOMPARE(helper.shareCount(), _expectedShareCount); + QCOMPARE(helper.shareCount(), _expectedRemoteShareCount); ShareModel model; QSignalSpy sharesChanged(&model, &ShareModel::sharesChanged); model.setAccountState(helper.accountState.data()); model.setLocalPath(helper.fakeFolder.localPath() + helper.testFileName); QVERIFY(sharesChanged.wait(5000)); - QCOMPARE(model.rowCount(), helper.shareCount()); + QCOMPARE(model.rowCount(), helper.shareCount() + 1); // Remember the internal link share! SortedShareModel sortedModel; QAbstractItemModelTester sortedModelTester(&sortedModel); @@ -153,14 +164,14 @@ private slots: { helper.resetTestData(); addAllTestShares(); - QCOMPARE(helper.shareCount(), _expectedShareCount); + QCOMPARE(helper.shareCount(), _expectedRemoteShareCount); ShareModel model; QSignalSpy sharesChanged(&model, &ShareModel::sharesChanged); model.setAccountState(helper.accountState.data()); model.setLocalPath(helper.fakeFolder.localPath() + helper.testFileName); QVERIFY(sharesChanged.wait(5000)); - QCOMPARE(model.rowCount(), helper.shareCount()); + QCOMPARE(model.rowCount(), helper.shareCount() + 1); // Remember the internal link share! SortedShareModel sortedModel; QAbstractItemModelTester sortedModelTester(&sortedModel); From 294ec8a2b67000cae37731a323b9ab8aa0de4f76 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Sat, 5 Nov 2022 13:20:13 +0100 Subject: [PATCH 3/6] Fix bad remote path in sharetestutils fakefolder, which led to failed FakePropfindReply being provided in tests Signed-off-by: Claudio Cambra --- test/sharetestutils.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/sharetestutils.cpp b/test/sharetestutils.cpp index 7f481a612dc43..249d7b1df3d71 100644 --- a/test/sharetestutils.cpp +++ b/test/sharetestutils.cpp @@ -143,7 +143,9 @@ void ShareTestHelper::setup() const auto folderMan = FolderMan::instance(); QCOMPARE(folderMan, &fm); - QVERIFY(folderMan->addFolder(accountState.data(), folderDefinition(fakeFolder.localPath()))); + auto folderDef = folderDefinition(fakeFolder.localPath()); + folderDef.targetPath = QString(); + QVERIFY(folderMan->addFolder(accountState.data(), folderDef)); const auto folder = FolderMan::instance()->folder(fakeFolder.localPath()); QVERIFY(folder); QVERIFY(fakeFolder.syncOnce()); From 4af2a8f9ded4e6465e4f09f48f1f45deade5f3d4 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Tue, 13 Dec 2022 17:34:23 +0100 Subject: [PATCH 4/6] Remove unneeded property from ShareDetailsPage Signed-off-by: Claudio Cambra --- src/gui/filedetails/ShareDetailsPage.qml | 1 - 1 file changed, 1 deletion(-) diff --git a/src/gui/filedetails/ShareDetailsPage.qml b/src/gui/filedetails/ShareDetailsPage.qml index 9c5618fece24c..b4ce6d90919bb 100644 --- a/src/gui/filedetails/ShareDetailsPage.qml +++ b/src/gui/filedetails/ShareDetailsPage.qml @@ -72,7 +72,6 @@ Page { readonly property bool passwordEnforced: shareModelData.passwordEnforced readonly property bool isLinkShare: shareModelData.shareType === ShareModel.ShareTypeLink - readonly property bool isPlaceholderLinkShare: shareModelData.shareType === ShareModel.ShareTypePlaceholderLink property bool waitingForEditingAllowedChange: false property bool waitingForNoteEnabledChange: false From bdfa923f8ad3ddc63347be33c33ad24c8d5ff34c Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Tue, 13 Dec 2022 17:34:41 +0100 Subject: [PATCH 5/6] Fix copy link button Signed-off-by: Claudio Cambra --- src/gui/filedetails/ShareDelegate.qml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/gui/filedetails/ShareDelegate.qml b/src/gui/filedetails/ShareDelegate.qml index e95cd1fa2b3d0..10ca1e6794b5f 100644 --- a/src/gui/filedetails/ShareDelegate.qml +++ b/src/gui/filedetails/ShareDelegate.qml @@ -59,6 +59,7 @@ GridLayout { readonly property string detailText: model.detailText ?? "" readonly property string iconUrl: model.iconUrl ?? "" readonly property string avatarUrl: model.avatarUrl ?? "" + readonly property string link: model.link ?? "" anchors.left: parent.left anchors.right: parent.right From b4ea35e95c1d2478d10ec4a7de840cd53011dd32 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Tue, 13 Dec 2022 17:35:40 +0100 Subject: [PATCH 6/6] Clean up data section for internal link in model Signed-off-by: Claudio Cambra --- src/gui/filedetails/sharemodel.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/gui/filedetails/sharemodel.cpp b/src/gui/filedetails/sharemodel.cpp index 9679cf5bf189c..bbd7bf24b2b0f 100644 --- a/src/gui/filedetails/sharemodel.cpp +++ b/src/gui/filedetails/sharemodel.cpp @@ -130,11 +130,8 @@ QVariant ShareModel::data(const QModelIndex &index, const int role) const return startOfExpireDayUTC.toMSecsSinceEpoch(); } } - } else if (share->getShareType() == Share::TypeInternalLink) { - switch(role) { - case LinkRole: - return _privateLinkUrl; - } + } else if (share->getShareType() == Share::TypeInternalLink && role == LinkRole) { + return _privateLinkUrl; } switch(role) {