From 406faec781bd707a130cc590e64d480072f4fa85 Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Wed, 25 Sep 2024 16:38:17 +0200 Subject: [PATCH 1/2] clarify when desktop client should offer to unlock a file a file can be unlocked when: * the lock is an user lock from the current user * the lock is a token lock from the current desktop files client Signed-off-by: Matthieu Gallien --- src/gui/socketapi/socketapi.cpp | 7 ++++--- src/libsync/account.cpp | 13 +++++++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/gui/socketapi/socketapi.cpp b/src/gui/socketapi/socketapi.cpp index effac32dfd8af..1482003761e88 100644 --- a/src/gui/socketapi/socketapi.cpp +++ b/src/gui/socketapi/socketapi.cpp @@ -1094,8 +1094,9 @@ void SocketApi::setFileLock(const QString &localFile, const SyncFileItem::LockSt } const auto record = fileData.journalRecord(); - if (static_cast(record._lockstate._lockOwnerType) != SyncFileItem::LockOwnerType::UserLock) { - qCDebug(lcSocketApi) << "Only user lock state or non-locked files can be affected manually!"; + + if (lockState == SyncFileItem::LockStatus::UnlockedItem && + !shareFolder->accountState()->account()->fileCanBeUnlocked(shareFolder->journalDb(), fileData.folderRelativePath)) { return; } @@ -1104,7 +1105,7 @@ void SocketApi::setFileLock(const QString &localFile, const SyncFileItem::LockSt shareFolder->path(), shareFolder->journalDb(), lockState, - SyncFileItem::LockOwnerType::UserLock); + (lockState == SyncFileItem::LockStatus::UnlockedItem) ? static_cast(record._lockstate._lockOwnerType) : SyncFileItem::LockOwnerType::UserLock); shareFolder->journalDb()->schedulePathForRemoteDiscovery(fileData.serverRelativePath); shareFolder->scheduleThisFolderSoon(); diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp index 9be583b49c8aa..9ff0c95bd9b6b 100644 --- a/src/libsync/account.cpp +++ b/src/libsync/account.cpp @@ -1018,11 +1018,20 @@ bool Account::fileCanBeUnlocked(SyncJournalDb * const journal, { SyncJournalFileRecord record; if (journal->getFileRecord(folderRelativePath, &record)) { - if (record._lockstate._lockOwnerType != static_cast(SyncFileItem::LockOwnerType::UserLock)) { + if (record._lockstate._lockOwnerType == static_cast(SyncFileItem::LockOwnerType::AppLock)) { + qCDebug(lcAccount()) << folderRelativePath << "cannot be unlocked: app lock"; return false; } - if (record._lockstate._lockOwnerId != sharedFromThis()->davUser()) { + if (record._lockstate._lockOwnerType == static_cast(SyncFileItem::LockOwnerType::UserLock) && + record._lockstate._lockOwnerId != sharedFromThis()->davUser()) { + qCDebug(lcAccount()) << folderRelativePath << "cannot be unlocked: user lock from" << record._lockstate._lockOwnerId; + return false; + } + + if (record._lockstate._lockOwnerType == static_cast(SyncFileItem::LockOwnerType::TokenLock) && + record._lockstate._lockToken.isEmpty()) { + qCDebug(lcAccount()) << folderRelativePath << "cannot be unlocked: token lock without known token"; return false; } From 2069c97e7158f86bcce45e92b20799eab799d6f1 Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Wed, 25 Sep 2024 17:20:59 +0200 Subject: [PATCH 2/2] lock token should be sent via webdav only for token lock type to be able to modify a locked file using token lock, we must sent it with webdav requests this must not be sent if the file is locked but the lock type is not a token lock Signed-off-by: Matthieu Gallien --- src/libsync/propagateuploadng.cpp | 3 ++- src/libsync/propagateuploadv1.cpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libsync/propagateuploadng.cpp b/src/libsync/propagateuploadng.cpp index a67225d2a2337..32e1192f3fa2f 100644 --- a/src/libsync/propagateuploadng.cpp +++ b/src/libsync/propagateuploadng.cpp @@ -328,7 +328,8 @@ void PropagateUploadFileNG::finishUpload() const auto fileSize = _fileToUpload._size; headers[QByteArrayLiteral("OC-Total-Length")] = QByteArray::number(fileSize); - if (_item->_locked == SyncFileItem::LockStatus::LockedItem) { + if (_item->_lockOwnerType == SyncFileItem::LockOwnerType::TokenLock && + _item->_locked == SyncFileItem::LockStatus::LockedItem) { headers[QByteArrayLiteral("If")] = (QLatin1String("<") + propagator()->account()->davUrl().toString() + _fileToUpload._file + "> (_lockToken.toUtf8() + ">)").toUtf8(); } diff --git a/src/libsync/propagateuploadv1.cpp b/src/libsync/propagateuploadv1.cpp index 7467b2ce31560..6bab06305b756 100644 --- a/src/libsync/propagateuploadv1.cpp +++ b/src/libsync/propagateuploadv1.cpp @@ -102,7 +102,8 @@ void PropagateUploadFileV1::startNextChunk() QString path = _fileToUpload._file; - if (_item->_locked == SyncFileItem::LockStatus::LockedItem) { + if (_item->_lockOwnerType == SyncFileItem::LockOwnerType::TokenLock && + _item->_locked == SyncFileItem::LockStatus::LockedItem) { headers[QByteArrayLiteral("If")] = (QLatin1String("<") + propagator()->account()->davUrl().toString() + _fileToUpload._file + "> (_lockToken.toUtf8() + ">)").toUtf8(); }